From: Sean Christopherson <seanjc@google.com>
To: Michal Luczaj <mhal@rbox.co>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, shuah@kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH v2] x86: Test illegal LEA handling
Date: Mon, 1 Aug 2022 16:44:18 +0000 [thread overview]
Message-ID: <YugC4rUvdbroNk3M@google.com> (raw)
In-Reply-To: <20220731204653.2516-1-mhal@rbox.co>
On Sun, Jul 31, 2022, Michal Luczaj wrote:
> Check if the emulator throws #UD on illegal LEA.
Please explicitly state exactly what illegal LEA is being generated. Requiring
readers to connect the dots of the LEA opcode and ModR/M encoding is unnecessarily
mean :-)
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
> v1 -> v2: Instead of racing decoder make use of force_emulation_prefix
>
> x86/emulator.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/x86/emulator.c b/x86/emulator.c
> index cd78e3c..c3898f2 100644
> --- a/x86/emulator.c
> +++ b/x86/emulator.c
> @@ -895,6 +895,24 @@ static void test_mov_dr(uint64_t *mem)
> report(rax == DR6_ACTIVE_LOW, "mov_dr6");
> }
>
> +static void illegal_lea_handler(struct ex_regs *regs)
> +{
> + extern char illegal_lea_cont;
> +
> + ++exceptions;
> + regs->rip = (ulong)&illegal_lea_cont;
> +}
> +
> +static void test_illegal_lea(uint64_t *mem)
@mem isn't needed.
> +{
> + exceptions = 0;
> + handle_exception(UD_VECTOR, illegal_lea_handler);
No need to use a custom handler (ignore any patterns in emulator.c that suggest
it's "mandatory", emulator is one of the oldest test). ASM_TRY() can handle all
of this without any globals.
> + asm(KVM_FEP ".byte 0x48; .byte 0x8d; .byte 0xc0\n\t"
> + "illegal_lea_cont:" : : : "rax");
"emulator" is compatible with 32-bit KUT, drop the REX prefix and clobber "eax"
instead of "xax".
> + report(exceptions == 1, "illegal lea");
Be nice to future debuggers. Call out what is illegal about LEA, capitalize LEA
to make it more obvious that its an instruction, and print the expected versus
actual.
> + handle_exception(UD_VECTOR, 0);
> +}
So this?
static void test_illegal_lea(void)
{
unsigned int vector;
asm volatile (ASM_TRY("1f")
KVM_FEP ".byte 0x8d; .byte 0xc0\n\t"
"1:"
: : : "memory", "eax");
vector = exception_vector();
report(vector == UD_VECTOR,
"Wanted #UD on LEA with /reg, got vector = %d", vector);
}
> +
> static void test_push16(uint64_t *mem)
> {
> uint64_t rsp1, rsp2;
> @@ -1193,6 +1211,7 @@ int main(void)
> test_smsw_reg(mem);
> test_nop(mem);
> test_mov_dr(mem);
> + test_illegal_lea(mem);
> } else {
> report_skip("skipping register-only tests, "
> "use kvm.force_emulation_prefix=1 to enable");
> --
> 2.32.0
>
next prev parent reply other threads:[~2022-08-01 16:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 13:48 [PATCH 1/2] KVM: x86: emulator: Fix illegal LEA handling Michal Luczaj
2022-07-29 13:48 ` [PATCH 2/2] KVM: selftests: x86: Test " Michal Luczaj
2022-07-29 16:53 ` Sean Christopherson
2022-07-31 20:43 ` Michal Luczaj
2022-07-31 20:46 ` [kvm-unit-tests PATCH v2] " Michal Luczaj
2022-08-01 16:44 ` Sean Christopherson [this message]
2022-08-02 23:07 ` Michal Luczaj
2022-08-02 23:41 ` Sean Christopherson
2022-08-03 17:21 ` Michal Luczaj
2022-08-03 17:25 ` [kvm-unit-tests PATCH 1/4] x86: emulator.c cleanup: Save and restore exception handlers Michal Luczaj
2022-08-03 17:25 ` [kvm-unit-tests PATCH 2/4] x86: emulator.c cleanup: Use ASM_TRY for the UD_VECTOR cases Michal Luczaj
2022-08-03 18:21 ` Sean Christopherson
2022-08-05 11:42 ` Paolo Bonzini
2022-08-05 18:55 ` Michal Luczaj
2022-08-05 19:59 ` Sean Christopherson
2022-08-06 2:00 ` Nadav Amit
2022-08-06 11:08 ` Michal Luczaj
2022-08-03 17:25 ` [kvm-unit-tests PATCH 3/4] x86: Test emulator's handling of LEA with /reg Michal Luczaj
2022-08-03 17:25 ` [kvm-unit-tests PATCH 4/4] x86: Extend ASM_TRY to handle #UD thrown by FEP-triggered emulator Michal Luczaj
2022-08-03 18:16 ` Sean Christopherson
2022-08-05 11:50 ` Paolo Bonzini
2022-07-29 16:41 ` [PATCH 1/2] KVM: x86: emulator: Fix illegal LEA handling Sean Christopherson
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=YugC4rUvdbroNk3M@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.