From nobody Wed Nov 27 17:38:17 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=1697730083; cv=none; d=zohomail.com; s=zohoarc; b=lR+iPhPCrqjL3aeROKw3DcFMeEbp/I1YrvUL22y9GC+U+hLFw6L8KCQDHxYOHWlie0tXIVsTBW6sTE1wX8cGQ4Jjmcxp4GhwwBjDTOwV+7mGdEJgwqHxLg1sv6+VRzP3fc/tNiFXw2RfeL2D73iA/cn+w8GQpkA8LhUejxIw6Vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697730083; 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=6eB6ZTu6F2pRboHgvVTkcuf9JVHV2C3gx4pFbRpACpA=; b=DSuV18HS4E64H0pMzLS8hKHZaN5qSBt41m79M5ZvcGYpZ/XqvyWQ3fMxirh6RZmMyyJ3emdMZfkQyyAbDzPhMM9SyNSbrP59IEG/eYq/yX6+GdayateflKBVT6UitW6CEOlywwQuNu795kb3G6loWahQ6qqgytYpLRbnej9JPLk= 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 169773008352924.106094204399938; Thu, 19 Oct 2023 08:41:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.619416.964452 (Exim 4.92) (envelope-from ) id 1qtV8o-0007KR-Tl; Thu, 19 Oct 2023 15:40:54 +0000 Received: by outflank-mailman (output) from mailman id 619416.964452; Thu, 19 Oct 2023 15:40:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtV8o-0007IV-Hc; Thu, 19 Oct 2023 15:40:54 +0000 Received: by outflank-mailman (input) for mailman id 619416; Thu, 19 Oct 2023 15:40:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qtV8n-0006dc-CN for xen-devel@lists.xenproject.org; Thu, 19 Oct 2023 15:40:53 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id df1c7b92-6e95-11ee-9b0e-b553b5be7939; Thu, 19 Oct 2023 17:40:48 +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-007osy-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-000Pv1-0W; 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: df1c7b92-6e95-11ee-9b0e-b553b5be7939 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=6eB6ZTu6F2pRboHgvVTkcuf9JVHV2C3gx4pFbRpACpA=; b=v3tBGDFXA8XlwBj+VDbGUIikdR YvZpeBmMRPn8PIScM+B62OOMnMNtlSRN9f488qg8iDo/npxFjE9lU/InslkYOKIpIezyq7k5YPht8 KshD2GVes/NkKgdIE9mBX3DoO/h/1f/BltQmn9++W+k582NPRu/KDohIJ+xJUbrCCpNeh7OmYonmv 2cpOPnmtC8QmUyaYA1AqWbn00FbvvzyWCSHWECn+Kwto5av9TPVZDFDGUO8hrhrm7fgZu+RFJQIbD 0b3BHphf2n2QuCHfcCuhuYYCoHB6Py8PkZcdR60uEMR0fVlYJgcjv5cOklq/bXCI7SpEmT/YVNp5B qiOyOYkQ==; 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 20/24] hw/xenpv: fix '-nic' support for xen-net-device Date: Thu, 19 Oct 2023 16:40:16 +0100 Message-Id: <20231019154020.99080-21-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: 1697730085436100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse I can't see how this has ever worked. If I start with the simple attempt "-nic user,model=3Dxen", it creates a device with index -1 because it's assuming that it'll be attached to a hubport. So it creates a frontend at e.g. "/local/domain/84/device/vif/-1" and the guest fails to connect. If I jump through hoops to give it a configuration that it might like: -netdev user,id=3Dusernic -netdev hubport,hubid=3D0,id=3Dhub0,netdev=3Dusernic -nic,hubport,hubid=3D0,model=3Dxen ... it *still* doesn't work. Qemu does actually use a slightly more sensible index in the XenStore frontend path now, and the guest does manage to connect to it. But on the Qemu side, the NIC still isn't actually *attached* to the netdev: qemu-system-x86_64: warning: hub port #net036 has no peer qemu-system-x86_64: warning: hub 0 with no nics qemu-system-x86_64: warning: netdev #net036 has no peer qemu-system-x86_64: warning: requested NIC (anonymous, model xen) was not c= reated (not supported by this machine?) I can't see any point in the git history where the xen-nic driver would actually look at that "handle" property, find the right netdev, and actually *attach* the emulated NIC to anything. Just rip out the special XenStore magic and instantiate a xen-net-device on the XenBus. It all works now. Accept "model=3Dxen-net-device" because that's the actual Qemu device name and that's what works on HVM & emu. Also accept model=3D=3DNULL because why in $DEITY's name was that excluded before anyway? What else are we doing to do for *PV* guests? Signed-off-by: David Woodhouse --- hw/xen/xen_devconfig.c | 28 ++++++---------------------- hw/xenpv/xen_machine_pv.c | 13 ++++++++----- include/hw/xen/xen-legacy-backend.h | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/hw/xen/xen_devconfig.c b/hw/xen/xen_devconfig.c index 3f77c675c6..d72bac38e7 100644 --- a/hw/xen/xen_devconfig.c +++ b/hw/xen/xen_devconfig.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/xen/xen-legacy-backend.h" #include "qemu/option.h" #include "sysemu/blockdev.h" @@ -46,29 +47,12 @@ static int xen_config_dev_all(char *fe, char *be) =20 /* ------------------------------------------------------------- */ =20 -int xen_config_dev_nic(NICInfo *nic) +int xen_config_dev_nic(BusState *xen_bus, NICInfo *nic) { - char fe[256], be[256]; - char mac[20]; - int vlan_id =3D -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=3D\"%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); + DeviceState *dev =3D qdev_new("xen-net-device"); + qdev_set_nic_properties(dev, nic); + qdev_realize_and_unref(dev, xen_bus, &error_fatal); + return 0; } =20 int xen_config_dev_vfb(int vdev, const char *type) diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c index 9f9f137f99..3d3a87e416 100644 --- a/hw/xenpv/xen_machine_pv.c +++ b/hw/xenpv/xen_machine_pv.c @@ -32,6 +32,7 @@ =20 static void xen_init_pv(MachineState *machine) { + BusState *xen_bus; int i; =20 setup_xen_backend_ops(); @@ -62,15 +63,17 @@ static void xen_init_pv(MachineState *machine) vga_interface_created =3D true; } =20 + xen_bus =3D xen_bus_init(); + /* configure nics */ for (i =3D 0; i < nb_nics; i++) { - if (!nd_table[i].model || 0 !=3D strcmp(nd_table[i].model, "xen")) - continue; - xen_config_dev_nic(nd_table + i); + if (!nd_table[i].model || + g_str_equal(nd_table[i].model, "xen") || + g_str_equal(nd_table[i].model, "xen-net-device")) { + xen_config_dev_nic(xen_bus, nd_table + i); + } } =20 - xen_bus_init(); - /* config cleanup hook */ atexit(xen_config_cleanup); } diff --git a/include/hw/xen/xen-legacy-backend.h b/include/hw/xen/xen-legac= y-backend.h index fc42146bc2..01cab3a35e 100644 --- a/include/hw/xen/xen-legacy-backend.h +++ b/include/hw/xen/xen-legacy-backend.h @@ -81,7 +81,7 @@ extern struct XenDevOps xen_usb_ops; /* xen-usb.= c */ =20 /* configuration (aka xenbus setup) */ void xen_config_cleanup(void); -int xen_config_dev_nic(NICInfo *nic); +int xen_config_dev_nic(BusState *xen_bus, 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); --=20 2.40.1