mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00

The system GSIs are not designed for sharing. One device might assert a
shared interrupt with qemu_set_irq() and another might deassert it, and
the level from the first device is lost.
This could be solved by refactoring the x86 GSI code to use an OrIrq
device, but that still wouldn't be ideal.
The best answer would be to have a 'resample' callback which is invoked
when the interrupt is acked at the interrupt controller, and causes the
devices to re-trigger the interrupt if it should still be pending. This
is the model that VFIO in Linux uses, with a 'resampler' eventfd that
actually unmasks the interrupt on the hardware device and thus triggers
a new interrupt from it if needed.
As things stand, QEMU currently doesn't use that VFIO interface
correctly, and just bashes on the resampler for every MMIO access to the
device "just in case". Which requires unmapping and trapping the MMIO
while an interrupt is pending!
For the Xen callback GSI, QEMU does something similar — a flag is set
which triggers a poll on *every* vmexst to see if the GSI should be
deasserted.
Proper resampler support would solve all of that, but is a task for
later which has already been on the TODO list for a while.
Since the Xen event channel GSI support *already* has hooks into the PC
gsi_handler() code for routing GSIs to PIRQs, we can use that for a
simpler bug fix.
So... remember the externally-driven state of the line (from e.g. PCI
INTx) and set the logical OR of that with the GSI. As a bonus, we now
only need to enable the polling of vcpu_info on vmexit if the Xen
callback GSI is the *only* reason the corresponding line is asserted.
Closes: https://gitlab.com/qemu-project/qemu/-/issues/2731
Fixes: ddf0fd9ae1
("hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback")
Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
87 lines
3.3 KiB
C
87 lines
3.3 KiB
C
/*
|
|
* QEMU Xen emulation: Event channel support
|
|
*
|
|
* Copyright © 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* Authors: David Woodhouse <dwmw2@infradead.org>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#ifndef QEMU_XEN_EVTCHN_H
|
|
#define QEMU_XEN_EVTCHN_H
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
typedef uint32_t evtchn_port_t;
|
|
|
|
void xen_evtchn_create(unsigned int nr_gsis, qemu_irq *system_gsis);
|
|
int xen_evtchn_soft_reset(void);
|
|
int xen_evtchn_set_callback_param(uint64_t param);
|
|
void xen_evtchn_set_callback_level(int level);
|
|
|
|
int xen_evtchn_set_port(uint16_t port);
|
|
|
|
bool xen_evtchn_set_gsi(int gsi, int *level);
|
|
void xen_evtchn_snoop_msi(PCIDevice *dev, bool is_msix, unsigned int vector,
|
|
uint64_t addr, uint32_t data, bool is_masked);
|
|
void xen_evtchn_remove_pci_device(PCIDevice *dev);
|
|
struct kvm_irq_routing_entry;
|
|
int xen_evtchn_translate_pirq_msi(struct kvm_irq_routing_entry *route,
|
|
uint64_t address, uint32_t data);
|
|
bool xen_evtchn_deliver_pirq_msi(uint64_t address, uint32_t data);
|
|
|
|
|
|
/*
|
|
* These functions mirror the libxenevtchn library API, providing the QEMU
|
|
* backend side of "interdomain" event channels.
|
|
*/
|
|
struct xenevtchn_handle;
|
|
struct xenevtchn_handle *xen_be_evtchn_open(void);
|
|
int xen_be_evtchn_bind_interdomain(struct xenevtchn_handle *xc, uint32_t domid,
|
|
evtchn_port_t guest_port);
|
|
int xen_be_evtchn_unbind(struct xenevtchn_handle *xc, evtchn_port_t port);
|
|
int xen_be_evtchn_close(struct xenevtchn_handle *xc);
|
|
int xen_be_evtchn_fd(struct xenevtchn_handle *xc);
|
|
int xen_be_evtchn_notify(struct xenevtchn_handle *xc, evtchn_port_t port);
|
|
int xen_be_evtchn_unmask(struct xenevtchn_handle *xc, evtchn_port_t port);
|
|
int xen_be_evtchn_pending(struct xenevtchn_handle *xc);
|
|
/* Apart from this which is a local addition */
|
|
int xen_be_evtchn_get_guest_port(struct xenevtchn_handle *xc);
|
|
|
|
struct evtchn_status;
|
|
struct evtchn_close;
|
|
struct evtchn_unmask;
|
|
struct evtchn_bind_virq;
|
|
struct evtchn_bind_pirq;
|
|
struct evtchn_bind_ipi;
|
|
struct evtchn_send;
|
|
struct evtchn_alloc_unbound;
|
|
struct evtchn_bind_interdomain;
|
|
struct evtchn_bind_vcpu;
|
|
struct evtchn_reset;
|
|
int xen_evtchn_status_op(struct evtchn_status *status);
|
|
int xen_evtchn_close_op(struct evtchn_close *close);
|
|
int xen_evtchn_unmask_op(struct evtchn_unmask *unmask);
|
|
int xen_evtchn_bind_virq_op(struct evtchn_bind_virq *virq);
|
|
int xen_evtchn_bind_pirq_op(struct evtchn_bind_pirq *pirq);
|
|
int xen_evtchn_bind_ipi_op(struct evtchn_bind_ipi *ipi);
|
|
int xen_evtchn_send_op(struct evtchn_send *send);
|
|
int xen_evtchn_alloc_unbound_op(struct evtchn_alloc_unbound *alloc);
|
|
int xen_evtchn_bind_interdomain_op(struct evtchn_bind_interdomain *interdomain);
|
|
int xen_evtchn_bind_vcpu_op(struct evtchn_bind_vcpu *vcpu);
|
|
int xen_evtchn_reset_op(struct evtchn_reset *reset);
|
|
|
|
struct physdev_map_pirq;
|
|
struct physdev_unmap_pirq;
|
|
struct physdev_eoi;
|
|
struct physdev_irq_status_query;
|
|
struct physdev_get_free_pirq;
|
|
int xen_physdev_map_pirq(struct physdev_map_pirq *map);
|
|
int xen_physdev_unmap_pirq(struct physdev_unmap_pirq *unmap);
|
|
int xen_physdev_eoi_pirq(struct physdev_eoi *eoi);
|
|
int xen_physdev_query_pirq(struct physdev_irq_status_query *query);
|
|
int xen_physdev_get_free_pirq(struct physdev_get_free_pirq *get);
|
|
|
|
#endif /* QEMU_XEN_EVTCHN_H */
|