Re: [kvm-unit-tests PATCH v3 3/4] x86/access: Forced emulation support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03.04.23 12:56, Mathias Krause wrote:
> Add support to enforce access tests to be handled by the emulator, if
> supported by KVM. Exclude it from the ac_test_exec() test, though, to
> not slow it down too much.

I tend to read a lot of objdumps and when initially looking at the
generated code it was kinda hard to recognize the FEP instruction, as
the FEP actually decodes to UD2 followed by some IMUL instruction that
lacks a byte, so when objdump does its linear disassembly, it eats a
byte from the to-be-emulated instruction. Like, "FEP; int $0xc3" would
decode to:
   0:	0f 0b                	ud2
   2:	6b 76 6d cd          	imul   $0xffffffcd,0x6d(%rsi),%esi
   6:	c3                   	retq
This is slightly confusing, especially when the shortened instruction is
actually a valid one as above ("retq" vs "int $0xc3").

I have the below diff to "fix" that. It adds 0x3e to the FEP which would
restore objdump's ability to generate a proper disassembly that won't
destroy the to-be-emulated instruction. As 0x3e decodes to the DS prefix
byte, which the emulator assumes by default anyways, this should mostly
be a no-op. However, it helped me to get a proper code dump.

If there's interest, I can send a proper patch. If not, this might help
others to understand garbled objdumps involving the FEP ;)

--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -104,6 +104,7 @@ typedef struct  __attribute__((packed)) {

 /* Forced emulation prefix, used to invoke the emulator unconditionally. */
 #define KVM_FEP "ud2; .byte 'k', 'v', 'm';"
+#define KVM_FEP_PRETTY KVM_FEP ".byte 0x3e;"
 #define ASM_TRY_FEP(catch) __ASM_TRY(KVM_FEP, catch)

 static inline bool is_fep_available(void)
diff --git a/x86/access.c b/x86/access.c
index eab3959bc871..ab1913313fbb 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -811,7 +811,7 @@ static int ac_test_do_access(ac_test_t *at)
                asm volatile ("mov $fixed2, %%rsi \n\t"
                              "cmp $0, %[fep] \n\t"
                              "jz 1f \n\t"
-                             KVM_FEP
+                             KVM_FEP_PRETTY
                              "1: mov (%[addr]), %[reg] \n\t"
                              "fixed2:"
                              : [reg]"=r"(r), [fault]"=a"(fault), "=b"(e)
@@ -838,12 +838,12 @@ static int ac_test_do_access(ac_test_t *at)
                      "jnz 1f \n\t"
                      "cmp $0, %[fep] \n\t"
                      "jz 0f \n\t"
-                     KVM_FEP
+                     KVM_FEP_PRETTY
                      "0: mov (%[addr]), %[reg] \n\t"
                      "jmp done \n\t"
                      "1: cmp $0, %[fep] \n\t"
                      "jz 0f \n\t"
-                     KVM_FEP
+                     KVM_FEP_PRETTY
                      "0: mov %[reg], (%[addr]) \n\t"
                      "jmp done \n\t"
                      "2: call *%[addr] \n\t"


Thanks,
Mathias



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux