Skip to content

Commit 214b0a8

Browse files
Metin Kayadwmw2
authored andcommitted
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 <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Reviewed-by: Paul Durrant <[email protected]>
1 parent df0bb47 commit 214b0a8

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

arch/x86/kvm/xen.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,20 +1201,45 @@ static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool longmode,
12011201
evtchn_port_t port, *ports;
12021202
gpa_t gpa;
12031203

1204-
if (!longmode || !lapic_in_kernel(vcpu) ||
1204+
if (!lapic_in_kernel(vcpu) ||
12051205
!(vcpu->kvm->arch.xen_hvm_config.flags & KVM_XEN_HVM_CONFIG_EVTCHN_SEND))
12061206
return false;
12071207

12081208
idx = srcu_read_lock(&vcpu->kvm->srcu);
12091209
gpa = kvm_mmu_gva_to_gpa_system(vcpu, param, NULL);
12101210
srcu_read_unlock(&vcpu->kvm->srcu, idx);
1211-
1212-
if (!gpa || kvm_vcpu_read_guest(vcpu, gpa, &sched_poll,
1213-
sizeof(sched_poll))) {
1211+
if (!gpa) {
12141212
*r = -EFAULT;
12151213
return true;
12161214
}
12171215

1216+
if (IS_ENABLED(CONFIG_64BIT) && !longmode) {
1217+
struct compat_sched_poll sp32;
1218+
1219+
/* Sanity check that the compat struct definition is correct */
1220+
BUILD_BUG_ON(sizeof(sp32) != 16);
1221+
1222+
if (kvm_vcpu_read_guest(vcpu, gpa, &sp32, sizeof(sp32))) {
1223+
*r = -EFAULT;
1224+
return true;
1225+
}
1226+
1227+
/*
1228+
* This is a 32-bit pointer to an array of evtchn_port_t which
1229+
* are uint32_t, so once it's converted no further compat
1230+
* handling is needed.
1231+
*/
1232+
sched_poll.ports = (void *)(unsigned long)(sp32.ports);
1233+
sched_poll.nr_ports = sp32.nr_ports;
1234+
sched_poll.timeout = sp32.timeout;
1235+
} else {
1236+
if (kvm_vcpu_read_guest(vcpu, gpa, &sched_poll,
1237+
sizeof(sched_poll))) {
1238+
*r = -EFAULT;
1239+
return true;
1240+
}
1241+
}
1242+
12181243
if (unlikely(sched_poll.nr_ports > 1)) {
12191244
/* Xen (unofficially) limits number of pollers to 128 */
12201245
if (sched_poll.nr_ports > 128) {

arch/x86/kvm/xen.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,11 @@ struct compat_vcpu_runstate_info {
207207
uint64_t time[4];
208208
} __attribute__((packed));
209209

210+
struct compat_sched_poll {
211+
/* This is actually a guest virtual address which points to ports. */
212+
uint32_t ports;
213+
unsigned int nr_ports;
214+
uint64_t timeout;
215+
};
216+
210217
#endif /* __ARCH_X86_KVM_XEN_H__ */

0 commit comments

Comments
 (0)