Re: [PATCH 4/6] x86/efi: Hoist page table switching code into efi_call_virt()

From: Borislav Petkov
Date: Fri Nov 13 2015 - 03:00:23 EST

On Thu, Nov 12, 2015 at 08:01:08PM +0000, Matt Fleming wrote:
> > That PUSHF implicitly pushes on the stack pointed by %rsp. But(!) we
> > have switched the pagetable (i.e., %cr3 has efi_scratch.efi_pgt) and
> > we're pushing to the VA where the stack *was* but is not anymore.
> All the kernel mappings will still exist in the page table we switch
> to, so pushing to the stack should be fine.
> The mappings have to exist so that the firmware can dereference
> pointer arguments, e.g. when writing variable data to a kernel buffer.
> Or have I misunderstood your point?
> > Or maybe it is because you're copying all the PUDs. It is still not 100%
> > clean, IMHO.

I think we're on the same page - you're copying the PUDs in
efi_sync_low_kernel_mappings() so the stack should be there.

> > Can you do the prolog/epilog calls inside the IRQs-off section?
> Not really because in the efi_enabled(EFI_OLD_MEMMAP) case we perform
> kmalloc(), see commit 23a0d4e8fa6d ("efi: Disable interrupts around
> EFI calls, not in the epilog/prolog calls").

n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
save_pgd = kmalloc(n_pgds * sizeof(pgd_t), GFP_KERNEL);


That n_pgds thing is of static size so you can pre-alloc it maybe even
once during boot and reuse it all the time when EFI_OLD_MEMMAP is


ECO tip #101: Trim your mails when you reply.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at