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 3/5] x86: Introduce ASM_TRY_FEP() to handle exceptions thrown by FEP-triggered emulator
Date: Sun, 7 Aug 2022 16:28:30 +0200 [thread overview]
Message-ID: <20220807142832.1576-4-mhal@rbox.co> (raw)
In-Reply-To: <20220807142832.1576-1-mhal@rbox.co>
From: Paolo Bonzini <pbonzini@redhat.com>
TRY_ASM() mishandles exceptions thrown by the forced-emulation-triggered
emulator. While the faulting address stored in the exception table points
at forced emulation prefix, when an exceptions comes, RIP is 5 bytes
(size of KVM_FEP) ahead and the exception ends up unhandled.
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
For the sake of completeness, I've added `prefix` to 32-bit __TRY_ASM()
as well.
lib/x86/desc.h | 8 ++++++--
x86/emulator.c | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index 2a285eb..8854fcc 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -81,21 +81,25 @@ typedef struct __attribute__((packed)) {
} tss64_t;
#ifdef __x86_64
-#define ASM_TRY(catch) \
+#define __ASM_TRY(prefix, catch) \
"movl $0, %%gs:4 \n\t" \
".pushsection .data.ex \n\t" \
".quad 1111f, " catch "\n\t" \
".popsection \n\t" \
+ prefix \
"1111:"
#else
-#define ASM_TRY(catch) \
+#define __ASM_TRY(prefix, catch) \
"movl $0, %%gs:4 \n\t" \
".pushsection .data.ex \n\t" \
".long 1111f, " catch "\n\t" \
".popsection \n\t" \
+ prefix \
"1111:"
#endif
+#define ASM_TRY(catch) __ASM_TRY("", catch)
+
/*
* selector 32-bit 64-bit
* 0x00 NULL descriptor NULL descriptor
diff --git a/x86/emulator.c b/x86/emulator.c
index 96d3ccd..0eb7c1a 100644
--- a/x86/emulator.c
+++ b/x86/emulator.c
@@ -19,6 +19,7 @@ static int exceptions;
/* Forced emulation prefix, used to invoke the emulator unconditionally. */
#define KVM_FEP "ud2; .byte 'k', 'v', 'm';"
+#define ASM_TRY_FEP(catch) __ASM_TRY(KVM_FEP, catch)
struct regs {
u64 rax, rbx, rcx, rdx;
--
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 ` [kvm-unit-tests PATCH v2 2/5] x86: emulator.c cleanup: Use ASM_TRY() for the UD_VECTOR cases Michal Luczaj
2022-08-07 14:28 ` Michal Luczaj [this message]
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-4-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