6096cf7877
The way that Xen handles MSI PIRQs is kind of awful. There is a special MSI message which targets a PIRQ. The vector in the low bits of data must be zero. The low 8 bits of the PIRQ# are in the destination ID field, the extended destination ID field is unused, and instead the high bits of the PIRQ# are in the high 32 bits of the address. Using the high bits of the address means that we can't intercept and translate these messages in kvm_send_msi(), because they won't be caught by the APIC — addresses like 0x1000fee46000 aren't in the APIC's range. So we catch them in pci_msi_trigger() instead, and deliver the event channel directly. That isn't even the worst part. The worst part is that Xen snoops on writes to devices' MSI vectors while they are *masked*. When a MSI message is written which looks like it targets a PIRQ, it remembers the device and vector for later. When the guest makes a hypercall to bind that PIRQ# (snooped from a marked MSI vector) to an event channel port, Xen *unmasks* that MSI vector on the device. Xen guests using PIRQ delivery of MSI don't ever actually unmask the MSI for themselves. Now that this is working we can finally enable XENFEAT_hvm_pirqs and let the guest use it all. Tested with passthrough igb and emulated e1000e + AHCI. CPU0 CPU1 0: 65 0 IO-APIC 2-edge timer 1: 0 14 xen-pirq 1-ioapic-edge i8042 4: 0 846 xen-pirq 4-ioapic-edge ttyS0 8: 1 0 xen-pirq 8-ioapic-edge rtc0 9: 0 0 xen-pirq 9-ioapic-level acpi 12: 257 0 xen-pirq 12-ioapic-edge i8042 24: 9600 0 xen-percpu -virq timer0 25: 2758 0 xen-percpu -ipi resched0 26: 0 0 xen-percpu -ipi callfunc0 27: 0 0 xen-percpu -virq debug0 28: 1526 0 xen-percpu -ipi callfuncsingle0 29: 0 0 xen-percpu -ipi spinlock0 30: 0 8608 xen-percpu -virq timer1 31: 0 874 xen-percpu -ipi resched1 32: 0 0 xen-percpu -ipi callfunc1 33: 0 0 xen-percpu -virq debug1 34: 0 1617 xen-percpu -ipi callfuncsingle1 35: 0 0 xen-percpu -ipi spinlock1 36: 8 0 xen-dyn -event xenbus 37: 0 6046 xen-pirq -msi ahci[0000:00:03.0] 38: 1 0 xen-pirq -msi-x ens4 39: 0 73 xen-pirq -msi-x ens4-rx-0 40: 14 0 xen-pirq -msi-x ens4-rx-1 41: 0 32 xen-pirq -msi-x ens4-tx-0 42: 47 0 xen-pirq -msi-x ens4-tx-1 Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org>
55 lines
1.8 KiB
C
55 lines
1.8 KiB
C
/*
|
|
* msi.h
|
|
*
|
|
* Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
|
|
* VA Linux Systems Japan K.K.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef QEMU_MSI_H
|
|
#define QEMU_MSI_H
|
|
|
|
#include "hw/pci/pci_device.h"
|
|
|
|
struct MSIMessage {
|
|
uint64_t address;
|
|
uint32_t data;
|
|
};
|
|
|
|
extern bool msi_nonbroken;
|
|
|
|
void msi_set_message(PCIDevice *dev, MSIMessage msg);
|
|
MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector);
|
|
bool msi_enabled(const PCIDevice *dev);
|
|
void msi_set_enabled(PCIDevice *dev);
|
|
int msi_init(struct PCIDevice *dev, uint8_t offset,
|
|
unsigned int nr_vectors, bool msi64bit,
|
|
bool msi_per_vector_mask, Error **errp);
|
|
void msi_uninit(struct PCIDevice *dev);
|
|
void msi_reset(PCIDevice *dev);
|
|
bool msi_is_masked(const PCIDevice *dev, unsigned int vector);
|
|
void msi_notify(PCIDevice *dev, unsigned int vector);
|
|
void msi_send_message(PCIDevice *dev, MSIMessage msg);
|
|
void msi_write_config(PCIDevice *dev, uint32_t addr, uint32_t val, int len);
|
|
unsigned int msi_nr_vectors_allocated(const PCIDevice *dev);
|
|
void msi_set_mask(PCIDevice *dev, int vector, bool mask, Error **errp);
|
|
|
|
static inline bool msi_present(const PCIDevice *dev)
|
|
{
|
|
return dev->cap_present & QEMU_PCI_CAP_MSI;
|
|
}
|
|
|
|
#endif /* QEMU_MSI_H */
|