Re: efi boot failures due to PTI with 32 bit builds and Intel CPUs

From: Joerg Roedel
Date: Thu Aug 30 2018 - 14:08:59 EST

On Thu, Aug 30, 2018 at 05:20:22AM -0700, Guenter Roeck wrote:
> Excellent.
> In case it matters: I can use the same 32-bit efi image to boot a 64-bit kernel
> without problems.

Okay, I tracked it down. The 32-bit EFI code switches the CPU to the
read-write version of the GDT which is not mapped in the user
page-table. This obviously faults when the kernel entry/exit code
restores the segment registers.

Without a mapped GDT the #PF and #DF handlers also can't be started, so
the machine triple-faults. Below diff fixes it for me, I'll send a
proper patch tomorrow.

diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
index 324b93328b37..892edb4664fb 100644
--- a/arch/x86/platform/efi/efi_32.c
+++ b/arch/x86/platform/efi/efi_32.c
@@ -87,7 +87,7 @@ void __init efi_call_phys_epilog(pgd_t *save_pgd)
struct desc_ptr gdt_descr;

- gdt_descr.address = (unsigned long)get_cpu_gdt_rw(0);
+ gdt_descr.address = (unsigned long)get_cpu_gdt_ro(0);
gdt_descr.size = GDT_SIZE - 1;