From: Michal Luczaj <mhal@rbox.co>
To: seanjc@google.com
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org,
linux-kselftest@vger.kernel.org, mhal@rbox.co
Subject: [kvm-unit-tests PATCH v2 2/5] x86: emulator.c cleanup: Use ASM_TRY() for the UD_VECTOR cases
Date: Sun, 7 Aug 2022 16:28:29 +0200 [thread overview]
Message-ID: <20220807142832.1576-3-mhal@rbox.co> (raw)
In-Reply-To: <20220807142832.1576-1-mhal@rbox.co>
For #UD handling use ASM_TRY() instead of handle_exception().
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
v1 -> v2: Change `mov` to `movl` to silence the compiler warning
x86/emulator.c | 42 ++++++++++++++++--------------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/x86/emulator.c b/x86/emulator.c
index 769a049..96d3ccd 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -17,10 +17,8 @@
static int exceptions;
-/* Forced emulation prefix, used to invoke the emulator unconditionally. */
+/* Forced emulation prefix, used to invoke the emulator unconditionally. */
#define KVM_FEP "ud2; .byte 'k', 'v', 'm';"
-#define KVM_FEP_LENGTH 5
-static int fep_available = 1;
struct regs {
u64 rax, rbx, rcx, rdx;
@@ -1099,33 +1097,23 @@ static void test_simplealu(u32 *mem)
report(*mem == 0x8400, "test");
}
-static void illegal_movbe_handler(struct ex_regs *regs)
-{
- extern char bad_movbe_cont;
-
- ++exceptions;
- regs->rip = (ulong)&bad_movbe_cont;
-}
-
static void test_illegal_movbe(void)
{
+ unsigned int vector;
+
if (!this_cpu_has(X86_FEATURE_MOVBE)) {
- report_skip("illegal movbe");
+ report_skip("MOVBE unsupported by CPU");
return;
}
- exceptions = 0;
- handle_exception(UD_VECTOR, illegal_movbe_handler);
- asm volatile(".byte 0x0f; .byte 0x38; .byte 0xf0; .byte 0xc0;\n\t"
- " bad_movbe_cont:" : : : "rax");
- report(exceptions == 1, "illegal movbe");
- handle_exception(UD_VECTOR, 0);
-}
+ asm volatile(ASM_TRY("1f")
+ ".byte 0x0f; .byte 0x38; .byte 0xf0; .byte 0xc0;\n\t"
+ "1:"
+ : : : "memory", "rax");
-static void record_no_fep(struct ex_regs *regs)
-{
- fep_available = 0;
- regs->rip += KVM_FEP_LENGTH;
+ vector = exception_vector();
+ report(vector == UD_VECTOR,
+ "Wanted #UD on MOVBE with /reg, got vector = %u", vector);
}
int main(void)
@@ -1135,11 +1123,13 @@ int main(void)
void *insn_ram;
void *cross_mem;
unsigned long t1, t2;
+ int fep_available = 0;
setup_vm();
- handle_exception(UD_VECTOR, record_no_fep);
- asm(KVM_FEP "nop");
- handle_exception(UD_VECTOR, 0);
+ asm volatile(ASM_TRY("1f")
+ KVM_FEP "movl $1, %[fep_available]\n\t"
+ "1:"
+ : [fep_available] "=m" (fep_available) : : "memory");
mem = alloc_vpages(2);
install_page((void *)read_cr3(), IORAM_BASE_PHYS, mem);
--
2.37.1
next prev parent reply other threads:[~2022-08-07 14:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-07 14:28 [kvm-unit-tests PATCH v2 0/5] Test for illegal LEA & related fixes Michal Luczaj
2022-08-07 14:28 ` [kvm-unit-tests PATCH v2 1/5] x86: emulator.c cleanup: Save and restore exception handlers Michal Luczaj
2022-08-08 15:27 ` Sean Christopherson
2022-08-07 14:28 ` Michal Luczaj [this message]
2022-08-07 14:28 ` [kvm-unit-tests PATCH v2 3/5] x86: Introduce ASM_TRY_FEP() to handle exceptions thrown by FEP-triggered emulator Michal Luczaj
2022-08-07 14:28 ` [kvm-unit-tests PATCH v2 4/5] x86: Dedup 32-bit vs. 64-bit ASM_TRY() by stealing kernel's __ASM_SEL() Michal Luczaj
2022-08-08 16:32 ` Sean Christopherson
2022-08-07 14:28 ` [kvm-unit-tests PATCH v2 5/5] x86: Test emulator's handling of LEA with /reg Michal Luczaj
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220807142832.1576-3-mhal@rbox.co \
--to=mhal@rbox.co \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox