Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge tag 'pull-xen-20230607' of https://xenbits.xen.org/git-http/peo…
…ple/aperard/qemu-dm into staging

Xen queue

- fix for xen-block segv
- Resolve TYPE_PIIX3_XEN_DEVICE
- Xen emulation build/Coverity fixes

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCgAdFiEE+AwAYwjiLP2KkueYDPVXL9f7Va8FAmSAkU0ACgkQDPVXL9f7
# Va/mMQf9Hs8pFGz7qRMc8RbuBvwVNGcdqOKZN+sbBKPb2pp9X8gkP5EV5SMLF/eu
# CjaoZU+SsZcVLZ0HZ/TevAEuMrflZeeRfneJzEcl58cwOxo5l18puRwy9iDxfh6m
# goqGGxQA2OmUa5eVZ7WX2JXo0wG/RQqqc/pChKbPAsTT9/QE23irOQBdUDf7sbGP
# WFI/LoLR0c6NNbQyZNWSP0e/+es8ztq+Is7Bl6d1fdG/6YeXK2yVaro1gyMmxKAm
# EKuvI9qva2ilV5RJEc/gB/x4PuIVCPizkrbB8XClQ81Szo49x55ChPdnpT5i7Sqd
# qjFWO2plgV/gXri1/RTCzyBujeuCOA==
# =E1Qb
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 07 Jun 2023 07:16:45 AM PDT
# gpg:                using RSA key F80C006308E22CFD8A92E7980CF5572FD7FB55AF
# gpg: Good signature from "Anthony PERARD <anthony.perard@gmail.com>" [unknown]
# gpg:                 aka "Anthony PERARD <anthony.perard@citrix.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 5379 2F71 024C 600F 778A  7161 D8D5 7199 DF83 42C8
#      Subkey fingerprint: F80C 0063 08E2 2CFD 8A92  E798 0CF5 572F D7FB 55AF

* tag 'pull-xen-20230607' of https://xenbits.xen.org/git-http/people/aperard/qemu-dm:
  xen-block: fix segv on unrealize
  hw/isa/piix3: Resolve redundant TYPE_PIIX3_XEN_DEVICE
  hw/isa/piix3: Resolve redundant k->config_write assignments
  hw/isa/piix3: Avoid Xen-specific variant of piix3_write_config()
  hw/isa/piix3: Wire up Xen PCI IRQ handling outside of PIIX3
  hw/isa/piix3: Reuse piix3_realize() in piix3_xen_realize()
  hw/pci/pci.c: Don't leak PCIBus::irq_count[] in pci_bus_irqs()
  include/hw/xen/xen: Rename xen_piix3_set_irq() to xen_intx_set_irq()
  hw/xen: Fix broken check for invalid state in xs_be_open()
  xen: Drop support for Xen versions below 4.7.1
  hw/xen: Fix memory leak in libxenstore_open() for Xen
  hw/xen: Simplify emulated Xen platform init

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Jun 7, 2023
2 parents e3bd519 + 9000666 commit 4f65e89
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 327 deletions.
40 changes: 20 additions & 20 deletions hw/i386/kvm/xen_evtchn.c
Expand Up @@ -147,7 +147,10 @@ struct XenEvtchnState {
QemuMutex port_lock;
uint32_t nr_ports;
XenEvtchnPort port_table[EVTCHN_2L_NR_CHANNELS];
qemu_irq gsis[IOAPIC_NUM_PINS];

/* Connected to the system GSIs for raising callback as GSI / INTx */
unsigned int nr_callback_gsis;
qemu_irq *callback_gsis;

struct xenevtchn_handle *be_handles[EVTCHN_2L_NR_CHANNELS];

Expand Down Expand Up @@ -299,7 +302,7 @@ static void gsi_assert_bh(void *opaque)
}
}

