From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534854; cv=none; d=zohomail.com; s=zohoarc; b=P4qScfCwL686vbGvbvOoqu4DH563DevzZaqdkOti7VdgR1Ou6Wtx43tmragUpVcSSNAwxU5oad8oGUQwnifchAME1P5jLYr11tnmjwmsH46BMOnVza6N9JiDnZ2ep9OPYa5aKiY6gkjsKom8PpMidlUIGYdBJQ935boZ4u9Auzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534854; h=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=hNNyaUEJ3Cj5e7CyfXk59JiOH0k3NnD3beCoPCNADKM=; b=XcZLWEGoQFCoczlcLuUM2aXNIY7BWwDRsHLVu22XL2mGkGfKuSvjdu5+lrm8rh10ZWE7sZgOAbpYL6Mts5hRRkEWsg0U1HLNS0FW1pd7K0/36slSzuZO7G923hs95/mlC/MEiIKn33gowBmr0Wv1HbAVkxI+T5r0PMhG9z6LL8A= 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 1760534854042317.3671057041955; Wed, 15 Oct 2025 06:27:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SR-0005QK-Ab; Wed, 15 Oct 2025 09:22:23 -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 1v91S3-0005Gx-NW for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rv-0002zP-Og for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:59 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 75D6488A64; Wed, 15 Oct 2025 16:21:41 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-l7UDiN5W; Wed, 15 Oct 2025 16:21:40 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534501; bh=hNNyaUEJ3Cj5e7CyfXk59JiOH0k3NnD3beCoPCNADKM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=PY3HgV8RuSOha2JrGPrKPtFeklRlXnm+OLZ7luBnb/06q1/Z8LRRh90M8e2ml55an iomAz/ecoKvsSLQ8AlzmlEPTRXQqZqb/knegWGhhkN3rTBo1AFAGulPQncura7oOTg H8JDTo8RkmdFRIK1r+g1TFeDEzY0HkjOY3VMmOcA= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 01/19] net/tap: net_init_tap_one(): drop extra error propagation Date: Wed, 15 Oct 2025 16:21:17 +0300 Message-ID: <20251015132136.1083972-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534856171154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index abe3b2d036..70de798fe8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -736,9 +736,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } =20 if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, &err); + vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - error_propagate(errp, err); goto failed; } if (!qemu_set_blocking(vhostfd, false, errp)) { --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534658; cv=none; d=zohomail.com; s=zohoarc; b=nS1g8yfzjDVo4PuVbznZU7UXJ5MOPbw6thwmVRdQ3flvIZpb4hMKhKA1z9Ez2Y6BCfcRALcbD0wI/HOKrxUMfeWfwS3niqKJGVfqLxXWl/L3l/EITflKqcTuNewuFDjlLUk6hWslL2T3x1dOIU4EedX7PTpAM80Sl9VBEKpJgKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534658; h=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=bbvjn2b2AN6mVV4jMAmeSq+jgoBhCopUSDtTBCApKuY=; b=oCFAKErn1Cn1RiJZRck01llJJzsZCkIbhUTMQ9/dmsNGS+5yoRt3nxEyb/ZKtJChGjuE6V7pUbee08SDkLilkYyZIl33G+vojxAAsl++So92lK93Z5LaDUGdPFvep/z4gwVfgPpPRugMoc5co09E+/xtzYUl9qxwKtNs6snFxjo= 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 1760534658529462.3800331448141; Wed, 15 Oct 2025 06:24:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SM-0005Ks-G6; Wed, 15 Oct 2025 09:22:20 -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 1v91S4-0005Ha-2H for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:00 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rv-0002zb-ML for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:59 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 4CD5C88A67; Wed, 15 Oct 2025 16:21:42 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-tnOhXPIG; Wed, 15 Oct 2025 16:21:41 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534501; bh=bbvjn2b2AN6mVV4jMAmeSq+jgoBhCopUSDtTBCApKuY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=HfwldODTizHDOND58VrdkzXcsy66eJeL/7+g+kPuTQbFmzdZT61nZ+zMB/MGObNkH lA1K2uZBQ4AicI6XzpHkB7CgM3qZgOcgnTHqJ1Mny4ji4QfIqe7Jp4h+7lmvY+JXr1 kg42tnyCGmurdHkJz3d9zic762hF6iLaUMl2wZAE= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 02/19] net/tap: net_init_tap_one(): move parameter checking earlier Date: Wed, 15 Oct 2025 16:21:18 +0300 Message-ID: <20251015132136.1083972-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534660695154100 Content-Type: text/plain; charset="utf-8" Let's keep all similar argument checking in net_init_tap() function. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index 70de798fe8..f90050c3a0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -768,9 +768,6 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, "vhost-net requested but could not be initialized"); goto failed; } - } else if (vhostfdname) { - error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); - goto failed; } =20 return; @@ -832,6 +829,11 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) { + error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); + return -1; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534864; cv=none; d=zohomail.com; s=zohoarc; b=UjhZDOsW0MqooM3+SHMCR3D4fjbWN2fO6gaCN07I3nWdH5mSvmcbLR0ypEHfUPGrN+KN4EyraQrVmnSRJB3IL+h48CnkNMfKZS+JW9u6C1BdLACrKroJeqxyzQyh1KSGvcm6VN5pgQTpxxHck0FVG4YOXW1AGXQDpblN3tVItks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534864; h=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=sWnY8ZzMlkKOLKPtaKjH3fVS/aysz4QqO5yCpSiiFBE=; b=NPafzRwod8ZoDEjkerKRflQUdNCE4Jb81tEJd9acvPeldOerKTnENiWYn4ORHNbidrn/r6+2iFLWbZHaQlgoFRAnQ2gkSh+FPOz9nuZBklRb6S/HbcZDvxwRXwD0Fe5SjKjmaLfphNRetZGuHdOwAMwW5Egeib8TZbh4hBleaZk= 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 1760534864230719.7820269135337; Wed, 15 Oct 2025 06:27:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SW-0005T7-FZ; Wed, 15 Oct 2025 09:22:28 -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 1v91SB-0005JE-Hc for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:08 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rv-0002zr-OB for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:05 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 1F11E88A3E; Wed, 15 Oct 2025 16:21:43 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-beisVgbX; Wed, 15 Oct 2025 16:21:42 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534502; bh=sWnY8ZzMlkKOLKPtaKjH3fVS/aysz4QqO5yCpSiiFBE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=m14ODcN+Bk8+KYTpnf4baGLNI7pd+mxsdu/TsnTUsIacllK2pqahsOeB1gXSJ0zEy 4S7Mw2/NMbs8B3m11OUT+pPAMY9oqisIWOKfvLmv6KayxtyMER+8TDf8uGwK+ypSYF EENjnd683gZsHZalLmHyMW7aCJAnuNGBtA1342/k= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 03/19] net/tap: rework net_tap_init() Date: Wed, 15 Oct 2025 16:21:19 +0300 Message-ID: <20251015132136.1083972-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534868361158500 Content-Type: text/plain; charset="utf-8" In future (to support backend-transfer migration for virtio-net/tap, which includes fds passing through unix socket) we'll want to postpone fd-initialization to the later point, when QAPI structured parameters are not available. So, let's now rework the function to interface without "tap" parameter. Also, rename to net_tap_open(), as it's just a wrapper on tap_open(), and having net_tap_init() and net_init_tap() functions in one file is confusing. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/tap.c b/net/tap.c index f90050c3a0..b1b64c508d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -655,20 +655,12 @@ int net_init_bridge(const Netdev *netdev, const char = *name, return 0; } =20 -static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, +static int net_tap_open(int *vnet_hdr, bool vnet_hdr_required, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required, Error **errp) { Error *err =3D NULL; - int fd, vnet_hdr_required; - - if (tap->has_vnet_hdr) { - *vnet_hdr =3D tap->vnet_hdr; - vnet_hdr_required =3D *vnet_hdr; - } else { - *vnet_hdr =3D 1; - vnet_hdr_required =3D 0; - } + int fd; =20 fd =3D RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_r= equired, mq_required, errp)); @@ -977,6 +969,8 @@ free_fail: } else { g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; + bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + if (tap->vhostfds) { error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); return -1; @@ -997,7 +991,9 @@ free_fail: } =20 for (i =3D 0; i < queues; i++) { - fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? "no" : script, + vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, + i >=3D 1 ? "no" : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534682; cv=none; d=zohomail.com; s=zohoarc; b=i8asf7QKUQ91O5zie9ldvNBWjLTtrYJ9B2rRY+zi284Kcq/9ZRzrkX5OFP8uhEVcal+sFCW7BVdbu98kdofjgbhH5e6/VrNlM3tmo51E1C86YLxPBxJnehNJcevMz1nx1jVvj8hjcz3WEPgf6YC5q+marq1GPlIDDhfwWp224xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534682; h=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=qRZTogNTqI/NlvPAmDaFtUT9hXrMy3NPHnhfaXmrOwM=; b=QKUfdTqmpf9cJsWirBhC0L1hoVMevpJcLOKsoBlg8swn7+BX1UP6hh7tt/m3y95CH5n81OkpZ5gzyOTLyTVm0vtgTDiVRpDhRywhSKmKoqBeoudjhviXxEmtgQzA86GgLw4r5e1/8BjAKFZ8aMezkUIRFOVszIuqmwBgQqwLuBk= 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 1760534682865755.9713609356594; Wed, 15 Oct 2025 06:24:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SM-0005LD-GO; Wed, 15 Oct 2025 09:22:20 -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 1v91S8-0005Iu-76 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:04 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Ry-0002zy-3P for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:03 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id ECF4D88A39; Wed, 15 Oct 2025 16:21:43 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-9ko4QUr0; Wed, 15 Oct 2025 16:21:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534503; bh=qRZTogNTqI/NlvPAmDaFtUT9hXrMy3NPHnhfaXmrOwM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZPMX/todzycs4H/A9I6tim6eZG/gJxHYaTSOsQ0AuJ5WqwedbqlzxDbG3eoMa+ACm YeuGNBG5EZdcikcK5JaUjp5VnOjPAjHQSrRycfH4nkUJU+CThI2Op7gwnuXr9WCB6m xOzBx2bNgZDQlBrgZ0lWEpJM4tAMPDcCfRxwjCes= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 04/19] net/tap: pass NULL to net_init_tap_one() in cases when scripts are NULL Date: Wed, 15 Oct 2025 16:21:20 +0300 Message-ID: <20251015132136.1083972-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534684542154100 Content-Type: text/plain; charset="utf-8" Directly pass NULL in cases where we report an error if script or downscript are set. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index b1b64c508d..a05cc7ef64 100644 --- a/net/tap.c +++ b/net/tap.c @@ -800,8 +800,6 @@ int net_init_tap(const Netdev *netdev, const char *name, const NetdevTapOptions *tap; int fd, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ - const char *script; - const char *downscript; Error *err =3D NULL; const char *vhostfdname; char ifname[128]; @@ -811,8 +809,6 @@ int net_init_tap(const Netdev *netdev, const char *name, tap =3D &netdev->u.tap; queues =3D tap->has_queues ? tap->queues : 1; vhostfdname =3D tap->vhostfd; - script =3D tap->script; - downscript =3D tap->downscript; =20 /* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ @@ -853,7 +849,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 net_init_tap_one(tap, peer, "tap", name, NULL, - script, downscript, + NULL, NULL, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); @@ -914,7 +910,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 net_init_tap_one(tap, peer, "tap", name, ifname, - script, downscript, + NULL, NULL, tap->vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd, &err); if (err) { @@ -959,7 +955,7 @@ free_fail: } =20 net_init_tap_one(tap, peer, "bridge", name, ifname, - script, downscript, vhostfdname, + NULL, NULL, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); @@ -967,6 +963,8 @@ free_fail: return -1; } } else { + const char *script =3D tap->script; + const char *downscript =3D tap->downscript; g_autofree char *default_script =3D NULL; g_autofree char *default_downscript =3D NULL; bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534613; cv=none; d=zohomail.com; s=zohoarc; b=d8+Hp7kQ6KIEMHsj/34aOhE9C0rbvg26Za2pGErI/vP/yzhYtQMexYmQRYOSk3hlxoO30R9uHH8Sutpl+9JIEXT57ESxQBFIm7KEACDrZBr5rWvhYL0p3/Cz0hVge4o85uAM/RfnelYUUrDlgQb997O2/6YN8ew9PX7dFiG/6tU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534613; h=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=CH1U52vxvOc9yKk9t/kUb3x+nUIUMQAF51KvUr2wRZY=; b=eRsX6SzJ+2yGo787TVXDv24rvnFp47ov8ZwI7A2PDMewEdvN1pFDsjRU6qE1oNovR+rRfhC5St+0e3Xjy1+kLvddMYKFScj6KD91ZKWDA1ENJjur07ch/w9fre4E9EHQ4lnHC2EdmCaI8+9eKGPkda4HnHuKeJIPfvyg91qHfMQ= 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 1760534612245480.2009949378421; Wed, 15 Oct 2025 06:23:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91S5-0005Ht-Dw; Wed, 15 Oct 2025 09:22:03 -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 1v91S2-0005Gc-El for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:58 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rv-000308-LQ for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:57 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id D53D788AC5; Wed, 15 Oct 2025 16:21:44 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-6uANg08g; Wed, 15 Oct 2025 16:21:44 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534504; bh=CH1U52vxvOc9yKk9t/kUb3x+nUIUMQAF51KvUr2wRZY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=a3kZQY22N1JK5ATWYfZ+HZxYeVIU9uf+F1yvIgiDHXZM2sv+ZXkKkenWl/rrVWj+k IHrTFWj8I5xU5dLS7gMwdtHv0k2kHFk2I+f5iy9RYr9VSI8MxifQwT83wWOExfBwQf /YGtv3imx5uYrarW9sHuseQIR5y7HmZhdWlly0ks= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 05/19] net/tap: rework scripts handling Date: Wed, 15 Oct 2025 16:21:21 +0300 Message-ID: <20251015132136.1083972-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534618735158500 Content-Type: text/plain; charset="utf-8" Simplify handling scripts: parse all these "no" and '\0' once, and then keep simpler logic for net_tap_open() and net_init_tap_one(): NULL means no script to run, otherwise run script. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/net/tap.c b/net/tap.c index a05cc7ef64..994e885c5f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -91,6 +91,21 @@ static void launch_script(const char *setup_script, cons= t char *ifname, static void tap_send(void *opaque); static void tap_writable(void *opaque); =20 +static char *tap_parse_script(const char *script_arg, const char *default_= path) +{ + g_autofree char *res =3D g_strdup(script_arg); + + if (!res) { + res =3D get_relocated_path(default_path); + } + + if (res[0] =3D=3D '\0' || strcmp(res, "no") =3D=3D 0) { + return NULL; + } + + return g_steal_pointer(&res); +} + static void tap_update_fd_handler(TAPState *s) { qemu_set_fd_handler(s->fd, @@ -668,9 +683,7 @@ static int net_tap_open(int *vnet_hdr, bool vnet_hdr_re= quired, return -1; } =20 - if (setup_script && - setup_script[0] !=3D '\0' && - strcmp(setup_script, "no") !=3D 0) { + if (setup_script) { launch_script(setup_script, ifname, fd, &err); if (err) { error_propagate(errp, err); @@ -706,9 +719,9 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, qemu_set_info_str(&s->nc, "helper=3D%s", tap->helper); } else { qemu_set_info_str(&s->nc, "ifname=3D%s,script=3D%s,downscript=3D%s= ", ifname, - script, downscript); + script ?: "no", downscript ?: "no"); =20 - if (strcmp(downscript, "no") !=3D 0) { + if (downscript) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); @@ -963,10 +976,10 @@ free_fail: return -1; } } else { - const char *script =3D tap->script; - const char *downscript =3D tap->downscript; - g_autofree char *default_script =3D NULL; - g_autofree char *default_downscript =3D NULL; + g_autofree char *script =3D + tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); + g_autofree char *downscript =3D + tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); bool vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; =20 if (tap->vhostfds) { @@ -974,14 +987,6 @@ free_fail: return -1; } =20 - if (!script) { - script =3D default_script =3D get_relocated_path(DEFAULT_NETWO= RK_SCRIPT); - } - if (!downscript) { - downscript =3D default_downscript =3D - get_relocated_path(DEFAULT_NETWORK_DOWN_S= CRIPT); - } - if (tap->ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); } else { @@ -991,7 +996,7 @@ free_fail: for (i =3D 0; i < queues; i++) { vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; fd =3D net_tap_open(&vnet_hdr, vnet_hdr_required, - i >=3D 1 ? "no" : script, + i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { return -1; @@ -1006,8 +1011,8 @@ free_fail: } =20 net_init_tap_one(tap, peer, "tap", name, ifname, - i >=3D 1 ? "no" : script, - i >=3D 1 ? "no" : downscript, + i >=3D 1 ? NULL : script, + i >=3D 1 ? NULL : downscript, vhostfdname, vnet_hdr, fd, &err); if (err) { error_propagate(errp, err); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534718; cv=none; d=zohomail.com; s=zohoarc; b=ITV2604dslRQBALE16SI8QBGWqxt9LOFCd/HKZXNkN2VhZwoMLMUZ1s4oAepkbl38nYEWa2CycHM4+ZR+si9fGRc03QnOqcDtEZHkZAJhhB674m7D8PjDfNPL6A2uWUBsxkNQlFL2m9M1Mt1f4HRbIkQIuXX3alFfSO/qqVreSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534718; h=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=AqHqBScLVphRHYcYitihKjsg9x0DNw0fNX+yiK30WWI=; b=Mdm6K4Jgy1gFB7CvIa8OxUmMqKN542fX8o2kBbx0PJi+HGn44lBX4p1oJWsYiRG2lW0VRT3YSg5ICZmv9aZncVCLeS7HFWLbrE/VqXV0nqyIdCp3ciVgJzGG2cKfSJKrP8ni7r2OszQEIQ5Jz+zvsHD7fn5rKmFlwJmvR1vr0Qs= 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 1760534718321638.6216939027324; Wed, 15 Oct 2025 06:25:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91ST-0005S8-5N; Wed, 15 Oct 2025 09:22:25 -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 1v91S3-0005Gv-Dy for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:59 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rw-00030P-Q3 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:21:58 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id B4A8A88A66; Wed, 15 Oct 2025 16:21:45 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-4jyuH5pW; Wed, 15 Oct 2025 16:21:45 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534505; bh=AqHqBScLVphRHYcYitihKjsg9x0DNw0fNX+yiK30WWI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=PLATewOUgOYJsoCngtpT4DP+5+/rY+JmjfA/0sLBz/huo7FuhHkyQyZ7BKH3IPvWw ok4a0xF8QQdTeEALUIIhATu3bJKUyGfF3G5aVsHz3KskLJJVYzT/4fNT2cHLWM3Noj ImBnDSrIjxVCjePwh0QpyvuWgv6rQsZKUxFokpE8= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 06/19] net/tap: setup exit notifier only when needed Date: Wed, 15 Oct 2025 16:21:22 +0300 Message-ID: <20251015132136.1083972-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534720752154100 Content-Type: text/plain; charset="utf-8" No reason to setup notifier on each queue of multique tap, when we actually want to run downscript only once. As well, let's not setup notifier, when downscript is not enabled (downsciprt=3D"no"). Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 994e885c5f..17ad561f9c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -326,11 +326,9 @@ static void tap_exit_notify(Notifier *notifier, void *= data) TAPState *s =3D container_of(notifier, TAPState, exit); Error *err =3D NULL; =20 - if (s->down_script[0]) { - launch_script(s->down_script, s->down_script_arg, s->fd, &err); - if (err) { - error_report_err(err); - } + launch_script(s->down_script, s->down_script_arg, s->fd, &err); + if (err) { + error_report_err(err); } } =20 @@ -346,8 +344,11 @@ static void tap_cleanup(NetClientState *nc) =20 qemu_purge_queued_packets(nc); =20 - tap_exit_notify(&s->exit, NULL); - qemu_remove_exit_notifier(&s->exit); + if (s->exit.notify) { + tap_exit_notify(&s->exit, NULL); + qemu_remove_exit_notifier(&s->exit); + s->exit.notify =3D NULL; + } =20 tap_read_poll(s, false); tap_write_poll(s, false); @@ -443,9 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, tap_read_poll(s, true); s->vhost_net =3D NULL; =20 - s->exit.notify =3D tap_exit_notify; - qemu_add_exit_notifier(&s->exit); - return s; } =20 @@ -725,6 +723,8 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); + s->exit.notify =3D tap_exit_notify; + qemu_add_exit_notifier(&s->exit); } } =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534757; cv=none; d=zohomail.com; s=zohoarc; b=DOl/8/SYbvBFDwTQWBL28MoE3O+bhJwQNZKZi1Ef5MPWwBV9Y7VfKZ0IrCA2YObY6Fz2e86wqX8S8koHcDmk1zd82E4srVpULVELx62xaVetqM97h4nlQXIvNCxIWNjdKQ1ck7ZV7IOiToMEnNHNBv4CSkUVcM3Ug4ce2JlbVjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534757; h=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=hBBLVUnal74IiYpctK3zPNaVGPEhk/xudXLj3q7/EVs=; b=lIuzZgMM+0Alr6b73QYcwj0k6am+PR3LiKbPRijy4z4HwDWBS9cUvtSHwYeEZnpTF8PaGkcqaho+dCgBVs9l7G2mbtLoFzQ6uM6T78cHWHp5rlr9TzZDHcvJc9/icdOa2SEl1f8h1O4dTwOn+RAtLC6INCAtLJ3LOiTm1JkF3G0= 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 1760534756993276.84590665419705; Wed, 15 Oct 2025 06:25:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SR-0005QI-Ad; Wed, 15 Oct 2025 09:22:23 -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 1v91S9-0005Iy-4H for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:06 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rw-00030b-QI for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:04 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 836C888AC9; Wed, 15 Oct 2025 16:21:46 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-Rak7kRhI; Wed, 15 Oct 2025 16:21:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534506; bh=hBBLVUnal74IiYpctK3zPNaVGPEhk/xudXLj3q7/EVs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=R2EEplC0SAaGkl+BCSc+irKPYBCv+2eANII7tIxQhE0CrquQ1Uk62MNX7hR+q+mQL YaLyp85cOo+/OViH8euhWYkf6dvqtFvYW1Mq0A8qL/gLB6ApWHFGpAb5pbtNuuAbG3 8DOBM5uoqS/88Z7acqvmqSN2oKrNvammbV5amb0c= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 07/19] net/tap: split net_tap_fd_init() Date: Wed, 15 Oct 2025 16:21:23 +0300 Message-ID: <20251015132136.1083972-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534759794154100 Content-Type: text/plain; charset="utf-8" Split the function into separate net_tap_new() and net_tap_set_fd(). We start move to the following picture: net_tap_new() - take QAPI @tap parameter, but don't have @fd, initialize the net client, called during initialization. net_tap_setup() - don't have @tap (QAPI), but have @fd parameter, may be called at later point. In this commit we introduce the first function. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index 17ad561f9c..7cb694e683 100644 --- a/net/tap.c +++ b/net/tap.c @@ -412,19 +412,20 @@ static NetClientInfo net_tap_info =3D { .get_vhost_net =3D tap_get_vhost_net, }; =20 -static TAPState *net_tap_fd_init(NetClientState *peer, - const char *model, - const char *name, - int fd, - int vnet_hdr) +static TAPState *net_tap_new(NetClientState *peer, const char *model, + const char *name) { - NetOffloads ol =3D {}; - NetClientState *nc; - TAPState *s; + NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); + s->fd =3D -1; =20 - s =3D DO_UPCAST(TAPState, nc, nc); + return s; +} + +static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +{ + NetOffloads ol =3D {}; =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -443,8 +444,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer, } tap_read_poll(s, true); s->vhost_net =3D NULL; - - return s; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,7 +660,9 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, close(fd); return -1; } - s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); + + s =3D net_tap_new(peer, "bridge", name); + net_tap_set_fd(s, fd, vnet_hdr); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -702,9 +703,11 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { Error *err =3D NULL; - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); + TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; =20 + net_tap_set_fd(s, fd, vnet_hdr); + tap_set_sndbuf(s->fd, tap, &err); if (err) { error_propagate(errp, err); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534614; cv=none; d=zohomail.com; s=zohoarc; b=bC9bx+noMXcmbYzo+ecXLUpmQ6eBDhh1Hm7dhbnU8+XvzGS4xkgzKA/4qvS8s+wJVRwNpDixm3cKq0VynIBJ5rBpqLMMVY9CuKtOaVOKrSiNfWGiBfEzTmKWFunINiAs2DNfqcvVegfzRWFg6j4YzEeYqNIZnxbchZ+pRriizqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534614; h=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=nnKwp9UVQ4ods/yG1iyoepfjor+lRBQrWYh08dJIpQ8=; b=BAyxxliXCseLAJEj8lnVIFfO7TL4xBKKJ7bUS5M8Y57rLgCWNtBLZOW3GKWhfRVcH3JaAu1jQ0vGboCMqTiEwdIrU3P9OBadQa8mTmMu5WQY5Dp03oqJedHBrCmNjuwYpnVl2AhDQc7zAiRBjqEDG3WBudGDe2XqWfubrc/z7EQ= 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 1760534614534992.065190342601; Wed, 15 Oct 2025 06:23:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SM-0005MB-Ha; Wed, 15 Oct 2025 09:22:20 -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 1v91S7-0005IG-VP for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:04 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Rw-00030u-N9 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:01 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 62FE288AC1; Wed, 15 Oct 2025 16:21:47 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-PRqTmiv9; Wed, 15 Oct 2025 16:21:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534506; bh=nnKwp9UVQ4ods/yG1iyoepfjor+lRBQrWYh08dJIpQ8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=m6IK00kB3nvjVLrEV83z1za65li4V182ZBqy37CPFdgoHeB0VOM8+/DjWUmTyyht5 ywFERsKifpYiV2sr/KdtgAgFgRNFnuyus7S/PWfqNJi2arT3pOThZzEhFiRUUjCs82 59qFYfZLMy9WZKD2WvWUyz1rgisvFaXOXvJ4ngDo= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 08/19] net/tap: tap_set_sndbuf(): add return value Date: Wed, 15 Oct 2025 16:21:24 +0300 Message-ID: <20251015132136.1083972-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534618746158500 Content-Type: text/plain; charset="utf-8" Follow common recommendations in include/qapi/error.h of having a return value together with errp. This allows to avoid error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap-bsd.c | 3 ++- net/tap-linux.c | 5 ++++- net/tap-solaris.c | 3 ++- net/tap-stub.c | 3 ++- net/tap.c | 5 +---- net/tap_int.h | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index bbf84d1828..9bd282b69c 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -206,8 +206,9 @@ error: } #endif /* __FreeBSD__ */ =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-linux.c b/net/tap-linux.c index 2a90b58467..db68693bbf 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -145,7 +145,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, */ #define TAP_DEFAULT_SNDBUF 0 =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { int sndbuf; =20 @@ -159,7 +159,10 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *ta= p, Error **errp) =20 if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); + return false; } + + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 75397e6c54..e5ba89d926 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -208,8 +208,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap-stub.c b/net/tap-stub.c index f7a5e0c163..86d7d38e0f 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,8 +33,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) { + return true; } =20 int tap_probe_vnet_hdr(int fd, Error **errp) diff --git a/net/tap.c b/net/tap.c index 7cb694e683..25dedd8492 100644 --- a/net/tap.c +++ b/net/tap.c @@ -702,15 +702,12 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - Error *err =3D NULL; TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; =20 net_tap_set_fd(s, fd, vnet_hdr); =20 - tap_set_sndbuf(s->fd, tap, &err); - if (err) { - error_propagate(errp, err); + if (!tap_set_sndbuf(s->fd, tap, errp)) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index b76a05044b..7963dd6aae 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -34,7 +34,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534848; cv=none; d=zohomail.com; s=zohoarc; b=fh6FMRWVA4jXSzsIexECSvd10EBBrg9D2DG0ac42ZJi7Aef56TsfMM1gVCyQDG2zUIq8duWAsuYXyzwNkzd17gtkkU62SqVgwrToqFfvm/0DS1DxoJW+Ma15zf8sj1uHROSZAzecOiDHjOS41ng05Opf33lvEipVGPuBFsgNSKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534848; h=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=i1cFQjSXciecDMWlo5WBjvLdJBze5d5h6eICW7ris+Q=; b=TE60tXUHzwUnUsnAb+e7PtgZKG+cd6X4FrdeywYCglVS04N+3EnbihVUSLcAtCXTMRU6tGwkzkG6saWgq8DUjPwelilSrxTsUEITQI759cJzND3WpTVduiDVWCCQCqzVrr+FTj40QFnfxDGlo1aBUPyn1Grqggnog1b7E6rAAY8= 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 1760534847578201.14288660436625; Wed, 15 Oct 2025 06:27:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SR-0005QG-A9; Wed, 15 Oct 2025 09:22:23 -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 1v91SE-0005K7-AL for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:12 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91Ry-00031G-3Q for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:09 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 3691388ACE; Wed, 15 Oct 2025 16:21:48 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-iHFOMZs5; Wed, 15 Oct 2025 16:21:47 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534507; bh=i1cFQjSXciecDMWlo5WBjvLdJBze5d5h6eICW7ris+Q=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gh+9l7xE3hbrpyQ+0PwC7j+Cn0nz7D6UdRvxpuBJ632AgecqN6wCqgQjpqxIxgxLR y7XOn1z+Ebver7nojPJUMnNdOKDpmzz9KLgNLhARfQAsEeiD434hnzvvHQEE+wsQ04 7wRwqsyAnyAU2upyDtMB9osVtZkN0G8FTYUk1xIo= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 09/19] net/tap: rework tap_set_sndbuf() Date: Wed, 15 Oct 2025 16:21:25 +0300 Message-ID: <20251015132136.1083972-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534850291158500 Content-Type: text/plain; charset="utf-8" Keep NetdevTapOptions related logic in tap.c, and make tap_set_sndbuf a simple system call wrapper, more like other functions in tap-linux.c Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap-bsd.c | 2 +- net/tap-linux.c | 16 ++-------------- net/tap-solaris.c | 2 +- net/tap-stub.c | 2 +- net/tap.c | 6 +++++- net/tap_int.h | 3 +-- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 9bd282b69c..4cea60664e 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -206,7 +206,7 @@ error: } #endif /* __FreeBSD__ */ =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap-linux.c b/net/tap-linux.c index db68693bbf..bb73fa4b13 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -143,21 +143,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_= hdr, * Ethernet NICs generally have txqueuelen=3D1000, so 1Mb is * a good value, given a 1500 byte MTU. */ -#define TAP_DEFAULT_SNDBUF 0 - -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { - int sndbuf; - - sndbuf =3D !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF : - tap->sndbuf > INT_MAX ? INT_MAX : - tap->sndbuf; - - if (!sndbuf) { - sndbuf =3D INT_MAX; - } - - if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1 && tap->has_sndbuf) { + if (ioctl(fd, TUNSETSNDBUF, &sndbuf) =3D=3D -1) { error_setg_errno(errp, errno, "TUNSETSNDBUF ioctl failed"); return false; } diff --git a/net/tap-solaris.c b/net/tap-solaris.c index e5ba89d926..e925ca8ae9 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -208,7 +208,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_h= dr, return fd; } =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap-stub.c b/net/tap-stub.c index 86d7d38e0f..6aa60d96ad 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -33,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return -1; } =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp) +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp) { return true; } diff --git a/net/tap.c b/net/tap.c index 25dedd8492..f5830f4b00 100644 --- a/net/tap.c +++ b/net/tap.c @@ -704,10 +704,14 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, { TAPState *s =3D net_tap_new(peer, model, name); int vhostfd; + bool sndbuf_required =3D tap->has_sndbuf; + int sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 net_tap_set_fd(s, fd, vnet_hdr); =20 - if (!tap_set_sndbuf(s->fd, tap, errp)) { + if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && + sndbuf_required) { goto failed; } =20 diff --git a/net/tap_int.h b/net/tap_int.h index 7963dd6aae..dc4f484006 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -26,7 +26,6 @@ #ifndef NET_TAP_INT_H #define NET_TAP_INT_H =20 -#include "qapi/qapi-types-net.h" #include "net/net.h" =20 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, @@ -34,7 +33,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, =20 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); =20 -bool tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); +bool tap_set_sndbuf(int fd, int sndbuf, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534766; cv=none; d=zohomail.com; s=zohoarc; b=V8WurRxY5U0EEkbv8DFhH2pKLHqLqXP/tJuay0XNkZ48h/52t779otAa5HeGKv4/zMttJpTUl8StdqplOdsyCDK6IK/N+s7MuKPHMfqYLjR9Kp7OzU+uWikaFod3V28CokfL8R/mVE5XVFIdGAwPEG8obP2c+/FpxLM7DAAgb0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534766; h=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=Rn2HksTFyzmo06oKJaSInOpdhEVFJkUFFxj6tzH9yK8=; b=QVIQrlle4XF2JONkmE9PNu4NGMVq6kYhLjpbwhwEM8HXjw0MjoCKnvwghmT5R23FGVXXzy8IV63rf48YIsfXG/dQjziKBBi02r2edjMA/wyMLxpkFeoWx6/WLbR9GqpPhC4vP9DpOKnuNjbnA4SoaRw9nx+UZIlUz4XmpNBD7xg= 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 1760534766911302.81670627041774; Wed, 15 Oct 2025 06:26:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91ST-0005S7-4R; Wed, 15 Oct 2025 09:22:25 -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 1v91SK-0005Lb-6l for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:18 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S7-000348-Qz for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:15 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 329D188AD6; Wed, 15 Oct 2025 16:21:49 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-dJiWNCkq; Wed, 15 Oct 2025 16:21:48 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534508; bh=Rn2HksTFyzmo06oKJaSInOpdhEVFJkUFFxj6tzH9yK8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=d0BJQ5e0F3buVgVWcLIMS77ErxFTNxwi/HnsxjUthgpniybvG0goMnAZD2iQhqY61 Ty6sqtlCR5MnUj2AwOruPY3KcK1Q8Dm4uZxZnmX9cGFNfWSjJbZ/bz5gIZsg+gW9aM BjV3NGUOh43D54py1NxL1UMtaU6A70OlGllBS6V0= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 10/19] net/tap: rework sndbuf handling Date: Wed, 15 Oct 2025 16:21:26 +0300 Message-ID: <20251015132136.1083972-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534769291154100 Content-Type: text/plain; charset="utf-8" Continue the main idea: avoid dependency on @tap in net_tap_setup(). So, move QAPI parsing to net_tap_new(). Move setting sndbuf to net_tap_set_fd(), as it's more appropriate place (other initial fd settings are here). Note that net_tap_new() and net_tap_set_fd() are shared with net_init_bridge(), which didn't set sndbuf. Handle this case by sndbuf=3D0 (we never pass zero to tap_set_sndbuf(), so let this specific value mean that we don't want touch sndbuf). Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index f5830f4b00..b5ac856a3d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -83,6 +83,9 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + + bool sndbuf_required; + int sndbuf; } TAPState; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -413,17 +416,25 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name) + const char *name, const NetdevTapOptions *tap) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; =20 + if (!tap) { + return s; + } + + s->sndbuf_required =3D tap->has_sndbuf; + s->sndbuf =3D + (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; + return s; } =20 -static void net_tap_set_fd(TAPState *s, int fd, int vnet_hdr) +static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) { NetOffloads ol =3D {}; =20 @@ -444,6 +455,15 @@ static void net_tap_set_fd(TAPState *s, int fd, int vn= et_hdr) } tap_read_poll(s, true); s->vhost_net =3D NULL; + + if (s->sndbuf) { + Error **e =3D s->sndbuf_required ? errp : NULL; + if (!tap_set_sndbuf(s->fd, s->sndbuf, e) && s->sndbuf_required) { + return false; + } + } + + return true; } =20 static void close_all_fds_after_fork(int excluded_fd) @@ -661,8 +681,8 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name); - net_tap_set_fd(s, fd, vnet_hdr); + s =3D net_tap_new(peer, "bridge", name, NULL); + net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -702,16 +722,10 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name); + TAPState *s =3D net_tap_new(peer, model, name, tap); int vhostfd; - bool sndbuf_required =3D tap->has_sndbuf; - int sndbuf =3D - (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; - - net_tap_set_fd(s, fd, vnet_hdr); =20 - if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && - sndbuf_required) { + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { goto failed; } =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534713; cv=none; d=zohomail.com; s=zohoarc; b=M4KAPV+FqtvKy4EtUqcMlOXYbbTTT59Ggxr2whV979JbZF0dGsC5hLelZUrVJNrHV5J9Vzte0qqrCmB0fN4/bGE6GWA2IJ22V0qKxXne6cEJFC5MWDXkfhBsjRlGa3KHFaE9xwgwydVT+7R5Rpx2DvyA35iDJoBshGdWkAVAhkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534713; h=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=bQt+gPOuzNBNYHmDfV4+WMNfu6qlQ2YEWlgC+gNksfY=; b=jHdfUeluwjFTdhGkhw6B8rHgU/6LfiWE7SWPXH33TpT4LlhCo8I5/B+5a/sMdN7MJbl3DqOcl9csad5z1h95pOHP9QzF0OHzxr5VlbUEo9TiL1wwkC9wDbwV5aLMHH4rseCuLDliy264l26YJTcg9hqTq51DpcgkJODgBI2p2F8= 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 1760534713966105.63619624273667; Wed, 15 Oct 2025 06:25:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SZ-0005VX-Dh; Wed, 15 Oct 2025 09:22:31 -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 1v91SH-0005L5-2e for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:16 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S4-000347-B5 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:11 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 013B288ADA; Wed, 15 Oct 2025 16:21:50 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-LKdf4lUi; Wed, 15 Oct 2025 16:21:49 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534509; bh=bQt+gPOuzNBNYHmDfV4+WMNfu6qlQ2YEWlgC+gNksfY=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=pDtaH8UPBuwdkiVwPvzFZ4ozBKUXWg6JbudhGqdKkhMOP1q+LPNAuo0/y3V0VIz8t BlEEj7wxeE3eOOyRFfddFbuHEKjFIyrkiyIOhRXv++bDYqxzrUaMi1Mp8as3IN0Fc1 43iEacFCZp/w8Qn8qEbp+VBecnkrL4EoUcC50Md4= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 11/19] net/tap: introduce net_tap_setup() Date: Wed, 15 Oct 2025 16:21:27 +0300 Message-ID: <20251015132136.1083972-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534744130154100 Content-Type: text/plain; charset="utf-8" Move most of net_init_tap_one() to net_tap_setup() - future pair for net_tap_new(), for postponed setup. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/net/tap.c b/net/tap.c index b5ac856a3d..b01cd4d6c2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -88,6 +88,10 @@ typedef struct TAPState { int sndbuf; } TAPState; =20 +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp); + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); =20 @@ -723,11 +727,6 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, int vnet_hdr, int fd, Error **errp) { TAPState *s =3D net_tap_new(peer, model, name, tap); - int vhostfd; - - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { - goto failed; - } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -746,6 +745,21 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } } =20 + if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + qemu_del_net_client(&s->nc); + } +} + +static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, + const char *vhostfdname, + int fd, int vnet_hdr, Error **errp) +{ + int vhostfd; + + if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + return false; + } + if (tap->has_vhost ? tap->vhost : vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; @@ -761,20 +775,20 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (vhostfdname) { vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); if (vhostfd =3D=3D -1) { - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } else { vhostfd =3D open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { error_setg_errno(errp, errno, "tap: open vhost char device failed"); - goto failed; + return false; } if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; + return false; } } options.opaque =3D (void *)(uintptr_t)vhostfd; @@ -789,14 +803,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, if (!s->vhost_net) { error_setg(errp, "vhost-net requested but could not be initialized"); - goto failed; + return false; } } =20 - return; - -failed: - qemu_del_net_client(&s->nc); + return true; } =20 static int get_fds(char *str, char *fds[], int max) --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534892; cv=none; d=zohomail.com; s=zohoarc; b=ORdGbHJDumtyuwyySSgcFXnp6921rulawEXG/QrBASCEbsUksx4CZEzoyIy1oFllYNdQKGq43h+wEWiI6hYMJ5i+ACoh+nAGxJwP85Kjqn1H1pa/tx/2lGGz3imiSp7x5ebCBdCYkfs642HGIbFFod6O0glhi6dYOvwBLS7avGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534892; h=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=nl2+2Bb8Tc8O3k95uaNJdjhEm6v2qoQg7sRCDCKeFb4=; b=mLj68xmj1BZErYO4e/rFCl3ecfTW2DszWNLPxVEq7CoL2VmwpSL4hWCmGsLlEcCBN/twFj8iFppEY2ls14ceNTETScoGD/TzyCdfzw/KolLbpMhVV6y/kysx4/Z+kxFJR99sa+ehT7Jo9ZdomOz1bDjzhwnGELq6G+bBi01WUuA= 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 1760534892352985.661937468947; Wed, 15 Oct 2025 06:28:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SV-0005TB-Oo; Wed, 15 Oct 2025 09:22:27 -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 1v91SL-0005M9-QU for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:18 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S5-00034U-Na for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:17 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id E55BA88ADC; Wed, 15 Oct 2025 16:21:50 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-nZgMKbbA; Wed, 15 Oct 2025 16:21:50 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534510; bh=nl2+2Bb8Tc8O3k95uaNJdjhEm6v2qoQg7sRCDCKeFb4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QZRdBRYWxgeMVJ1vHELP9uFTCa7TxcIc/v7j4XUwFvuUYQiaBdc119J9/1HUuTfGK ai1iABbJmhgFPRQX63JRy5MF+5akTacUiOx7p03jIzrCJX0ysCQab3U0uu0zCG5vhE 6D/mBXiDepXftr3qQ5LO/kHuIDrj+pKyOISAUV7s= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 12/19] net/tap: move vhost fd initialization to net_tap_new() Date: Wed, 15 Oct 2025 16:21:28 +0300 Message-ID: <20251015132136.1083972-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534898473158500 Content-Type: text/plain; charset="utf-8" Continue the track to avoid dependency on @tap in net_tap_setup(), no move the vhost fd initialization to net_tap_new(). So in net_tap_setup() we simply check, do we have and vhostfd at this point or not. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 90 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/net/tap.c b/net/tap.c index b01cd4d6c2..d08ef070e9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -86,11 +86,11 @@ typedef struct TAPState { =20 bool sndbuf_required; int sndbuf; + int vhostfd; + uint32_t vhost_busyloop_timeout; } TAPState; =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp); +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -361,6 +361,11 @@ static void tap_cleanup(NetClientState *nc) tap_write_poll(s, false); close(s->fd); s->fd =3D -1; + + if (s->vhostfd !=3D -1) { + close(s->vhostfd); + s->vhostfd =3D -1; + } } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -420,12 +425,14 @@ static NetClientInfo net_tap_info =3D { }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, - const char *name, const NetdevTapOptions *tap) + const char *name, const NetdevTapOptions *tap, + const char *vhostfdname, Error **errp) { NetClientState *nc =3D qemu_new_net_client(&net_tap_info, peer, model,= name); TAPState *s =3D DO_UPCAST(TAPState, nc, nc); =20 s->fd =3D -1; + s->vhostfd =3D -1; =20 if (!tap) { return s; @@ -435,7 +442,36 @@ static TAPState *net_tap_new(NetClientState *peer, con= st char *model, s->sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + if (tap->has_vhost ? tap->vhost : + vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfdname) { + s->vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, er= rp); + if (s->vhostfd =3D=3D -1) { + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } else { + s->vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (s->vhostfd < 0) { + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + goto failed; + } + if (!qemu_set_blocking(s->vhostfd, false, errp)) { + goto failed; + } + } + + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll_us : 0; + } + return s; + +failed: + qemu_del_net_client(&s->nc); + return NULL; } =20 static bool net_tap_set_fd(TAPState *s, int fd, int vnet_hdr, Error **errp) @@ -685,7 +721,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, return -1; } =20 - s =3D net_tap_new(peer, "bridge", name, NULL); + s =3D net_tap_new(peer, "bridge", name, NULL, NULL, &error_abort); net_tap_set_fd(s, fd, vnet_hdr, &error_abort); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); @@ -726,7 +762,10 @@ static void net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, const char *downscript, const char *vhostfdna= me, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_new(peer, model, name, tap); + TAPState *s =3D net_tap_new(peer, model, name, tap, vhostfdname, errp); + if (!s) { + return; + } =20 if (tap->fd || tap->fds) { qemu_set_info_str(&s->nc, "fd=3D%d", fd); @@ -745,53 +784,24 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (!net_tap_setup(s, tap, vhostfdname, fd, vnet_hdr, errp)) { + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { qemu_del_net_client(&s->nc); } } =20 -static bool net_tap_setup(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, - int fd, int vnet_hdr, Error **errp) +static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - int vhostfd; - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 - if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } else { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_errno(errp, errno, - "tap: open vhost char device failed"); - return false; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return false; - } - } - options.opaque =3D (void *)(uintptr_t)vhostfd; + options.busyloop_timeout =3D s->vhost_busyloop_timeout; + options.opaque =3D (void *)(uintptr_t)s->vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; options.get_acked_features =3D NULL; --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534810; cv=none; d=zohomail.com; s=zohoarc; b=mNd15O98EE4m2+nQC/wPWTOYc/sKUV/uLiwwUaHLsXE5BlqVF3Z5UdqXxDHV26xQqz/pzbuzHwR2NPNeFBhfeq7JEFV/zvGi3Q5CYGjLTXQYpNLx/1Aa19OCDVc0BwJU9ISLOvicx4nwicSJCX38lMpKyibesHZdEfxajuhuOFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534810; h=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=UicDA5etzsJjSp7/6GitAPJDaIZ/euilBHmOaCwUrWA=; b=ivi2wuWPQAbQpQnmD10phGPnnqVIACasWOWmrH2KgSwJlRc44sZnMRqaq0W5brUlp47vOix601O8osdo4n+eorQR+0E6furV/jR1vRJFnJCAPZ+PZMXUjr+w0E71mlfa1EW8xTckRjNzZqVIfIIXR386bx56rJi1R1oQlnmDW6Q= 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 1760534810421694.6447870214646; Wed, 15 Oct 2025 06:26:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SU-0005SS-28; Wed, 15 Oct 2025 09:22:26 -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 1v91SH-0005LC-AE for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:16 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S5-00034T-Mc for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:12 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id B70C488ACA; Wed, 15 Oct 2025 16:21:51 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-YUx9oEma; Wed, 15 Oct 2025 16:21:51 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534511; bh=UicDA5etzsJjSp7/6GitAPJDaIZ/euilBHmOaCwUrWA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=0l9HQFpRW9HahnlIIlnh07lEoEoW9dHjaHm0Phi4S9Z62djBdNt75gGZ7pjjDnzql pz2b4qLLLw91PVqh1mO3L2Nn4G9l6JE52e620ZiVxXxY1qZx0vB7qh+SynfsApVTJm +DgSlJvtuTaz2k0jb9UHylFNozsJ8AUuuuCXLi8k= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 13/19] net/tap: finalize net_tap_set_fd() logic Date: Wed, 15 Oct 2025 16:21:29 +0300 Message-ID: <20251015132136.1083972-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534811697154100 Content-Type: text/plain; charset="utf-8" Let net_tap_set_fd() do only fd-related setup. Actually, for further backend-transfer migration for virtio-net/tap we'll want to skip net_tap_set_fd() (as incoming fds are already prepared by source QEMU). So move tap_read_poll() to net_tap_setup(). Don't care about using_vnet_hdr and vhost_net, the state is zero-initialized. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- net/tap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/tap.c b/net/tap.c index d08ef070e9..7e85444ace 100644 --- a/net/tap.c +++ b/net/tap.c @@ -480,7 +480,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; - s->using_vnet_hdr =3D false; s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); s->has_tunnel =3D tap_probe_has_tunnel(s->fd); @@ -493,8 +492,6 @@ static bool net_tap_set_fd(TAPState *s, int fd, int vne= t_hdr, Error **errp) if (vnet_hdr) { tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); } - tap_read_poll(s, true); - s->vhost_net =3D NULL; =20 if (s->sndbuf) { Error **e =3D s->sndbuf_required ? errp : NULL; @@ -795,6 +792,8 @@ static bool net_tap_setup(TAPState *s, int fd, int vnet= _hdr, Error **errp) return false; } =20 + tap_read_poll(s, true); + if (s->vhostfd !=3D -1) { VhostNetOptions options; =20 --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534813; cv=none; d=zohomail.com; s=zohoarc; b=Z+WAfrKoIomGna5miPMcMq2tOzgSPnM+eCPqHEWpnldbjmD2HR23EZMeaQm5rVI2EtUyVIBbK/N+EJXe8SSG8XhHmdfG/eaHiOhNjT7A+bDJiCjZSZK6J9IuIiQAlzIDwYxPfx66YKXbX4A2/wMNHyEoxBu2d1sRLWc+Qu7t5ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534813; h=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=epLLCR8ij3dHxAHhRc5jqkckW9iNH25iSe9D+lSfzyE=; b=fHNDK5B/kjXlivQ9C9EZuSo9ZRFe4Z15gpy0GkNdqijOMtrhvBNwk4t/CewL9nhT+oCcH9jzmgmJDr/jgl6BjyUIX+sOQva4cnJC80XmtgZ5dxYdhuhL09cFrdNwrKs9F+2ou9XMysBYTzvJ7JcPJyIlYi0WbiXlLG7jXZpRTDM= 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 1760534813360768.4520472699053; Wed, 15 Oct 2025 06:26:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SU-0005SY-Rb; Wed, 15 Oct 2025 09:22:26 -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 1v91SR-0005Qp-P6 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:23 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S8-00034f-TQ for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:23 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 96D9E88AE0; Wed, 15 Oct 2025 16:21:52 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-B0WHwHfg; Wed, 15 Oct 2025 16:21:52 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534512; bh=epLLCR8ij3dHxAHhRc5jqkckW9iNH25iSe9D+lSfzyE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ry9ghpp5XI9gVkuUvEnpczgGR11Ad+VufNxAl+MSibZzL1cV0+VPvzfApfQIniVf1 GUCbCGaEi+M2usXxfkmNxZFWGaV1sKTkrMT/EgYD1f9bbB97AKCxp6w58r43etZ6kw oqz2h3+FXyjy+i07aHnX7NWfMLo6Di30+AfQVDXM= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 14/19] migration: introduce .pre_incoming() vmsd handler Date: Wed, 15 Oct 2025 16:21:30 +0300 Message-ID: <20251015132136.1083972-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534815753154100 Content-Type: text/plain; charset="utf-8" Add possibility for devices to hook into top of migrate-incoming QMP command. It's a place, where migration capabilities and parameters are already set, but migration downtime is not yet started (source is still running). So here devices may do some remaining initializations dependent on migration capabilities. This will be used in further commit to support backend-transfer migration feature for vhost-user-blk. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Peter Xu Tested-by: Lei Yang --- include/migration/vmstate.h | 1 + migration/migration.c | 4 ++++ migration/savevm.c | 15 +++++++++++++++ migration/savevm.h | 1 + 4 files changed, 21 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 63ccaee07a..f243518fb5 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -217,6 +217,7 @@ struct VMStateDescription { int version_id; int minimum_version_id; MigrationPriority priority; + bool (*pre_incoming)(void *opaque, Error **errp); int (*pre_load)(void *opaque); int (*pre_load_errp)(void *opaque, Error **errp); int (*post_load)(void *opaque, int version_id); diff --git a/migration/migration.c b/migration/migration.c index a63b46bbef..6ed6a10f57 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1983,6 +1983,10 @@ void qmp_migrate_incoming(const char *uri, bool has_= channels, return; } =20 + if (!qemu_pre_incoming(errp)) { + return; + } + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { return; } diff --git a/migration/savevm.c b/migration/savevm.c index 7b35ec4dd0..6e240ea100 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1268,6 +1268,21 @@ bool qemu_savevm_state_blocked(Error **errp) return false; } =20 +bool qemu_pre_incoming(Error **errp) +{ + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->vmsd && se->vmsd->pre_incoming) { + if (!se->vmsd->pre_incoming(se->opaque, errp)) { + return false; + } + } + } + + return true; +} + void qemu_savevm_non_migratable_list(strList **reasons) { SaveStateEntry *se; diff --git a/migration/savevm.h b/migration/savevm.h index c337e3e3d1..4ad8997f94 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -29,6 +29,7 @@ #define QEMU_VM_COMMAND 0x08 #define QEMU_VM_SECTION_FOOTER 0x7e =20 +bool qemu_pre_incoming(Error **errp); bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_non_migratable_list(strList **reasons); int qemu_savevm_state_prepare(Error **errp); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534744; cv=none; d=zohomail.com; s=zohoarc; b=CGJ/QPKua7rTeomM+CGi/xmMNNNwqLfeTg6uPVb5NC8kgncHPs0yGESUNdz88ypTBLC4NCZ7AmEf7HtB8BYA5YmDI7LkrOIy1s3zKz3AIyFWBLXyhMSUTOO+E6x9UpkqHkqZrz4gI5O4BsLMFn90Jzq6n2jmfAf7DuGEM3Cma6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534744; h=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=XTOoRgjZxbvOOe/95H3efUvxXfxwDYqJdenVX8jbsHM=; b=NeeBvqNDWYGLZ9+CcR+6pa3HD/o3dBr2Ay6i07YmJB75tfczerTnTudhWbIGdx4zi4GcqOWoNMd0b//DKBYE9rh4Y24A8QITM71gXC4Yesyam9dEwJKsa6cyyvVycZTjPL6/jDEAkVpaoxeMuKAEe+WgekZjf3Y0a+DKtp/pQgo= 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 1760534744601554.7412727607873; Wed, 15 Oct 2025 06:25:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91SZ-0005Vr-0Y; Wed, 15 Oct 2025 09:22:31 -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 1v91SP-0005Of-K9 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:22 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S8-00035A-Be for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:20 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 8D1F288ACC; Wed, 15 Oct 2025 16:21:53 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-ReoYg5YL; Wed, 15 Oct 2025 16:21:52 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534512; bh=XTOoRgjZxbvOOe/95H3efUvxXfxwDYqJdenVX8jbsHM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OeLJuhSuwSJgEFCNjYLZoxaXReYsOL0TMm6gMBsFF9M0teWCerTEGYuiDA+BZgjgO JQxVEQUQILyqXske7HI8b/pLqsSiY4iGIa+ciu8zmoq+RazPsxcv2B+y95ty/ByPU5 T8mZHLrfrz9V5SC37aYqfXQMXdgDpum03TXMMcA4= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 15/19] net/tap: postpone tap setup to pre-incoming Date: Wed, 15 Oct 2025 16:21:31 +0300 Message-ID: <20251015132136.1083972-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534749425158500 Content-Type: text/plain; charset="utf-8" As described in previous commit, to support backend-transfer migration for virtio-net/tap, we need to postpone the decision to open the device or to wait for incoming fds up to pre-incoming point (when we actually can decide). This commit only postpones TAP-open case of initialization. We don't try to postpone the all cases of initialization, as it will require a lot more work of refactoring the code. So we postpone only the simple case, for which we are going to support fd-incoming migration: 1. No fds / fd parameters: obviously, if user give fd/fds the should be used, no incoming backend-transfer migration is possible. 2. No helper: just for simplicity. It probably possible to allow it (and just ignore in case of backend-transfer migration), to allow user use same cmdline on target QEMU.. But that questionable, and postponable. 3. No sciprt/downscript. It's not simple to support downscript: we should pass the responsiblity to call it on target QEMU with migration.. And back to source QEMU on migration failure. It feasible, but may be implemented later on demand. 3. Concrete ifname: to not try to share it between queues, when we only can setup queues as separate entities. Supporting undecided ifname will require to create some extra netdev state, connecting all the taps, to be able to iterate through them. No part of backend-transfer migration is here, we only prepare the code for future implementation of it. Are net-drivers prepared to postponed initialization of NICs? For future feature of backend-transfer migration, we are mainly interested in virtio-net. So, let's prepare virtio-net to work with postponed initialization of TAP (two places about early set/get features) and for other drivers let's simply finalize initialization on setting netdev property. Support for other drivers may be added later if needed. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- hw/net/virtio-net.c | 78 ++++++++++++++++++++++++- include/net/tap.h | 3 + net/tap-win32.c | 11 ++++ net/tap.c | 136 +++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 226 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 33116712eb..661413c72f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -719,6 +719,30 @@ default_value: return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; } =20 +static bool peer_wait_incoming(VirtIONet *n) +{ + NetClientState *nc =3D qemu_get_queue(n->nic); + + if (!nc->peer) { + return false; + } + + if (nc->peer->info->type !=3D NET_CLIENT_DRIVER_TAP) { + return false; + } + + return tap_wait_incoming(nc->peer); +} + +static bool peer_postponed_init(VirtIONet *n, int index, Error **errp) +{ + NetClientState *nc =3D qemu_get_subqueue(n->nic, index); + + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + return tap_postponed_init(nc->peer, errp); +} + static int peer_attach(VirtIONet *n, int index) { NetClientState *nc =3D qemu_get_subqueue(n->nic, index); @@ -3060,7 +3084,17 @@ static void virtio_net_set_multiqueue(VirtIONet *n, = int multiqueue) n->multiqueue =3D multiqueue; virtio_net_change_num_queues(n, max * 2 + 1); =20 - virtio_net_set_queue_pairs(n); + /* + * virtio_net_set_multiqueue() called from set_features(0) on early + * reset, when peer may wait for incoming (and is not initialized + * yet). + * Don't worry about it: virtio_net_set_queue_pairs() will be called + * later form virtio_net_post_load_device(), and anyway will be + * noop for local incoming migration with live backend passing. + */ + if (!peer_wait_incoming(n)) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3089,6 +3123,17 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, =20 virtio_add_feature_ex(features, VIRTIO_NET_F_MAC); =20 + if (peer_wait_incoming(n)) { + /* + * Excessive feature set is OK for early initialization when + * we wait for local incoming migration: actual guest-negotiated + * features will come with migration stream anyway. And we are sure + * that we support same host-features as source, because the backe= nd + * is the same (the same TAP device, for example). + */ + return; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature_ex(features, VIRTIO_NET_F_CSUM); virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO4); @@ -3180,6 +3225,18 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, } } =20 +static bool virtio_net_update_host_features(VirtIONet *n, Error **errp) +{ + ERRP_GUARD(); + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + + peer_test_vnet_hdr(n); + + virtio_net_get_features(vdev, &vdev->host_features, errp); + + return !*errp; +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n =3D opaque; @@ -4177,6 +4234,24 @@ static bool dev_unplug_pending(void *opaque) return vdc->primary_unplug_pending(dev); } =20 +static bool vhost_user_blk_pre_incoming(void *opaque, Error **errp) +{ + VirtIONet *n =3D opaque; + int i; + + if (peer_wait_incoming(n)) { + for (i =3D 0; i < n->max_queue_pairs; i++) { + if (!peer_postponed_init(n, i, errp)) { + return false; + } + } + + return virtio_net_update_host_features(n, errp); + } + + return true; +} + static const VMStateDescription vmstate_virtio_net =3D { .name =3D "virtio-net", .minimum_version_id =3D VIRTIO_NET_VM_VERSION, @@ -4185,6 +4260,7 @@ static const VMStateDescription vmstate_virtio_net = =3D { VMSTATE_VIRTIO_DEVICE, VMSTATE_END_OF_LIST() }, + .pre_incoming =3D vhost_user_blk_pre_incoming, .pre_save =3D virtio_net_pre_save, .dev_unplug_pending =3D dev_unplug_pending, }; diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..5a926ba513 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -33,4 +33,7 @@ int tap_disable(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); =20 +bool tap_wait_incoming(NetClientState *nc); +bool tap_postponed_init(NetClientState *nc, Error **errp); + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap-win32.c b/net/tap-win32.c index 38baf90e0b..7430cdf6fa 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -766,3 +766,14 @@ int tap_disable(NetClientState *nc) { abort(); } + +bool tap_wait_incoming(NetClientState *nc) +{ + return false; +} + +bool tap_postponed_init(NetClientState *nc, Error **errp) +{ + error_setg(errp, "win32 tap postponed init is not supported"); + return false; +} diff --git a/net/tap.c b/net/tap.c index 7e85444ace..8afbf3b407 100644 --- a/net/tap.c +++ b/net/tap.c @@ -35,7 +35,9 @@ #include "net/eth.h" #include "net/net.h" #include "clients.h" +#include "migration/misc.h" #include "monitor/monitor.h" +#include "system/runstate.h" #include "system/system.h" #include "qapi/error.h" #include "qemu/cutils.h" @@ -88,6 +90,13 @@ typedef struct TAPState { int sndbuf; int vhostfd; uint32_t vhost_busyloop_timeout; + + /* for postponed setup */ + QTAILQ_ENTRY(TAPState) next; + bool vnet_hdr_required; + int vnet_hdr; + bool mq_required; + char *ifname; } TAPState; =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp); @@ -366,6 +375,8 @@ static void tap_cleanup(NetClientState *nc) close(s->vhostfd); s->vhostfd =3D -1; } + + g_free(s->ifname); } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -383,6 +394,25 @@ static bool tap_set_steering_ebpf(NetClientState *nc, = int prog_fd) return tap_fd_set_steering_ebpf(s->fd, prog_fd) =3D=3D 0; } =20 +static bool tap_check_peer_type(NetClientState *nc, ObjectClass *oc, + Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + const char *driver =3D object_class_get_name(oc); + + if (!g_str_has_prefix(driver, "virtio-net-")) { + /* + * Only virtio-net support postponed TAP initialization, so + * for other drivers let's finalize initialization now. + */ + if (tap_wait_incoming(nc)) { + return tap_postponed_init(&s->nc, errp); + } + } + + return true; +} + int tap_get_fd(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -422,6 +452,7 @@ static NetClientInfo net_tap_info =3D { .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, .get_vhost_net =3D tap_get_vhost_net, + .check_peer_type =3D tap_check_peer_type, }; =20 static TAPState *net_tap_new(NetClientState *peer, const char *model, @@ -845,6 +876,93 @@ static int get_fds(char *str, char *fds[], int max) return i; } =20 +#define TAP_OPEN_IFNAME_SZ 128 + +bool tap_postponed_init(NetClientState *nc, Error **errp) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + char ifname[TAP_OPEN_IFNAME_SZ]; + int vnet_hdr =3D s->vnet_hdr; + int fd; + + pstrcpy(ifname, sizeof(ifname), s->ifname); + fd =3D net_tap_open(&vnet_hdr, s->vnet_hdr_required, NULL, + ifname, sizeof(ifname), + s->mq_required, errp); + if (fd < 0) { + goto fail; + } + + if (!net_tap_setup(s, fd, vnet_hdr, errp)) { + goto fail; + } + + return true; + +fail: + qemu_del_net_client(&s->nc); + return false; +} + +static bool check_no_script(const char *script_arg) +{ + return script_arg && + (script_arg[0] =3D=3D '\0' || strcmp(script_arg, "no") =3D=3D 0); +} + +static bool tap_postpone_init(const NetdevTapOptions *tap, + const char *name, NetClientState *peer, + bool *postponed, Error **errp) +{ + int queues =3D tap->has_queues ? tap->queues : 1; + + *postponed =3D false; + + if (!runstate_check(RUN_STATE_INMIGRATE)) { + return true; + } + + if (tap->fd || tap->fds || tap->helper || tap->vhostfds) { + return true; + } + + if (!tap->ifname || tap->ifname[0] =3D=3D '\0' || + strstr(tap->ifname, "%d") !=3D NULL) { + /* + * It's hard to postpone logic of parsing template or + * absent ifname + */ + return true; + } + + /* + * Supporting downscipt means understanding and realizing the logic of + * transfer of responsibility to call it in target QEMU process. Or in + * source QEMU process in case of migration failure. So for simplicity= we + * don't support scripts together with fds migration. + */ + if (!check_no_script(tap->script) || !check_no_script(tap->downscript)= ) { + return true; + } + + for (int i =3D 0; i < queues; i++) { + TAPState *s =3D net_tap_new(peer, "tap", name, tap, NULL, errp); + if (!s) { + return false; + } + + s->vnet_hdr_required =3D tap->has_vnet_hdr && tap->vnet_hdr; + s->vnet_hdr =3D tap->has_vnet_hdr ? tap->vnet_hdr : 1; + s->mq_required =3D queues > 1; + s->ifname =3D g_strdup(tap->ifname); + qemu_set_info_str(&s->nc, "ifname=3D%s,script=3Dno,downscript=3Dno= ", + tap->ifname); + } + + *postponed =3D true; + return true; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -853,8 +971,9 @@ int net_init_tap(const Netdev *netdev, const char *name, /* for the no-fd, no-helper case */ Error *err =3D NULL; const char *vhostfdname; - char ifname[128]; + char ifname[TAP_OPEN_IFNAME_SZ]; int ret =3D 0; + bool postponed =3D false; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -873,6 +992,14 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (!tap_postpone_init(tap, name, peer, &postponed, errp)) { + return -1; + } + + if (postponed) { + return 0; + } + if (tap->fd) { if (tap->ifname || tap->script || tap->downscript || tap->has_vnet_hdr || tap->helper || tap->has_queues || @@ -1097,3 +1224,10 @@ int tap_disable(NetClientState *nc) return ret; } } + +bool tap_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->fd =3D=3D -1; +} --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534683; cv=none; d=zohomail.com; s=zohoarc; b=JfECow/VPXRbIR+Ao9MkSc5tR2FisW7vHd/LlupqeyVl+QDbqhPGs8SRTyWXcbuZXrnhVXiXpICwpNIz7zNlXeVgqnaXU/KaoUgRtRGNYMQQM2gqZolDyQrJfzJgpd9jgNzL/FtYfGJpiBWMiDRWOE1/UqpSdC48F3p1Zebr+/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534683; h=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=MqiBmROUNBmcgWznWmpS2J0vN0EQYgRHjh9r7Qc714k=; b=aLYNTWzJjjaWwO3nb0c8/VhknsurWQxtJBxgml11CuLgeX3Pcf0QmLs60toqVEFnEOOqaTieosMzA+Wb/0D2cV6s9GjZo5azNXj4W8wrCT5H9IWHsGpZczbYECNitNpAlqdD4sa+fskPcSk622huufeOF6D3uUhWPzeZEidzvv8= 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 1760534683338180.23822424106106; Wed, 15 Oct 2025 06:24:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91T1-0005dz-Dy; Wed, 15 Oct 2025 09:22:59 -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 1v91SV-0005TA-MR for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:27 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S9-00034l-4r for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:27 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 8166588ACF; Wed, 15 Oct 2025 16:21:54 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-95StWcB1; Wed, 15 Oct 2025 16:21:53 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534513; bh=MqiBmROUNBmcgWznWmpS2J0vN0EQYgRHjh9r7Qc714k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fX7heLf4GCGYP8i3Cov6V7R1LuO7yyjyND2b1DBJg1pL/Yxh3qElFmPlhIozhV8NL NRo8ON2xDFXSBbq6+uiUJ37GI27O3pMXi6O1eCdQiBY+nVFhNslsPnfRdvUwc8QGt0 amhNDkijw+XlsGWFuFaWaoYfd1h8pPLMd4kp57dU= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 16/19] qapi: introduce backend-transfer migration parameter Date: Wed, 15 Oct 2025 16:21:32 +0300 Message-ID: <20251015132136.1083972-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534688558158500 Content-Type: text/plain; charset="utf-8" This parameter enables backend-transfer feature: all devices which support it will migrate their backends (for example a TAP device, by passing open file descriptor to migration channel). Currently no such devices, so the new parameter is a noop. Next commit will add support for virtio-net, to migrate its TAP backend. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- migration/options.c | 18 ++++++++++++++++++ migration/options.h | 2 ++ qapi/migration.json | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/migration/options.c b/migration/options.c index 5183112775..a461b07b54 100644 --- a/migration/options.c +++ b/migration/options.c @@ -262,6 +262,12 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_backend_transfer(void) +{ + MigrationState *s =3D migrate_get_current(); + return s->parameters.backend_transfer; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -963,6 +969,9 @@ MigrationParameters *qmp_query_migrate_parameters(Error= **errp) params->cpr_exec_command =3D QAPI_CLONE(strList, s->parameters.cpr_exec_command); =20 + params->has_backend_transfer =3D true; + params->backend_transfer =3D s->parameters.backend_transfer; + return params; } =20 @@ -997,6 +1006,7 @@ void migrate_params_init(MigrationParameters *params) params->has_zero_page_detection =3D true; params->has_direct_io =3D true; params->has_cpr_exec_command =3D true; + params->has_backend_transfer =3D true; } =20 /* @@ -1305,6 +1315,10 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_cpr_exec_command) { dest->cpr_exec_command =3D params->cpr_exec_command; } + + if (params->has_backend_transfer) { + dest->backend_transfer =3D params->backend_transfer; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1443,6 +1457,10 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) s->parameters.cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_command); } + + if (params->has_backend_transfer) { + s->parameters.backend_transfer =3D params->backend_transfer; + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/migration/options.h b/migration/options.h index 82d839709e..755ba1c024 100644 --- a/migration/options.h +++ b/migration/options.h @@ -87,6 +87,8 @@ const char *migrate_tls_hostname(void); uint64_t migrate_xbzrle_cache_size(void); ZeroPageDetection migrate_zero_page_detection(void); =20 +bool migrate_backend_transfer(void); + /* parameters helpers */ =20 bool migrate_params_check(MigrationParameters *params, Error **errp); diff --git a/qapi/migration.json b/qapi/migration.json index be0f3fcc12..35601a1f87 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -951,9 +951,16 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # Since: 2.4 @@ -978,7 +985,8 @@ 'mode', 'zero-page-detection', 'direct-io', - 'cpr-exec-command'] } + 'cpr-exec-command', + { 'name': 'backend-transfer', 'features': ['unstable'] } ] } =20 ## # @MigrateSetParameters: @@ -1137,9 +1145,16 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # TODO: either fuse back into `MigrationParameters`, or make @@ -1179,7 +1194,9 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': { 'type': 'bool', + 'features': [ 'unstable' ] } } } =20 ## # @migrate-set-parameters: @@ -1352,9 +1369,16 @@ # is @cpr-exec. The first list element is the program's filename, # the remainder its arguments. (Since 10.2) # +# @backend-transfer: Enable backend-transfer feature for devices that +# supports it. In general that means that backend state and its +# file descriptors are passed to the destination in the migraton +# channel (which must be a UNIX socket). Individual devices +# declare the support for backend-transfer by per-device +# backend-transfer option. (Since 10.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay and +# @unstable: Members @backend-transfer, @x-checkpoint-delay and # @x-vcpu-dirty-limit-period are experimental. # # Since: 2.4 @@ -1391,7 +1415,9 @@ '*mode': 'MigMode', '*zero-page-detection': 'ZeroPageDetection', '*direct-io': 'bool', - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*backend-transfer': { 'type': 'bool', + 'features': [ 'unstable' ] } } } =20 ## # @query-migrate-parameters: --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534751; cv=none; d=zohomail.com; s=zohoarc; b=bnVpmFpI2IqAqIL2cJ60lqXx/PUjvmaMG2ZGAd+E6fz3tibEnM6Nsqy4hE4xCKIA4lWn/Zbv9HwMC+svjPdXok2VSccWscsGLPcMNW4NamPeT7/HcVCtuaLIUsv515xtgiVBWNYL/uYpWSlXbF71KD88iZg8hxwN36v8e8/TOVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534751; h=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=AmK5dTR7FNJv8BYt1ii1QHE7ubRAYsDylzbe2+T8b9U=; b=faSvN6ERIec65/D3wrXPCEjXVl4W3AhFDHVjIktV0yCQoBzhkGXBUMn/EIbS08ioKKk0M5xvqEy1wIOPIf8xQdRNUuylNyVvSnpc9gfbuSyEuwmleruIvJDsJNpklJn6BKvP+eUNVmWBT4i5SPxoE68CWTTAmuuxQUrYGUAGwvo= 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 1760534751257106.95489393035598; Wed, 15 Oct 2025 06:25:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91Sa-0005Ve-Ba; Wed, 15 Oct 2025 09:22:33 -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 1v91SO-0005OZ-Fa for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:22 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S8-00034m-An for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:19 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 5C22088B0F; Wed, 15 Oct 2025 16:21:55 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-NWwvEDBJ; Wed, 15 Oct 2025 16:21:54 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534514; bh=AmK5dTR7FNJv8BYt1ii1QHE7ubRAYsDylzbe2+T8b9U=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fz2iEiGT6d0xIoewgcCwzZuxx+hqQjq+QvqQeZ0aQPG4FICKIvsEqSBn9b9IqXmib qq/zt7Rb5Y7tEnkfPKiuEFe3qjta/xt32mWGU8bD2iw/hwwE5Xlq0R5zvWJ6UzaR7Q uA9FA+Q9+35zq08A+iUy5sxOf1N9ckkBhSmDGLWg= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 17/19] virtio-net: support backend-transfer migration for virtio-net/tap Date: Wed, 15 Oct 2025 16:21:33 +0300 Message-ID: <20251015132136.1083972-18-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=178.154.239.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534754850158500 Content-Type: text/plain; charset="utf-8" Add virtio-net option backend-transfer, which is true by default, but false for older machine types, which doesn't support the feature. For backend-transfer migration, both global migration parameter backend-transfer and virtio-net backend-transfer option should be set to true. With the parameters enabled (both on source and target) of-course, and with unix-socket used as migration-channel, we do "migrate" the virtio-net backend - TAP device, with all its fds. This way management tool should not care about creating new TAP, and should not handle switching to it. Migration downtime become shorter. How it works: 1. For incoming migration, we postpone TAP initialization up to pre-incoming point. 2. At pre-incoming point we see that "virtio-net-tap" is set for backend-transfer, so we postpone TAP initialization up to post-load 3. During virtio-load, we get TAP state (and fds) as part of virtio-net state 4. In post-load we finalize TAP initialization Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- hw/core/machine.c | 1 + hw/net/virtio-net.c | 75 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 1 + include/net/tap.h | 2 + net/tap.c | 45 +++++++++++++++++++- 5 files changed, 122 insertions(+), 2 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 681adbb7ac..a3d77f5604 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -40,6 +40,7 @@ =20 GlobalProperty hw_compat_10_1[] =3D { { TYPE_ACPI_GED, "x-has-hest-addr", "false" }, + { TYPE_VIRTIO_NET, "backend-transfer", "false" }, }; const size_t hw_compat_10_1_len =3D G_N_ELEMENTS(hw_compat_10_1); =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 661413c72f..5f9711dee7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -38,6 +38,7 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -3358,6 +3359,9 @@ struct VirtIONetMigTmp { uint16_t curr_queue_pairs_1; uint8_t has_ufo; uint32_t has_vnet_hdr; + + NetClientState *ncs; + uint32_t max_queue_pairs; }; =20 /* The 2nd and subsequent tx_waiting flags are loaded later than @@ -3627,6 +3631,71 @@ static const VMStateDescription vhost_user_net_backe= nd_state =3D { } }; =20 +static bool virtio_net_is_tap_mig(void *opaque, int version_id) +{ + VirtIONet *n =3D opaque; + NetClientState *nc; + + nc =3D qemu_get_queue(n->nic); + + return migrate_backend_transfer() && n->backend_transfer && nc->peer && + nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP; +} + +static int virtio_net_nic_pre_save(void *opaque) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + + tmp->ncs =3D tmp->parent->nic->ncs; + tmp->max_queue_pairs =3D tmp->parent->max_queue_pairs; + + return 0; +} + +static int virtio_net_nic_pre_load(void *opaque) +{ + /* Reuse the pointer setup from save */ + virtio_net_nic_pre_save(opaque); + + return 0; +} + +static int virtio_net_nic_post_load(void *opaque, int version_id) +{ + struct VirtIONetMigTmp *tmp =3D opaque; + Error *local_err =3D NULL; + + if (!virtio_net_update_host_features(tmp->parent, &local_err)) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static const VMStateDescription vmstate_virtio_net_nic_nc =3D { + .name =3D "virtio-net-nic-nc", + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_POINTER(peer, NetClientState, vmstate_tap, + NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + +static const VMStateDescription vmstate_virtio_net_nic =3D { + .name =3D "virtio-net-nic", + .pre_load =3D virtio_net_nic_pre_load, + .pre_save =3D virtio_net_nic_pre_save, + .post_load =3D virtio_net_nic_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(ncs, struct VirtIONetMigTmp, + max_queue_pairs, + vmstate_virtio_net_nic_nc, + struct NetClientState), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, @@ -3658,6 +3727,9 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { * but based on the uint. */ VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + VMSTATE_WITH_TMP_TEST(VirtIONet, virtio_net_is_tap_mig, + struct VirtIONetMigTmp, + vmstate_virtio_net_nic), VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -4239,7 +4311,7 @@ static bool vhost_user_blk_pre_incoming(void *opaque,= Error **errp) VirtIONet *n =3D opaque; int i; =20 - if (peer_wait_incoming(n)) { + if (!virtio_net_is_tap_mig(opaque, 0) && peer_wait_incoming(n)) { for (i =3D 0; i < n->max_queue_pairs; i++) { if (!peer_postponed_init(n, i, errp)) { return false; @@ -4389,6 +4461,7 @@ static const Property virtio_net_properties[] =3D { host_features_ex, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM, false), + DEFINE_PROP_BOOL("backend-transfer", VirtIONet, backend_transfer, true= ), }; =20 static void virtio_net_class_init(ObjectClass *klass, const void *data) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 5b8ab7bda7..bf07f8a4cb 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -231,6 +231,7 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; uint32_t nr_ebpf_rss_fds; char **ebpf_rss_fds; + bool backend_transfer; }; =20 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, diff --git a/include/net/tap.h b/include/net/tap.h index 5a926ba513..506f7ab719 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -36,4 +36,6 @@ int tap_get_fd(NetClientState *nc); bool tap_wait_incoming(NetClientState *nc); bool tap_postponed_init(NetClientState *nc, Error **errp); =20 +extern const VMStateDescription vmstate_tap; + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap.c b/net/tap.c index 8afbf3b407..b9c12dd64c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -819,7 +819,7 @@ static void net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, =20 static bool net_tap_setup(TAPState *s, int fd, int vnet_hdr, Error **errp) { - if (!net_tap_set_fd(s, fd, vnet_hdr, errp)) { + if (fd !=3D -1 && !net_tap_set_fd(s, fd, vnet_hdr, errp)) { return false; } =20 @@ -1225,6 +1225,49 @@ int tap_disable(NetClientState *nc) } } =20 +static int tap_pre_load(void *opaque) +{ + TAPState *s =3D opaque; + + if (s->fd !=3D -1) { + error_report( + "TAP is already initialized and cannot receive incoming fd"); + return -EINVAL; + } + + return 0; +} + +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + Error *local_err =3D NULL; + + if (!net_tap_setup(s, -1, -1, &local_err)) { + error_report_err(local_err); + qemu_del_net_client(&s->nc); + return -EINVAL; + } + + return 0; +} + +const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .pre_load =3D tap_pre_load, + .post_load =3D tap_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_FD(fd, TAPState), + VMSTATE_BOOL(using_vnet_hdr, TAPState), + VMSTATE_BOOL(has_ufo, TAPState), + VMSTATE_BOOL(has_uso, TAPState), + VMSTATE_BOOL(has_tunnel, TAPState), + VMSTATE_BOOL(enabled, TAPState), + VMSTATE_UINT32(host_vnet_hdr_len, TAPState), + VMSTATE_END_OF_LIST() + } +}; + bool tap_wait_incoming(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534682; cv=none; d=zohomail.com; s=zohoarc; b=iSrcFOUhnRIP2CRw4APtliQ+477RuJY3RTJPQ2hp/yzj8AqLaCWQVhqDDM3LrjQYx/7XT7AKLZ8dkur/7mzCHeRIW2XHkg4ad+Alzk4kJLkFUzaqOUlQUHwjT9AqxwHCn8UaymMzI9aM+6XBlCdKN8itA17DscUqoHztGsB2YZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534682; 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=vOw5oa65DZ0Z+eI0DURWrqAVxZOetTHC4LKJBWHMDPQ=; b=YiCGXJbBQPPa3qNUsfqrpGpALTmBL9omfkKCyvilW7ZAzh8RXRMBzya5YbO//n7caZSHLI5w8z2p3DX7XHLgQ+DeFO4FEVsStipT354fZauf7nu88Dp/KHZIW+wRnomgh19AcjY0tuVNM0zl1OikddW97llF76YeRq048g0ozw0= 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 1760534682184300.4817763270703; Wed, 15 Oct 2025 06:24:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91Sb-0005XH-Mh; Wed, 15 Oct 2025 09:22:33 -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 1v91SO-0005Oa-GC for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:22 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S9-00035Q-3u for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:18 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 3936E88B11; Wed, 15 Oct 2025 16:21:56 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-ncbDdCOD; Wed, 15 Oct 2025 16:21:55 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534515; bh=vOw5oa65DZ0Z+eI0DURWrqAVxZOetTHC4LKJBWHMDPQ=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=cq0LGXlOw1uGRNgON1YHChSpitpYD1qRFRe0BHIl6mYosvbwmfVji96woZtWCvJsB 4bWfhb1d5vGYlrrK/vaPufR9seSFdXNtdOv+7dL2oxS97VuefLeB0fUKCnD/bnHaIY sezUwJR/HuIoRzDlPe30S7HXsbbS5ducJkNjyo30= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 18/19] tests/functional: add skipWithoutSudo() decorator Date: Wed, 15 Oct 2025 16:21:34 +0300 Message-ID: <20251015132136.1083972-19-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534684532154100 To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Thomas Huth Tested-by: Lei Yang Reviewed-by: Maksim Davydov --- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qe= mu_test/decorators.py index b239295804..125d31dda6 100644 --- a/tests/functional/qemu_test/decorators.py +++ b/tests/functional/qemu_test/decorators.py @@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless =20 from .cmd import which @@ -167,3 +168,18 @@ def skipLockedMemoryTest(locked_memory): ulimit_memory =3D=3D resource.RLIM_INFINITY or ulimit_memory >=3D = locked_memory * 1024, f'Test required {locked_memory} kB of available locked memory', ) + +''' +Decorator to skip execution of a test if passwordless +sudo command is not available. +''' +def skipWithoutSudo(): + proc =3D subprocess.run(["sudo", "-n", "/bin/true"], + stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + check=3DFalse) + + return skipUnless(proc.returncode =3D=3D 0, + f'requires password-less sudo access: {proc.stdout}') --=20 2.48.1 From nobody Fri Nov 14 18:23:29 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1760534655; cv=none; d=zohomail.com; s=zohoarc; b=AdraTPl9C/1fX2BFV8IpzARnrR9MggdP8PlcxmzR8WLxKMO1PXnFb+p9V22hNgn7OR1Yl/uEZ1NO6P06U+Yw8lvxFdbLrAuQwrE/6J9hBhg34E8vDyhUxrSLW4mgH40m7YIHp72gLUO0ZE1diuDoIrOB40xjP7s+xUU2LwHAcko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760534655; h=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=2QWun4PDSBRqArplE35Al6AZx/Pt7cH/PznL8Fspd7c=; b=cLw5bmNE8L/7F7DjnaUPodZV1jcyw+pS3IldaCApxLSh3R9oXxHGdgj23gNYpM36l5txIu6o8uHJtU3CKcK+bKoBYL8C8G/SSXiAJMccSmmZGNDEfBx42nrYSTyYZb1ueHkHft1Eq8rvQEiI5TNwRPGH0tLa7MM0rd3Mmlpi2Pg= 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 1760534654618731.8061517610155; Wed, 15 Oct 2025 06:24:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v91Sa-0005Wy-Fi; Wed, 15 Oct 2025 09:22:32 -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 1v91SU-0005Sa-PW for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:26 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v91S9-00035R-H9 for qemu-devel@nongnu.org; Wed, 15 Oct 2025 09:22:26 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c10:49f:0:640:b99a:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 7624588B15; Wed, 15 Oct 2025 16:21:57 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:a94::1:15]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bLQ5oq0N5Os0-6I2oIpHs; Wed, 15 Oct 2025 16:21:56 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1760534516; bh=2QWun4PDSBRqArplE35Al6AZx/Pt7cH/PznL8Fspd7c=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yNp610auOjyScPns0M4sqNPg5oVqm9jq4Sve8IL8cKCtc8UepWfWtRFl/aOJ42jPS t3zJFH6XsUMp/cmSIENSVX4E4TnCas0aC2kOEm4HNAHgl/9pNG6sodjVjqEmvJi8hl +/t25ZhUt4ElzREBRR+//nMEehX+QJe3XgKKEF4Q= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: mst@redhat.com, jasowang@redhat.com Cc: peterx@redhat.com, farosas@suse.de, sw@weilnetz.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com, qemu-devel@nongnu.org, michael.roth@amd.com, steven.sistare@oracle.com, leiyang@redhat.com, davydov-max@yandex-team.ru, yc-core@yandex-team.ru, vsementsov@yandex-team.ru, raphael.s.norwitz@gmail.com Subject: [PATCH v8 19/19] tests/functional: add test_x86_64_tap_migration Date: Wed, 15 Oct 2025 16:21:35 +0300 Message-ID: <20251015132136.1083972-20-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251015132136.1083972-1-vsementsov@yandex-team.ru> References: <20251015132136.1083972-1-vsementsov@yandex-team.ru> 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: pass client-ip=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 @yandex-team.ru) X-ZM-MESSAGEID: 1760534663208154100 Content-Type: text/plain; charset="utf-8" Add test for a new backend-transfer migration of virtio-net/tap, with fd passing through unix socket. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Lei Yang --- tests/functional/test_x86_64_tap_migration.py | 395 ++++++++++++++++++ 1 file changed, 395 insertions(+) create mode 100644 tests/functional/test_x86_64_tap_migration.py diff --git a/tests/functional/test_x86_64_tap_migration.py b/tests/function= al/test_x86_64_tap_migration.py new file mode 100644 index 0000000000..1f88ff174c --- /dev/null +++ b/tests/functional/test_x86_64_tap_migration.py @@ -0,0 +1,395 @@ +#!/usr/bin/env python3 +# +# Functional test that tests TAP local migration +# with fd passing +# +# Copyright (c) Yandex Technologies LLC, 2025 +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess +from subprocess import run +import signal +from typing import Tuple + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) +from qemu_test.decorators import skipWithoutSudo + +GUEST_IP =3D "10.0.1.2" +GUEST_IP_MASK =3D f"{GUEST_IP}/24" +GUEST_MAC =3D "d6:0d:75:f8:0f:b7" +HOST_IP =3D "10.0.1.1" +HOST_IP_MASK =3D f"{HOST_IP}/24" +TAP_ID =3D "tap0" +TAP_ID2 =3D "tap1" +TAP_MAC =3D "e6:1d:44:b5:03:5d" + + +def ip(args, check=3DTrue) -> None: + """Run ip command with sudo""" + run(["sudo", "ip"] + args, check=3Dcheck) + + +def del_tap(tap_name: str =3D TAP_ID) -> None: + ip(["tuntap", "del", tap_name, "mode", "tap", "multi_queue"], check=3D= False) + + +def init_tap(tap_name: str =3D TAP_ID, with_ip: bool =3D True) -> None: + ip(["tuntap", "add", "dev", tap_name, "mode", "tap", "multi_queue"]) + if with_ip: + ip(["link", "set", "dev", tap_name, "address", TAP_MAC]) + ip(["addr", "add", HOST_IP_MASK, "dev", tap_name]) + ip(["link", "set", tap_name, "up"]) + + +def switch_network_to_tap2() -> None: + ip(["link", "set", TAP_ID2, "down"]) + ip(["link", "set", TAP_ID, "down"]) + ip(["addr", "delete", HOST_IP_MASK, "dev", TAP_ID]) + ip(["link", "set", "dev", TAP_ID2, "address", TAP_MAC]) + ip(["addr", "add", HOST_IP_MASK, "dev", TAP_ID2]) + ip(["link", "set", TAP_ID2, "up"]) + + +def parse_ping_line(line: str) -> float: + # suspect lines like + # [1748524876.590509] 64 bytes from 94.245.155.3 \ + # (94.245.155.3): icmp_seq=3D1 ttl=3D250 time=3D101 ms + spl =3D line.split() + return float(spl[0][1:-1]) + + +def parse_ping_output(out) -> Tuple[bool, float, float]: + lines =3D [x for x in out.split("\n") if x.startswith("[")] + + try: + first_no_ans =3D next( + (ind for ind in range(len(lines)) if lines[ind][20:26] =3D=3D = "no ans") + ) + except StopIteration: + return False, parse_ping_line(lines[0]), parse_ping_line(lines[-1]) + + last_no_ans =3D next( + ind + for ind in range(len(lines) - 1, -1, -1) + if lines[ind][20:26] =3D=3D "no ans" + ) + + return ( + True, + parse_ping_line(lines[first_no_ans]), + parse_ping_line(lines[last_no_ans]), + ) + + +def wait_migration_finish(source_vm, target_vm): + migr_events =3D ( + ("MIGRATION", {"data": {"status": "completed"}}), + ("MIGRATION", {"data": {"status": "failed"}}), + ) + + source_e =3D source_vm.events_wait(migr_events)["data"] + target_e =3D target_vm.events_wait(migr_events)["data"] + + source_s =3D source_vm.cmd("query-status")["status"] + target_s =3D target_vm.cmd("query-status")["status"] + + assert ( + source_e["status"] =3D=3D "completed" + and target_e["status"] =3D=3D "completed" + and source_s =3D=3D "postmigrate" + and target_s =3D=3D "paused" + ), f"""Migration failed: + SRC status: {source_s} + SRC event: {source_e} + TGT status: {target_s} + TGT event:{target_e}""" + + +@skipWithoutSudo() +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + ASSET_ALPINE_ISO =3D Asset( + ( + "https://dl-cdn.alpinelinux.org/" + "alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.is= o" + ), + "96d1b44ea1b8a5a884f193526d92edb4676054e9fa903ad2f016441a0fe13089", + ) + + def setUp(self): + super().setUp() + + init_tap() + + self.outer_ping_proc =3D None + + def tearDown(self): + try: + del_tap(TAP_ID) + del_tap(TAP_ID2) + + if self.outer_ping_proc: + self.stop_outer_ping() + finally: + super().tearDown() + + def start_outer_ping(self) -> None: + assert self.outer_ping_proc is None + self.outer_ping_log =3D self.scratch_file("ping.log") + with open(self.outer_ping_log, "w") as f: + self.outer_ping_proc =3D subprocess.Popen( + ["ping", "-i", "0", "-O", "-D", GUEST_IP], + text=3DTrue, + stdout=3Df, + ) + + def stop_outer_ping(self) -> str: + assert self.outer_ping_proc + self.outer_ping_proc.send_signal(signal.SIGINT) + + self.outer_ping_proc.communicate(timeout=3D5) + self.outer_ping_proc =3D None + + with open(self.outer_ping_log) as f: + return f.read() + + def stop_ping_and_check(self, stop_time, resume_time): + ping_res =3D self.stop_outer_ping() + + discon, a, b =3D parse_ping_output(ping_res) + + if not discon: + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: {a} -= {b}" + ) + if a > stop_time or b < resume_time: + self.fail(f"PING failed: {text}") + self.log.info(f"PING: no packets lost: {text}") + return + + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," + f"PING: disconnect: {a} - {b}" + ) + self.log.info(text) + eps =3D 0.01 + if a < stop_time - eps or b > resume_time + eps: + self.fail(text) + + def one_ping_from_guest(self, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f"ping -c 1 -W 1 {HOST_IP}", + "1 packets transmitted, 1 packets received", + "1 packets transmitted, 0 packets received", + vm=3Dvm, + ) + self.wait_for_console_pattern("# ", vm=3Dvm) + + def one_ping_from_host(self) -> None: + run(["ping", "-c", "1", "-W", "1", GUEST_IP]) + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm( + self, shm_path, vhost, incoming=3DFalse, vm=3DNone, backend_transf= er=3DTrue + ): + if not vm: + vm =3D self.vm + + vm.set_console() + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args( + "-drive", + f"file=3D{self.ASSET_ALPINE_ISO.fetch()},media=3Dcdrom,format= =3Draw", + ) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm, backend_transfer) + + if not backend_transfer: + tap_name =3D TAP_ID2 if incoming else TAP_ID + else: + tap_name =3D TAP_ID + + self.add_virtio_net(vm, vhost, tap_name, backend_transfer) + + def add_virtio_net(self, vm, vhost: bool, tap_name: str, + backend_transfer: bool): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "ifname": tap_name, + "script": "no", + "downscript": "no", + "queues": 4, + "vnet_hdr": True, + } + + vm.cmd("netdev_add", netdev_params) + + vm.cmd( + "device_add", + driver=3D"virtio-net-pci", + romfile=3D"", + id=3D"vnet.1", + netdev=3D"netdev.1", + mq=3DTrue, + vectors=3D18, + bus=3D"pci.1", + mac=3DGUEST_MAC, + disable_legacy=3D"off", + backend_transfer=3Dbackend_transfer, + ) + + def set_migration_capabilities(self, vm, backend_transfer=3DTrue): + vm.cmd("migrate-set-capabilities", { "capabilities": [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ]}) + vm.cmd("migrate-set-parameters", { + "backend-transfer": backend_transfer + }) + + def setup_guest_network(self) -> None: + exec_command_and_wait_for_pattern(self, "ip addr", "# ") + exec_command_and_wait_for_pattern( + self, + f"ip addr add {GUEST_IP_MASK} dev eth0 && " + "ip link set eth0 up && echo OK", + "OK", + ) + self.wait_for_console_pattern("# ") + + def do_test_tap_fd_migration(self, vhost, backend_transfer=3DTrue): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + shm_path =3D self.setup_shared_memory() + + # Setup second TAP if needed + if not backend_transfer: + del_tap(TAP_ID2) + init_tap(TAP_ID2, with_ip=3DFalse) + + self.prepare_and_launch_vm( + shm_path, vhost, backend_transfer=3Dbackend_transfer + ) + self.vm.cmd("cont") + self.wait_for_console_pattern("login:") + exec_command_and_wait_for_pattern(self, "root", "# ") + + self.setup_guest_network() + + self.one_ping_from_guest(self.vm) + self.one_ping_from_host() + self.start_outer_ping() + + # Get some successful pings before migration + time.sleep(0.5) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm( + shm_path, + vhost, + incoming=3DTrue, + vm=3Dtarget_vm, + backend_transfer=3Dbackend_transfer, + ) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + freeze_start =3D time.time() + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + # Switch network to tap1 if not using backend transfer + if not backend_transfer: + switch_network_to_tap2() + + target_vm.cmd("cont") + freeze_end =3D time.time() + + self.vm.shutdown() + + self.log.info("Verifying PING on target VM after migration") + self.one_ping_from_guest(target_vm) + self.one_ping_from_host() + + # And a bit more pings after source shutdown + time.sleep(0.3) + self.stop_ping_and_check(freeze_start, freeze_end) + + target_vm.shutdown() + + def test_tap_fd_migration(self): + self.do_test_tap_fd_migration(False) + + def test_tap_fd_migration_vhost(self): + self.do_test_tap_fd_migration(True) + + def test_tap_new_tap_migration(self): + self.do_test_tap_fd_migration(False, backend_transfer=3DFalse) + + def test_tap_new_tap_migration_vhost(self): + self.do_test_tap_fd_migration(True, backend_transfer=3DFalse) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1