On Thu, Oct 21, 2021 at 7:12 AM Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote: > > On 04/10/21 22:49, Zixuan Wang wrote: > > From: Zixuan Wang <zixuanwang@xxxxxxxxxx> > > > > UEFI loads EFI applications to dynamic runtime addresses, so it requires > > all applications to be compiled as PIC (position independent code). PIC > > does not allow the usage of compile time absolute address. > > > > This commit converts multiple x86 test cases to PIC so they can compile > > and run in UEFI: > > > > - x86/cet.efi > > > > - x86/emulator.c: x86/emulator.c depends on lib/x86/usermode.c. But > > usermode.c contains non-PIC inline assembly code. This commit converts > > lib/x86/usermode.c and x86/emulator.c to PIC, so x86/emulator.c can > > compile and run in UEFI. > > > > - x86/vmware_backdoors.c: it depends on lib/x86/usermode.c and now works > > without modifications > > > > - x86/eventinj.c > > > > - x86/smap.c > > > > - x86/access.c > > > > - x86/umip.c > > > > Signed-off-by: Zixuan Wang <zixuanwang@xxxxxxxxxx> > > I have left this patch out for now, because it breaks 32-bit builds. > It's not a huge deal and can be redone on top of the rest. > > Paolo > Marc and I are working on a follow-up patch set that includes the fixes for this patch under 32-bit mode. I have also identified a potential bug in x86/umip.c and fixed it in the next patch set. The full debugging detail is described in our off-list GitHub discussion [1]. In summary, in the following line, %[sp0] can be compiled as a %r8-based offset address: x86/umip.c:127 "mov %%" R "sp, %[sp0]\n\t" /* kernel sp for exception handlers */ %r8 is then modified in the function call without saving/restoring, thus making the following line using the wrong address. x86/umip.c:148 "mov %[sp0], %%" R "sp\n\t" This register is selected by the compiler, it's not guaranteed to be %r8 so we cannot just push/pop %r8 before/after the function call. A simple fix is to save the %rsp to %rbx (in addition to saving it to %[sp0]). %rbx is a callee-saved register, so its value is not modified. We already have this fix in the patch set draft [1] and will post it once ready. [1] https://github.com/marc-orr/KVM-Unit-Tests-dev-fork/pull/9 Best regards, Zixuan