Hello all,
kernel/src/plat/pc99/machine/intel-vtd.c::vtd_get_n_paging() confused me a lot. Wish to get any help.
This func intends to calculate paging pages needed for all RMRRs. The following code 'filter the identical regions by pci bus id', and use them to figure out the final result. ``` for (word_t i = 1; i < rmrr_list->num; i++) { if (vtd_get_root_index(rmrr_list->entries[i].device) != vtd_get_root_index(filtered.entries[filtered.num - 1].device) && rmrr_list->entries[i].base != filtered.entries[filtered.num - 1].base && rmrr_list->entries[i].limit != filtered.entries[filtered.num - 1].limit) { filtered.entries[filtered.num] = rmrr_list->entries[i]; filtered.num++; } } ``` But vtd_map_reserved_page() says, every different devices(with diff bus-dev- func ID) have their own paging structures. Then why do filter here like this , yet the logic looks so confusing.
And on line 313, it counts pages according to the specified level address bits. ``` size += get_n_paging(region, 32 - (VTD_PT_INDEX_BITS * i + seL4_PageBits)); ``` So what does 32 mean? Maybe a typo?
Thanks, laokz
Hi laokz, `vtd_get_n_paging()` tries to pre-calculate how many page tables will be needed to set up the initial VTD mappings. The value that it returns gets used to preallocate the memory required and then later on in the boot process the page tables are allocated using `it_alloc_paging`. Part of the logic in vtd_get_n_paging appears to try and calculate how many page tables are required for creating the reserved memory mapping regions. As you identify, the logic doesn't seem to be correct in several places. Currently, the final result is that it overcalculates the amount of page tables required by quite a lot, so the consequence for the overall system is some memory gets leaked during boot due to the overallocation. I'm working on a patch and I'll notify you when it's up on GitHub. Thanks for tracking this down! Kent