From: Vishal Annapurve <vannapurve@google.com>
To: x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: pbonzini@redhat.com, shuah@kernel.org, bgardon@google.com,
seanjc@google.com, oupton@google.com, peterx@redhat.com,
vkuznets@redhat.com, dmatlack@google.com,
Vishal Annapurve <vannapurve@google.com>
Subject: [V2 PATCH 8/8] KVM: selftests: x86: xen: Execute cpu specific vmcall instruction
Date: Thu, 15 Sep 2022 00:04:48 +0000 [thread overview]
Message-ID: <20220915000448.1674802-9-vannapurve@google.com> (raw)
In-Reply-To: <20220915000448.1674802-1-vannapurve@google.com>
Update xen specific hypercall invocation to execute cpu specific vmcall
instructions.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
.../selftests/kvm/x86_64/xen_shinfo_test.c | 64 +++++++------------
.../selftests/kvm/x86_64/xen_vmcall_test.c | 14 ++--
2 files changed, 34 insertions(+), 44 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
index 8a5cb800f50e..92ed07f1c772 100644
--- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
+++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
@@ -145,6 +145,23 @@ static void guest_wait_for_irq(void)
guest_saw_irq = false;
}
+static unsigned long vmcall_helper(unsigned long reg_a, unsigned long reg_di,
+ unsigned long reg_si)
+{
+ unsigned long ret;
+
+ if (is_amd_cpu())
+ __asm__ __volatile__ ("vmmcall" :
+ "=a" (ret) :
+ "a" (reg_a), "D" (reg_di), "S" (reg_si));
+ else
+ __asm__ __volatile__ ("vmcall" :
+ "=a" (ret) :
+ "a" (reg_a), "D" (reg_di), "S" (reg_si));
+
+ return ret;
+}
+
static void guest_code(void)
{
struct vcpu_runstate_info *rs = (void *)RUNSTATE_VADDR;
@@ -217,12 +234,7 @@ static void guest_code(void)
* EVTCHNOP_send hypercall. */
unsigned long rax;
struct evtchn_send s = { .port = 127 };
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_event_channel_op),
- "D" (EVTCHNOP_send),
- "S" (&s));
-
+ rax = vmcall_helper(__HYPERVISOR_event_channel_op, EVTCHNOP_send, (unsigned long)&s);
GUEST_ASSERT(rax == 0);
guest_wait_for_irq();
@@ -232,12 +244,7 @@ static void guest_code(void)
/* Deliver "outbound" event channel to an eventfd which
* happens to be one of our own irqfds. */
s.port = 197;
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_event_channel_op),
- "D" (EVTCHNOP_send),
- "S" (&s));
-
+ rax = vmcall_helper(__HYPERVISOR_event_channel_op, EVTCHNOP_send, (unsigned long)&s);
GUEST_ASSERT(rax == 0);
guest_wait_for_irq();
@@ -245,10 +252,7 @@ static void guest_code(void)
GUEST_SYNC(13);
/* Set a timer 100ms in the future. */
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_set_timer_op),
- "D" (rs->state_entry_time + 100000000));
+ rax = vmcall_helper(__HYPERVISOR_set_timer_op, (rs->state_entry_time + 100000000), 0);
GUEST_ASSERT(rax == 0);
GUEST_SYNC(14);
@@ -271,36 +275,21 @@ static void guest_code(void)
.timeout = 0,
};
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_sched_op),
- "D" (SCHEDOP_poll),
- "S" (&p));
-
+ rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p);
GUEST_ASSERT(rax == 0);
GUEST_SYNC(17);
/* Poll for an unset port and wait for the timeout. */
p.timeout = 100000000;
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_sched_op),
- "D" (SCHEDOP_poll),
- "S" (&p));
-
+ rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p);
GUEST_ASSERT(rax == 0);
GUEST_SYNC(18);
/* A timer will wake the masked port we're waiting on, while we poll */
p.timeout = 0;
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_sched_op),
- "D" (SCHEDOP_poll),
- "S" (&p));
-
+ rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p);
GUEST_ASSERT(rax == 0);
GUEST_SYNC(19);
@@ -309,12 +298,7 @@ static void guest_code(void)
* actual interrupt, while we're polling on a different port. */
ports[0]++;
p.timeout = 0;
- __asm__ __volatile__ ("vmcall" :
- "=a" (rax) :
- "a" (__HYPERVISOR_sched_op),
- "D" (SCHEDOP_poll),
- "S" (&p));
-
+ rax = vmcall_helper(__HYPERVISOR_sched_op, SCHEDOP_poll, (unsigned long)&p);
GUEST_ASSERT(rax == 0);
guest_wait_for_irq();
diff --git a/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c b/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c
index 88914d48c65e..e78f1b5d3af8 100644
--- a/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c
+++ b/tools/testing/selftests/kvm/x86_64/xen_vmcall_test.c
@@ -37,10 +37,16 @@ static void guest_code(void)
register unsigned long r9 __asm__("r9") = ARGVALUE(6);
/* First a direct invocation of 'vmcall' */
- __asm__ __volatile__("vmcall" :
- "=a"(rax) :
- "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx),
- "r"(r10), "r"(r8), "r"(r9));
+ if (is_amd_cpu())
+ __asm__ __volatile__("vmmcall" :
+ "=a"(rax) :
+ "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx),
+ "r"(r10), "r"(r8), "r"(r9));
+ else
+ __asm__ __volatile__("vmcall" :
+ "=a"(rax) :
+ "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx),
+ "r"(r10), "r"(r8), "r"(r9));
GUEST_ASSERT(rax == RETVALUE);
/* Fill in the Xen hypercall page */
--
2.37.2.789.g6183377224-goog
next prev parent reply other threads:[~2022-09-15 0:05 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 0:04 [V2 PATCH 0/8] Execute hypercalls from guests according to cpu type Vishal Annapurve
2022-09-15 0:04 ` [V2 PATCH 1/8] KVM: selftests: move common startup logic to kvm_util.c Vishal Annapurve
2022-09-15 9:45 ` Andrew Jones
2022-09-15 0:04 ` [V2 PATCH 2/8] KVM: selftests: Add arch specific initialization Vishal Annapurve
2022-09-15 9:44 ` Andrew Jones
2022-09-26 23:18 ` Vishal Annapurve
2022-09-21 20:50 ` David Matlack
2022-09-26 23:18 ` Vishal Annapurve
2022-09-15 0:04 ` [V2 PATCH 3/8] KVM: selftests: Add arch specific post vm load setup Vishal Annapurve
2022-09-21 20:54 ` David Matlack
2022-09-26 23:18 ` Vishal Annapurve
2022-10-03 15:42 ` Sean Christopherson
2022-10-04 0:02 ` Vishal Annapurve
2022-10-04 20:10 ` Sean Christopherson
2022-10-13 11:36 ` Vishal Annapurve
2022-09-15 0:04 ` [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu() Vishal Annapurve
2022-09-21 21:19 ` David Matlack
2022-09-26 23:27 ` Vishal Annapurve
2022-09-26 23:34 ` David Matlack
2022-09-26 23:40 ` Vishal Annapurve
2022-09-21 21:39 ` David Matlack
2022-09-26 23:48 ` Vishal Annapurve
2022-09-26 23:53 ` David Matlack
2022-09-15 0:04 ` [V2 PATCH 5/8] KVM: selftests: x86: delete svm_vmcall_test Vishal Annapurve
2022-09-21 21:34 ` David Matlack
2022-09-26 23:32 ` Vishal Annapurve
2022-09-15 0:04 ` [V2 PATCH 6/8] KVM: selftests: x86: Execute cpu specific hypercall from nested guests Vishal Annapurve
2022-09-15 0:04 ` [V2 PATCH 7/8] Kvm: selftests: x86: Execute cpu specific vmcall instruction Vishal Annapurve
2022-09-21 21:43 ` David Matlack
2022-09-26 23:35 ` Vishal Annapurve
2022-09-15 0:04 ` Vishal Annapurve [this message]
2022-09-21 21:47 ` [V2 PATCH 8/8] KVM: selftests: x86: xen: " David Matlack
2022-09-26 23:37 ` Vishal Annapurve
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=20220915000448.1674802-9-vannapurve@google.com \
--to=vannapurve@google.com \
--cc=bgardon@google.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vkuznets@redhat.com \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).