void xen_evtchn_create(void)
void xen_evtchn_create(unsigned int nr_gsis, qemu_irq *system_gsis)
{
XenEvtchnState *s = XEN_EVTCHN(sysbus_create_simple(TYPE_XEN_EVTCHN,
-1, NULL));
Expand All @@ -310,8 +313,19 @@ void xen_evtchn_create(void)
qemu_mutex_init(&s->port_lock);
s->gsi_bh = aio_bh_new(qemu_get_aio_context(), gsi_assert_bh, s);

for (i = 0; i < IOAPIC_NUM_PINS; i++) {
sysbus_init_irq(SYS_BUS_DEVICE(s), &s->gsis[i]);
/*
* These are the *output* GSI from event channel support, for
* signalling CPU0's events via GSI or PCI INTx instead of the
* per-CPU vector. We create a *set* of irqs and connect one to
* each of the system GSIs which were passed in from the platform
* code, and then just trigger the right one as appropriate from
* xen_evtchn_set_callback_level().
*/
s->nr_callback_gsis = nr_gsis;
s->callback_gsis = g_new0(qemu_irq, nr_gsis);
for (i = 0; i < nr_gsis; i++) {
sysbus_init_irq(SYS_BUS_DEVICE(s), &s->callback_gsis[i]);
sysbus_connect_irq(SYS_BUS_DEVICE(s), i, system_gsis[i]);
}

/*
Expand All @@ -336,20 +350,6 @@ void xen_evtchn_create(void)
xen_evtchn_ops = &emu_evtchn_backend_ops;
}

void xen_evtchn_connect_gsis(qemu_irq *system_gsis)
{
XenEvtchnState *s = xen_evtchn_singleton;
int i;

if (!s) {
return;
}

for (i = 0; i < IOAPIC_NUM_PINS; i++) {
sysbus_connect_irq(SYS_BUS_DEVICE(s), i, system_gsis[i]);
}
}

static void xen_evtchn_register_types(void)
{
type_register_static(&xen_evtchn_info);
Expand Down Expand Up @@ -430,8 +430,8 @@ void xen_evtchn_set_callback_level(int level)
return;
}

if (s->callback_gsi && s->callback_gsi < IOAPIC_NUM_PINS) {
qemu_set_irq(s->gsis[s->callback_gsi], level);
if (s->callback_gsi && s->callback_gsi < s->nr_callback_gsis) {
qemu_set_irq(s->callback_gsis[s->callback_gsi], level);
if (level) {
/* Ensure the vCPU polls for deassertion */
kvm_xen_set_callback_asserted();
Expand Down
3 changes: 1 addition & 2 deletions hw/i386/kvm/xen_evtchn.h
Expand Up @@ -16,10 +16,9 @@

typedef uint32_t evtchn_port_t;

void xen_evtchn_create(void);
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_connect_gsis(qemu_irq *system_gsis);
void xen_evtchn_set_callback_level(int level);

int xen_evtchn_set_port(uint16_t port);
Expand Down
2 changes: 1 addition & 1 deletion hw/i386/kvm/xen_xenstore.c
Expand Up @@ -1688,7 +1688,7 @@ static struct qemu_xs_handle *xs_be_open(void)
XenXenstoreState *s = xen_xenstore_singleton;
struct qemu_xs_handle *h;

if (!s && !s->impl) {
if (!s || !s->impl) {
errno = -ENOSYS;
return NULL;
}
Expand Down
13 changes: 4 additions & 9 deletions hw/i386/pc.c
Expand Up @@ -1332,7 +1332,10 @@ void pc_basic_device_init(struct PCMachineState *pcms,

#ifdef CONFIG_XEN_EMU
if (xen_mode == XEN_EMULATE) {
xen_evtchn_connect_gsis(gsi);
xen_overlay_create();
xen_evtchn_create(IOAPIC_NUM_PINS, gsi);
xen_gnttab_create();
xen_xenstore_create();
if (pcms->bus) {
pci_create_simple(pcms->bus, -1, "xen-platform");
}
Expand Down Expand Up @@ -1882,14 +1885,6 @@ static void pc_machine_initfn(Object *obj)

int pc_machine_kvm_type(MachineState *machine, const char *kvm_type)
{
#ifdef CONFIG_XEN_EMU
if (xen_mode == XEN_EMULATE) {
xen_overlay_create();
xen_evtchn_create();
xen_gnttab_create();
xen_xenstore_create();
}
#endif
return 0;
}

Expand Down
36 changes: 33 additions & 3 deletions hw/i386/pc_piix.c
Expand Up @@ -71,6 +71,7 @@
#include "kvm/kvm-cpu.h"

#define MAX_IDE_BUS 2
#define XEN_IOAPIC_NUM_PIRQS 128ULL

#ifdef CONFIG_IDE_ISA
static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
Expand All @@ -89,6 +90,21 @@ static int pc_pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
return (pci_intx + slot_addend) & 3;
}

static void piix_intx_routing_notifier_xen(PCIDevice *dev)
{
int i;

/* Scan for updates to PCI link routes (0x60-0x63). */
for (i = 0; i < PIIX_NUM_PIRQS; i++) {
uint8_t v = dev->config_read(dev, PIIX_PIRQCA + i, 1);
if (v & 0x80) {
v = 0;
}
v &= 0xf;
xen_set_pci_link_route(i, v);
}
}

/* PC hardware initialisation */
static void pc_init1(MachineState *machine,
const char *host_type, const char *pci_type)
Expand Down Expand Up @@ -223,8 +239,6 @@ static void pc_init1(MachineState *machine,
if (pcmc->pci_enabled) {
PIIX3State *piix3;
PCIDevice *pci_dev;
const char *type = xen_enabled() ? TYPE_PIIX3_XEN_DEVICE
: TYPE_PIIX3_DEVICE;

pci_bus = i440fx_init(pci_type,
i440fx_host,
Expand All @@ -237,7 +251,23 @@ static void pc_init1(MachineState *machine,
: pc_pci_slot_get_pirq);
pcms->bus = pci_bus;

pci_dev = pci_create_simple_multifunction(pci_bus, -1, true, type);
pci_dev = pci_create_simple_multifunction(pci_bus, -1, true,
TYPE_PIIX3_DEVICE);

if (xen_enabled()) {
pci_device_set_intx_routing_notifier(
pci_dev, piix_intx_routing_notifier_xen);

/*
* Xen supports additional interrupt routes from the PCI devices to
* the IOAPIC: the four pins of each PCI device on the bus are also
* connected to the IOAPIC directly.
* These additional routes can be discovered through ACPI.
*/
pci_bus_irqs(pci_bus, xen_intx_set_irq, pci_dev,
XEN_IOAPIC_NUM_PIRQS);
}

piix3 = PIIX3_PCI_DEVICE(pci_dev);
piix3->pic = x86ms->gsi;
piix3_devfn = piix3->dev.devfn;
Expand Down
2 changes: 1 addition & 1 deletion hw/i386/xen/xen-hvm.c
Expand Up @@ -143,7 +143,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
return irq_num + (PCI_SLOT(pci_dev->devfn) << 2);
}

void xen_piix3_set_irq(void *opaque, int irq_num, int level)
void xen_intx_set_irq(void *opaque, int irq_num, int level)
{
xen_set_pci_intx_level(xen_domid, 0, 0, irq_num >> 2,
irq_num & 3, level);
Expand Down
60 changes: 1 addition & 59 deletions hw/isa/piix3.c
Expand Up @@ -30,13 +30,10 @@
#include "hw/irq.h"
#include "hw/qdev-properties.h"
#include "hw/isa/isa.h"
#include "hw/xen/xen.h"
#include "sysemu/runstate.h"
#include "migration/vmstate.h"
#include "hw/acpi/acpi_aml_interface.h"

#define XEN_PIIX_NUM_PIRQS 128ULL

static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
{
qemu_set_irq(piix3->pic[pic_irq],
Expand Down Expand Up @@ -124,26 +121,6 @@ static void piix3_write_config(PCIDevice *dev,
}
}

static void piix3_write_config_xen(PCIDevice *dev,
uint32_t address, uint32_t val, int len)
{
int i;

/* Scan for updates to PCI link routes (0x60-0x63). */
for (i = 0; i < len; i++) {
uint8_t v = (val >> (8 * i)) & 0xff;
if (v & 0x80) {
v = 0;
}
v &= 0xf;
if (((address + i) >= PIIX_PIRQCA) && ((address + i) <= PIIX_PIRQCD)) {
xen_set_pci_link_route(address + i - PIIX_PIRQCA, v);
}
}

piix3_write_config(dev, address, val, len);
}

static void piix3_reset(DeviceState *dev)
{
PIIX3State *d = PIIX3_PCI_DEVICE(dev);
Expand Down Expand Up @@ -344,6 +321,7 @@ static void pci_piix3_class_init(ObjectClass *klass, void *data)
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);

k->config_write = piix3_write_config;
dc->reset = piix3_reset;
dc->desc = "ISA bridge";
dc->vmsd = &vmstate_piix3;
Expand Down Expand Up @@ -393,7 +371,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
{
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

k->config_write = piix3_write_config;
k->realize = piix3_realize;
}

Expand All @@ -403,45 +380,10 @@ static const TypeInfo piix3_info = {
.class_init = piix3_class_init,
};

static void piix3_xen_realize(PCIDevice *dev, Error **errp)
{
ERRP_GUARD();
PIIX3State *piix3 = PIIX3_PCI_DEVICE(dev);
PCIBus *pci_bus = pci_get_bus(dev);

pci_piix3_realize(dev, errp);
if (*errp) {
return;
}

/*
* Xen supports additional interrupt routes from the PCI devices to
* the IOAPIC: the four pins of each PCI device on the bus are also
* connected to the IOAPIC directly.
* These additional routes can be discovered through ACPI.
*/
pci_bus_irqs(pci_bus, xen_piix3_set_irq, piix3, XEN_PIIX_NUM_PIRQS);
}

static void piix3_xen_class_init(ObjectClass *klass, void *data)
{
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);

k->config_write = piix3_write_config_xen;
k->realize = piix3_xen_realize;
}

static const TypeInfo piix3_xen_info = {
.name = TYPE_PIIX3_XEN_DEVICE,
.parent = TYPE_PIIX3_PCI_DEVICE,
.class_init = piix3_xen_class_init,
};

static void piix3_register_types(void)
{
type_register_static(&piix3_pci_type_info);
type_register_static(&piix3_info);
type_register_static(&piix3_xen_info);
}

type_init(piix3_register_types)
2 changes: 2 additions & 0 deletions hw/pci/pci.c
Expand Up @@ -560,6 +560,7 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq,
bus->set_irq = set_irq;
bus->irq_opaque = irq_opaque;
bus->nirq = nirq;
g_free(bus->irq_count);
bus->irq_count = g_malloc0(nirq * sizeof(bus->irq_count[0]));
}

Expand All @@ -575,6 +576,7 @@ void pci_bus_irqs_cleanup(PCIBus *bus)
bus->irq_opaque = NULL;
bus->nirq = 0;
g_free(bus->irq_count);
bus->irq_count = NULL;
}

PCIBus *pci_register_root_bus(DeviceState *parent, const char *name,
Expand Down
6 changes: 4 additions & 2 deletions hw/xen/xen-bus.c
Expand Up @@ -923,8 +923,10 @@ void xen_device_unbind_event_channel(XenDevice *xendev,

QLIST_REMOVE(channel, list);

aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh),
NULL, NULL, NULL, NULL, NULL);
if (channel->ctx) {
aio_set_fd_handler(channel->ctx, qemu_xen_evtchn_fd(channel->xeh),
NULL, NULL, NULL, NULL, NULL);
}

if (qemu_xen_evtchn_unbind(channel->xeh, channel->local_port) < 0) {
error_setg_errno(errp, errno, "xenevtchn_unbind failed");
Expand Down

0 comments on commit 4f65e89

Please sign in to comment.