From nobody Wed Nov 27 04:57:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1700560726; cv=none; d=zohomail.com; s=zohoarc; b=fGvxHNLc/DmTshHfIpd2zn7Scol+ZeBPcBmCWU8q43cQTIFpjqvuJHHkU2NCu5Nb6uucNPMXRbD4eYbRzfHvhEn3xZggq7/SI0euB6GkjSLMjNz1e9KpHhK7AWAjG6arVkLsrXrlsb/mpbAwCjIPGeOrY0Vi7DGBCuXa57nm4HY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700560726; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r5/7B6Z9NrBDkrjuUHMM2ugc6hAW4PVpMEUoMC8o2nk=; b=P0iGB6VQUtLqACpOfqcNS45kMAwbkk1lTePVzA/EFr4BpDEU+24LyYUjEKLqsElp39no+gFXuhnzku+vAny38fx9wa8tYjqGPoID2oomdNqWCHOomFxvGOBkSWMQXsxlFG7S/wyzkeqcb3qS3E2YR6DWqSmCg9JPpTfmXh0rzl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700560726678544.0214789378501; Tue, 21 Nov 2023 01:58:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5NVv-0000oJ-Mz; Tue, 21 Nov 2023 04:57:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NVu-0000nV-7l for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NVr-0001Bm-Jd for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:49 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-rP3zIEdjMDuRBBmEJ8JclQ-1; Tue, 21 Nov 2023 04:57:45 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F35C51C05ECE; Tue, 21 Nov 2023 09:57:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65809492BE0; Tue, 21 Nov 2023 09:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700560667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r5/7B6Z9NrBDkrjuUHMM2ugc6hAW4PVpMEUoMC8o2nk=; b=FOxSH+BO50lV0TUaY5mxRhqjDC9HC7NWEHhhrV8VSkd8gpBwYHOhKy9GOBOwdQKm9wL2ho HDG0B1MGoQ4mf1xNsH64U1z+Yz5E9NJ+9dK8DBW7/uE0EZX9kbnlwiShSjIdYXNCXX/dyg i7/06VUYVhJQ++ehlQkZVefQ+6TxVLM= X-MC-Unique: rP3zIEdjMDuRBBmEJ8JclQ-1 From: Jason Wang To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Alexander Bulekov , Jason Wang Subject: [PULL 1/3] net: Provide MemReentrancyGuard * to qemu_new_nic() Date: Tue, 21 Nov 2023 17:57:35 +0800 Message-ID: <20231121095737.31438-2-jasowang@redhat.com> In-Reply-To: <20231121095737.31438-1-jasowang@redhat.com> References: <20231121095737.31438-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1700560728694100007 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device. In preparation for such a change, add MemReentrancyGuard * as a parameter of qemu_new_nic(). Signed-off-by: Akihiko Odaki Reviewed-by: Alexander Bulekov Signed-off-by: Jason Wang --- hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 3 ++- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- include/net/net.h | 1 + net/net.c | 1 + 40 files changed, 75 insertions(+), 40 deletions(-) diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c index fac4405..cc350d4 100644 --- a/hw/net/allwinner-sun8i-emac.c +++ b/hw/net/allwinner-sun8i-emac.c @@ -824,7 +824,8 @@ static void allwinner_sun8i_emac_realize(DeviceState *d= ev, Error **errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_allwinner_sun8i_emac_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c index 372e5b6..e10965d 100644 --- a/hw/net/allwinner_emac.c +++ b/hw/net/allwinner_emac.c @@ -453,7 +453,8 @@ static void aw_emac_realize(DeviceState *dev, Error **e= rrp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_aw_emac_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 fifo8_create(&s->rx_fifo, RX_FIFO_SIZE); diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index 19adbc0..296bba2 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -1743,7 +1743,8 @@ static void gem_realize(DeviceState *dev, Error **err= p) qemu_macaddr_default_if_unset(&s->conf.macaddr); =20 s->nic =3D qemu_new_nic(&net_gem_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); =20 if (s->jumbo_max_len > MAX_FRAME_SIZE) { error_setg(errp, "jumbo-max-len is greater than %d", diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index c6f5fb7..b16b18b 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -913,7 +913,8 @@ static void dp8393x_realize(DeviceState *dev, Error **e= rrp) "dp8393x-regs", SONIC_REG_COUNT << s->it_shift); =20 s->nic =3D qemu_new_nic(&net_dp83932_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 s->watchdog =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, dp8393x_watchdog, s); diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 548bcab..8ffe107 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -1666,7 +1666,8 @@ static void pci_e1000_realize(PCIDevice *pci_dev, Err= or **errp) macaddr); =20 d->nic =3D qemu_new_nic(&net_e1000_info, &d->conf, - object_get_typename(OBJECT(d)), dev->id, d); + object_get_typename(OBJECT(d)), dev->id, + &dev->mem_reentrancy_guard, d); =20 qemu_format_nic_info_str(qemu_get_queue(d->nic), macaddr); =20 diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index c384879..e41a6c1 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -320,7 +320,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev= , uint8_t *macaddr) int i; =20 s->nic =3D qemu_new_nic(&net_e1000e_info, &s->conf, - object_get_typename(OBJECT(s)), dev->id, s); + object_get_typename(OBJECT(s)), dev->id, &dev->mem_reentrancy_guar= d, s); =20 s->core.max_queue_num =3D s->conf.peers.queues ? s->conf.peers.queues = - 1 : 0; =20 diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 94ce9e1..69e1c4b 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1874,7 +1874,9 @@ static void e100_nic_realize(PCIDevice *pci_dev, Erro= r **errp) nic_reset(s); =20 s->nic =3D qemu_new_nic(&net_eepro100_info, &s->conf, - object_get_typename(OBJECT(pci_dev)), pci_dev->q= dev.id, s); + object_get_typename(OBJECT(pci_dev)), + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s); =20 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); TRACE(OTHER, logout("%s\n", qemu_get_queue(s->nic)->info_str)); diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index 1b82aec..ba57a97 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -618,7 +618,8 @@ static void etraxfs_eth_realize(DeviceState *dev, Error= **errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_etraxfs_info, &s->conf, - object_get_typename(OBJECT(s)), dev->id, s); + object_get_typename(OBJECT(s)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 s->phy.read =3D tdk_read; diff --git a/hw/net/fsl_etsec/etsec.c b/hw/net/fsl_etsec/etsec.c index 798ea33..00315f3 100644 --- a/hw/net/fsl_etsec/etsec.c +++ b/hw/net/fsl_etsec/etsec.c @@ -391,7 +391,8 @@ static void etsec_realize(DeviceState *dev, Error **err= p) eTSEC *etsec =3D ETSEC_COMMON(dev); =20 etsec->nic =3D qemu_new_nic(&net_etsec_info, &etsec->conf, - object_get_typename(OBJECT(dev)), dev->id, e= tsec); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, etsec); qemu_format_nic_info_str(qemu_get_queue(etsec->nic), etsec->conf.macad= dr.a); =20 etsec->ptimer =3D ptimer_init(etsec_timer_hit, etsec, PTIMER_POLICY_LE= GACY); diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c index 702b001..78e594a 100644 --- a/hw/net/ftgmac100.c +++ b/hw/net/ftgmac100.c @@ -1110,7 +1110,8 @@ static void ftgmac100_realize(DeviceState *dev, Error= **errp) qemu_macaddr_default_if_unset(&s->conf.macaddr); =20 s->nic =3D qemu_new_nic(&net_ftgmac100_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/i82596.c b/hw/net/i82596.c index 6defa9d..a907f0d 100644 --- a/hw/net/i82596.c +++ b/hw/net/i82596.c @@ -726,7 +726,7 @@ void i82596_common_init(DeviceState *dev, I82596State *= s, NetClientInfo *info) qemu_macaddr_default_if_unset(&s->conf.macaddr); } s->nic =3D qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev= )), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 if (USE_TIMER) { diff --git a/hw/net/igb.c b/hw/net/igb.c index dfb722b..8089acf 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -325,7 +325,7 @@ igb_init_net_peer(IGBState *s, PCIDevice *pci_dev, uint= 8_t *macaddr) int i; =20 s->nic =3D qemu_new_nic(&net_igb_info, &s->conf, - object_get_typename(OBJECT(s)), dev->id, s); + object_get_typename(OBJECT(s)), dev->id, &dev->mem_reentrancy_guar= d, s); =20 s->core.max_queue_num =3D s->conf.peers.queues ? s->conf.peers.queues = - 1 : 0; =20 diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index 5d1f1f1..6881e3e 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -1334,7 +1334,7 @@ static void imx_eth_realize(DeviceState *dev, Error *= *errp) =20 s->nic =3D qemu_new_nic(&imx_eth_net_info, &s->conf, object_get_typename(OBJECT(dev)), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s); =20 qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index e5c4af1..cf7b8c8 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -1361,7 +1361,8 @@ static void lan9118_realize(DeviceState *dev, Error *= *errp) qemu_macaddr_default_if_unset(&s->conf.macaddr); =20 s->nic =3D qemu_new_nic(&net_lan9118_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); s->eeprom[0] =3D 0xa5; for (i =3D 0; i < 6; i++) { diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c index ec3ddf5..e690271 100644 --- a/hw/net/mcf_fec.c +++ b/hw/net/mcf_fec.c @@ -643,7 +643,8 @@ static void mcf_fec_realize(DeviceState *dev, Error **e= rrp) mcf_fec_state *s =3D MCF_FEC_NET(dev); =20 s->nic =3D qemu_new_nic(&net_mcf_fec_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c index 2ade72d..8e925de 100644 --- a/hw/net/mipsnet.c +++ b/hw/net/mipsnet.c @@ -255,7 +255,8 @@ static void mipsnet_realize(DeviceState *dev, Error **e= rrp) sysbus_init_irq(sbd, &s->irq); =20 s->nic =3D qemu_new_nic(&net_mipsnet_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c index db3a04d..145a5e4 100644 --- a/hw/net/msf2-emac.c +++ b/hw/net/msf2-emac.c @@ -530,7 +530,8 @@ static void msf2_emac_realize(DeviceState *dev, Error *= *errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_msf2_emac_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/mv88w8618_eth.c b/hw/net/mv88w8618_eth.c index ef30b0d..2185f11 100644 --- a/hw/net/mv88w8618_eth.c +++ b/hw/net/mv88w8618_eth.c @@ -350,7 +350,8 @@ static void mv88w8618_eth_realize(DeviceState *dev, Err= or **errp) =20 address_space_init(&s->dma_as, s->dma_mr, "emac-dma"); s->nic =3D qemu_new_nic(&net_mv88w8618_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); } =20 static const VMStateDescription mv88w8618_eth_vmsd =3D { diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index 6ced677..a79f7fa 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -74,7 +74,8 @@ static void isa_ne2000_realizefn(DeviceState *dev, Error = **errp) ne2000_reset(s); =20 s->nic =3D qemu_new_nic(&net_ne2000_isa_info, &s->c, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a); } =20 diff --git a/hw/net/ne2000-pci.c b/hw/net/ne2000-pci.c index edc6689..fee93c6 100644 --- a/hw/net/ne2000-pci.c +++ b/hw/net/ne2000-pci.c @@ -71,7 +71,8 @@ static void pci_ne2000_realize(PCIDevice *pci_dev, Error = **errp) =20 s->nic =3D qemu_new_nic(&net_ne2000_info, &s->c, object_get_typename(OBJECT(pci_dev)), - pci_dev->qdev.id, s); + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a); } =20 diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c index 8156f70..1d4e8f5 100644 --- a/hw/net/npcm7xx_emc.c +++ b/hw/net/npcm7xx_emc.c @@ -821,7 +821,8 @@ static void npcm7xx_emc_realize(DeviceState *dev, Error= **errp) =20 qemu_macaddr_default_if_unset(&emc->conf.macaddr); emc->nic =3D qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf, - object_get_typename(OBJECT(dev)), dev->id, emc= ); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, emc); qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a= ); } =20 diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c index 0b3dc31..f96d6ea 100644 --- a/hw/net/opencores_eth.c +++ b/hw/net/opencores_eth.c @@ -732,7 +732,8 @@ static void sysbus_open_eth_realize(DeviceState *dev, E= rror **errp) sysbus_init_irq(sbd, &s->irq); =20 s->nic =3D qemu_new_nic(&net_open_eth_info, &s->conf, - object_get_typename(OBJECT(s)), dev->id, s); + object_get_typename(OBJECT(s)), dev->id, + &dev->mem_reentrancy_guard, s); } =20 static void qdev_open_eth_reset(DeviceState *dev) diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c index 02828ae..a7e123e 100644 --- a/hw/net/pcnet.c +++ b/hw/net/pcnet.c @@ -1709,7 +1709,8 @@ void pcnet_common_init(DeviceState *dev, PCNetState *= s, NetClientInfo *info) s->poll_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, pcnet_poll_timer, s= ); =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); - s->nic =3D qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev= )), dev->id, s); + s->nic =3D qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev= )), + dev->id, &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 /* Initialize the PROM */ diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c index 9afd0c5..cb87ff7 100644 --- a/hw/net/rocker/rocker_fp.c +++ b/hw/net/rocker/rocker_fp.c @@ -241,8 +241,8 @@ FpPort *fp_port_alloc(Rocker *r, char *sw_name, port->conf.bootindex =3D -1; port->conf.peers =3D *peers; =20 - port->nic =3D qemu_new_nic(&fp_port_info, &port->conf, - sw_name, NULL, port); + port->nic =3D qemu_new_nic(&fp_port_info, &port->conf, sw_name, NULL, + &DEVICE(r)->mem_reentrancy_guard, port); qemu_format_nic_info_str(qemu_get_queue(port->nic), port->conf.macaddr.a); =20 diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 4525fda..4af8c66 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -3388,7 +3388,8 @@ static void pci_rtl8139_realize(PCIDevice *dev, Error= **errp) s->eeprom.contents[9] =3D s->conf.macaddr.a[4] | s->conf.macaddr.a[5] = << 8; =20 s->nic =3D qemu_new_nic(&net_rtl8139_info, &s->conf, - object_get_typename(OBJECT(dev)), d->id, s); + object_get_typename(OBJECT(dev)), d->id, + &d->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 s->cplus_txbuffer =3D NULL; diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index ddbceda..876a784 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -783,7 +783,8 @@ static void smc91c111_realize(DeviceState *dev, Error *= *errp) sysbus_init_irq(sbd, &s->irq); qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_smc91c111_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); /* ??? Save/restore. */ } diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c index a6876a9..475d5f3 100644 --- a/hw/net/spapr_llan.c +++ b/hw/net/spapr_llan.c @@ -325,7 +325,8 @@ static void spapr_vlan_realize(SpaprVioDevice *sdev, Er= ror **errp) memcpy(&dev->perm_mac.a, &dev->nicconf.macaddr.a, sizeof(dev->perm_mac= .a)); =20 dev->nic =3D qemu_new_nic(&net_spapr_vlan_info, &dev->nicconf, - object_get_typename(OBJECT(sdev)), sdev->qdev.= id, dev); + object_get_typename(OBJECT(sdev)), sdev->qdev.= id, + &sdev->qdev.mem_reentrancy_guard, dev); qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macadd= r.a); =20 dev->rxp_timer =3D timer_new_us(QEMU_CLOCK_VIRTUAL, spapr_vlan_flush_r= x_queue, diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index 8dd6078..6768a69 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -492,7 +492,8 @@ static void stellaris_enet_realize(DeviceState *dev, Er= ror **errp) qemu_macaddr_default_if_unset(&s->conf.macaddr); =20 s->nic =3D qemu_new_nic(&net_stellaris_enet_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/sungem.c b/hw/net/sungem.c index c2e2c90..013cfc2 100644 --- a/hw/net/sungem.c +++ b/hw/net/sungem.c @@ -1399,7 +1399,7 @@ static void sungem_realize(PCIDevice *pci_dev, Error = **errp) qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_sungem_info, &s->conf, object_get_typename(OBJECT(dev)), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } diff --git a/hw/net/sunhme.c b/hw/net/sunhme.c index 64d4ea5..ddc83a6 100644 --- a/hw/net/sunhme.c +++ b/hw/net/sunhme.c @@ -881,7 +881,8 @@ static void sunhme_realize(PCIDevice *pci_dev, Error **= errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_sunhme_info, &s->conf, - object_get_typename(OBJECT(d)), d->id, s); + object_get_typename(OBJECT(d)), d->id, + &d->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/net/tulip.c b/hw/net/tulip.c index 11d866e..962086a 100644 --- a/hw/net/tulip.c +++ b/hw/net/tulip.c @@ -983,7 +983,8 @@ static void pci_tulip_realize(PCIDevice *pci_dev, Error= **errp) =20 s->nic =3D qemu_new_nic(&net_tulip_info, &s->c, object_get_typename(OBJECT(pci_dev)), - pci_dev->qdev.id, s); + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a); } =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b85c794..80c56f0 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3714,10 +3714,12 @@ static void virtio_net_device_realize(DeviceState *= dev, Error **errp) * Happen when virtio_net_set_netclient_name has been called. */ n->nic =3D qemu_new_nic(&net_virtio_info, &n->nic_conf, - n->netclient_type, n->netclient_name, n); + n->netclient_type, n->netclient_name, + &dev->mem_reentrancy_guard, n); } else { n->nic =3D qemu_new_nic(&net_virtio_info, &n->nic_conf, - object_get_typename(OBJECT(dev)), dev->id, n= ); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, n); } =20 for (i =3D 0; i < n->max_queue_pairs; i++) { diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 1b48d77..6fb4102 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2078,7 +2078,7 @@ static void vmxnet3_net_init(VMXNET3State *s) =20 s->nic =3D qemu_new_nic(&net_vmxnet3_info, &s->conf, object_get_typename(OBJECT(s)), - d->id, s); + d->id, &d->mem_reentrancy_guard, s); =20 s->peer_has_vhdr =3D vmxnet3_peer_has_vnet_hdr(s); s->tx_sop =3D true; diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index af4ba3f..1e2b3bae 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -325,7 +325,8 @@ static void xen_netdev_realize(XenDevice *xendev, Error= **errp) =20 netdev->nic =3D qemu_new_nic(&net_xen_info, &netdev->conf, object_get_typename(OBJECT(xendev)), - DEVICE(xendev)->id, netdev); + DEVICE(xendev)->id, + &xendev->qdev.mem_reentrancy_guard, netdev); =20 nc =3D qemu_get_queue(netdev->nic); qemu_format_nic_info_str(nc, netdev->conf.macaddr.a); diff --git a/hw/net/xgmac.c b/hw/net/xgmac.c index 0ab6ae9..1f4f277 100644 --- a/hw/net/xgmac.c +++ b/hw/net/xgmac.c @@ -402,7 +402,8 @@ static void xgmac_enet_realize(DeviceState *dev, Error = **errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_xgmac_enet_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 s->regs[XGMAC_ADDR_HIGH(0)] =3D (s->conf.macaddr.a[5] << 8) | diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c index 5b19a01..7d1fd37 100644 --- a/hw/net/xilinx_axienet.c +++ b/hw/net/xilinx_axienet.c @@ -967,7 +967,8 @@ static void xilinx_enet_realize(DeviceState *dev, Error= **errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_xilinx_enet_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); =20 tdk_init(&s->TEMAC.phy); diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index 89f4f3b..989afaf 100644 --- a/hw/net/xilinx_ethlite.c +++ b/hw/net/xilinx_ethlite.c @@ -235,7 +235,8 @@ static void xilinx_ethlite_realize(DeviceState *dev, Er= ror **errp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->id, s); + object_get_typename(OBJECT(dev)), dev->id, + &dev->mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); } =20 diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 5fff487..2c33e36 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1386,7 +1386,8 @@ static void usb_net_realize(USBDevice *dev, Error **e= rrp) =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_usbnet_info, &s->conf, - object_get_typename(OBJECT(s)), s->dev.qdev.id, = s); + object_get_typename(OBJECT(s)), s->dev.qdev.id, + &s->dev.qdev.mem_reentrancy_guard, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); snprintf(s->usbstring_mac, sizeof(s->usbstring_mac), "%02x%02x%02x%02x%02x%02x", diff --git a/include/net/net.h b/include/net/net.h index 2fb1c91..24deea2 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -159,6 +159,7 @@ NICState *qemu_new_nic(NetClientInfo *info, NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque); void qemu_del_nic(NICState *nic); NetClientState *qemu_get_subqueue(NICState *nic, int queue_index); diff --git a/net/net.c b/net/net.c index 8e67a20..aaf0c2b 100644 --- a/net/net.c +++ b/net/net.c @@ -319,6 +319,7 @@ NICState *qemu_new_nic(NetClientInfo *info, NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque) { NetClientState **peers =3D conf->peers.ncs; --=20 2.7.4 From nobody Wed Nov 27 04:57:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1700560723; cv=none; d=zohomail.com; s=zohoarc; b=HbO24I6eVXJi9Orxwia69RgTR5JF7JRePRGYcqElbaK3n4mfXWgc7jFHnsxUDUVNGGPr+b/7G5+xPY91EKrqqwN6NsVF10mIJ6cpUGibKiMtNBGmfu93Sqy6IZXptULGen5c2tFHGJ1Q8SlCd5uv9vlYU9pnuuxoXbJAo3N+m0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700560723; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZnYTLRvA3wQpOnegveXL1pz7dTZe5FnGbrT5ocQnsPs=; b=G7oQB19FuMFj+8NBKgpizI6IR+56Z/CDgrEQD4mpPKBVF52jrN1aBcjd08KOAcq/RswHifh9vX4rLPQvLL/pMAoIwoIHTHAazswHSK9LcU7Xw+PjavqCrzb0cmbvVZhS9SS6Ys0qYJxHG5mAcZ4CgEDgnGC9tViK7+sK9ETnf9M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1700560723788426.4106894706092; Tue, 21 Nov 2023 01:58:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5NW3-0000pF-4f; Tue, 21 Nov 2023 04:57:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NW1-0000os-DR for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NVz-0001CL-OW for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:57 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-xXLGBty1PJS01CFdUyIsdA-1; Tue, 21 Nov 2023 04:57:48 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A386D811E88; Tue, 21 Nov 2023 09:57:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id A90B0492BE0; Tue, 21 Nov 2023 09:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700560675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZnYTLRvA3wQpOnegveXL1pz7dTZe5FnGbrT5ocQnsPs=; b=cOMuGewegvd23a3q9g4UZ5jN3Ye6kiSLi1O0fNjb9ZsXtnlI+P5Nff4TGuhWHVSR2czjzy ChSfvSIRpLkaQLRdapNtFeVYqueW8pQiqYAf15ZHO71EQBXRYK2zFLOMbrmVPbMczdmrg6 e4AqqD79hVgquKDiH1C0eK2KnNP34pU= X-MC-Unique: xXLGBty1PJS01CFdUyIsdA-1 From: Jason Wang To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Alexander Bulekov , Jason Wang Subject: [PULL 2/3] net: Update MemReentrancyGuard for NIC Date: Tue, 21 Nov 2023 17:57:36 +0800 Message-ID: <20231121095737.31438-3-jasowang@redhat.com> In-Reply-To: <20231121095737.31438-1-jasowang@redhat.com> References: <20231121095737.31438-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1700560724548100001 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device. This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for qemu_flush_queued_packets() and is insignificant. Fixes: CVE-2023-3019 Reported-by: Alexander Bulekov Signed-off-by: Akihiko Odaki Acked-by: Alexander Bulekov Signed-off-by: Jason Wang --- include/net/net.h | 1 + net/net.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 24deea2..ffbd2c8 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -126,6 +126,7 @@ typedef QTAILQ_HEAD(NetClientStateList, NetClientState)= NetClientStateList; typedef struct NICState { NetClientState *ncs; NICConf *conf; + MemReentrancyGuard *reentrancy_guard; void *opaque; bool peer_deleted; } NICState; diff --git a/net/net.c b/net/net.c index aaf0c2b..4d1ff7a 100644 --- a/net/net.c +++ b/net/net.c @@ -332,6 +332,7 @@ NICState *qemu_new_nic(NetClientInfo *info, nic =3D g_malloc0(info->size + sizeof(NetClientState) * queues); nic->ncs =3D (void *)nic + info->size; nic->conf =3D conf; + nic->reentrancy_guard =3D reentrancy_guard, nic->opaque =3D opaque; =20 for (i =3D 0; i < queues; i++) { @@ -814,6 +815,7 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *= sender, int iovcnt, void *opaque) { + MemReentrancyGuard *owned_reentrancy_guard; NetClientState *nc =3D opaque; int ret; =20 @@ -826,12 +828,24 @@ static ssize_t qemu_deliver_packet_iov(NetClientState= *sender, return 0; } =20 + if (nc->info->type !=3D NET_CLIENT_DRIVER_NIC || + qemu_get_nic(nc)->reentrancy_guard->engaged_in_io) { + owned_reentrancy_guard =3D NULL; + } else { + owned_reentrancy_guard =3D qemu_get_nic(nc)->reentrancy_guard; + owned_reentrancy_guard->engaged_in_io =3D true; + } + if (nc->info->receive_iov && !(flags & QEMU_NET_PACKET_FLAG_RAW)) { ret =3D nc->info->receive_iov(nc, iov, iovcnt); } else { ret =3D nc_sendv_compat(nc, iov, iovcnt, flags); } =20 + if (owned_reentrancy_guard) { + owned_reentrancy_guard->engaged_in_io =3D false; + } + if (ret =3D=3D 0) { nc->receive_disabled =3D 1; } --=20 2.7.4 From nobody Wed Nov 27 04:57:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1700560740; cv=none; d=zohomail.com; s=zohoarc; b=M2tMpvG27j9asMbrtQtomXRKiTPkNg9DVpfMwTWQ2I3+WwAT7vgyR/tAYwtxbelU6V+4VYkDz7v21RNSSLmo4LQS/Bqgc4wHHgIDG4w3i1ljgjZhkgryJMIb279f/kA+c5BjYPSBp76TE76Y9+iAL23xkXQAPz/TT59nqNd6uW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700560740; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h0NkkCZLBjfuB5HIuMxZbeDi6CbZrn5cFBtwvrBEFus=; b=D+WgxjQCL5XnHp1uKxpsTwC8VPcM29FxEE5Vw7e4MKRX45gFmJbBIB1TWQ8zSqxXjZm2a1q/KZ7Srhiwir/3oeiieW+jB/Gdwi6mLxGXpabtuYsYB52dQ6whTxxjn3EChFZlRHfUNgQZsp8PBEJBscm2hv6t+Ic9+Z1oyJ+MsFA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17005607405158.84367303342242; Tue, 21 Nov 2023 01:59:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5NW2-0000pB-Jb; Tue, 21 Nov 2023 04:57:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NW1-0000ol-4h for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5NVz-0001CF-He for qemu-devel@nongnu.org; Tue, 21 Nov 2023 04:57:56 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-fenempAOOneLhZ0fZl0wIA-1; Tue, 21 Nov 2023 04:57:50 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5126538143C2; Tue, 21 Nov 2023 09:57:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44E07492BE0; Tue, 21 Nov 2023 09:57:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700560674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h0NkkCZLBjfuB5HIuMxZbeDi6CbZrn5cFBtwvrBEFus=; b=Sl2JZLb/b/JS02RY68uG3OlOzwLxzeFA0QX1U0ff5KSMRCmGvvE02AnLFkW+9gLEWonJo5 Qg7asgYkIV/j5CDxTtnaDCOwnkIakv/5MO1sxdI2hV3VAmf6t033xCUXyoen3kwIzppJ6+ tRACIHPOHs33NFA/USB5qOIeOFg03VY= X-MC-Unique: fenempAOOneLhZ0fZl0wIA-1 From: Jason Wang To: qemu-devel@nongnu.org Cc: David Woodhouse , Paul Durrant , Jason Wang Subject: [PULL 3/3] net: do not delete nics in net_cleanup() Date: Tue, 21 Nov 2023 17:57:37 +0800 Message-ID: <20231121095737.31438-4-jasowang@redhat.com> In-Reply-To: <20231121095737.31438-1-jasowang@redhat.com> References: <20231121095737.31438-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.035, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1700560740950100001 Content-Type: text/plain; charset="utf-8" From: David Woodhouse In net_cleanup() we only need to delete the netdevs, as those may have state which outlives Qemu when it exits, and thus may actually need to be cleaned up on exit. The nics, on the other hand, are owned by the device which created them. Most devices don't bother to clean up on exit because they don't have any state which will outlive Qemu... but XenBus devices do need to clean up their nodes in XenStore, and do have an exit handler to delete them. When the XenBus exit handler destroys the xen-net-device, it attempts to delete its nic after net_cleanup() had already done so. And crashes. Fix this by only deleting netdevs as we walk the list. As the comment notes, we can't use QTAILQ_FOREACH_SAFE() as each deletion may remove *multiple* entries, including the "safely" saved 'next' pointer. But we can store the *previous* entry, since nics are safe. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant Signed-off-by: Jason Wang --- net/net.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/net/net.c b/net/net.c index 4d1ff7a..0520bc1 100644 --- a/net/net.c +++ b/net/net.c @@ -1514,18 +1514,34 @@ static void net_vm_change_state_handler(void *opaqu= e, bool running, =20 void net_cleanup(void) { - NetClientState *nc; + NetClientState *nc, **p =3D &QTAILQ_FIRST(&net_clients); =20 /*cleanup colo compare module for COLO*/ colo_compare_cleanup(); =20 - /* We may del multiple entries during qemu_del_net_client(), - * so QTAILQ_FOREACH_SAFE() is also not safe here. + /* + * Walk the net_clients list and remove the netdevs but *not* any + * NET_CLIENT_DRIVER_NIC entries. The latter are owned by the device + * model which created them, and in some cases (e.g. xen-net-device) + * the device itself may do cleanup at exit and will be upset if we + * just delete its NIC from underneath it. + * + * Since qemu_del_net_client() may delete multiple entries, using + * QTAILQ_FOREACH_SAFE() is not safe here. The only safe pointer + * to keep as a bookmark is a NET_CLIENT_DRIVER_NIC entry, so keep + * 'p' pointing to either the head of the list, or the 'next' field + * of the latest NET_CLIENT_DRIVER_NIC, and operate on *p as we walk + * the list. + * + * The 'nc' variable isn't part of the list traversal; it's purely + * for convenience as too much '(*p)->' has a tendency to make the + * readers' eyes bleed. */ - while (!QTAILQ_EMPTY(&net_clients)) { - nc =3D QTAILQ_FIRST(&net_clients); + while (*p) { + nc =3D *p; if (nc->info->type =3D=3D NET_CLIENT_DRIVER_NIC) { - qemu_del_nic(qemu_get_nic(nc)); + /* Skip NET_CLIENT_DRIVER_NIC entries */ + p =3D &QTAILQ_NEXT(nc, next); } else { qemu_del_net_client(nc); } --=20 2.7.4