From: Sean Christopherson <seanjc@google.com>
To: Maxim Levitsky <mlevitsk@redhat.com>
Cc: kvm@vger.kernel.org, Cathy Avery <cavery@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [kvm-unit-tests PATCH 07/16] x86: Add a simple test for SYSENTER instruction.
Date: Thu, 20 Oct 2022 19:25:53 +0000 [thread overview]
Message-ID: <Y1GgwQDrfg9wd4ej@google.com> (raw)
In-Reply-To: <20221020152404.283980-8-mlevitsk@redhat.com>
On Thu, Oct 20, 2022, Maxim Levitsky wrote:
> Run the test with Intel's vendor ID and in the long mode,
> to test the emulation of this instruction on AMD.
>
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> x86/Makefile.x86_64 | 2 +
> x86/sysenter.c | 127 ++++++++++++++++++++++++++++++++++++++++++++
> x86/unittests.cfg | 5 ++
> 3 files changed, 134 insertions(+)
> create mode 100644 x86/sysenter.c
>
> diff --git a/x86/Makefile.x86_64 b/x86/Makefile.x86_64
> index 865da07d..8ce53650 100644
> --- a/x86/Makefile.x86_64
> +++ b/x86/Makefile.x86_64
> @@ -33,6 +33,7 @@ tests += $(TEST_DIR)/vmware_backdoors.$(exe)
> tests += $(TEST_DIR)/rdpru.$(exe)
> tests += $(TEST_DIR)/pks.$(exe)
> tests += $(TEST_DIR)/pmu_lbr.$(exe)
> +tests += $(TEST_DIR)/sysenter.$(exe)
>
>
> ifeq ($(CONFIG_EFI),y)
> @@ -60,3 +61,4 @@ $(TEST_DIR)/hyperv_clock.$(bin): $(TEST_DIR)/hyperv_clock.o
> $(TEST_DIR)/vmx.$(bin): $(TEST_DIR)/vmx_tests.o
> $(TEST_DIR)/svm.$(bin): $(TEST_DIR)/svm_tests.o
> $(TEST_DIR)/svm_npt.$(bin): $(TEST_DIR)/svm_npt.o
> +$(TEST_DIR)/sysenter.o: CFLAGS += -Wa,-mintel64
> diff --git a/x86/sysenter.c b/x86/sysenter.c
> new file mode 100644
> index 00000000..6c32fea4
> --- /dev/null
> +++ b/x86/sysenter.c
> @@ -0,0 +1,127 @@
> +#include "alloc.h"
> +#include "libcflat.h"
> +#include "processor.h"
> +#include "msr.h"
> +#include "desc.h"
> +
> +
> +// undefine this to run the syscall instruction in 64 bit mode.
> +// this won't work on AMD due to disabled code in the emulator.
> +#define COMP32
Why not run the test in both 32-bit and 64-bit mode, and skip the 64-bit mode
version if the vCPU model is AMD?
> +
> +int main(int ac, char **av)
> +{
> + extern void sysenter_target(void);
> + extern void test_done(void);
Tabs instead of spaces.
> +
> + setup_vm();
> +
> + int gdt_index = 0x50 >> 3;
> + ulong rax = 0xDEAD;
> +
> + /* init the sysenter GDT block */
> + /*gdt64[gdt_index+0] = gdt64[KERNEL_CS >> 3];
> + gdt64[gdt_index+1] = gdt64[KERNEL_DS >> 3];
> + gdt64[gdt_index+2] = gdt64[USER_CS >> 3];
> + gdt64[gdt_index+3] = gdt64[USER_DS >> 3];*/
> +
> + /* init the sysenter msrs*/
> + wrmsr(MSR_IA32_SYSENTER_CS, gdt_index << 3);
> + wrmsr(MSR_IA32_SYSENTER_ESP, 0xAAFFFFFFFF);
> + wrmsr(MSR_IA32_SYSENTER_EIP, (uint64_t)sysenter_target);
> +
> + u8 *thunk = (u8*)malloc(50);
> + u8 *tmp = thunk;
> +
> + printf("Thunk at 0x%lx\n", (u64)thunk);
> +
> + /* movabs test_done, %rdx*/
> + *tmp++ = 0x48; *tmp++ = 0xBA;
> + *(u64 *)tmp = (uint64_t)test_done; tmp += 8;
> + /* jmp %%rdx*/
> + *tmp++ = 0xFF; *tmp++ = 0xe2;
> +
> + asm volatile (
Can we add a helper sysenter_asm.S or whatever instead of making this a gigantic
inline asm blob? And then have separate routines for 32-bit vs. 64-bit? That'd
require a bit of code duplication, but macros could be used to dedup the common
parts if necessary.
And with a .S file, I believe there's no need to dynamically generate the thunk,
e.g. pass the jump target through a GPR that's not modified/used by SYSENTER.
> +#ifdef COMP32
> + "# switch to comp32, mode prior to running the test\n"
> + "ljmpl *1f\n"
> + "1:\n"
> + ".long 1f\n"
> + ".long " xstr(KERNEL_CS32) "\n"
> + "1:\n"
> + ".code32\n"
> +#else
> + "# store the 64 bit thunk address to rdx\n"
> + "mov %[thunk], %%rdx\n"
> +#endif
next prev parent reply other threads:[~2022-10-20 19:26 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 15:23 [kvm-unit-tests PATCH 00/16] kvm-unit-tests: set of fixes and new tests Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 01/16] x86: make irq_enable avoid the interrupt shadow Maxim Levitsky
2022-10-20 18:01 ` Sean Christopherson
2022-10-24 12:36 ` Maxim Levitsky
2022-10-24 22:49 ` Sean Christopherson
2022-10-27 10:16 ` Maxim Levitsky
2022-10-27 15:50 ` Sean Christopherson
2022-10-27 17:10 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 02/16] x86: add few helper functions for apic local timer Maxim Levitsky
2022-10-20 19:14 ` Sean Christopherson
2022-10-24 12:37 ` Maxim Levitsky
2022-10-24 16:10 ` Sean Christopherson
2022-10-27 10:19 ` Maxim Levitsky
2022-10-27 15:54 ` Sean Christopherson
2022-10-27 17:11 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 03/16] svm: use irq_enable instead of sti/nop Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 04/16] svm: make svm_intr_intercept_mix_if/gif test a bit more robust Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 05/16] svm: use apic_start_timer/apic_stop_timer instead of open coding it Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 06/16] x86: Add test for #SMI during interrupt window Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 07/16] x86: Add a simple test for SYSENTER instruction Maxim Levitsky
2022-10-20 19:25 ` Sean Christopherson [this message]
2022-10-24 12:38 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 08/16] svm: add nested shutdown test Maxim Levitsky
2022-10-20 15:26 ` Maxim Levitsky
2022-10-20 19:06 ` Sean Christopherson
2022-10-24 12:39 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 09/16] svm: move svm spec definitions to lib/x86/svm.h Maxim Levitsky
2022-10-20 19:08 ` Sean Christopherson
2022-10-20 15:23 ` [kvm-unit-tests PATCH 10/16] svm: move some svm support functions into lib/x86/svm_lib.h Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 11/16] svm: add svm_suported Maxim Levitsky
2022-10-20 18:21 ` Sean Christopherson
2022-10-24 12:40 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 12/16] svm: move setup_svm to svm_lib.c Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 13/16] svm: move vmcb_ident " Maxim Levitsky
2022-10-20 18:37 ` Sean Christopherson
2022-10-24 12:46 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 14/16] svm: rewerite vm entry macros Maxim Levitsky
2022-10-20 18:55 ` Sean Christopherson
2022-10-24 12:45 ` Maxim Levitsky
2022-10-24 19:56 ` Sean Christopherson
2022-10-27 12:07 ` Maxim Levitsky
2022-10-27 19:39 ` Sean Christopherson
2022-10-20 15:24 ` [kvm-unit-tests PATCH 15/16] svm: introduce svm_vcpu Maxim Levitsky
2022-10-20 19:02 ` Sean Christopherson
2022-10-24 12:46 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 16/16] add IPI loss stress test Maxim Levitsky
2022-10-20 20:23 ` Sean Christopherson
2022-10-24 12:54 ` Maxim Levitsky
2022-10-24 17:19 ` Sean Christopherson
2022-10-27 11:00 ` Maxim Levitsky
2022-10-27 18:41 ` 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=Y1GgwQDrfg9wd4ej@google.com \
--to=seanjc@google.com \
--cc=cavery@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
/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