Re: [RFC KVM 19/27] kvm/isolation: initialize the KVM page table with core mappings

From: Alexandre Chartre
Date: Tue May 14 2019 - 06:31:09 EST

On 5/13/19 6:47 PM, Alexandre Chartre wrote:

On 5/13/19 5:50 PM, Dave Hansen wrote:
+ÂÂÂ /*
+ÂÂÂÂ * Copy the mapping for all the kernel text. We copy at the PMD
+ÂÂÂÂ * level since the PUD is shared with the module mapping space.
+ÂÂÂÂ */
+ÂÂÂ rv = kvm_copy_mapping((void *)__START_KERNEL_map, KERNEL_IMAGE_SIZE,
+ÂÂÂ if (rv)
+ÂÂÂÂÂÂÂ goto out_uninit_page_table;

Could you double-check this? We (I) have had some repeated confusion
with the PTI code and kernel text vs. kernel data vs. __init.
KERNEL_IMAGE_SIZE looks to be 512MB which is quite a bit bigger than
kernel text.

I probably have the same confusion :-) but I will try to check again.

mm.txt says that kernel text is 512MB, and that's probably why I used

Start addr | Offset | End addr | Size | VM area description
ffffffff80000000 | -2 GB | ffffffff9fffffff | 512 MB | kernel text mapping, mapped to physical address 0

However, does:

. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
"kernel image bigger than KERNEL_IMAGE_SIZE");

So this covers everything between _text and _end, which includes text, data,
init and other stuff

The end of the text section is tagged with _etext. So the text section is
effectively (_etext - _text). This matches with what efi_setup_page_tables()
used to copy kernel text:

int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
npages = (_etext - _text) >> PAGE_SHIFT;
text = __pa(_text);
pfn = text >> PAGE_SHIFT;

pf = _PAGE_RW | _PAGE_ENC;
if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) {
pr_err("Failed to map kernel text 1:1\n");
return 1;