From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711137; cv=none; d=zohomail.com; s=zohoarc; b=hewcKbCqK+jCxDNbMPirUrcEZpQjj9it4YvZtirvW/prMfBQ/AcoUvqFpLGwe1RE6HkssuoCqj4AOf1jCBhMwUckH79YYy29403o2Cs/Kw6x4zVdgbjcy2HZ7j2Wc40Lqkujdnfcx1vTWacyCk/FD8zqYBOMDQa0So8T1mRM3m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711137; 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=mJdkRWSOhzq8wvcrtU+0pBu22CGS5GmslG9eOtXQXn4=; b=jNYobqsbCgFqz1LfyaiM62ZW3Uiqos2U6DsPEEyjRRL5DMgIi3sL/XJzclu1FLOcaJuEx8NIVBWdXR8VDmHcimu+HZasXp4Hha0Gu7/QA3sBwp1xpJdMogXOSoPWecxQblq71WDnwB5/C6u9pQGt2V7QnCjqRBHpo6CGcXGhSZQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711137387491.6937341958136; Fri, 10 Jul 2026 12:18:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGjw-0000fA-EW; Fri, 10 Jul 2026 15:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGju-0000ea-D0 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:22 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGjr-00054M-VC for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id F027280898; Fri, 10 Jul 2026 22:18:16 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-75QvDYpY; Fri, 10 Jul 2026 22:18:16 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711096; bh=mJdkRWSOhzq8wvcrtU+0pBu22CGS5GmslG9eOtXQXn4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=fmOnku1yfkLX7RvNNxAvslUm7qZPdWKkzJEQ8Cm+sv35Deiy5I7WfL6crXFIZNtNq uLniD0PmmoDd72kZZGKXOs1HVSx7NXV7aEaElQ/L6VyuvNX1u6N7Vm9xRAjdIiftA+ BwoQN/kCxWW4M3QH/zF3mMPfFAGLCKgTw7U834s4= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 01/14] net/tap: rework tap_parse_script Date: Fri, 10 Jul 2026 22:17:50 +0300 Message-ID: <20260710191809.721154-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711141245158500 Content-Type: text/plain; charset="utf-8" Factor out tap_is_explicit_no_script() helper, to simplify further changes. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index 57ffb09885c..fedd48c48d2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -92,19 +92,34 @@ static void launch_script(const char *setup_script, con= st 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) +static bool tap_is_explicit_no_script(const char *script_arg) { - g_autofree char *res =3D g_strdup(script_arg); + if (!script_arg) { + return false; + } =20 - if (!res) { - res =3D get_relocated_path(default_path); + if (script_arg[0] =3D=3D '\0') { + return true; + } + + if (strcmp(script_arg, "no") =3D=3D 0) { + return true; } =20 - if (res[0] =3D=3D '\0' || strcmp(res, "no") =3D=3D 0) { + return false; +} + +static char *tap_parse_script(const char *script_arg, const char *default_= path) +{ + if (tap_is_explicit_no_script(script_arg)) { return NULL; } =20 - return g_steal_pointer(&res); + if (!script_arg) { + return get_relocated_path(default_path); + } + + return g_strdup(script_arg); } =20 static void tap_update_fd_handler(TAPState *s) --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711138; cv=none; d=zohomail.com; s=zohoarc; b=LvURl6P3rC8tt71HqDTj5u+Bj1XQkj3xWFH1GtBNM6VZoXOH84Kb5pTm/68OqV+2KcgPE/Kub+4CLfDADoZZ5V/6USuHv6YKqYDtwEPCk0Gi6w8R4ZYKjF8zNfUBgCgUB3/4mRMXZb0mOsRu+AXsjhx5lqPyqvp/qbtXQqUBhmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711138; 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=ySKR8znfCSK85AX+fMA3St2SdKWQ2bOSFRO1n106T/I=; b=OFNB8GPKsiav1W4ZZzLsmlNxfY3SOAOYw1dWaNAmk3S2FmqFyjpdiK9KqQJEywO9I+7ppwCZutAk3BbMva+Wydtnjoexc6ZIl+C3YVofLf4orER70Qsm9QuJAoTjWYYjpH6glJmH2s32rOClu9V/w3ciQR8fjQ7S+P0oZzVnmMw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711137597201.5600986300168; Fri, 10 Jul 2026 12:18:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGjy-0000fQ-0S; Fri, 10 Jul 2026 15:18:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGjv-0000f1-T5 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:23 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGjt-00054h-Ms for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:23 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 5826480E21; Fri, 10 Jul 2026 22:18:19 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-2cZW9bI0; Fri, 10 Jul 2026 22:18:18 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711098; bh=ySKR8znfCSK85AX+fMA3St2SdKWQ2bOSFRO1n106T/I=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=otg4Qd/ISgb4PcxcrE0NV5ww/Sg8j59Ng7hTInqEyESZr5LKmxWYguazZPlCaHv3W H5Bu5MlhtcysDYxaqaPimLsNRXXfRzvK871Sii8stBtWjyYMN/pU9vkC9yT76jPbYN HCHcDZd7B2mSbwbrwpOTD7dKq2pzQvN8SShwDir8= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang , Eric Blake Subject: [PATCH v18 02/14] net/tap: improve script/downscript options documentation Date: Fri, 10 Jul 2026 22:17:51 +0300 Message-ID: <20260710191809.721154-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711141589158500 Content-Type: text/plain; charset="utf-8" Properly document defaults and special values of "" and "no". Signed-off-by: Vladimir Sementsov-Ogievskiy --- qapi/net.json | 12 +++++++++--- qemu-options.hx | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/qapi/net.json b/qapi/net.json index 1a6382825c5..8f0915c4d86 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -399,9 +399,15 @@ # @fds: multiple file descriptors of already opened multiqueue capable # tap # -# @script: script to initialize the interface -# -# @downscript: script to shut down the interface +# @script: script to initialize the interface. An empty string or +# "no" disables script execution. Defaults to +# ``/qemu-ifup``, where ```` is the +# system configuration directory at build time (typically /etc). +# +# @downscript: script to shut down the interface. An empty string or +# "no" disables script execution. Defaults to +# ``/qemu-ifdown``, where ```` is the +# system configuration directory at build time (typically /etc). # # @br: bridge name (since 2.8) # diff --git a/qemu-options.hx b/qemu-options.hx index 34970fffc94..200949655ea 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3014,7 +3014,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " use network scripts 'file' (default=3D" DEFAULT_NETWO= RK_SCRIPT ")\n" " to configure it and 'dfile' (default=3D" DEFAULT_NETW= ORK_DOWN_SCRIPT ")\n" " to deconfigure it\n" - " use '[down]script=3Dno' to disable script execution\n" + " use '[down]script=3Dno' or '[down]script=3D' to disab= le script execution\n" " use network helper 'helper' (default=3D" DEFAULT_BRID= GE_HELPER ") to\n" " configure it\n" " use 'fd=3Dh' to connect to an already opened TAP inte= rface\n" @@ -3550,9 +3550,10 @@ SRST Use the network script file to configure it and the network script dfile to deconfigure it. If name is not provided, the OS automatically provides one. The default network configure script is - ``/etc/qemu-ifup`` and the default network deconfigure script is - ``/etc/qemu-ifdown``. Use ``script=3Dno`` or ``downscript=3Dno`` to - disable script execution. + ``/qemu-ifup`` and the default network deconfigure script = is + ``/qemu-ifdown``, where ```` is the system + configuration directory at build time (typically ``/etc``). + Use ``[down]script=3Dno`` or ``[down]script=3D`` to disable script exe= cution. =20 If running QEMU as an unprivileged user, use the network helper to configure the TAP interface and attach it to the bridge. --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711142; cv=none; d=zohomail.com; s=zohoarc; b=SwwH4GXJrJXgdHCjXLk8zoqeq4+1dXgZ8YY9xdG2LmVbiU59fNHamhQtgF+UsehisJSfy+VdVnsoz8Je7zmmZ7zYd0nhoNy3kdcODSmxzppegiOfifBp/qW9j3l+CCZaBffRT7oHqmo+po2VW/s01hkQ4eHJwAg3Rz0IL7LYl58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711142; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XU6rFdMa6qjuR/yF7DSa18zwJcjKZIiGNqq4ynL/1x8=; b=X3/D1xHRf3BZib3oSy67AzmnDAwa9uipnr1WzGNWVQe+IeuyOqGccL5+Wa9DgnqHvl3wzJLJ/dKTA6HnmIFPA/PZYaPfzRQfq0BVdbR8Bx8p5h0esKZjRc0wsZEA8rxwALUVkDO9MGoUhcEa+U57rYKxYluA3D/kwgu1fC7lNgE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1783711142404887.6486588112263; Fri, 10 Jul 2026 12:19:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1359816.1613195 (Exim 4.92) (envelope-from ) id 1wiGk1-0004UA-Rh; Fri, 10 Jul 2026 19:18:29 +0000 Received: by outflank-mailman (output) from mailman id 1359816.1613195; Fri, 10 Jul 2026 19:18:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wiGk1-0004U3-OV; Fri, 10 Jul 2026 19:18:29 +0000 Received: by outflank-mailman (input) for mailman id 1359816; Fri, 10 Jul 2026 19:18:28 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wiGk0-0004Tw-61 for xen-devel@lists.xenproject.org; Fri, 10 Jul 2026 19:18:28 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wiGjy-007y69-CJ for xen-devel@lists.xenproject.org; Fri, 10 Jul 2026 21:18:26 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a514579-e002-0a2a0a5209dd-0a2a450be1b2-6 for ; Fri, 10 Jul 2026 21:18:25 +0200 Received: from [178.154.239.200] (helo=forwardcorp1d.mail.yandex.net) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.2) (envelope-from ) id 6a514580-b7da-0a2a450b0019-b29aefc8cd14-3 for ; Fri, 10 Jul 2026 21:18:25 +0200 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 84770808B9; Fri, 10 Jul 2026 22:18:24 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-gmOl9KC0; Fri, 10 Jul 2026 22:18:23 +0300 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=default header.d=yandex-team.ru header.i="@yandex-team.ru" header.h="Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From" Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711103; bh=XU6rFdMa6qjuR/yF7DSa18zwJcjKZIiGNqq4ynL/1x8=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=Huru2vOhEY5FtAh3de7SS4ROuzpqxri8ELZL2ZgVKslOnDU0DfKT5P+IwqV4USFGL CvZLpUZro8P/Zgi3ps9C+mqz0Pc30RJOFPDxFJt15QMj4aX1tSTvuE4ybn2GgV/p6X SisTpLxIrfspR/+wKaBJUCssDt0CSapYm9zxq/u4= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Pierrick Bouvier , Sergio Lopez , Zhao Liu , Stefano Stabellini , Anthony PERARD , "Edgar E. Iglesias" , Bernhard Beschow , Alistair Francis , Palmer Dabbelt , Jason Wang , Eric Blake , devel@lists.libvirt.org (open list:Incompatible changes), xen-devel@lists.xenproject.org (open list:X86 Xen CPUs), qemu-ppc@nongnu.org (open list:e500), qemu-riscv@nongnu.org (open list:Microchip PolarFi...) Subject: [PATCH v18 03/14] net/tap: deprecate "no" as special value for script/downscript Date: Fri, 10 Jul 2026 22:17:52 +0300 Message-ID: <20260710191809.721154-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1783711105-4857B9ED-10B65025/0/0 X-purgate-type: clean X-purgate-size: 10175 X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1783711145868158500 The interface is ambiguous, as "no" is valid file name. So, using "no" as a special value to disable script is deprecated. Use an empty string ("script=3D" / "downscript=3D") instead. In a future version, "no" will be treated as a plain file name, just like any other non-empty value. Document the deprecation in docs/about/deprecated.rst, qapi/net.json, and qemu-options.hx. Update other docs to use empty string instead of "no". Add a warning. Signed-off-by: Vladimir Sementsov-Ogievskiy --- docs/about/deprecated.rst | 18 ++++++++++++++++++ docs/system/i386/microvm.rst | 4 ++-- docs/system/i386/xenpvh.rst | 2 +- docs/system/ppc/ppce500.rst | 4 ++-- docs/system/riscv/microchip-icicle-kit.rst | 2 +- docs/system/riscv/sifive_u.rst | 2 +- net/tap.c | 2 ++ qapi/net.json | 12 ++++++++---- qemu-options.hx | 7 +++++-- 9 files changed, 40 insertions(+), 13 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 0c656a968fc..c4929317e3a 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -71,6 +71,15 @@ flexible enough. The monitor objects have been converted= to QOM, so ``-mon mode=3Dcontrol`` is replaced by ``-object monitor-qmp``. The short convenience options are not deprecated, only ``-mon``. =20 +``script=3Dno`` and ``downscript=3Dno`` for ``-netdev tap`` (since 11.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +The special value ``"no"`` for the ``script`` and ``downscript`` +parameters of ``-netdev tap`` disables script execution. This special +treatment of ``"no"`` is deprecated. Use an empty string (``script=3D`` +or ``downscript=3D``) to disable script execution instead. In a future +version, ``"no"`` will be treated as a plain file name. + QEMU Machine Protocol (QMP) commands ------------------------------------ =20 @@ -164,6 +173,15 @@ Use ``job-finalize`` instead. =20 Use ``query-accelerators`` instead. =20 +``"no"`` as value of ``script``/``downscript`` for tap in ``netdev_add`` (= since 11.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''= ''''''''''' + +The special value ``"no"`` for the ``script`` and ``downscript`` +parameters of ``netdev_add`` with ``type=3Dtap`` disables script +execution. This special treatment of ``"no"`` is deprecated. Use an +empty string instead. In a future version, ``"no"`` will be treated as +a plain file name. + Human Machine Protocol (HMP) commands ------------------------------------- =20 diff --git a/docs/system/i386/microvm.rst b/docs/system/i386/microvm.rst index 1675e37d3e7..077ea15751e 100644 --- a/docs/system/i386/microvm.rst +++ b/docs/system/i386/microvm.rst @@ -79,7 +79,7 @@ legacy ``ISA serial`` device as console:: -serial stdio \ -drive id=3Dtest,file=3Dtest.img,format=3Draw,if=3Dnone \ -device virtio-blk-device,drive=3Dtest \ - -netdev tap,id=3Dtap0,script=3Dno,downscript=3Dno \ + -netdev tap,id=3Dtap0,script=3D,downscript=3D \ -device virtio-net-device,netdev=3Dtap0 =20 While the example above works, you might be interested in reducing the @@ -103,7 +103,7 @@ disabled:: -device virtconsole,chardev=3Dvirtiocon0 \ -drive id=3Dtest,file=3Dtest.img,format=3Draw,if=3Dnone \ -device virtio-blk-device,drive=3Dtest \ - -netdev tap,id=3Dtap0,script=3Dno,downscript=3Dno \ + -netdev tap,id=3Dtap0,script=3D,downscript=3D \ -device virtio-net-device,netdev=3Dtap0 =20 =20 diff --git a/docs/system/i386/xenpvh.rst b/docs/system/i386/xenpvh.rst index 904778e3f5c..862f38830b1 100644 --- a/docs/system/i386/xenpvh.rst +++ b/docs/system/i386/xenpvh.rst @@ -42,7 +42,7 @@ case you need to construct one manually: -vnc none \ -display none \ -device virtio-net-pci,id=3Dnic0,netdev=3Dnet0,mac=3D00:16:3e:5c:81:= 78 \ - -netdev type=3Dtap,id=3Dnet0,ifname=3Dvif3.0-emu,br=3Dxenbr0,script= =3Dno,downscript=3Dno \ + -netdev type=3Dtap,id=3Dnet0,ifname=3Dvif3.0-emu,br=3Dxenbr0,script= =3D,downscript=3D \ -smp 4,maxcpus=3D4 \ -nographic \ -machine xenpvh,ram-low-base=3D0,ram-low-size=3D2147483648,ram-high-= base=3D4294967296,ram-high-size=3D2147483648,pci-ecam-base=3D824633720832,p= ci-ecam-size=3D268435456,pci-mmio-base=3D4026531840,pci-mmio-size=3D3355443= 2,pci-mmio-high-base=3D824902156288,pci-mmio-high-size=3D68719476736 \ diff --git a/docs/system/ppc/ppce500.rst b/docs/system/ppc/ppce500.rst index c9fe0915dc5..ec5aaf14fd9 100644 --- a/docs/system/ppc/ppce500.rst +++ b/docs/system/ppc/ppce500.rst @@ -158,14 +158,14 @@ interface at PCI address 0.1.0, but we can switch tha= t to an e1000 NIC by: $ qemu-system-ppc64 -M ppce500 -smp 4 -m 2G \ -display none -serial stdio \ -bios u-boot \ - -nic tap,ifname=3Dtap0,script=3Dno,downscript=3Dno,m= odel=3De1000 + -nic tap,ifname=3Dtap0,script=3D,downscript=3D,model= =3De1000 =20 The QEMU ``ppce500`` machine can also dynamically instantiate an eTSEC dev= ice if =E2=80=9C-device eTSEC=E2=80=9D is given to QEMU: =20 .. code-block:: bash =20 - -netdev tap,ifname=3Dtap0,script=3Dno,downscript=3Dno,id=3Dnet0 -device = eTSEC,netdev=3Dnet0 + -netdev tap,ifname=3Dtap0,script=3D,downscript=3D,id=3Dnet0 -device eTSE= C,netdev=3Dnet0 =20 Root file system on flash drive ------------------------------- diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv= /microchip-icicle-kit.rst index 9809e94b84b..7fdb96601ad 100644 --- a/docs/system/riscv/microchip-icicle-kit.rst +++ b/docs/system/riscv/microchip-icicle-kit.rst @@ -84,7 +84,7 @@ Then we can boot the machine by: $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 -m 2G \ -sd path/to/sdcard.img \ -nic user,model=3Dcadence_gem \ - -nic tap,ifname=3Dtap,model=3Dcadence_gem,script=3Dno \ + -nic tap,ifname=3Dtap,model=3Dcadence_gem,script=3D \ -display none -serial stdio \ -kernel path/to/u-boot/build/dir/u-boot.bin \ -dtb path/to/u-boot/build/dir/u-boot.dtb diff --git a/docs/system/riscv/sifive_u.rst b/docs/system/riscv/sifive_u.rst index 8f55ae8e313..0e4dcf3e70c 100644 --- a/docs/system/riscv/sifive_u.rst +++ b/docs/system/riscv/sifive_u.rst @@ -199,7 +199,7 @@ To boot the VxWorks kernel in QEMU with the ``sifive_u`= ` machine, use: =20 $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \ -display none -serial stdio \ - -nic tap,ifname=3Dtap0,script=3Dno,downscript=3Dno \ + -nic tap,ifname=3Dtap0,script=3D,downscript=3D \ -kernel /path/to/vxWorks \ -append "gem(0,0)host:vxWorks h=3D192.168.200.1 e=3D192.168.200.2:ff= ffff00 u=3Dtarget pw=3DvxTarget f=3D0x01" =20 diff --git a/net/tap.c b/net/tap.c index fedd48c48d2..1ec9e5ebe6f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -103,6 +103,8 @@ static bool tap_is_explicit_no_script(const char *scrip= t_arg) } =20 if (strcmp(script_arg, "no") =3D=3D 0) { + warn_report("script=3Dno/downscript=3Dno is deprecated; " + "use script=3D/downscript=3D instead"); return true; } =20 diff --git a/qapi/net.json b/qapi/net.json index 8f0915c4d86..ada0329ef9d 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -399,15 +399,19 @@ # @fds: multiple file descriptors of already opened multiqueue capable # tap # -# @script: script to initialize the interface. An empty string or -# "no" disables script execution. Defaults to +# @script: script to initialize the interface. An empty string +# disables script execution. Defaults to # ``/qemu-ifup``, where ```` is the # system configuration directory at build time (typically /etc). +# Using "no" to disable script execution is deprecated (since +# 11.2); use an empty string instead. # -# @downscript: script to shut down the interface. An empty string or -# "no" disables script execution. Defaults to +# @downscript: script to shut down the interface. An empty string +# disables script execution. Defaults to # ``/qemu-ifdown``, where ```` is the # system configuration directory at build time (typically /etc). +# Using "no" to disable script execution is deprecated (since +# 11.2); use an empty string instead. # # @br: bridge name (since 2.8) # diff --git a/qemu-options.hx b/qemu-options.hx index 200949655ea..7b9a14f5b38 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3014,7 +3014,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " use network scripts 'file' (default=3D" DEFAULT_NETWO= RK_SCRIPT ")\n" " to configure it and 'dfile' (default=3D" DEFAULT_NETW= ORK_DOWN_SCRIPT ")\n" " to deconfigure it\n" - " use '[down]script=3Dno' or '[down]script=3D' to disab= le script execution\n" + " use '[down]script=3D' to disable script execution\n" + " ('[down]script=3Dno' is deprecated and will be treate= d as a file name in future)\n" " use network helper 'helper' (default=3D" DEFAULT_BRID= GE_HELPER ") to\n" " configure it\n" " use 'fd=3Dh' to connect to an already opened TAP inte= rface\n" @@ -3553,7 +3554,9 @@ SRST ``/qemu-ifup`` and the default network deconfigure script = is ``/qemu-ifdown``, where ```` is the system configuration directory at build time (typically ``/etc``). - Use ``[down]script=3Dno`` or ``[down]script=3D`` to disable script exe= cution. + Use ``[down]script=3D`` to disable script execution. + Using ``[down]script=3Dno`` is deprecated; in a future version it will + be treated as a plain file name. =20 If running QEMU as an unprivileged user, use the network helper to configure the TAP interface and attach it to the bridge. --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711242; cv=none; d=zohomail.com; s=zohoarc; b=GzUgpABub5WfNE9aX4cikVlQ01hnYJOdhcX2f9G41SvzqEUu3OdKO8ps+TWwWNwbcyhb1o2T87isUP7VIMYc58Ruor2p4ve6ZIUobN0DaeFvci3gAj1InGhWdPo5ViSTXeQJ20DBWJlCg12//Xb2ouhgavGzc9CrUChZyMdBaPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711242; 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=j7F5sxJJQ7DY0xSPYnrtHnlNZtfSI/XPubp89utS5OE=; b=hZblRUXzUNydkzipPFzA8YfgO71NSg7CWtBTQpILNze/Hb3ebQ8PoR63XW45aVl6pbDBB+Zo0hzIvQ7bA7fQZcsLtiFhpZdeNUSi6MLLZfq+ZENVugz4+p5zVCnk7k2JVZTS7R9ruIV4apDVSD8P/gQLVP49arIot2tOKJ2hR1k= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711242030425.1672743089165; Fri, 10 Jul 2026 12:20:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGk4-0000hW-Kh; Fri, 10 Jul 2026 15:18:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGk1-0000gE-Ml for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:29 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGk0-00055X-3y for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:29 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id E315780DF8; Fri, 10 Jul 2026 22:18:26 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-LkxFyIts; Fri, 10 Jul 2026 22:18:26 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711106; bh=j7F5sxJJQ7DY0xSPYnrtHnlNZtfSI/XPubp89utS5OE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=NqfL5z6JbpfOBLZqtem4pq7xu3Wy+bSx3HhNfQhgIiTG8kYJXy4FE04k8pFD+27Pz RvO30aJgbThpXVnAn4OZGZGTOdxILhKup3/+QzuGke/z0O8iOPxOLmadZLBG1myFEB JGIuL5fJ3yO61okDWWKzRBRKiqh8YYbMPk0Ic9OA= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 04/14] net/tap: move vhost-net open() calls to tap_parse_vhost_fds() Date: Fri, 10 Jul 2026 22:17:53 +0300 Message-ID: <20260710191809.721154-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711244124158500 Content-Type: text/plain; charset="utf-8" 1. Simplify code path: get vhostfds for all cases in one function. 2. Prepare for further tap-fd-migraton feature, when we'll need to postpone vhost initialization up to post-load stage. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1ec9e5ebe6f..2f0ccc138da 100644 --- a/net/tap.c +++ b/net/tap.c @@ -753,8 +753,7 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } } =20 - if (tap->has_vhost ? tap->vhost : - (vhostfd !=3D -1) || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; @@ -764,17 +763,6 @@ static bool net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } else { options.busyloop_timeout =3D 0; } - - if (vhostfd =3D=3D -1) { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_file_open(errp, errno, "/dev/vhost-net"); - goto failed; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; - } - } options.opaque =3D (void *)(uintptr_t)vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; @@ -860,14 +848,31 @@ static int tap_parse_fds_and_queues(const NetdevTapOp= tions *tap, int **fds, static bool tap_parse_vhost_fds(const NetdevTapOptions *tap, int **vhost_f= ds, int queues, Error **errp) { - if (!(tap->vhostfd || tap->vhostfds)) { + bool need_vhost =3D tap->has_vhost ? tap->vhost : + ((tap->vhostfd || tap->vhostfds) || + (tap->has_vhostforce && tap->vhostforce)); + + if (!need_vhost) { *vhost_fds =3D NULL; return true; } =20 - if (net_parse_fds(tap->vhostfd ?: tap->vhostfds, - vhost_fds, queues, errp) < 0) { - return false; + if (tap->vhostfd || tap->vhostfds) { + if (net_parse_fds(tap->vhostfd ?: tap->vhostfds, + vhost_fds, queues, errp) < 0) { + return false; + } + } else { + *vhost_fds =3D g_new(int, queues); + for (int i =3D 0; i < queues; i++) { + int vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (vhostfd < 0) { + error_setg_file_open(errp, errno, "/dev/vhost-net"); + net_free_fds(*vhost_fds, i); + return false; + } + (*vhost_fds)[i] =3D vhostfd; + } } =20 if (!unblock_fds(*vhost_fds, queues, errp)) { --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711208; cv=none; d=zohomail.com; s=zohoarc; b=Z0hF5vMUDmxndYCSQ1r3Yjg9yB65PfGEfXuYJ/iHfpA9FMCCP6VdgJGw45oN4ZPy4XxPxp8OLemXrT+N/cm44+vKW0o9ssMD8KvCCwrvjPdY2t4I58DPEyP6qC93Ru+Vgpxz38oslKIIp3XmvoOyZHVeKu925KzCta4/pO5tbV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711208; 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=wYTFMxty67cpxrqvnVb0SdexdR1ptDjH3O3T1+cVtfo=; b=d6+bj/gk3m0yauhCtG1LY8Oi/Q4CihCvBsBO89XC3oTG0up8f6mpW6/RNUHQLYL1rqZuqm1EwiGpjpF4v+mtENpq/HoBRWBn/XOgFttKuU+tlCmudmzguBQz2rc7GB4n++cVPPt2C7afDGnzBICoGuoCc+OZ8OllsM2bESZ2GtY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711208739761.9558112843944; Fri, 10 Jul 2026 12:20:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGk5-0000hu-LN; Fri, 10 Jul 2026 15:18:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGk4-0000hL-Af for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:32 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGk2-00055v-LM for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:32 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 6C55C80E16; Fri, 10 Jul 2026 22:18:29 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-FFBigJfd; Fri, 10 Jul 2026 22:18:28 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711108; bh=wYTFMxty67cpxrqvnVb0SdexdR1ptDjH3O3T1+cVtfo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=sgk3rNmClcz1VrpbO9nqRkPN6vhyDSgg/Mqs9HvT2od5x5yZji+VAvX/yaGk5E4pD 3I4HViqtUBsBrXmnKka/96eenPkkjMKNNnj3ftc7U9pSsAKlG5G9aJKc0mtK1SppHk 85GkJNvzp0HMhAxlXwQXhRStDgwENEzyerGj7QL8= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 05/14] net/tap: move vhost initialization to tap_setup_vhost() Date: Fri, 10 Jul 2026 22:17:54 +0300 Message-ID: <20260710191809.721154-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711210021158500 Content-Type: text/plain; charset="utf-8" Make a new helper function in a way it can be reused later for TAP fd-migration feature: we'll need to initialize vhost in a later point when we doesn't have access to QAPI parameters. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2f0ccc138da..bc269a2fc3b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -71,6 +71,8 @@ static const int kernel_feature_bits[] =3D { typedef struct TAPState { NetClientState nc; int fd; + int vhostfd; + uint32_t vhost_busyloop_timeout; char down_script[1024]; char down_script_arg[128]; uint8_t buf[NET_BUFSIZE]; @@ -719,6 +721,38 @@ static int net_tap_init(const NetdevTapOptions *tap, i= nt *vnet_hdr, return fd; } =20 +static bool tap_setup_vhost(TAPState *s, Error **errp) +{ + VhostNetOptions options; + + if (s->vhostfd =3D=3D -1) { + return true; + } + + options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; + options.net_backend =3D &s->nc; + 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; + options.save_acked_features =3D NULL; + options.max_tx_queue_size =3D 0; + options.is_vhost_user =3D false; + + s->vhost_net =3D vhost_net_init(&options); + if (!s->vhost_net) { + error_setg(errp, + "vhost-net requested but could not be initialized"); + return false; + } + + /* vhostfd ownership is passed to s->vhost_net */ + s->vhostfd =3D -1; + + return true; +} + static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, const char *name, const char *ifname, const char *script, @@ -753,30 +787,10 @@ static bool net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (vhostfd !=3D -1) { - VhostNetOptions options; - - 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; - } - options.opaque =3D (void *)(uintptr_t)vhostfd; - options.nvqs =3D 2; - options.feature_bits =3D kernel_feature_bits; - options.get_acked_features =3D NULL; - options.save_acked_features =3D NULL; - options.max_tx_queue_size =3D 0; - options.is_vhost_user =3D false; - - s->vhost_net =3D vhost_net_init(&options); - if (!s->vhost_net) { - error_setg(errp, - "vhost-net requested but could not be initialized"); - goto failed; - } + s->vhostfd =3D vhostfd; + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll_us : 0; + if (!tap_setup_vhost(s, errp)) { + return false; } =20 return true; --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711214; cv=none; d=zohomail.com; s=zohoarc; b=idriKWgELYAhRrR9vEl2pQP8t3dqEOTkchaLJWUhbIaFCiEyVWD3lIRncq/wX+MR8Un4SaJJQqYIqvDOMpBPf+RONeHE3848s9Oew3IC1qpk6ySHTNUVU1VIr3kH4pA37cEV9nBmMQj4PClOCrteSP4ppvYG7zgTzcHt/wwFAhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711214; 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=0h4FRshqjUqB96nBxw2kg+mDvm+Iz910HInQMIOp/rg=; b=HIPq/VmcJYhpMeXH6vxcukv59XGXovABzVbxduA3etuwh4l8ZhrLxujlZIHAOQ65cAeipM0YhWe58L/I9VCK0MPQuyM6wFMZj8RRNMW/MMqmekmQqjKpoPjFy53YWjtHfd9GiI2PE4rMJBxqdO0FHf/DolJGAdSkao3pMAiqETw= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711214823378.96114092010225; Fri, 10 Jul 2026 12:20:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkA-0000iV-QA; Fri, 10 Jul 2026 15:18:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGk7-0000i9-3u for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:35 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGk5-00056B-68 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:34 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id DC9A480E18; Fri, 10 Jul 2026 22:18:31 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-wXYy6fBB; Fri, 10 Jul 2026 22:18:31 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711111; bh=0h4FRshqjUqB96nBxw2kg+mDvm+Iz910HInQMIOp/rg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=EHkCR90Viq3Qc07aJDYgyHqFZAgjjFqpp6bE1OKA5YsGCNkc/2kF+lLpr+aryns+O Px+zc2S7Q3cEtQZ+yWy1K1D68QF2ekoV7ONM3rA99GhGesm2HXCgYULlXW3qkHlw7o dEIX7ExgduEwB9vetlB9GkTo6YmTxKhofgfI0Y+s= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 06/14] net/tap: use container_of instead of DO_UPCAST Date: Fri, 10 Jul 2026 22:17:55 +0300 Message-ID: <20260710191809.721154-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711216384158500 Content-Type: text/plain; charset="utf-8" We are going to QOMify tap backend, which includes deriving TAPState from Object. So "NetClientState nc" will not be a first member. Let's parepare for this change, and use container_of(), which will work regardless position of "nc" field. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index bc269a2fc3b..7380a62da80 100644 --- a/net/tap.c +++ b/net/tap.c @@ -172,7 +172,7 @@ static ssize_t tap_write_packet(TAPState *s, const stru= ct iovec *iov, int iovcnt static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); const struct iovec *iovp =3D iov; g_autofree struct iovec *iov_copy =3D NULL; struct virtio_net_hdr hdr =3D { }; @@ -208,7 +208,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int ma= xlen) =20 static void tap_send_completed(NetClientState *nc, ssize_t len) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); tap_read_poll(s, true); } =20 @@ -268,7 +268,7 @@ static void tap_send(void *opaque) =20 static bool tap_has_ufo(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -277,7 +277,7 @@ static bool tap_has_ufo(NetClientState *nc) =20 static bool tap_has_uso(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -286,7 +286,7 @@ static bool tap_has_uso(NetClientState *nc) =20 static bool tap_has_tunnel(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->has_tunnel; @@ -294,7 +294,7 @@ static bool tap_has_tunnel(NetClientState *nc) =20 static bool tap_has_vnet_hdr(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -308,7 +308,7 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, in= t len) =20 static void tap_set_vnet_hdr_len(NetClientState *nc, int len) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 @@ -319,21 +319,21 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, = int len) =20 static int tap_set_vnet_le(NetClientState *nc, bool is_le) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 return tap_fd_set_vnet_le(s->fd, is_le); } =20 static int tap_set_vnet_be(NetClientState *nc, bool is_be) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 return tap_fd_set_vnet_be(s->fd, is_be); } =20 static void tap_set_offload(NetClientState *nc, const NetOffloads *ol) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); if (s->fd < 0) { return; } @@ -354,7 +354,7 @@ static void tap_exit_notify(Notifier *notifier, void *d= ata) =20 static void tap_cleanup(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); =20 if (s->vhost_net) { vhost_net_cleanup(s->vhost_net); @@ -378,14 +378,14 @@ static void tap_cleanup(NetClientState *nc) =20 static void tap_poll(NetClientState *nc, bool enable) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); tap_read_poll(s, enable); tap_write_poll(s, enable); } =20 static bool tap_set_steering_ebpf(NetClientState *nc, int prog_fd) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); =20 return tap_fd_set_steering_ebpf(s->fd, prog_fd) =3D=3D 0; @@ -393,7 +393,7 @@ static bool tap_set_steering_ebpf(NetClientState *nc, i= nt prog_fd) =20 int tap_get_fd(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->fd; } @@ -405,7 +405,7 @@ int tap_get_fd(NetClientState *nc) */ static VHostNetState *tap_get_vhost_net(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); return s->vhost_net; } @@ -444,7 +444,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, =20 nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); =20 - s =3D DO_UPCAST(TAPState, nc, nc); + s =3D container_of(nc, TAPState, nc); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -1012,7 +1012,7 @@ fail: =20 int tap_enable(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); int ret; =20 if (s->enabled) { @@ -1029,7 +1029,7 @@ int tap_enable(NetClientState *nc) =20 int tap_disable(NetClientState *nc) { - TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + TAPState *s =3D container_of(nc, TAPState, nc); int ret; =20 if (s->enabled =3D=3D 0) { --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711276; cv=none; d=zohomail.com; s=zohoarc; b=KR0sFG+Bju3B1BSz5DlT6XBdn6vCWtvxFf2AJCy36hzvT/G3/klurAryMQ5+AZ3j6hx1MW/LXN+09Wsd5r30v7SlayaFHj5DvH+jd3KeRuBXK7B7hTLSCC1aF0UhaFRPfckp/JdYIQNJLUxPYOwQeVQFAL6qgB0w51HdL6kNXHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711276; 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=De8W8Ko9E4F+ee8MUEPj7G1MJp2jPFgwZ8rISzk+8y0=; b=aEirc8t0FEgs3VUln7cNENiF1EADXy2i/ZHPX3dCH2rXXXrORkz31OjiBeDeX2TQs2DNF74ZCQB8h6FOdbebHRYhJMjsjcprAzd+2Wm7wNf8iDs+sZVDKbfY5Y5CfTGE/MkP3psV+jXeV+w9HUZre7bnutO4Sn4ujEbjPG+ZQwE= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711276626989.5185028403503; Fri, 10 Jul 2026 12:21:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkO-0000jn-8m; Fri, 10 Jul 2026 15:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGk9-0000iW-HV for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:38 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGk7-00056T-PD for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 84B3580DF8; Fri, 10 Jul 2026 22:18:34 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-08mUSZoc; Fri, 10 Jul 2026 22:18:33 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711114; bh=De8W8Ko9E4F+ee8MUEPj7G1MJp2jPFgwZ8rISzk+8y0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=oEmvtZtsc61gzu32wT+purYZQrOs66S7TKxzsXqysYnn0siUMkb1fI02kghqI6Hh/ lrz7SAkXh6yAKFdV51nhsSLlUbZ7WInEKjxF23WIY3hDtpZbdDTU0tux+Cm/1vawj6 VDhjUW5Q3FHbvHpAi68qnFa5I4FQN6Mqj+vox9ZM= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 07/14] net/tap: QOMify tap backend Date: Fri, 10 Jul 2026 22:17:56 +0300 Message-ID: <20260710191809.721154-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711278272158500 Content-Type: text/plain; charset="utf-8" We prepare for being able to migrate TAP backend. We'll need a user change-able property for it, which can be set from machine type. So, let's QOMify it first. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/net/net.h | 7 +++++++ include/net/tap.h | 2 ++ net/net.c | 14 +++++++------- net/tap.c | 48 +++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 45bc86fc86b..bdf16bb3e64 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -160,6 +160,13 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr); NetClientState *qemu_find_netdev(const char *id); int qemu_find_net_clients_except(const char *id, NetClientState **ncs, NetClientDriver type, int max); +void qemu_net_client_setup(NetClientState *nc, + NetClientInfo *info, + NetClientState *peer, + const char *model, + const char *name, + NetClientDestructor *destructor, + bool is_datapath); NetClientState *qemu_new_net_client(NetClientInfo *info, NetClientState *peer, const char *model, diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae4..268570571f4 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -28,6 +28,8 @@ =20 #include "standard-headers/linux/virtio_net.h" =20 +#define TYPE_TAP_NETDEV "tap-netdev" + int tap_enable(NetClientState *nc); int tap_disable(NetClientState *nc); =20 diff --git a/net/net.c b/net/net.c index 2892f1730d1..a06558b75bf 100644 --- a/net/net.c +++ b/net/net.c @@ -261,13 +261,13 @@ static ssize_t qemu_deliver_packet_iov(NetClientState= *sender, int iovcnt, void *opaque); =20 -static void qemu_net_client_setup(NetClientState *nc, - NetClientInfo *info, - NetClientState *peer, - const char *model, - const char *name, - NetClientDestructor *destructor, - bool is_datapath) +void qemu_net_client_setup(NetClientState *nc, + NetClientInfo *info, + NetClientState *peer, + const char *model, + const char *name, + NetClientDestructor *destructor, + bool is_datapath) { nc->info =3D info; nc->model =3D g_strdup(model); diff --git a/net/tap.c b/net/tap.c index 7380a62da80..c2f63308ff9 100644 --- a/net/tap.c +++ b/net/tap.c @@ -43,6 +43,7 @@ #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "hw/virtio/vhost.h" +#include "qom/object.h" =20 #include "net/tap.h" #include "net/util.h" @@ -68,7 +69,11 @@ static const int kernel_feature_bits[] =3D { VHOST_INVALID_FEATURE_BIT }; =20 -typedef struct TAPState { +OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV) + +struct TAPState { + Object parent_obj; + NetClientState nc; int fd; int vhostfd; @@ -86,7 +91,7 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; -} TAPState; +}; =20 static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -410,6 +415,19 @@ static VHostNetState *tap_get_vhost_net(NetClientState= *nc) return s->vhost_net; } =20 + +static const TypeInfo tap_netdev_info =3D { + .name =3D TYPE_TAP_NETDEV, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(TAPState), +}; + +static void tap_net_client_destructor(NetClientState *nc) +{ + TAPState *s =3D container_of(nc, TAPState, nc); + object_unref(OBJECT(s)); +} + /* fd support */ =20 static NetClientInfo net_tap_info =3D { @@ -432,6 +450,18 @@ static NetClientInfo net_tap_info =3D { .get_vhost_net =3D tap_get_vhost_net, }; =20 +static TAPState *new_tap(NetClientState *peer, + const char *model, + const char *name) +{ + TAPState *s =3D TAP_NETDEV(object_new(TYPE_TAP_NETDEV)); + + qemu_net_client_setup(&s->nc, &net_tap_info, peer, model, name, + tap_net_client_destructor, true); + + return s; +} + static TAPState *net_tap_fd_init(NetClientState *peer, const char *model, const char *name, @@ -439,12 +469,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, int vnet_hdr) { NetOffloads ol =3D {}; - NetClientState *nc; - TAPState *s; - - nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); - - s =3D container_of(nc, TAPState, nc); + TAPState *s =3D new_tap(peer, model, name); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -1044,3 +1069,10 @@ int tap_disable(NetClientState *nc) return ret; } } + +static void tap_register_types(void) +{ + type_register_static(&tap_netdev_info); +} + +type_init(tap_register_types) --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711172; cv=none; d=zohomail.com; s=zohoarc; b=X7tHZzX1YczDnH1tOQhydMdyMcs9NBvvNi7smGMdCHllaFlqhVeW7FYrBX2PSwuP/k/EyWFuIuW9x2BKvx5YnshjWZlVrSpkLkiH0/w/mu4UmxuT8lPIxXEkcXMPjxzQECKSQLsPB94E1VxWyk8qGnSmSfymquEmQYxx/8c1trc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711172; 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=mlaZ6apYEnKewoMIOTTboOZsP/6zLw/eEpvWPVWwxjg=; b=mTLwlm1V0R5qzEhetMXdBlndcouGDqtuPg5AVKBtghKX93A5fFpytxsPpmTCaiHpSBdAb5TRMm+7dG5/XCjCZ+NMzXI6GxDi2xlwnuGCQ7Y0AbePuLpi+lWEFXGHGpjisR3QlyueS/xGkDOp5C6bXzNfRagvIFB5tYWAhhITDeg= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711172010709.9557956387848; Fri, 10 Jul 2026 12:19:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkS-0000kZ-3J; Fri, 10 Jul 2026 15:18:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkC-0000iq-Oq for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:44 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGkB-00056k-2d for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id CC49980898; Fri, 10 Jul 2026 22:18:36 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-XBorONAa; Fri, 10 Jul 2026 22:18:36 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711116; bh=mlaZ6apYEnKewoMIOTTboOZsP/6zLw/eEpvWPVWwxjg=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=J/9yfkI8xM6aCog6dVhi9UGEN8kv9eLK4eI0om655uIhdxyZDU2ESHjmiLaQufwFt aMI/xh32uP2Tvq0CsEgvcPEdygiKzNseL6EOsts0SieSALcuF5Nxgs+XwvwPkpkjvk We7mnexqALezSLd0UzDV/eE3cKmOYmsWVr9pHNc0= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 08/14] net/tap: add TYPE_VMSTATE_IF interface Date: Fri, 10 Jul 2026 22:17:57 +0300 Message-ID: <20260710191809.721154-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711173943158500 Content-Type: text/plain; charset="utf-8" We'll need it to implement TAP backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/net/tap.c b/net/tap.c index c2f63308ff9..b5be456936d 100644 --- a/net/tap.c +++ b/net/tap.c @@ -43,7 +43,6 @@ #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "hw/virtio/vhost.h" -#include "qom/object.h" =20 #include "net/tap.h" #include "net/util.h" @@ -91,6 +90,8 @@ struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + + int queue_index; }; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -416,10 +417,29 @@ static VHostNetState *tap_get_vhost_net(NetClientStat= e *nc) } =20 =20 +static char *tap_vmstate_if_get_id(VMStateIf *obj) +{ + TAPState *s =3D TAP_NETDEV(obj); + char *res =3D g_strdup_printf("%s/%d", s->nc.name, s->queue_index); + return res; +} + +static void tap_class_init(ObjectClass *klass, const void *data) +{ + VMStateIfClass *vc =3D VMSTATE_IF_CLASS(klass); + + vc->get_id =3D tap_vmstate_if_get_id; +} + static const TypeInfo tap_netdev_info =3D { .name =3D TYPE_TAP_NETDEV, .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(TAPState), + .class_init =3D tap_class_init, + .interfaces =3D (const InterfaceInfo[]) { + { TYPE_VMSTATE_IF }, + { } + }, }; =20 static void tap_net_client_destructor(NetClientState *nc) @@ -452,13 +472,16 @@ static NetClientInfo net_tap_info =3D { =20 static TAPState *new_tap(NetClientState *peer, const char *model, - const char *name) + const char *name, + int queue_index) { TAPState *s =3D TAP_NETDEV(object_new(TYPE_TAP_NETDEV)); =20 qemu_net_client_setup(&s->nc, &net_tap_info, peer, model, name, tap_net_client_destructor, true); =20 + s->queue_index =3D queue_index; + return s; } =20 @@ -466,10 +489,11 @@ static TAPState *net_tap_fd_init(NetClientState *peer, const char *model, const char *name, int fd, - int vnet_hdr) + int vnet_hdr, + int queue_index) { NetOffloads ol =3D {}; - TAPState *s =3D new_tap(peer, model, name); + TAPState *s =3D new_tap(peer, model, name, queue_index); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -706,7 +730,7 @@ 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_fd_init(peer, "bridge", name, fd, vnet_hdr, 0); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -782,10 +806,11 @@ static bool net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, const char *name, const char *ifname, const char *script, const char *downscript, int vhostfd, - int vnet_hdr, int fd, Error **errp) + int vnet_hdr, int fd, int queue_index, + Error **errp) { TAPState *s =3D net_tap_fd_init(peer, tap->helper ? "bridge" : "tap", - name, fd, vnet_hdr); + name, fd, vnet_hdr, queue_index); bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; @@ -986,7 +1011,7 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, if (!net_init_tap_one(tap, peer, name, ifname, NULL, NULL, vhost_fds ? vhost_fds[i] : -1, - vnet_hdr, fds[i], errp)) { + vnet_hdr, fds[i], i, errp)) { goto fail; } } @@ -1020,7 +1045,7 @@ int net_init_tap(const Netdev *netdev, const char *na= me, i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, vhost_fds ? vhost_fds[i] : -1, - vnet_hdr, fd, errp)) { + vnet_hdr, fd, i, errp)) { goto fail; } } --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711219; cv=none; d=zohomail.com; s=zohoarc; b=E0qgTx4HhleGCW4gtJNGEkTGjhx6OKvj75jXbNrIi9zkZSF69C4PMgUtDVAJvO5VvWFHJyn1MRTfvhhhoRT+n5OuiNxVKrRtbtKEek0eIveVAXvJfr1HhSWFH77BIOFUcIm5NvEPPxlZg4QqhD2MlJky5ZCe+d+HhBTH/N9avTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711219; 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=ttlb87vMsTqUA7FIWcHgDFVA2A253o/PTpf/Af7BP8c=; b=JP0HX4q19w++gMlYNlJIys0iDOGku5khkErG34s/W2TpL7Q5CWA0tr5iuBSqzbbQ67yeWw2DcAEJoonOnIGeqnBSD8k2VhM1TvpqIVuQuUQnf89nw8905LwG4tUMmNScr7/DN/xIEWG/WWLOf2lj5C6K2cg74WBo0XPRganycQM= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711219086208.8883326391218; Fri, 10 Jul 2026 12:20:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkc-0000qq-Gc; Fri, 10 Jul 2026 15:19:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkE-0000ir-AR for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:48 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGkC-00056x-KR for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 6CA8480DF8; Fri, 10 Jul 2026 22:18:39 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-ELicxnEe; Fri, 10 Jul 2026 22:18:38 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1783711118; bh=ttlb87vMsTqUA7FIWcHgDFVA2A253o/PTpf/Af7BP8c=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=ZW9dQf9t1ctqQfOwgWnB+8cjaEwIZxC8wi0HMh6efLLeAqQWQ9g6N8c+gwqWXOdSf yoaTI5fYUb7ny8f0IOAqOUioNClrmf5XUuF8Qrj2T/J4PMnBnMuCilh8K3ZIU3pYfd IFC4ZABeNckK1DSNh2AuBnrrn7QPrxP7359HGZZU= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Eric Blake Subject: [PATCH v18 09/14] qapi: add local migration parameter Date: Fri, 10 Jul 2026 22:17:58 +0300 Message-ID: <20260710191809.721154-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711220162158500 Content-Type: text/plain; charset="utf-8" We are going to implement local-migration feature: some devices will be able to transfer open file descriptors through migration stream (which must UNIX domain socket for that purpose). This allows to transfer the whole backend state without reconnecting and restarting the backend service. For example, virtio-net will migrate its attached TAP netdev, together with its connected file descriptors. In this commit we introduce a migration parameter, which enables the feature for devices that support it (none at the moment). Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster Acked-by: Peter Xu Reviewed-by: Ben Chaney --- include/migration/misc.h | 2 ++ migration/options.c | 18 +++++++++++++++++- qapi/migration.json | 12 ++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 2b2fbb59a40..019717f4cda 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -161,4 +161,6 @@ bool multifd_join_device_state_save_threads(void); =20 void migration_request_switchover_ack_legacy(const char *requester); =20 +bool migrate_local(void); + #endif diff --git a/migration/options.c b/migration/options.c index dfce19405d4..5c439f6d724 100644 --- a/migration/options.c +++ b/migration/options.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/units.h" +#include "qapi/util.h" #include "exec/target_page.h" #include "qapi/clone-visitor.h" #include "qapi/error.h" @@ -25,6 +26,7 @@ #include "migration/colo.h" #include "migration/cpr.h" #include "migration/misc.h" +#include "migration/options.h" #include "migration.h" #include "migration-stats.h" #include "qemu-file.h" @@ -350,6 +352,12 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_local(void) +{ + MigrationState *s =3D migrate_get_current(); + return s->parameters.local; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -1085,7 +1093,7 @@ static void migrate_mark_all_params_present(Migration= Parameters *p) &p->has_announce_step, &p->has_block_bitmap_mapping, &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit, &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io, - &p->has_x_rdma_chunk_size, &p->has_cpr_exec_command, + &p->has_x_rdma_chunk_size, &p->has_cpr_exec_command, &p->has_local, }; =20 len =3D ARRAY_SIZE(has_fields); @@ -1433,6 +1441,10 @@ static void migrate_params_test_apply(MigrationParam= eters *params, qapi_free_strList(dest->cpr_exec_command); dest->cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_co= mmand); } + + if (params->has_local) { + dest->local =3D params->local; + } } =20 static void migrate_params_apply(MigrationParameters *params) @@ -1565,6 +1577,10 @@ static void migrate_params_apply(MigrationParameters= *params) s->parameters.cpr_exec_command =3D QAPI_CLONE(strList, params->cpr_exec_command); } + + if (params->has_local) { + s->parameters.local =3D params->local; + } } =20 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) diff --git a/qapi/migration.json b/qapi/migration.json index 66bd900465a..03bdf19f3a6 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -830,7 +830,8 @@ 'zero-page-detection', 'direct-io', { 'name': 'x-rdma-chunk-size', 'features': [ 'unstable' ] }, - 'cpr-exec-command'] } + 'cpr-exec-command', + 'local'] } =20 ## # @migrate-set-parameters: @@ -1012,6 +1013,12 @@ # Must be set to the same value on both source and destination # before migration starts. (Since 11.1) # +# @local: Enable local migration for devices that support it. Backend +# state and its file descriptors can then be passed to the +# destination in the migration channel. The migration channel +# must be a Unix domain socket. Usually needs to be enabled per +# device. (Since 11.2) +# # Features: # # @unstable: Members @x-checkpoint-delay, @x-rdma-chunk-size, and @@ -1053,7 +1060,8 @@ '*direct-io': 'bool', '*x-rdma-chunk-size': { 'type': 'uint64', 'features': [ 'unstable' ] }, - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*local': 'bool' } } =20 ## # @query-migrate-parameters: --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711215; cv=none; d=zohomail.com; s=zohoarc; b=b3xRYKDpA8OBhz7pzC+t4EpNB64zyV7cLHsWvF5KxE01X0BWONhtcelsp6Xqjy8Nv7zGaTzaWFmaDWPRC+jDyGnypDp6lS2+lQt+b8NldKtLnCmWwmBoDqQm8g27Efg/I2wHu/u2agkvNrr20BGxQAjguvVw6oZ5+pLM9BHjVUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711215; 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=rk3jpiKczHrXG+RJOKOqlMLCq/7RFqs8/9lPtTVxFxo=; b=AYwM9ao8WFJzy2cbioWpGQzsviN9cyKqmDDVztpIQiTf+ZK+ZJSXtJGrg6bCJbQPs37Gy9UinuaEHzKMHFXAbn41DGnFUyYGBq7qLzeGz4eDk9r0smXgO/l99tG72FulJF3sDYCGk44Ddg2NHFjdXJ8VwUpdL8f9AlfQi8O+qzk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711215140944.8520329371013; Fri, 10 Jul 2026 12:20:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGke-0000rW-8W; Fri, 10 Jul 2026 15:19:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkH-0000j5-4V for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:50 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGkF-00057O-5e for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:44 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id F1EE780E21; Fri, 10 Jul 2026 22:18:41 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-69lGHUjv; Fri, 10 Jul 2026 22:18: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=1783711121; bh=rk3jpiKczHrXG+RJOKOqlMLCq/7RFqs8/9lPtTVxFxo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=eGO9zaXPyhuV+U3rmenLnKlTVJZe7e+uA6bHuphhsl9npWoCEsbvD7tM/lJFGic1M mfYFCdpZMfYXoCEYasR4PX1PA4mbWLPCDLpyPPp4gIS2Qk4n5y/Lrruo1ns+4NINh5 ePEOZmQZ6YxxSge4s9XcDqXjSwrCHskEuttwrLkg= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 10/14] virtio-net: support local migration of backend Date: Fri, 10 Jul 2026 22:17:59 +0300 Message-ID: <20260710191809.721154-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711216416158500 Content-Type: text/plain; charset="utf-8" Next commit will introduce live-migration (with fd-passing) for TAP net backend. So, now we prepare virtio-net for it Add virtio-net option local-migration, which is true by default, but false for older machine types, which doesn't support the feature. We introduce interface for live-migrating backends: 1. ->is_wait_incoming() handler, so that virtio-net knows, that backend is not fully intialized, as it waits for incoming migration stream. 2. MIG_PRI_BACKEND priority: backends should migrate with higher priority than virtio-net, so that we can do final preparations here in post-load handlers and be sure, that backends are already prepared. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 89 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 1 + include/migration/vmstate.h | 2 + include/net/net.h | 2 + 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f0e3beb2903..c6e7f7a370f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -40,6 +40,7 @@ #include "migration/misc.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" +#include "system/runstate.h" #include "system/replay.h" #include "trace.h" #include "monitor/qdev.h" @@ -3060,7 +3061,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 from virtio_net_post_load_device(), and anyway will be + * no-op for local incoming migration with live backend passing. + */ + if (!n->peers_wait_incoming) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3089,6 +3100,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 (n->peers_wait_incoming) { + /* + * 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); @@ -3185,6 +3207,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int i, link_down; bool has_tunnel_hdr =3D virtio_has_tunnel_hdr(vdev->guest_features_ex); + Error *local_err =3D NULL; =20 trace_virtio_net_post_load_device(); virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, @@ -3242,6 +3265,20 @@ static int virtio_net_post_load_device(void *opaque,= int version_id) } =20 virtio_net_commit_rss_config(n); + + /* + * If live-migration is enabled for some backend, than backend + * has already been migrated at higher priority (MIG_PRI_BACKEND) + * and virtio_net_vnet_post_load() has already called + * peer_test_vnet_hdr(). Recompute host_features so that virtio-net + * reflects the capabilities of the restored backend. + */ + virtio_net_get_features(vdev, &vdev->host_features, &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + return 0; } =20 @@ -3392,6 +3429,14 @@ static int virtio_net_vnet_post_load(void *opaque, i= nt version_id) { struct VirtIONetMigTmp *tmp =3D opaque; =20 + /* + * If live-migration is enabled for some backend, than backend + * has already been migrated at higher priority (MIG_PRI_BACKEND), + * so n->has_vnet_hdr can be refreshed from the live backend right + * here. + */ + peer_test_vnet_hdr(tmp->parent); + if (tmp->has_vnet_hdr && !peer_has_vnet_hdr(tmp->parent)) { error_report("virtio-net: saved image requires vnet_hdr=3Don"); return -EINVAL; @@ -3871,6 +3916,42 @@ static bool failover_hide_primary_device(DeviceListe= ner *listener, return qatomic_read(&n->failover_primary_hidden); } =20 +static bool virtio_net_check_peers_wait_incoming(VirtIONet *n, bool *waiti= ng, + Error **errp) +{ + bool has_waiting =3D false; + bool has_not_waiting =3D false; + + for (int i =3D 0; i < n->max_queue_pairs; i++) { + NetClientState *peer =3D n->nic->ncs[i].peer; + if (!peer) { + continue; + } + + if (peer->info->is_wait_incoming && + peer->info->is_wait_incoming(peer)) { + has_waiting =3D true; + } else { + has_not_waiting =3D true; + } + + if (has_waiting && has_not_waiting) { + error_setg(errp, "Mixed peer states: some peers wait for incom= ing " + "migration while others don't"); + return false; + } + } + + if (has_waiting && !runstate_check(RUN_STATE_INMIGRATE)) { + error_setg(errp, "Peers wait for incoming, but it's not an incomin= g " + "migration."); + return false; + } + + *waiting =3D has_waiting; + return true; +} + static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -4008,6 +4089,12 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->nic->ncs[i].do_not_pad =3D true; } =20 + if (!virtio_net_check_peers_wait_incoming(n, &n->peers_wait_incoming, + errp)) { + virtio_cleanup(vdev); + return; + } + peer_test_vnet_hdr(n); if (peer_has_vnet_hdr(n)) { n->host_hdr_len =3D sizeof(struct virtio_net_hdr); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 371e3764282..8c967760c2a 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -230,6 +230,7 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; uint32_t nr_ebpf_rss_fds; char **ebpf_rss_fds; + bool peers_wait_incoming; }; =20 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 1b7f295417e..bbc569adc52 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -178,6 +178,8 @@ typedef enum { =20 MIG_PRI_LOW, /* Must happen after default */ MIG_PRI_DEFAULT, + MIG_PRI_BACKEND, /* Must happen before emulated devices, */ + /* e.g. virtio-net */ MIG_PRI_IOMMU, /* Must happen before PCI devices */ MIG_PRI_PCI_BUS, /* Must happen before IOMMU */ MIG_PRI_VIRTIO_MEM, /* Must happen before IOMMU */ diff --git a/include/net/net.h b/include/net/net.h index bdf16bb3e64..658b0d0aaf1 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -81,6 +81,7 @@ typedef void (SocketReadStateFinalize)(SocketReadState *r= s); typedef void (NetAnnounce)(NetClientState *); typedef bool (SetSteeringEBPF)(NetClientState *, int); typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **); +typedef bool (IsWaitIncoming)(NetClientState *); typedef struct vhost_net *(GetVHostNet)(NetClientState *nc); =20 typedef struct NetClientInfo { @@ -109,6 +110,7 @@ typedef struct NetClientInfo { NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; + IsWaitIncoming *is_wait_incoming; GetVHostNet *get_vhost_net; } NetClientInfo; =20 --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711162; cv=none; d=zohomail.com; s=zohoarc; b=JUXRV5hAdt8P0FIgQgc8ijlkDcGX1x1n5sWTcuKeWeA1Nn3WAwubE8RVp2TBmxgoJUlbz2yD1ONZF9HQTuZhY554Q6CbIsmtuoYdFDYLa6ZgPEpoV7PT1UkHp7gFB8nO/rrqWagk/6djSaTXzXr7sZWzSLqIPsv5pkiHEzZ+JbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711162; 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=hbYiRyekA3Dmh3vtzBsAip8Kg3UYaird5OyQROLYaS0=; b=Ae1WPj1U4rBheI80o8IMKzF0mvD7HTI6zFIsD3T0wy0YkUvFIWQSN98nFqeVJblFeTLsog4+46jzhz3eCYH1xPsPBx48NT4C5N5WUrb3Ftt+U/XgRIjG8j+MrwqTUiQiRPUbxGiuXh6tz2EMiaeu3deytKEOBaOfQbijMRx9GyY= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711162024593.7018160114836; Fri, 10 Jul 2026 12:19:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkZ-0000pR-Ny; Fri, 10 Jul 2026 15:19:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkJ-0000j8-L4 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:50 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkI-00057d-29 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:47 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id CD8DF807BA; Fri, 10 Jul 2026 22:18:44 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-rMEDC6Ws; Fri, 10 Jul 2026 22:18: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=1783711124; bh=hbYiRyekA3Dmh3vtzBsAip8Kg3UYaird5OyQROLYaS0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=y5lDmJqjXzzWdpiK+tSSdBTEAMnXhQ7VHeY8IHInlbQDpqsvIK6/7gmZpynqF9z5T UkONJBiJKX4f6aTxLFDqYz8THBMKQFHyYVhk8rguNjcRcdh+DSKlCgKM/gSBXO0BDz 3NGKmpgw7dDb6mQJlINz4jyW3tuW+vel7Ap6iHDY= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Jason Wang Subject: [PATCH v18 11/14] net/tap: disable read polling for stopped VM Date: Fri, 10 Jul 2026 22:18:00 +0300 Message-ID: <20260710191809.721154-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711163782158500 Content-Type: text/plain; charset="utf-8" Polling when VM is stopped doesn't make real sense, as stopped VM can't handle incoming traffic anyway. And it's critical for introduction of local TAP migration feature in the next commit: the TAP device will be transferred to the target (open fd will be passed through migration channel), and if we continue polling on source, we may get a package, which we'll never handle on source (already stopped), it will be lost. Better is save this package for target VM to handle. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/net/tap.c b/net/tap.c index b5be456936d..605e5867b01 100644 --- a/net/tap.c +++ b/net/tap.c @@ -36,6 +36,7 @@ #include "net/net.h" #include "clients.h" #include "monitor/monitor.h" +#include "system/runstate.h" #include "system/system.h" #include "qapi/error.h" #include "qemu/cutils.h" @@ -92,6 +93,8 @@ struct TAPState { Notifier exit; =20 int queue_index; + bool read_poll_detached; + VMChangeStateEntry *vmstate; }; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -146,6 +149,23 @@ static void tap_read_poll(TAPState *s, bool enable) tap_update_fd_handler(s); } =20 +static void tap_vm_state_change(void *opaque, bool running, RunState state) +{ + TAPState *s =3D opaque; + + if (running) { + if (s->read_poll_detached) { + tap_read_poll(s, true); + s->read_poll_detached =3D false; + } + } else if (state =3D=3D RUN_STATE_FINISH_MIGRATE) { + if (s->read_poll) { + s->read_poll_detached =3D true; + tap_read_poll(s, false); + } + } +} + static void tap_write_poll(TAPState *s, bool enable) { s->write_poll =3D enable; @@ -376,6 +396,11 @@ static void tap_cleanup(NetClientState *nc) s->exit.notify =3D NULL; } =20 + if (s->vmstate) { + qemu_del_vm_change_state_handler(s->vmstate); + s->vmstate =3D NULL; + } + tap_read_poll(s, false); tap_write_poll(s, false); close(s->fd); @@ -815,6 +840,9 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; =20 + s->read_poll_detached =3D false; + s->vmstate =3D qemu_add_vm_change_state_handler(tap_vm_state_change, s= ); + if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) && sndbuf_required) { goto failed; --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711185; cv=none; d=zohomail.com; s=zohoarc; b=jshG441KfUEX/m6XW+au7ByG3Oye65CoKqt7oc5SQY98Wnv5z3JUTCcrmTH8m5+WrlOKk812Q/B3jNpqPjDMGI9yA7h5CWCwiHXf9IIhPsaOKf3hesgpt+RO2Pn/kN7vqOeTAtWH4Fuo9YqW6ZADyajaaIEmL0tjz7st9dYA/y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711185; 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=QkOwoMXn6aVbh3Vcos0lrw9l1awW+f+7IIrb4muwImI=; b=P1otNWlYnvfRWoWDd0dntz8eScO3n8Mvjp4EXo8KMFmdyv7a+bqTOupcoQYJGDUMgXetgyrV6z8pEf2FkJklAhjz+JLBhgmQtyE8D+tqXGEf5fX21iwKlszibuywgoel1WMcuTxhsq2NONyiBAlGqecXZpYe0rBklEtQAKOHbrA= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711185029817.9649007183457; Fri, 10 Jul 2026 12:19:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkk-0000sw-6s; Fri, 10 Jul 2026 15:19:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkO-0000jw-9D for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:54 -0400 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkL-00057y-49 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id D502B80DDA; Fri, 10 Jul 2026 22:18:47 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-2fnHdEZE; Fri, 10 Jul 2026 22:18: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=1783711127; bh=QkOwoMXn6aVbh3Vcos0lrw9l1awW+f+7IIrb4muwImI=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=kzB7YPFPhwQuWd9bhgLiSNwR6zosrjaf/Ihj5eJxv0oBI8pMJbcdlFMPfneHfKdjb nYMdrrunasfsbk+KX9GjIBUXpE42+qKTdxx6HjmPsibxS53NXTYm0nHqC6YFTA7geC KJtLh+ORH8LXpI39h/22ore18I+wdrpS3NfjpYLc= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Jason Wang , Eric Blake Subject: [PATCH v18 12/14] net/tap: support local migration with virtio-net Date: Fri, 10 Jul 2026 22:18:01 +0300 Message-ID: <20260710191809.721154-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711186353158500 Content-Type: text/plain; charset="utf-8" Support transferring of TAP state (including open fd). Add new property "local-migration-supported", which defines whether local-migration is actually supported for this TAP device. Starting from 11.2 QEMU Machine Types it's enabled by default. Note, that local-migration (including migrating opened FDs through migration channel, which must be UNIX socket), is enabled by global "local" migration parameters. But individual devices may have additional options to enable/disable it per device. The tricky thing, is that we need to know, should we do call open/connect in TAP initialization code. That means, that on incoming migration we want to know status of "local" migration parameter at time of creating TAP device. So, currently, for incoming local migration only TAP device created through QMP is supported, as you need to set migration parameter first (through QMP as well). So the full picture is: On source, to start outgoing "local" migration you need: - migration parameter "local" set to true - "local-migration-supported" TAP option set to true (the default, starting from 11.2 QEMU Machine Types) If at least one of these options is not set, TAP backend doesn't participate in migration. On target, things are more difficult: Same, you need both "local" and "local-migration-supported" be set. And same, if one of them is not set, TAP backend is initialized as usual, and doesn't accept any incoming state. Additionally, if you are going to set "local", it must be set before creating the TAP device. If TAP device created with "local" unset, it initializes as usual. If you enable "local" after it and start incoming migration, it will fail in .pre_load handler of TAP backend. Moreover, there are interface restrictions: if you create TAP device when QEMU is in INCOMING state, and both "local" and "local-migration-supported" set, most of TAP options are not allowed, and script/downscript are required to be explicitly unset (set to "" or "no"). Signed-off-by: Vladimir Sementsov-Ogievskiy --- In v17 thread we considered making new qapi parameters "unstable". Still, it was because of doubtful "incoming-fds" parameter. In this v18 it's completely removed, and we may live only with "local" migration parameter + "local-migration-supported" TAP option. This way the series doesn't conflict with suggested by Peter [PATCH RFC 0/2] migration/vl: new -incoming config:* for early migration = parameters So, I think, worth making one more iteration as "stable candidate". If still some doubts, not problem for me to resend with "unstable" features. hw/core/machine.c | 7 ++ net/tap.c | 162 ++++++++++++++++++++++++++++++++++++++++++++-- qapi/net.json | 23 ++++++- 3 files changed, 185 insertions(+), 7 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 15886a56b19..2a1abb29041 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -36,10 +36,16 @@ #include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-iommu.h" +#include "net/tap.h" #include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" #include "hw/arm/smmuv3.h" =20 +/* + * TODO: When hw_compat_11_1 appears, local-migration-supported=3Dfalse + * for TYPE_TAP_NETDEV should be move to it from hw_compat_11_0. + */ + GlobalProperty hw_compat_11_0[] =3D { { "chardev-vc", "encoding", "cp437" }, { "tpm-crb", "cap-chunk", "off" }, @@ -49,6 +55,7 @@ GlobalProperty hw_compat_11_0[] =3D { { TYPE_ARM_SMMUV3, "ssidsize", "0" }, { TYPE_ARM_SMMUV3, "oas", "44" }, { "migration", "switchover-ack-legacy", "on" }, + { TYPE_TAP_NETDEV, "local-migration-supported", "false" }, }; const size_t hw_compat_11_0_len =3D G_N_ELEMENTS(hw_compat_11_0); =20 diff --git a/net/tap.c b/net/tap.c index 605e5867b01..adcac70b7ea 100644 --- a/net/tap.c +++ b/net/tap.c @@ -38,12 +38,17 @@ #include "monitor/monitor.h" #include "system/runstate.h" #include "system/system.h" +#include "migration/misc.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/sockets.h" #include "hw/virtio/vhost.h" +#include "hw/core/vmstate-if.h" +#include "migration/vmstate.h" +#include "qom/object.h" +#include "qom/compat-properties.h" =20 #include "net/tap.h" #include "net/util.h" @@ -71,6 +76,8 @@ static const int kernel_feature_bits[] =3D { =20 OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV) =20 +static const VMStateDescription vmstate_tap; + struct TAPState { Object parent_obj; =20 @@ -95,6 +102,7 @@ struct TAPState { int queue_index; bool read_poll_detached; VMChangeStateEntry *vmstate; + bool local_migration_supported; }; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -405,6 +413,8 @@ static void tap_cleanup(NetClientState *nc) tap_write_poll(s, false); close(s->fd); s->fd =3D -1; + + vmstate_unregister(VMSTATE_IF(s), &vmstate_tap, s); } =20 static void tap_poll(NetClientState *nc, bool enable) @@ -441,6 +451,73 @@ static VHostNetState *tap_get_vhost_net(NetClientState= *nc) return s->vhost_net; } =20 +static bool tap_is_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D container_of(nc, TAPState, nc); + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + return s->fd =3D=3D -1; +} + +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 bool tap_setup_vhost(TAPState *s, Error **errp); + +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + Error *local_err =3D NULL; + + tap_read_poll(s, true); + + if (s->fd < 0) { + return -1; + } + + if (!tap_setup_vhost(s, &local_err)) { + error_prepend(&local_err, + "Failed to setup vhost during TAP post-load: "); + error_report_err(local_err); + return -1; + } + + return 0; +} + +static bool tap_needed(void *opaque) +{ + TAPState *s =3D opaque; + + return s->local_migration_supported && migrate_local(); +} + +static const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .priority =3D MIG_PRI_BACKEND, + .pre_load =3D tap_pre_load, + .post_load =3D tap_post_load, + .needed =3D tap_needed, + .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() + } +}; =20 static char *tap_vmstate_if_get_id(VMStateIf *obj) { @@ -449,17 +526,42 @@ static char *tap_vmstate_if_get_id(VMStateIf *obj) return res; } =20 +static bool tap_get_local_migration_supported_prop(Object *obj, Error **er= rp) +{ + TAPState *s =3D TAP_NETDEV(obj); + return s->local_migration_supported; +} + +static void tap_set_local_migration_supported_prop(Object *obj, bool value, + Error **errp) +{ + TAPState *s =3D TAP_NETDEV(obj); + s->local_migration_supported =3D value; +} + +static void tap_instance_init(Object *obj) +{ + TAPState *s =3D TAP_NETDEV(obj); + s->local_migration_supported =3D true; +} + static void tap_class_init(ObjectClass *klass, const void *data) { VMStateIfClass *vc =3D VMSTATE_IF_CLASS(klass); =20 vc->get_id =3D tap_vmstate_if_get_id; + + object_class_property_add_bool(klass, "local-migration-supported", + tap_get_local_migration_supported_prop, + tap_set_local_migration_supported_prop); } =20 static const TypeInfo tap_netdev_info =3D { .name =3D TYPE_TAP_NETDEV, .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(TAPState), + .instance_init =3D tap_instance_init, + .instance_post_init =3D object_apply_compat_props, .class_init =3D tap_class_init, .interfaces =3D (const InterfaceInfo[]) { { TYPE_VMSTATE_IF }, @@ -492,13 +594,16 @@ static NetClientInfo net_tap_info =3D { .set_vnet_le =3D tap_set_vnet_le, .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, + .is_wait_incoming =3D tap_is_wait_incoming, .get_vhost_net =3D tap_get_vhost_net, }; =20 static TAPState *new_tap(NetClientState *peer, const char *model, const char *name, - int queue_index) + int queue_index, + bool has_local_migration_supported, + bool local_migration_supported) { TAPState *s =3D TAP_NETDEV(object_new(TYPE_TAP_NETDEV)); =20 @@ -507,6 +612,12 @@ static TAPState *new_tap(NetClientState *peer, =20 s->queue_index =3D queue_index; =20 + if (has_local_migration_supported) { + s->local_migration_supported =3D local_migration_supported; + } + + vmstate_register(VMSTATE_IF(s), VMSTATE_INSTANCE_ID_ANY, &vmstate_tap,= s); + return s; } =20 @@ -515,10 +626,14 @@ static TAPState *net_tap_fd_init(NetClientState *peer, const char *name, int fd, int vnet_hdr, - int queue_index) + int queue_index, + bool has_local_migration_supported, + bool local_migration_supported) { NetOffloads ol =3D {}; - TAPState *s =3D new_tap(peer, model, name, queue_index); + TAPState *s =3D new_tap(peer, model, name, queue_index, + has_local_migration_supported, + local_migration_supported); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -755,7 +870,7 @@ 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, 0); + s =3D net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr, 0, true, fal= se); =20 qemu_set_info_str(&s->nc, "helper=3D%s,br=3D%s", helper, br); =20 @@ -835,7 +950,9 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, Error **errp) { TAPState *s =3D net_tap_fd_init(peer, tap->helper ? "bridge" : "tap", - name, fd, vnet_hdr, queue_index); + name, fd, vnet_hdr, queue_index, + tap->has_local_migration_supported, + tap->local_migration_supported); bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; @@ -983,6 +1100,7 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, /* for the no-fd, no-helper case */ char ifname[128]; int *fds =3D NULL, *vhost_fds =3D NULL; + bool incoming_fds; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -1005,6 +1123,23 @@ int net_init_tap(const Netdev *netdev, const char *n= ame, return -1; } =20 + incoming_fds =3D tap->local_migration_supported && migrate_local() && + runstate_check(RUN_STATE_INMIGRATE); + + if (incoming_fds && + (tap->fd || tap->fds || tap->helper || tap->br || tap->ifname || + tap->has_sndbuf || tap->has_vnet_hdr || + !tap_is_explicit_no_script(tap->script) || + !tap_is_explicit_no_script(tap->downscript))) { + error_setg(errp, "Local incoming migration of TAP device (-incomin= g, " + "migration parameter @local is set, " + "TAP parameter @local-migration-supported is set) " + "is incompatible with " + "fd=3D, fds=3D, helper=3D, br=3D, ifname=3D, sndbuf=3D = and vnet_hdr=3D, " + "and requires explicit empty script=3D and downscript= =3D"); + return -1; + } + queues =3D tap_parse_fds_and_queues(tap, &fds, errp); if (queues < 0) { return -1; @@ -1023,7 +1158,22 @@ int net_init_tap(const Netdev *netdev, const char *n= ame, goto fail; } =20 - if (fds) { + if (incoming_fds) { + for (i =3D 0; i < queues; i++) { + TAPState *s =3D new_tap(peer, "tap", name, i, + tap->has_local_migration_supported, + tap->local_migration_supported); + qemu_set_info_str(&s->nc, "incoming"); + + s->fd =3D -1; + if (vhost_fds) { + s->vhostfd =3D vhost_fds[i]; + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll= _us : 0; + } else { + s->vhostfd =3D -1; + } + } + } else if (fds) { for (i =3D 0; i < queues; i++) { if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fds[i], errp); diff --git a/qapi/net.json b/qapi/net.json index ada0329ef9d..2070979f20e 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -435,6 +435,26 @@ # @poll-us: maximum number of microseconds that could be spent on busy # polling for tap (since 2.7) # +# @local-migration-supported: enable local migration for this TAP +# backend. When set, local migration is enabled/disabled by +# migration parameter @local for this TAP backend. When unset, +# migration parameter @local is ignored for this TAP backend. +# To be able to do incoming local migration of TAP backend, +# migration parameter @local must be set _before_ creating the +# TAP backend. Otherwise, TAP backend is initialized as usual, +# opening/creating TAP devices in kernel. In this case further +# local incoming migration (with migration parameter @local set +# after creating TAP backend with @local-migration-supporeted +# parameter set) will simply fail. +# Moreover, when QEMU is in incoming migration state, migration +# parameter @local is set and @local-migration-supported is set, +# following options are not supported and must not be set: +# @ds, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr. +# Additionally in this case @script and @downscipt must be +# explicitly disabled (empty strings or "no"). +# (Since 11.2. Defaults to true for QEMU Machine Types >=3D 11.2, +# and to false for QEMU Machine Types < 11.2) +# # Since: 1.2 ## { 'struct': 'NetdevTapOptions', @@ -453,7 +473,8 @@ '*vhostfds': 'str', '*vhostforce': 'bool', '*queues': 'uint32', - '*poll-us': 'uint32'} } + '*poll-us': 'uint32', + '*local-migration-supported': 'bool' } } =20 ## # @NetdevSocketOptions: --=20 2.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711239; cv=none; d=zohomail.com; s=zohoarc; b=RkfCC8sD9LZO8nVjtSY9ns4TpdrBdrdtgQg1wTZdGjsiY//cV7ntF5IpaGBM+S2nFdUyi78AXrZ0+j3eCQ9zngdR5dqaqgQfTDP3oLSUdx/Mx07jr30fKHWzTwurUjCjjfKs6kVzcyIxF9WZXKozO09Md1CvZTcXK4x2NRc+3zk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711239; 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=ZyIouWud7rbL1EFPuOUataXp3Mt3zQlDWZq23EqDr5k=; b=aOXgtYsPUa+tCudHqBd4SaVhIzDik+hGjDHTalev+xiG8CYTsSbNjsOiYHmUcabxrjHftd1O53EF6MHcbu3HSZJ0dPnBTTR1eE8laxn//CIY34EODucdOaliRYREWYxtJ3wsaxEREL4ugo/SfcSeYzFirHmw680kxlqvy/PBMG4= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178371123976028.496014090023095; Fri, 10 Jul 2026 12:20:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGki-0000sg-A1; Fri, 10 Jul 2026 15:19:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkP-0000kJ-PZ for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:54 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGkO-00058R-BI for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:53 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 20A5C80DF7; Fri, 10 Jul 2026 22:18:51 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-VFGXCG7b; Fri, 10 Jul 2026 22:18: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=1783711130; bh=ZyIouWud7rbL1EFPuOUataXp3Mt3zQlDWZq23EqDr5k=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=FU8cg5tidNLbJdtbw0QDeHLPWjPb4KHfWJgEqGDrGL7tBCGtkHs5ViFHGJJ6tY5vX E+GnL4kfUaNNIp72CREZVnzczRAQ7VUXh45WdlBPJgMdonZcqu1Iu9KTIxI8WKIVrP LkTQ4pcRiYNm4WwcCuJqsqNZJETvcpd1axrUpPVk= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Thomas Huth , Lei Yang , Maksim Davydov , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v18 13/14] tests/functional: add skipWithoutSudo() decorator Date: Fri, 10 Jul 2026 22:18:02 +0300 Message-ID: <20260710191809.721154-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711240415158500 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 Reviewed-by: Ben Chaney --- 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 fcf236ecfdf..aa135acc785 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 @@ -177,3 +178,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.43.0 From nobody Sat Jul 11 03:34:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1783711265; cv=none; d=zohomail.com; s=zohoarc; b=BJgY6+z6snfwWim1zGG541qgxagYhe6tl9OZAPKc0X5bsp9fDSPwAg4Q+S6wE7W6hcs8WjJzPaP1CNA7tEJRUmNDQMpGLV7yR6LvtzL0EJVQ9VFJfuqcazKBufnbh+/nNIHSljth0wHfhxp+Ae/VTggoR6c5vgcP6KyzBjNuWz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783711265; 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=QM2KU/F61kdTE1Pxw6JsF4+Uk9m8MAG959brpWilJEA=; b=ATD3Xttv7MC3xeu0RNIljl4uerqwTLZ3jT4qu9FYMl11cKhA7zGVNO2vwNlnFZCpIK9YpKy8eGOuxBY7U0Dcmbs42z+t3sHFrMln4jG2QzsEiwKuXKGyxeoOyDT8k43VAL/PvUw4aHsVlJ4gY/wHN7yGuOWKd4B6/R9znbchJFc= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783711265695148.8028714419736; Fri, 10 Jul 2026 12:21:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wiGkg-0000sX-CB; Fri, 10 Jul 2026 15:19:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wiGkU-0000np-D4 for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:59 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1wiGkR-00058s-KH for qemu-devel@nongnu.org; Fri, 10 Jul 2026 15:18:58 -0400 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 6138B807BA; Fri, 10 Jul 2026 22:18:54 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c7d::1:20]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AIRXsO0a8eA0-fUtzjV6i; Fri, 10 Jul 2026 22:18: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=1783711133; bh=QM2KU/F61kdTE1Pxw6JsF4+Uk9m8MAG959brpWilJEA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=I+iWQKQMnn/13b26Oq/5FA1ORAIa4sjdtCg0Yri2Ct1aeKGb1lv3qK7Sh171GvSTo Ju19Q8bEXs6Oe9YTce0/UCkQ+jQYOvXkjr0Bcmb6C3YkC9pWYmXjUoHMQ4TaAY7T3u lq7UNg+vir6aAxrdRH0B70o/vrNtQOQaOJpRzb68= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: armbru@redhat.com, peterx@redhat.com, farosas@suse.de, raphael.s.norwitz@gmail.com, bchaney@akamai.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, yc-core@yandex-team.ru, mark.caveayland@nutanix.com, Zhao Liu Subject: [PATCH v18 14/14] tests/functional: add test_tap_migration Date: Fri, 10 Jul 2026 22:18:03 +0300 Message-ID: <20260710191809.721154-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710191809.721154-1-vsementsov@yandex-team.ru> References: <20260710191809.721154-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=lists1p.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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: qemu development 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: 1783711268358158500 Content-Type: text/plain; charset="utf-8" Add test for a new local-migration migration of virtio-net/tap, with fd passing through UNIX socket. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- tests/functional/x86_64/meson.build | 1 + tests/functional/x86_64/test_tap_migration.py | 455 ++++++++++++++++++ 2 files changed, 456 insertions(+) create mode 100755 tests/functional/x86_64/test_tap_migration.py diff --git a/tests/functional/x86_64/meson.build b/tests/functional/x86_64/= meson.build index 27b31f2e966..eaf2ec0005a 100644 --- a/tests/functional/x86_64/meson.build +++ b/tests/functional/x86_64/meson.build @@ -47,4 +47,5 @@ tests_x86_64_system_thorough =3D [ 'virtio_balloon', 'virtio_gpu', 'rebuild_vmfd', + 'tap_migration', ] diff --git a/tests/functional/x86_64/test_tap_migration.py b/tests/function= al/x86_64/test_tap_migration.py new file mode 100755 index 00000000000..bcc0a60dfe9 --- /dev/null +++ b/tests/functional/x86_64/test_tap_migration.py @@ -0,0 +1,455 @@ +#!/usr/bin/env python3 +# +# Functional test that tests TAP local migration +# with fd passing +# +# Copyright (c) Yandex Technologies LLC, 2026 +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess +from subprocess import run +import signal +import ctypes +import ctypes.util +import unittest +from contextlib import contextmanager, ExitStack +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 "192.168.100.2" +GUEST_IP_MASK =3D f"{GUEST_IP}/24" +GUEST_MAC =3D "d6:0d:75:f8:0f:b7" +HOST_IP =3D "192.168.100.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" +NETNS =3D f"qemu_test_ns_{os.getpid()}" + + +def ip(args, check=3DTrue) -> None: + """Run ip command with sudo""" + run(["sudo", "ip"] + args, check=3Dcheck) + + +@contextmanager +def switch_netns(netns_name): + libc =3D ctypes.CDLL(ctypes.util.find_library("c")) + netns_path =3D f"/var/run/netns/{netns_name}" + + def switch_to_fd(fd, check: bool =3D False): + """Switch to netns by file descriptor""" + SYS_setns =3D 308 + CLONE_NEWNET =3D 0x40000000 + ret =3D libc.syscall(SYS_setns, fd, CLONE_NEWNET) + if check and ret !=3D 0: + raise RuntimeError("syscall SETNS failed") + + with ExitStack() as stack: + original_netns_fd =3D os.open("/proc/self/ns/net", os.O_RDONLY) + stack.callback(os.close, original_netns_fd) + + ip(["netns", "add", netns_name]) + stack.callback(ip, ["netns", "del", netns_name], check=3DFalse) + + new_netns_fd =3D os.open(netns_path, os.O_RDONLY) + stack.callback(os.close, new_netns_fd) + + switch_to_fd(new_netns_fd) + stack.callback(switch_to_fd, original_netns_fd, check=3DFalse) + + yield + + +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 TAPFdMigration(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", + ) + + @classmethod + def setUpClass(cls): + super().setUpClass() + + try: + cls.netns_context =3D switch_netns(NETNS) + cls.netns_context.__enter__() + except (OSError, subprocess.CalledProcessError) as e: + raise unittest.SkipTest(f"can't switch network namespace: {e}") + + @classmethod + def tearDownClass(cls): + if hasattr(cls, "netns_context"): + cls.netns_context.__exit__(None, None, None) + super().tearDownClass() + + def setUp(self): + super().setUp() + + init_tap() + + self.outer_ping_proc =3D None + self.shm_path =3D None + + def tearDown(self): + try: + del_tap(TAP_ID) + del_tap(TAP_ID2) + + if self.outer_ping_proc: + self.stop_outer_ping() + + if self.shm_path: + os.unlink(self.shm_path) + 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.05 + 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], + stdout=3Dsubprocess.DEVNULL, + check=3DTrue, + ) + + def setup_shared_memory(self): + self.shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(self.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}") + + def prepare_and_launch_vm( + self, shm_path, vhost, incoming=3DFalse, vm=3DNone, local=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() + + if not local: + tap_name =3D TAP_ID2 if incoming else TAP_ID + else: + tap_name =3D TAP_ID + + self.set_migration_capabilities(vm, local) + self.add_virtio_net(vm, vhost, tap_name, local, incoming) + + def add_virtio_net( + self, vm, vhost: bool, tap_name: str, local: bool, incoming: bool + ): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "queues": 4, + "script": "no", + "downscript": "no", + "local-migration-supported": local, + } + + if not (local and incoming): + netdev_params["vnet_hdr"] =3D True + netdev_params["ifname"] =3D tap_name + + 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", + ) + + def set_migration_capabilities(self, vm, local=3DTrue): + vm.cmd( + "migrate-set-capabilities", + { + "capabilities": [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + ] + }, + ) + vm.cmd("migrate-set-parameters", {"local": local}) + + 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, local=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= ") + + self.setup_shared_memory() + + # Setup second TAP if needed + if not local: + del_tap(TAP_ID2) + init_tap(TAP_ID2, with_ip=3DFalse) + + self.prepare_and_launch_vm(self.shm_path, vhost, local=3Dlocal) + 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( + self.shm_path, + vhost, + incoming=3DTrue, + vm=3Dtarget_vm, + local=3Dlocal, + ) + + 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 local-migration + if not local: + 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, local=3DFalse) + + def test_tap_new_tap_migration_vhost(self): + self.do_test_tap_fd_migration(True, local=3DFalse) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.43.0