From nobody Wed Nov 27 17:50:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1697730102; cv=none; d=zohomail.com; s=zohoarc; b=hYa9EhE9Zfq+WRC7cVOBl66J1HfxmQH1nB9J0jc1EU4y2vwRyKb2BvavrWTAaEZN27BRjXduEg6zzhmhZqeUXhVIKEcMN6YCmFU/GsP0nkWzds28W4gcicYi9Y6Vttq1pBnU5+hVkIfriUL8ntJj3BtL+CL5MDANL22dIdT9TH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697730102; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zEVOklvlUUQyQZ4N1FCYWmPuynX0GZRTCMHzzJrC3Bo=; b=jspSxfRpAqD8YOzR88f1urxoYaVcV4R0kM2QywvE1mcxhzMJqPA9hi1tTshvC74gT4a+FFJKNH4ls1Fi07UXqB1e1qntZshwhvZDBxF3rTtyAs6m1eDt9wlqX7xIr2EOtqaehC1QuXNmXttIUXCljNYnLzFZgBilXsH3iVUjePE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16977301019991004.8471833616641; Thu, 19 Oct 2023 08:41:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.619423.964510 (Exim 4.92) (envelope-from ) id 1qtV8u-0000M8-G7; Thu, 19 Oct 2023 15:41:00 +0000 Received: by outflank-mailman (output) from mailman id 619423.964510; Thu, 19 Oct 2023 15:41:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtV8t-0000I3-Kg; Thu, 19 Oct 2023 15:40:59 +0000 Received: by outflank-mailman (input) for mailman id 619423; Thu, 19 Oct 2023 15:40:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtV8q-0005v1-7o for xen-devel@lists.xenproject.org; Thu, 19 Oct 2023 15:40:56 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e38ed611-6e95-11ee-98d5-6d05b1d4d9a1; Thu, 19 Oct 2023 17:40:54 +0200 (CEST) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qtV8N-007osx-KY; Thu, 19 Oct 2023 15:40:27 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qtV8N-000Puv-0D; Thu, 19 Oct 2023 16:40:27 +0100 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: e38ed611-6e95-11ee-98d5-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=zEVOklvlUUQyQZ4N1FCYWmPuynX0GZRTCMHzzJrC3Bo=; b=hJ6t4WNhxI9VEdHaki64Gxt2yZ 1yWmIl3OnKjrwiGCXuB4T28FJZS2qTF0IaKIFe/iLTDnX2sQlYtDaQy8w8d/Yfaw5buoIOl7jIWXk mTrlW0CtffIarggvIBFT3vnyIM23G01VOKOzKagy8C7eMWO7c+GN+M3ELLq3J3l6O14nNC7DCTjwA fbFqixN3jxynJwJn3vKd93xmbFnC+a6ImoaZDkCscpn+bJpI5Gq9wMXncbqiQOeUTGEeUxyTx2wGr Q3t4RzMeiGQ82/Ea9V+F6Q4u7ugAsepDqDJdkosIrN2Iuu2qr/nfmk1pLy6+K/YjNuFi1GKgNMZVX tizHSZZQ==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Jason Wang , Marcelo Tosatti , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Beraldo Leal , qemu-block@nongnu.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Bernhard Beschow , Joel Upham Subject: [PATCH v2 19/24] hw/i386/pc: support '-nic' for xen-net-device Date: Thu, 19 Oct 2023 16:40:15 +0100 Message-Id: <20231019154020.99080-20-dwmw2@infradead.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231019154020.99080-1-dwmw2@infradead.org> References: <20231019154020.99080-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1697730103290100027 Content-Type: text/plain; charset="utf-8" From: David Woodhouse The default NIC creation seems a bit hackish to me. I don't understand why each platform has to call pci_nic_init_nofail() from a point in the code where it actually has a pointer to the PCI bus, and then we have the special cases for things like ne2k_isa. If qmp_device_add() can *find* the appropriate bus and instantiate the device on it, why can't we just do that from generic code for creating the default NICs too? But that isn't a yak I want to shave today. Add a xenbus field to the PCMachineState so that it can make its way from pc_basic_device_init() to pc_nic_init() and be handled as a special case like ne2k_isa is. Now we can launch emulated Xen guests with '-nic user'. Signed-off-by: David Woodhouse --- hw/i386/pc.c | 11 ++++++++--- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/xen/xen-bus.c | 4 +++- include/hw/i386/pc.h | 4 +++- include/hw/xen/xen-bus.h | 2 +- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index bb3854d1d0..7413ca50c8 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1265,7 +1265,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, if (pcms->bus) { pci_create_simple(pcms->bus, -1, "xen-platform"); } - xen_bus_init(); + pcms->xenbus =3D xen_bus_init(); xen_be_init(); } #endif @@ -1291,7 +1291,8 @@ void pc_basic_device_init(struct PCMachineState *pcms, pcms->vmport !=3D ON_OFF_AUTO_ON); } =20 -void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus) +void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, + BusState *xen_bus) { MachineClass *mc =3D MACHINE_CLASS(pcmc); int i; @@ -1301,7 +1302,11 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_b= us, PCIBus *pci_bus) NICInfo *nd =3D &nd_table[i]; const char *model =3D nd->model ? nd->model : mc->default_nic; =20 - if (g_str_equal(model, "ne2k_isa")) { + if (xen_bus && (!nd->model || g_str_equal(model, "xen-net-device")= )) { + DeviceState *dev =3D qdev_new("xen-net-device"); + qdev_set_nic_properties(dev, nd); + qdev_realize_and_unref(dev, xen_bus, &error_fatal); + } else if (g_str_equal(model, "ne2k_isa")) { pc_init_ne2k_isa(isa_bus, nd); } else { pci_nic_init_nofail(nd, pci_bus, model, NULL); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index e36a3262b2..90b5ae7258 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -322,7 +322,7 @@ static void pc_init1(MachineState *machine, pc_basic_device_init(pcms, isa_bus, x86ms->gsi, rtc_state, true, 0x4); =20 - pc_nic_init(pcmc, isa_bus, pci_bus); + pc_nic_init(pcmc, isa_bus, pci_bus, pcms->xenbus); =20 if (pcmc->pci_enabled) { PCIDevice *dev; diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index a7386f2ca2..2ed0aab2a7 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -340,7 +340,7 @@ static void pc_q35_init(MachineState *machine) =20 /* 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); + pc_nic_init(pcmc, isa_bus, host_bus, pcms->xenbus); =20 if (machine->nvdimms_state->is_enabled) { nvdimm_init_acpi_state(machine->nvdimms_state, system_io, diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 0da2aa219a..d7823964f8 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -1127,11 +1127,13 @@ static void xen_register_types(void) =20 type_init(xen_register_types) =20 -void xen_bus_init(void) +BusState *xen_bus_init(void) { DeviceState *dev =3D qdev_new(TYPE_XEN_BRIDGE); BusState *bus =3D qbus_new(TYPE_XEN_BUS, dev, NULL); =20 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); qbus_set_bus_hotplug_handler(bus); + + return bus; } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index bec38cb92c..feabf3d195 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -33,6 +33,7 @@ typedef struct PCMachineState { =20 /* Pointers to devices and objects: */ PCIBus *bus; + BusState *xenbus; I2CBus *smbus; PFlashCFI01 *flash[2]; ISADevice *pcspk; @@ -182,7 +183,8 @@ 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); +void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, + BusState *xen_bus); =20 void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); =20 diff --git a/include/hw/xen/xen-bus.h b/include/hw/xen/xen-bus.h index eb440880b5..acad871b80 100644 --- a/include/hw/xen/xen-bus.h +++ b/include/hw/xen/xen-bus.h @@ -75,7 +75,7 @@ struct XenBusClass { OBJECT_DECLARE_TYPE(XenBus, XenBusClass, XEN_BUS) =20 -void xen_bus_init(void); +BusState *xen_bus_init(void); =20 void xen_device_backend_set_state(XenDevice *xendev, enum xenbus_state state); --=20 2.40.1