From nobody Mon Feb 9 18:14:06 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1685414650; cv=none; d=zohomail.com; s=zohoarc; b=GwxWQm6VInYjsRP9Tp6+oSfcR9h3sQlHDiHELInuM3WmluS6pIa7eQXX4iCweVb/YgD7puo2kjw/UXokHASLc/fncSUmauVjql+LdFCGKEqcxt7eoMNwfWCfhnLdG0JwzCeA5c3Tt6igvUT/D4NRwskbFsKQjBlBpjE+mZ7znuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685414650; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=ejrIrGDi4fwDc42huLgpjGNxWrqatNvW4qPUqySFFzs=; b=OoTes7tMslCsclsBNyEP8Tz9ikrrAmlIk/pclPWdSxOZcaA89zTumO56ckMD+AB44eP+QsH8CgVbZUt9P6YfH8II5B9iT3kBHnbKAXCDgmrg0xu9d0hS0rWXJsECjO80TFdGKMDPFhTLO/XTx+SWZmLYBe7Hc27zfNTfKcKFnLo= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685414650535567.3521032212743; Mon, 29 May 2023 19:44:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3pKt-0000Tt-4I; Mon, 29 May 2023 22:43:47 -0400 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 1q3pKq-0000TP-J9 for qemu-devel@nongnu.org; Mon, 29 May 2023 22:43:44 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q3pKn-0005C3-2v for qemu-devel@nongnu.org; Mon, 29 May 2023 22:43:44 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64fec2e0e25so669215b3a.1 for ; Mon, 29 May 2023 19:43:40 -0700 (PDT) Received: from alarm.. ([157.82.204.253]) by smtp.gmail.com with ESMTPSA id 63-20020a630542000000b0051baf3f1b3esm7801785pgf.76.2023.05.29.19.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 19:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1685414619; x=1688006619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ejrIrGDi4fwDc42huLgpjGNxWrqatNvW4qPUqySFFzs=; b=bA03kVN0LRRXIzKN4XRu7rfTWzkdAzIu5vrroA41QIqCpQkLzqpjwbAKDmNVrQc619 sel8WanjG9YLk5mNX33VW98hchhdEjHAjMcVWMOs98OW41wGMxEr94iO1KxTFBIMgiPA mjJzoZXp3qVL1Firr5Vy8may4ZNLv7dUH3ERx5Uvq1sGdqZ3uKieNa3iZvE0Le9gfN1m VutCkV1KEbIvbRwPj4wqIy2kZTcaHUeJZ6aEezuK2d86xDfoF2+Kgn4zuSX2aTRnEtPW bA1j++wF+++Qk/bOAfW4Gd9EqnZ4kQYwpQoN9StGcROzUAjdbV6aRYnloFE3Wx4G3OBc oGgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685414619; x=1688006619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ejrIrGDi4fwDc42huLgpjGNxWrqatNvW4qPUqySFFzs=; b=ReT/UF7aB3dLZPvn3uCN9ByZKbOoC0AF6qvb7USFF7ujUHf+KyzudT8g5hmq5IlZpk aCyuaEJUQyqO0SgoPDEzrsy+JDWUVIhyAPCcUB6t3N/duGqO4+/bg3+j2QopbLsTVR3q inaWRqd2Vl1m/U7SqxuNLyzCr1QkJwY1HYp5hqvuyCHDLHcTt4zXaQ1zHQMbllpfPAL0 cTpgJ3t+qQf5D/9p9809JxJ3QBcbZGNuKN5LwOx3J4cX0HT/Y6DWIZqiKn0PAOoFPL5r ncSL6pa3YnYN6u+pbWhOfPF93rYSh/X6WdyRrFEwbNtF+QR5GGDnbvppyRQwxFG4lbME oFww== X-Gm-Message-State: AC+VfDwyVtnOsPOwi7VnSLVpH6gFizlR4j0YVn3JnQBwFypLtufwnEVl VWOt2HJ3G7TzPiykXlAImXZSAA== X-Google-Smtp-Source: ACHHUZ6aiCOJhP/F1eiuxvqFrg32PvLvuYZpAKh2r88y5LDB6dQkwW+lr4Qrw3EN74hLySTW1nk6pA== X-Received: by 2002:a05:6a20:d805:b0:10b:78d7:502 with SMTP id iv5-20020a056a20d80500b0010b78d70502mr906865pzb.36.1685414619631; Mon, 29 May 2023 19:43:39 -0700 (PDT) From: Akihiko Odaki To: Cc: Mauro Matteo Cascella , P J P , Alexander Bulekov , Dmitry Fleytman , Beniamino Galvani , Peter Maydell , Strahinja Jankovic , Jason Wang , "Edgar E. Iglesias" , Alistair Francis , Stefan Weil , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Andrew Jeffery , Joel Stanley , Richard Henderson , Helge Deller , Sriram Yagnaraman , Thomas Huth , Aleksandar Rikalo , Subbaraya Sundeep , Jan Kiszka , Tyrone Ting , Hao Wu , Max Filippov , Jiri Pirko , Daniel Henrique Barboza , David Gibson , Greg Kurz , Harsh Prateek Bora , Sven Schnelle , "Michael S. Tsirkin" , Stefano Stabellini , Anthony Perard , Paul Durrant , Rob Herring , Gerd Hoffmann , qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, Akihiko Odaki Subject: [PATCH 2/2] net: Update MemReentrancyGuard for NIC Date: Tue, 30 May 2023 11:43:02 +0900 Message-Id: <20230530024302.14215-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530024302.14215-1-akihiko.odaki@daynix.com> References: <20230530024302.14215-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1685414652588100011 Content-Type: text/plain; charset="utf-8" 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. Reported-by: Alexander Bulekov Signed-off-by: Akihiko Odaki --- 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 a7d8deaccb..685ec58318 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -124,6 +124,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 982df2479f..3523cceafc 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++) { @@ -805,6 +806,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 @@ -817,12 +819,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.40.1