Skip to content

Commit

Permalink
i386/xen: fix per-vCPU upcall vector for Xen emulation
Browse files Browse the repository at this point in the history
The per-vCPU upcall vector support had three problems. Firstly it was
using the wrong hypercall argument and would always return -EFAULT when
the guest tried to set it up. Secondly it was using the wrong ioctl() to
pass the vector to the kernel and thus the *kernel* would always return
-EINVAL. Finally, even when delivering the event directly from userspace
with an MSI, it put the destination CPU ID into the wrong bits of the
MSI address.

Linux doesn't (yet) use this mode so it went without decent testing
for a while.

Cc: qemu-stable@nongnu.org
Fixes: 105b47f ("i386/xen: implement HVMOP_set_evtchn_upcall_vector")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
  • Loading branch information
dwmw2 committed Nov 6, 2023
1 parent e969f99 commit e7dbb62
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions target/i386/kvm/xen-emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static int kvm_xen_set_vcpu_callback_vector(CPUState *cs)

trace_kvm_xen_set_vcpu_callback(cs->cpu_index, vector);

return kvm_vcpu_ioctl(cs, KVM_XEN_HVM_SET_ATTR, &xva);
return kvm_vcpu_ioctl(cs, KVM_XEN_VCPU_SET_ATTR, &xva);
}

static void do_set_vcpu_callback_vector(CPUState *cs, run_on_cpu_data data)
Expand Down Expand Up @@ -440,7 +440,8 @@ void kvm_xen_inject_vcpu_callback_vector(uint32_t vcpu_id, int type)
* deliver it as an MSI.
*/
MSIMessage msg = {
.address = APIC_DEFAULT_ADDRESS | X86_CPU(cs)->apic_id,
.address = APIC_DEFAULT_ADDRESS |
(X86_CPU(cs)->apic_id << MSI_ADDR_DEST_ID_SHIFT),
.data = vector | (1UL << MSI_DATA_LEVEL_SHIFT),
};
kvm_irqchip_send_msi(kvm_state, msg);
Expand Down Expand Up @@ -849,8 +850,7 @@ static bool kvm_xen_hcall_hvm_op(struct kvm_xen_exit *exit, X86CPU *cpu,
int ret = -ENOSYS;
switch (cmd) {
case HVMOP_set_evtchn_upcall_vector:
ret = kvm_xen_hcall_evtchn_upcall_vector(exit, cpu,
exit->u.hcall.params[0]);
ret = kvm_xen_hcall_evtchn_upcall_vector(exit, cpu, arg);
break;

case HVMOP_pagetable_dying:
Expand Down

0 comments on commit e7dbb62

Please sign in to comment.