Skip to content

Commit

Permalink
hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs
Browse files Browse the repository at this point in the history
When instantiating XenBus itself, for each NIC which is configured with
either the model unspecified, or set to to "xen" or "xen-net-device",
create a corresponding xen-net-device for it.

Now we can revert the previous more hackish version which relied on the
platform code explicitly registering the NICs on its own XenBus, having
returned the BusState* from xen_bus_init() itself.

This also fixes the setup for Xen PV guests, which was previously broken
in various ways and never actually managed to peer with the netdev.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Paul Durrant <paul@xen.org>
  • Loading branch information
dwmw2 committed Feb 2, 2024
1 parent 8d39f9b commit 7d6eff1
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 54 deletions.
13 changes: 2 additions & 11 deletions hw/i386/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
if (pcms->bus) {
pci_create_simple(pcms->bus, -1, "xen-platform");
}
pcms->xenbus = xen_bus_init();
xen_bus_init();
xen_be_init();
}
#endif
Expand Down Expand Up @@ -1297,23 +1297,14 @@ void pc_basic_device_init(struct PCMachineState *pcms,
pcms->vmport != ON_OFF_AUTO_ON);
}

void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus,
BusState *xen_bus)
void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
{
MachineClass *mc = MACHINE_CLASS(pcmc);
bool default_is_ne2k = g_str_equal(mc->default_nic, TYPE_ISA_NE2000);
NICInfo *nd;

rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC);

if (xen_bus) {
while ((nd = qemu_find_nic_info("xen-net-device", true, NULL))) {
DeviceState *dev = qdev_new("xen-net-device");
qdev_set_nic_properties(dev, nd);
qdev_realize_and_unref(dev, xen_bus, &error_fatal);
}
}

while ((nd = qemu_find_nic_info(TYPE_ISA_NE2000, default_is_ne2k, NULL))) {
pc_init_ne2k_isa(isa_bus, nd, &error_fatal);
}
Expand Down
2 changes: 1 addition & 1 deletion hw/i386/pc_piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static void pc_init1(MachineState *machine,
pc_basic_device_init(pcms, isa_bus, x86ms->gsi, rtc_state, true,
0x4);

pc_nic_init(pcmc, isa_bus, pci_bus, pcms->xenbus);
pc_nic_init(pcmc, isa_bus, pci_bus);

if (pcmc->pci_enabled) {
pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state);
Expand Down
2 changes: 1 addition & 1 deletion hw/i386/pc_q35.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static void pc_q35_init(MachineState *machine)

/* the rest devices to which pci devfn is automatically assigned */
pc_vga_init(isa_bus, host_bus);
pc_nic_init(pcmc, isa_bus, host_bus, pcms->xenbus);
pc_nic_init(pcmc, isa_bus, host_bus);

if (machine->nvdimms_state->is_enabled) {
nvdimm_init_acpi_state(machine->nvdimms_state, system_io,
Expand Down
6 changes: 4 additions & 2 deletions hw/xen/xen-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "sysemu/sysemu.h"
#include "net/net.h"
#include "trace.h"

static char *xen_device_get_backend_path(XenDevice *xendev)
Expand Down Expand Up @@ -1133,13 +1134,14 @@ static void xen_register_types(void)

type_init(xen_register_types)

BusState *xen_bus_init(void)
void xen_bus_init(void)
{
DeviceState *dev = qdev_new(TYPE_XEN_BRIDGE);
BusState *bus = qbus_new(TYPE_XEN_BUS, dev, NULL);

sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
qbus_set_bus_hotplug_handler(bus);

return bus;
qemu_create_nic_bus_devices(bus, TYPE_XEN_DEVICE, "xen-net-device",
"xen", "xen-net-device");
}
25 changes: 0 additions & 25 deletions hw/xen/xen_devconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,6 @@ static int xen_config_dev_all(char *fe, char *be)

/* ------------------------------------------------------------- */

int xen_config_dev_nic(NICInfo *nic)
{
char fe[256], be[256];
char mac[20];
int vlan_id = -1;

net_hub_id_for_client(nic->netdev, &vlan_id);
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
xen_pv_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", vlan_id, mac);
xen_config_dev_dirs("vif", "qnic", vlan_id, fe, be, sizeof(fe));

/* frontend */
xenstore_write_int(fe, "handle", vlan_id);
xenstore_write_str(fe, "mac", mac);

/* backend */
xenstore_write_int(be, "handle", vlan_id);
xenstore_write_str(be, "mac", mac);

/* common stuff */
return xen_config_dev_all(fe, be);
}

int xen_config_dev_vfb(int vdev, const char *type)
{
char fe[256], be[256];
Expand Down
9 changes: 0 additions & 9 deletions hw/xenpv/xen_machine_pv.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

static void xen_init_pv(MachineState *machine)
{
int i;

setup_xen_backend_ops();

/* Initialize backend core & drivers */
Expand Down Expand Up @@ -62,13 +60,6 @@ static void xen_init_pv(MachineState *machine)
vga_interface_created = true;
}

/* configure nics */
for (i = 0; i < nb_nics; i++) {
if (!nd_table[i].model || 0 != strcmp(nd_table[i].model, "xen"))
continue;
xen_config_dev_nic(nd_table + i);
}

xen_bus_init();

/* config cleanup hook */
Expand Down
4 changes: 1 addition & 3 deletions include/hw/i386/pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ typedef struct PCMachineState {

/* Pointers to devices and objects: */
PCIBus *bus;
BusState *xenbus;
I2CBus *smbus;
PFlashCFI01 *flash[2];
ISADevice *pcspk;
Expand Down Expand Up @@ -185,8 +184,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
void pc_cmos_init(PCMachineState *pcms,
BusState *ide0, BusState *ide1,
ISADevice *s);
void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus,
BusState *xen_bus);
void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus);

void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs);

Expand Down
2 changes: 1 addition & 1 deletion include/hw/xen/xen-bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct XenBusClass {
OBJECT_DECLARE_TYPE(XenBus, XenBusClass,
XEN_BUS)

BusState *xen_bus_init(void);
void xen_bus_init(void);

void xen_device_backend_set_state(XenDevice *xendev,
enum xenbus_state state);
Expand Down
1 change: 0 additions & 1 deletion include/hw/xen/xen-legacy-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ extern struct XenDevOps xen_usb_ops; /* xen-usb.c */

/* configuration (aka xenbus setup) */
void xen_config_cleanup(void);
int xen_config_dev_nic(NICInfo *nic);
int xen_config_dev_vfb(int vdev, const char *type);
int xen_config_dev_vkbd(int vdev);
int xen_config_dev_console(int vdev);
Expand Down

0 comments on commit 7d6eff1

Please sign in to comment.