From nobody Fri May 17 06:43:32 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=1681325515; cv=none; d=zohomail.com; s=zohoarc; b=lu+lRCqyJFRqTnfWmuy7I12h3AcG1+Zp0p5heq3BOTMOxdZwstn+rg8WUctWLj2t1RHlV1hoVnQRNKnRWmPsdXi+Mbj+3YI8Cz0Y0uhPPbLM/bpQ/8yDkqZhA2QSllkV93rd0lDVgHdClOFhimMCH3C1oTSuIjcqev2sg4wMEII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681325515; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tO8ebQO7hdBkDVSP4r+H8wDgeYM8ejzEVuKZ0cLSybE=; b=W6BALydq4UQ2L+xLw5Ce0tTEhPyB/DI2Y69S9vD5hx4G1Usmdkm+wThUIucpNMFCIkhmKgfDpVtjNn7GL6al90A68Iq0lrEhvnVsoPLuBxtFpBHwPQxxVLOBi84h9Fi0nx3vog89SqQYLsB3CVyGldIAMWS+VhA2Gx+OkwUumPs= 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 1681325515474288.750366074006; Wed, 12 Apr 2023 11:51:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520314.807785 (Exim 4.92) (envelope-from ) id 1pmfYw-0002bs-MT; Wed, 12 Apr 2023 18:51:22 +0000 Received: by outflank-mailman (output) from mailman id 520314.807785; Wed, 12 Apr 2023 18:51:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmfYw-0002bj-Jl; Wed, 12 Apr 2023 18:51:22 +0000 Received: by outflank-mailman (input) for mailman id 520314; Wed, 12 Apr 2023 18:51:20 +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 1pmfYu-0001qk-QE for xen-devel@lists.xenproject.org; Wed, 12 Apr 2023 18:51:20 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 00cacccc-d963-11ed-8611-37d641c3527e; Wed, 12 Apr 2023 20:51:15 +0200 (CEST) Received: from [2001:8b0:10b:5::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pmfYf-0077lC-4l; Wed, 12 Apr 2023 18:51:05 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYe-001r1E-1o; Wed, 12 Apr 2023 19:51:04 +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: 00cacccc-d963-11ed-8611-37d641c3527e 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=tO8ebQO7hdBkDVSP4r+H8wDgeYM8ejzEVuKZ0cLSybE=; b=XNrj8BMABVv6sUMXdtjglSDnX8 3vqc0BHSKUVoTm4KdYsPLXfvX4sg8NBLll2N3jWqzzy1XjtXhTso4UClv3zK+Wo/lXaWTIKROWAXk n8V6T9UBtmYBSg9NMdsP7hiQhPxZoolCMSUzWdMFVrb/wHfVc4To4//Se0e86u8oU9+t4hyPezTbH f5MJasfK2wQfTiJs7w5l/hYZYx2CDcsMh7Hwr5uho1w8CUdyi62f2QwEgOT7RJLjBRi8CwnVD9JNN 4T2rynFSIcpVIvoF02xBSckWGDbUY0yH2mpFcVj7EgK7zOJFQpvAXN7f/sN77jA/1LGpvocufAjv5 3J7SUvwQ==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: no Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH 1/5] hw/xen: Simplify emulated Xen platform init Date: Wed, 12 Apr 2023 19:50:58 +0100 Message-Id: <20230412185102.441523-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412185102.441523-1-dwmw2@infradead.org> References: <20230412185102.441523-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: 1681325515973100007 Content-Type: text/plain; charset="utf-8" From: David Woodhouse I initially put the basic platform init (overlay pages, grant tables, event channels) into mc->kvm_type because that was the earliest place that could sensibly test for xen_mode=3D=3DXEN_EMULATE. The intent was to do this early enough that we could then initialise the XenBus and other parts which would have depended on them, from a generic location for both Xen and KVM/Xen in the PC-specific code, as seen in https://lore.kernel.org/qemu-devel/20230116221919.1124201-16-dwmw2@infradea= d.org/ However, then the Xen on Arm patches came along, and *they* wanted to do the XenBus init from a 'generic' Xen-specific location instead: https://lore.kernel.org/qemu-devel/20230210222729.957168-4-sstabellini@kern= el.org/ Since there's no generic location that covers all three, I conceded to do it for XEN_EMULATE mode in pc_basic_devices_init(). And now there's absolutely no point in having some of the platform init done from pc_machine_kvm_type(); we can move it all up to live in a single place in pc_basic_devices_init(). This has the added benefit that we can drop the separate xen_evtchn_connect_gsis() function completely, and pass just the system GSIs in directly to xen_evtchn_create(). While I'm at it, it does no harm to explicitly pass in the *number* of said GSIs, because it does make me twitch a bit to pass an array of impicit size. During the lifetime of the KVM/Xen patchset, that had already changed (albeit just cosmetically) from GSI_NUM_PINS to IOAPIC_NUM_PINS. And document a bit better that this is for the *output* GSI for raising CPU0's events when the per-CPU vector isn't available. The fact that we create a whole set of them and then only waggle the one we're told to, instead of having a single output and only *connecting* it to the GSI that it should be connected to, is still non-intuitive for me. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/kvm/xen_evtchn.c | 40 ++++++++++++++++++++-------------------- hw/i386/kvm/xen_evtchn.h | 3 +-- hw/i386/pc.c | 13 ++++--------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c index 3048329474..3d810dbd59 100644 --- a/hw/i386/kvm/xen_evtchn.c +++ b/hw/i386/kvm/xen_evtchn.c @@ -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; =20 struct xenevtchn_handle *be_handles[EVTCHN_2L_NR_CHANNELS]; =20 @@ -299,7 +302,7 @@ static void gsi_assert_bh(void *opaque) } } =20 -void xen_evtchn_create(void) +void xen_evtchn_create(unsigned int nr_gsis, qemu_irq *system_gsis) { XenEvtchnState *s =3D XEN_EVTCHN(sysbus_create_simple(TYPE_XEN_EVTCHN, -1, NULL)); @@ -310,8 +313,19 @@ void xen_evtchn_create(void) qemu_mutex_init(&s->port_lock); s->gsi_bh =3D aio_bh_new(qemu_get_aio_context(), gsi_assert_bh, s); =20 - for (i =3D 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 =3D nr_gsis; + s->callback_gsis =3D g_new0(qemu_irq, nr_gsis); + for (i =3D 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]); } =20 /* @@ -336,20 +350,6 @@ void xen_evtchn_create(void) xen_evtchn_ops =3D &emu_evtchn_backend_ops; } =20 -void xen_evtchn_connect_gsis(qemu_irq *system_gsis) -{ - XenEvtchnState *s =3D xen_evtchn_singleton; - int i; - - if (!s) { - return; - } - - for (i =3D 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); @@ -430,8 +430,8 @@ void xen_evtchn_set_callback_level(int level) return; } =20 - 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(); diff --git a/hw/i386/kvm/xen_evtchn.h b/hw/i386/kvm/xen_evtchn.h index bfb67ac2bc..b740acfc0d 100644 --- a/hw/i386/kvm/xen_evtchn.h +++ b/hw/i386/kvm/xen_evtchn.h @@ -16,10 +16,9 @@ =20 typedef uint32_t evtchn_port_t; =20 -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); =20 int xen_evtchn_set_port(uint16_t port); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 1489abf010..25584cb8f3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1319,7 +1319,10 @@ void pc_basic_device_init(struct PCMachineState *pcm= s, =20 #ifdef CONFIG_XEN_EMU if (xen_mode =3D=3D 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"); } @@ -1868,14 +1871,6 @@ static void pc_machine_initfn(Object *obj) =20 int pc_machine_kvm_type(MachineState *machine, const char *kvm_type) { -#ifdef CONFIG_XEN_EMU - if (xen_mode =3D=3D XEN_EMULATE) { - xen_overlay_create(); - xen_evtchn_create(); - xen_gnttab_create(); - xen_xenstore_create(); - } -#endif return 0; } =20 --=20 2.39.2 From nobody Fri May 17 06:43:32 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=1681325514; cv=none; d=zohomail.com; s=zohoarc; b=dNJrMClWsUMF4OGaNLwwecSsZSTqHmgLjAYFsWT2URaD+L8964WE5LspSFyuHvdRztXUgFPRv+p9FaK0vt1zrqTV+ukYRvPh99NGMWoUcSoQG3VjKVdQLJg6xn+lcK5veur+IKUulpSgsI4HkbhSPI8BzFHPKV9rcPxuSCWpnho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681325514; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xa7ooeKNSf+k8dNFDJzvKocJu/52pawuc5iQqeYJl9c=; b=GnKAf5TFgDPG4jwYDe+EWHT7/DJ1Qs1ByYH0tO3uLq+OWKSIyIh9+udnftPmuJBufjg3J59jN63qg7mEIcUpVxn25XBh+kBVqCH+aJX+JSzq39QL9yBKiv9/MgS+DkplQplvxCWG8p10qtESWvKfQtycTDGwDvkjYcVkW7VJy7Q= 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 168132551371664.46070036781055; Wed, 12 Apr 2023 11:51:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520315.807794 (Exim 4.92) (envelope-from ) id 1pmfYy-0002tS-UA; Wed, 12 Apr 2023 18:51:24 +0000 Received: by outflank-mailman (output) from mailman id 520315.807794; Wed, 12 Apr 2023 18:51:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmfYy-0002tL-RD; Wed, 12 Apr 2023 18:51:24 +0000 Received: by outflank-mailman (input) for mailman id 520315; Wed, 12 Apr 2023 18:51:24 +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 1pmfYx-0001qS-Kg for xen-devel@lists.xenproject.org; Wed, 12 Apr 2023 18:51:24 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 045f501b-d963-11ed-b21e-6b7b168915f2; Wed, 12 Apr 2023 20:51:22 +0200 (CEST) Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYf-00E0VL-3D; Wed, 12 Apr 2023 18:51:06 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYe-001r1H-1y; Wed, 12 Apr 2023 19:51:04 +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: 045f501b-d963-11ed-b21e-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=Xa7ooeKNSf+k8dNFDJzvKocJu/52pawuc5iQqeYJl9c=; b=nxQF+PYllY75sHqovcNk2BH4Gi RpVSWDgHzGp6LR/J9XHEZ/8NcMhK+wvi2yYuhn1/gaMykPZ42EuBEZDwbpl+7j+9ffR82KtYbpKHp jDMpMfdHfLyMA6cWiFQ9a+98ywwxU3E4Ks45R78pIEPXpoIkT8fg91nyZVcDyzekRslNMu+N3+Dmi vWtqtkYz9VGIPOJ6qJHf/pF+xK8y0jdGcEwCDtzTR1tSBnHGNjIVmY6iljd5SJMmR7UXzcXXwRDsC ZEJtD3rZKBTKNS1GAyETt1GMxjt9mnIJoRAy5zmBRb9118HdiHPaxBwJA1NYFEIvolFPS+Z3L+hAX p3eq+52w==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: no Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH 2/5] hw/xen: Fix memory leak in libxenstore_open() for Xen Date: Wed, 12 Apr 2023 19:50:59 +0100 Message-Id: <20230412185102.441523-3-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412185102.441523-1-dwmw2@infradead.org> References: <20230412185102.441523-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1681325514529100003 Content-Type: text/plain; charset="utf-8" From: David Woodhouse There was a superfluous allocation of the XS handle, leading to it being leaked on both the error path and the success path (where it gets allocated again). Spotted by Coverity (CID 1508098). Fixes: ba2a92db1ff6 ("hw/xen: Add xenstore operations to allow redirection = to internal emulation") Suggested-by: Peter Maydell Signed-off-by: David Woodhouse Reviewed-by: Peter Maydell Reviewed-by: Paul Durrant --- hw/xen/xen-operations.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c index 4b78fbf4bd..3d213d28df 100644 --- a/hw/xen/xen-operations.c +++ b/hw/xen/xen-operations.c @@ -287,7 +287,7 @@ static void watch_event(void *opaque) static struct qemu_xs_handle *libxenstore_open(void) { struct xs_handle *xsh =3D xs_open(0); - struct qemu_xs_handle *h =3D g_new0(struct qemu_xs_handle, 1); + struct qemu_xs_handle *h; =20 if (!xsh) { return NULL; --=20 2.39.2 From nobody Fri May 17 06:43:32 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=1681325513; cv=none; d=zohomail.com; s=zohoarc; b=PyWcQLi0zt8+TrZKIJbT/MpC9anf880/NeF0AEZIR7AmaXWEiceFTMx0+OrqCtCPCPiGMg++NEpbt/1Z/H4adSEeFJjxK7zPdoRpe/Bq0Q2nJXyanZ7n0f4cwcVD/SLeP26EuJ9IunQdYu8ROMDWNIA9RLsFw30UhgYiNqgvscI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681325513; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r0KrVFy8wO5hkkGDmOWYariQi9uMlzauvQswU3PX06g=; b=ViT/TJLI5HlTsD4hkRTwyORmxm3KgQ3Yh4aBv4KOhDtaWEmd1w0sIPAwejpQ+w8yVs0U/PLEWl+qPW4LX3YQH4NGazAFyE+buihN8l8I2ZALLD61Ltj7otw6Qcc9cw9g7g5G5m3UOGG+7pspB1e7IAk8jNUa+onTNiv0267toQ8= 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 168132551253045.16955909251362; Wed, 12 Apr 2023 11:51:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520316.807805 (Exim 4.92) (envelope-from ) id 1pmfZ0-0003AM-7z; Wed, 12 Apr 2023 18:51:26 +0000 Received: by outflank-mailman (output) from mailman id 520316.807805; Wed, 12 Apr 2023 18:51:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmfZ0-00039k-42; Wed, 12 Apr 2023 18:51:26 +0000 Received: by outflank-mailman (input) for mailman id 520316; Wed, 12 Apr 2023 18:51:24 +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 1pmfYy-0001qS-Ki for xen-devel@lists.xenproject.org; Wed, 12 Apr 2023 18:51:24 +0000 Received: from desiato.infradead.org (desiato.infradead.org [2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04a6bb6f-d963-11ed-b21e-6b7b168915f2; Wed, 12 Apr 2023 20:51:22 +0200 (CEST) Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYg-00E0VM-03; Wed, 12 Apr 2023 18:51:06 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYe-001r1N-2D; Wed, 12 Apr 2023 19:51:04 +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: 04a6bb6f-d963-11ed-b21e-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=r0KrVFy8wO5hkkGDmOWYariQi9uMlzauvQswU3PX06g=; b=ksJ5J0ZCaGPS+w9bWo3qQ38f/f 5dx1E09HdQlfCQ7zAQv5t2wDpola+fKSQIlh1VljOSAovETc/RoDS2hP3KrOuLWG9duJ5tX9z9DaW taNp+hP4l9lhhhObZc8K4m8DgnbwxhK9vx6czSEsBsDqOXqeXUDOEh28woBd+9HCM1BEPGXEaYzoV l8v2T/LFJWOzVC1kPWOvBjP7dR8xE41+HAp7IxxgMcgQzxkCQXqYiF9Rx2XJqYn6KM1GSM3i8zmw9 2DVadTK32LRFcm29UdnVR0tSfHTiHb1bXNHb8L4WHF7YnzgGmkL7bxff29Izie8M7mcFw9H83AOyG 9x+LnoVg==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: no Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH 3/5] xen: Drop support for Xen versions below 4.7.1 Date: Wed, 12 Apr 2023 19:51:00 +0100 Message-Id: <20230412185102.441523-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412185102.441523-1-dwmw2@infradead.org> References: <20230412185102.441523-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 desiato.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1681325514182100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse In restructuring to allow for internal emulation of Xen functionality, I broke compatibility for Xen 4.6 and earlier. Fix this by explicitly removing support for anything older than 4.7.1, which is also ancient but it does still build, and the compatibility support for it is fairly unintrusive. Fixes: 15e283c5b684 ("hw/xen: Add foreignmem operations to allow redirectio= n to internal emulation") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/xen/xen-operations.c | 57 +------------------ include/hw/xen/xen_native.h | 107 +----------------------------------- meson.build | 5 +- scripts/xen-detect.c | 60 -------------------- 4 files changed, 3 insertions(+), 226 deletions(-) diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c index 3d213d28df..e00983ec44 100644 --- a/hw/xen/xen-operations.c +++ b/hw/xen/xen-operations.c @@ -28,46 +28,13 @@ #include =20 /* - * We don't support Xen prior to 4.2.0. + * We don't support Xen prior to 4.7.1. */ =20 -/* Xen 4.2 through 4.6 */ -#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701 - -typedef xc_evtchn xenevtchn_handle; -typedef evtchn_port_or_error_t xenevtchn_port_or_error_t; - -#define xenevtchn_open(l, f) xc_evtchn_open(l, f); -#define xenevtchn_close(h) xc_evtchn_close(h) -#define xenevtchn_fd(h) xc_evtchn_fd(h) -#define xenevtchn_pending(h) xc_evtchn_pending(h) -#define xenevtchn_notify(h, p) xc_evtchn_notify(h, p) -#define xenevtchn_bind_interdomain(h, d, p) xc_evtchn_bind_interdomain(h, = d, p) -#define xenevtchn_unmask(h, p) xc_evtchn_unmask(h, p) -#define xenevtchn_unbind(h, p) xc_evtchn_unbind(h, p) - -typedef xc_gnttab xengnttab_handle; - -#define xengnttab_open(l, f) xc_gnttab_open(l, f) -#define xengnttab_close(h) xc_gnttab_close(h) -#define xengnttab_set_max_grants(h, n) xc_gnttab_set_max_grants(h, n) -#define xengnttab_map_grant_ref(h, d, r, p) xc_gnttab_map_grant_ref(h, d, = r, p) -#define xengnttab_unmap(h, a, n) xc_gnttab_munmap(h, a, n) -#define xengnttab_map_grant_refs(h, c, d, r, p) \ - xc_gnttab_map_grant_refs(h, c, d, r, p) -#define xengnttab_map_domain_grant_refs(h, c, d, r, p) \ - xc_gnttab_map_domain_grant_refs(h, c, d, r, p) - -typedef xc_interface xenforeignmemory_handle; - -#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40701 */ - #include #include #include =20 -#endif - /* Xen before 4.8 */ =20 static int libxengnttab_fallback_grant_copy(xengnttab_handle *xgt, @@ -223,26 +190,6 @@ static struct gnttab_backend_ops libxengnttab_backend_= ops =3D { .unmap =3D libxengnttab_backend_unmap, }; =20 -#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701 - -static void *libxenforeignmem_backend_map(uint32_t dom, void *addr, int pr= ot, - size_t pages, xfn_pfn_t *pfns, - int *errs) -{ - if (errs) { - return xc_map_foreign_bulk(xen_xc, dom, prot, pfns, errs, pages); - } else { - return xc_map_foreign_pages(xen_xc, dom, prot, pfns, pages); - } -} - -static int libxenforeignmem_backend_unmap(void *addr, size_t pages) -{ - return munmap(addr, pages * XC_PAGE_SIZE); -} - -#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40701 */ - static void *libxenforeignmem_backend_map(uint32_t dom, void *addr, int pr= ot, size_t pages, xen_pfn_t *pfns, int *errs) @@ -256,8 +203,6 @@ static int libxenforeignmem_backend_unmap(void *addr, s= ize_t pages) return xenforeignmemory_unmap(xen_fmem, addr, pages); } =20 -#endif - struct foreignmem_backend_ops libxenforeignmem_backend_ops =3D { .map =3D libxenforeignmem_backend_map, .unmap =3D libxenforeignmem_backend_unmap, diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h index 6bcc83baf9..f11eb423e3 100644 --- a/include/hw/xen/xen_native.h +++ b/include/hw/xen/xen_native.h @@ -24,23 +24,11 @@ extern xc_interface *xen_xc; =20 /* - * We don't support Xen prior to 4.2.0. + * We don't support Xen prior to 4.7.1. */ =20 -/* Xen 4.2 through 4.6 */ -#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701 - -typedef xc_interface xenforeignmemory_handle; - -#define xenforeignmemory_open(l, f) xen_xc -#define xenforeignmemory_close(h) - -#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40701 */ - #include =20 -#endif - extern xenforeignmemory_handle *xen_fmem; =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40900 @@ -148,8 +136,6 @@ static inline xendevicemodel_handle *xendevicemodel_ope= n( return xen_xc; } =20 -#if CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40500 - static inline int xendevicemodel_create_ioreq_server( xendevicemodel_handle *dmod, domid_t domid, int handle_bufioreq, ioservid_t *id) @@ -211,8 +197,6 @@ static inline int xendevicemodel_set_ioreq_server_state( return xc_hvm_set_ioreq_server_state(dmod, domid, id, enabled); } =20 -#endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40500 */ - static inline int xendevicemodel_set_pci_intx_level( xendevicemodel_handle *dmod, domid_t domid, uint16_t segment, uint8_t bus, uint8_t device, uint8_t intx, unsigned int level) @@ -340,15 +324,6 @@ static inline int xen_get_vmport_regs_pfn(xc_interface= *xc, domid_t dom, } #endif =20 -/* Xen before 4.6 */ -#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40600 - -#ifndef HVM_IOREQSRV_BUFIOREQ_ATOMIC -#define HVM_IOREQSRV_BUFIOREQ_ATOMIC 2 -#endif - -#endif - static inline int xen_get_default_ioreq_server_info(domid_t dom, xen_pfn_t *ioreq_pfn, xen_pfn_t *bufioreq_pf= n, @@ -386,84 +361,6 @@ static inline int xen_get_default_ioreq_server_info(do= mid_t dom, return 0; } =20 -/* Xen before 4.5 */ -#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40500 - -#ifndef HVM_PARAM_BUFIOREQ_EVTCHN -#define HVM_PARAM_BUFIOREQ_EVTCHN 26 -#endif - -#define IOREQ_TYPE_PCI_CONFIG 2 - -typedef uint16_t ioservid_t; - -static inline void xen_map_memory_section(domid_t dom, - ioservid_t ioservid, - MemoryRegionSection *section) -{ -} - -static inline void xen_unmap_memory_section(domid_t dom, - ioservid_t ioservid, - MemoryRegionSection *section) -{ -} - -static inline void xen_map_io_section(domid_t dom, - ioservid_t ioservid, - MemoryRegionSection *section) -{ -} - -static inline void xen_unmap_io_section(domid_t dom, - ioservid_t ioservid, - MemoryRegionSection *section) -{ -} - -static inline void xen_map_pcidev(domid_t dom, - ioservid_t ioservid, - PCIDevice *pci_dev) -{ -} - -static inline void xen_unmap_pcidev(domid_t dom, - ioservid_t ioservid, - PCIDevice *pci_dev) -{ -} - -static inline void xen_create_ioreq_server(domid_t dom, - ioservid_t *ioservid) -{ -} - -static inline void xen_destroy_ioreq_server(domid_t dom, - ioservid_t ioservid) -{ -} - -static inline int xen_get_ioreq_server_info(domid_t dom, - ioservid_t ioservid, - xen_pfn_t *ioreq_pfn, - xen_pfn_t *bufioreq_pfn, - evtchn_port_t *bufioreq_evtchn) -{ - return xen_get_default_ioreq_server_info(dom, ioreq_pfn, - bufioreq_pfn, - bufioreq_evtchn); -} - -static inline int xen_set_ioreq_server_state(domid_t dom, - ioservid_t ioservid, - bool enable) -{ - return 0; -} - -/* Xen 4.5 */ -#else - static bool use_default_ioreq_server; =20 static inline void xen_map_memory_section(domid_t dom, @@ -624,6 +521,4 @@ static inline int xen_set_ioreq_server_state(domid_t do= m, enable); } =20 -#endif - #endif /* QEMU_HW_XEN_NATIVE_H */ diff --git a/meson.build b/meson.build index c44d05a13f..1f223ae7fc 100644 --- a/meson.build +++ b/meson.build @@ -1425,16 +1425,13 @@ if get_option('xen').enabled() or (get_option('xen'= ).auto() and have_system) endif endif if not xen.found() - xen_tests =3D [ '4.11.0', '4.10.0', '4.9.0', '4.8.0', '4.7.1', '4.6.0'= , '4.5.0', '4.2.0' ] + xen_tests =3D [ '4.11.0', '4.10.0', '4.9.0', '4.8.0', '4.7.1' ] xen_libs =3D { '4.11.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemo= ry', 'xengnttab', 'xenevtchn', 'xentoolcore' ], '4.10.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemo= ry', 'xengnttab', 'xenevtchn', 'xentoolcore' ], '4.9.0': [ 'xenstore', 'xenctrl', 'xendevicemodel', 'xenforeignmemor= y', 'xengnttab', 'xenevtchn' ], '4.8.0': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', '= xenevtchn' ], '4.7.1': [ 'xenstore', 'xenctrl', 'xenforeignmemory', 'xengnttab', '= xenevtchn' ], - '4.6.0': [ 'xenstore', 'xenctrl' ], - '4.5.0': [ 'xenstore', 'xenctrl' ], - '4.2.0': [ 'xenstore', 'xenctrl' ], } xen_deps =3D {} foreach ver: xen_tests diff --git a/scripts/xen-detect.c b/scripts/xen-detect.c index 85e8206490..db049e605c 100644 --- a/scripts/xen-detect.c +++ b/scripts/xen-detect.c @@ -138,66 +138,6 @@ return 0; } =20 -#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40600 - #include - #include - #include - #include - #if !defined(HVM_MAX_VCPUS) - # error HVM_MAX_VCPUS not defined - #endif - int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - xc_reserved_device_memory_map(xc, 0, 0, 0, 0, NULL, 0); - return 0; - } - -#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40500 - #include - #include - #include - #include - #if !defined(HVM_MAX_VCPUS) - # error HVM_MAX_VCPUS not defined - #endif - int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - xc_hvm_create_ioreq_server(xc, 0, 0, NULL); - return 0; - } - -#elif CONFIG_XEN_CTRL_INTERFACE_VERSION =3D=3D 40200 - #include - #include - #include - #include - #if !defined(HVM_MAX_VCPUS) - # error HVM_MAX_VCPUS not defined - #endif - int main(void) { - xc_interface *xc; - xs_daemon_open(); - xc =3D xc_interface_open(0, 0, 0); - xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); - xc_gnttab_open(NULL, 0); - xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); - xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); - return 0; - } - #else #error invalid CONFIG_XEN_CTRL_INTERFACE_VERSION #endif --=20 2.39.2 From nobody Fri May 17 06:43:32 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=1681325513; cv=none; d=zohomail.com; s=zohoarc; b=ROP8YJ6/I5dwYP57q0VMy6zTq6VeGKrZoy95QzHCOxvDG+ygMYJ9dlfME9fFh70GQWw0rEgk6ra/GNg5tw3w1aHQfqEvbPHNtc8yrXApn4A2neWt6Z5P2I5KeC2QW+IjOSVSOfBJWMe73YbypgjvhPeEksQiTEQ7+sX7pCe8t3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681325513; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pvefxXf1YhjL3JSf+V8JRgGjqQjxWW3E4QNSUXU8Vyk=; b=VEGdhyUea24awQ/dRFUo9vhqqhmtGa9pKCTM1VOEDQsn/MqtcmtpcSR1LX/hDd10HEx3GYUJr7KdQ6rgnOByvNxNv1+6q7E38f1ORUyMhl/TUqGWeL4fcpORjwdS3AUhUAMYC8jBGj2bNoy6Cy3ACgBH0EUqKlfsGDR/ODOV13Q= 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 1681325513835665.8342646911951; Wed, 12 Apr 2023 11:51:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520312.807765 (Exim 4.92) (envelope-from ) id 1pmfYu-00025d-2G; Wed, 12 Apr 2023 18:51:20 +0000 Received: by outflank-mailman (output) from mailman id 520312.807765; Wed, 12 Apr 2023 18:51:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmfYt-00025V-Ub; Wed, 12 Apr 2023 18:51:19 +0000 Received: by outflank-mailman (input) for mailman id 520312; Wed, 12 Apr 2023 18:51:19 +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 1pmfYt-0001qk-4D for xen-devel@lists.xenproject.org; Wed, 12 Apr 2023 18:51:19 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 00c6275a-d963-11ed-8611-37d641c3527e; Wed, 12 Apr 2023 20:51:15 +0200 (CEST) Received: from [2001:8b0:10b:5::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pmfYf-0077lE-7x; Wed, 12 Apr 2023 18:51:06 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYe-001r1R-2I; Wed, 12 Apr 2023 19:51:04 +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: 00c6275a-d963-11ed-8611-37d641c3527e 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=pvefxXf1YhjL3JSf+V8JRgGjqQjxWW3E4QNSUXU8Vyk=; b=TjPE0dW5/ekjTjDaeeWQk5fUJV nNUgr4r4gwcl33okRN07A5zJwF7Q0B4b01PnDXOtfu3v7VarXGfsZZNSPBiwmIfLc2EdIZ2EGBo4o QTqoNs4SeLgJml9Y/6rUfD8FuNIh2wI+nWzJS/7XYaEwpMo+wj7PQJ9f5m1MKj8o0U6AFB1l5km3X rElR8Zf42jdPGjQ1hHcqk1DSpdw5yW/z9RBJwQGSUYukk2JFnGU7rFkK9jtVNSx3ySS6kedTvELwC pvVDHGxtrOnUPo8v7MBvIwMGNL0HzMnLXSZ8RfjifLwUOnrHdF05EhNKDHsy1O0kxGie2f4iVThoa QyhSoxew==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: no Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH 4/5] hw/xen: Fix double-free in xen_console store_con_info() Date: Wed, 12 Apr 2023 19:51:01 +0100 Message-Id: <20230412185102.441523-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412185102.441523-1-dwmw2@infradead.org> References: <20230412185102.441523-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: 1681325515907100005 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Coverity spotted a double-free (CID 1508254); we g_string_free(path) and then for some reason immediately call free(path) too. We should just use g_autoptr() for it anyway, which simplifies the code a bit. Fixes: 7a8a749da7d3 ("hw/xen: Move xenstore_store_pv_console_info to xen_co= nsole.c") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant Reviewed-by: Peter Maydell --- hw/char/xen_console.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index c7a19c0e7c..810dae3f44 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -178,8 +178,7 @@ static int store_con_info(struct XenConsole *con) Chardev *cs =3D qemu_chr_fe_get_driver(&con->chr); char *pts =3D NULL; char *dom_path; - GString *path; - int ret =3D -1; + g_autoptr(GString) path =3D NULL; =20 /* Only continue if we're talking to a pty. */ if (!CHARDEV_IS_PTY(cs)) { @@ -204,15 +203,9 @@ static int store_con_info(struct XenConsole *con) =20 if (xenstore_write_str(con->console, path->str, pts)) { fprintf(stderr, "xenstore_write_str for '%s' fail", path->str); - goto out; + return -1; } - ret =3D 0; - -out: - g_string_free(path, true); - free(path); - - return ret; + return 0; } =20 static int con_init(struct XenLegacyDevice *xendev) --=20 2.39.2 From nobody Fri May 17 06:43:32 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=1681325511; cv=none; d=zohomail.com; s=zohoarc; b=FPFR7mBOhYoQgSHs0vZ5HZ5SLDgDumzVNY32LnY3Rga2l0Nt+J011+Hiwe19YifINFUZINd3dA+v0fSw/u63mTlzSSt/fgzMH89zsaxgrdIZ/xAqZcaxWs1qR/W+P+B0lkQXyywHQywYMSJKu4GXF0SEbtWqnmB/I1C8FXmjLz0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681325511; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NIk/dSGE1S/XkSMWglE5vSkIy2Aotr95wrmjXgO3qTE=; b=dcIj/9mG5HCQ9iaG0Xk8b6+P5ctdF2BeyWozLlOHXi7bEaYz39teTW2G4ZY+UP7C7aQkMsJxvA8fn5J2+gcYLqoV/WmHrOe9UPY/B0srYn7tBIx9phks0VuOOkUSh9tkgDxM3jAC2GOA7V20F27KypXDlTEw5e0+tz+Cg9t2U+c= 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 1681325511465500.1744016929754; Wed, 12 Apr 2023 11:51:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520313.807775 (Exim 4.92) (envelope-from ) id 1pmfYv-0002Lv-E3; Wed, 12 Apr 2023 18:51:21 +0000 Received: by outflank-mailman (output) from mailman id 520313.807775; Wed, 12 Apr 2023 18:51:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmfYv-0002Lk-BD; Wed, 12 Apr 2023 18:51:21 +0000 Received: by outflank-mailman (input) for mailman id 520313; Wed, 12 Apr 2023 18:51:19 +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 1pmfYt-0001qk-Q3 for xen-devel@lists.xenproject.org; Wed, 12 Apr 2023 18:51:19 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 00ceabaf-d963-11ed-8611-37d641c3527e; Wed, 12 Apr 2023 20:51:16 +0200 (CEST) Received: from [2001:8b0:10b:5::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pmfYf-0077lF-7n; Wed, 12 Apr 2023 18:51:05 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pmfYe-001r1V-2S; Wed, 12 Apr 2023 19:51:04 +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: 00ceabaf-d963-11ed-8611-37d641c3527e 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=NIk/dSGE1S/XkSMWglE5vSkIy2Aotr95wrmjXgO3qTE=; b=jjZUxe9t2zm5dC09PCwBEOxg1z joZy6jDOxzr1nMq4pNbcp3WLngm4pYpiqE8AoYSdmmYEq9kGeF6bv9Z2a4WWxpA7YiY0Xtz7jkDNZ VMLSp2/tDON07Uv3Yd4BFcaGPn27lWka2nduaqL3piYJyOoFIM7uSZqKzax8Kh6VsHdHz0zYgSqqO ILzM43hX1ULSuqD1DrDrzjbRoUwQetje20sfAqhL/5s+GMRopH8X5yY3w5y/cRZoRoZGcwy+b3i9P WZYW1Tl6JlHkIlCYN93JjtiITKBL2dr6Oz/qojqVcvQj/3dU01ZHLF4uYLj6QxJIzAGsOfpqp4I7B a9J7iXrQ==; From: David Woodhouse To: qemu-devel@nongnu.org Cc: no Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , xen-devel@lists.xenproject.org Subject: [PATCH 5/5] hw/xen: Fix broken check for invalid state in xs_be_open() Date: Wed, 12 Apr 2023 19:51:02 +0100 Message-Id: <20230412185102.441523-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230412185102.441523-1-dwmw2@infradead.org> References: <20230412185102.441523-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: 1681325511994100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Coverity points out that if (!s && !s->impl) isn't really what we intended to do here. CID 1508131. Fixes: 032475127225 ("hw/xen: Add emulated implementation of XenStore opera= tions") Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant Reviewed-by: Peter Maydell --- hw/i386/kvm/xen_xenstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index 900679af8a..65f91e87d7 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -1688,7 +1688,7 @@ static struct qemu_xs_handle *xs_be_open(void) XenXenstoreState *s =3D xen_xenstore_singleton; struct qemu_xs_handle *h; =20 - if (!s && !s->impl) { + if (!s || !s->impl) { errno =3D -ENOSYS; return NULL; } --=20 2.39.2