From: "Kaya, Metin" <metikaya@amazon.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Cc: "Woodhouse, David" <dwmw@amazon.co.uk>,
"Durrant, Paul" <pdurrant@amazon.co.uk>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>
Subject: [PATCH 1/1] KVM: x86/xen: add support for 32-bit guests in SCHEDOP_poll
Date: Mon, 21 Mar 2022 16:46:31 +0000 [thread overview]
Message-ID: <1647881191688.60603@amazon.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 0 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-KVM-x86-xen-add-support-for-32-bit-guests-in-SCHEDOP.patch --]
[-- Type: text/x-patch; name="0001-KVM-x86-xen-add-support-for-32-bit-guests-in-SCHEDOP.patch", Size: 2871 bytes --]
From 49113959550525be40c23e8bfc4addf69edeca47 Mon Sep 17 00:00:00 2001
From: Metin Kaya <metikaya@amazon.com>
Date: Mon, 21 Mar 2022 11:05:32 +0000
Subject: [PATCH] KVM: x86/xen: add support for 32-bit guests in SCHEDOP_poll
This patch introduces compat version of struct sched_poll for
SCHEDOP_poll sub-operation of sched_op hypercall, reads correct amount
of data (16 bytes in 32-bit case, 24 bytes otherwise) by using new
compat_sched_poll struct, copies it to sched_poll properly, and lets
rest of the code run as is.
Signed-off-by: Metin Kaya <metikaya@amazon.com>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <pdurrant@amazon.co.uk>
---
arch/x86/kvm/xen.c | 30 ++++++++++++++++++++++++++----
arch/x86/kvm/xen.h | 7 +++++++
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 7d01983d1087..c02163bf1a97 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -998,20 +998,42 @@ static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool longmode,
evtchn_port_t port, *ports;
gpa_t gpa;
- if (!longmode || !lapic_in_kernel(vcpu) ||
+ if (!lapic_in_kernel(vcpu) ||
!(vcpu->kvm->arch.xen_hvm_config.flags & KVM_XEN_HVM_CONFIG_EVTCHN_SEND))
return false;
idx = srcu_read_lock(&vcpu->kvm->srcu);
gpa = kvm_mmu_gva_to_gpa_system(vcpu, param, NULL);
srcu_read_unlock(&vcpu->kvm->srcu, idx);
-
- if (!gpa || kvm_vcpu_read_guest(vcpu, gpa, &sched_poll,
- sizeof(sched_poll))) {
+ if (!gpa) {
*r = -EFAULT;
return true;
}
+ if (IS_ENABLED(CONFIG_64BIT) && longmode) {
+ if (kvm_vcpu_read_guest(vcpu, gpa, &sched_poll,
+ sizeof(sched_poll))) {
+ *r = -EFAULT;
+ return true;
+ }
+ } else {
+ struct compat_sched_poll sp;
+
+ /*
+ * We assume size of compat_sched_poll is 16 bytes in 32-bit
+ * environment. Let's be honest.
+ */
+ BUILD_BUG_ON(sizeof(struct compat_sched_poll) != 16);
+
+ if (kvm_vcpu_read_guest(vcpu, gpa, &sp, sizeof(sp))) {
+ *r = -EFAULT;
+ return true;
+ }
+ sched_poll.ports = (evtchn_port_t *)(unsigned long)(sp.ports);
+ sched_poll.nr_ports = sp.nr_ports;
+ sched_poll.timeout = sp.timeout;
+ }
+
if (unlikely(sched_poll.nr_ports > 1)) {
/* Xen (unofficially) limits number of pollers to 128 */
if (sched_poll.nr_ports > 128) {
diff --git a/arch/x86/kvm/xen.h b/arch/x86/kvm/xen.h
index ee5c4ae0755c..b5b208cd8c9f 100644
--- a/arch/x86/kvm/xen.h
+++ b/arch/x86/kvm/xen.h
@@ -196,6 +196,13 @@ struct compat_shared_info {
struct compat_arch_shared_info arch;
};
+struct compat_sched_poll {
+ /* This is actually a pointer which has to be 4 bytes in size. */
+ uint32_t ports;
+ unsigned int nr_ports;
+ uint64_t timeout;
+} __packed;
+
#define COMPAT_EVTCHN_2L_NR_CHANNELS (8 * \
sizeof_field(struct compat_shared_info, \
evtchn_pending))
--
2.32.0
next reply other threads:[~2022-03-21 16:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-21 16:46 Kaya, Metin [this message]
2022-03-21 17:15 ` [PATCH v2 1/1] KVM: x86/xen: add support for 32-bit guests in SCHEDOP_poll Kaya, Metin
2022-03-21 17:27 ` Kaya, Metin
2022-11-24 0:33 ` David Woodhouse
2022-11-25 12:34 ` David Woodhouse
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=1647881191688.60603@amazon.com \
--to=metikaya@amazon.com \
--cc=boris.ostrovsky@oracle.com \
--cc=dwmw@amazon.co.uk \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=pdurrant@amazon.co.uk \
--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