From nobody Wed Aug 26 10:14:38 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=1787162609; cv=none; d=zohomail.com; s=zohoarc; b=HzjwS5d6iI6C6eYXBtnFwVouarXBeSchNv+wHeFRd30mpeMaj6EbawNItXvJCk7VoJjycV+a+6NLDK7iJ+KXbYq+xFlh428DCsK6ANmR60L+zrcNd0xFt97wlU9Ue2Kcr5GYmHnMxW6P/q8AT6HvX5+L4qY3y0aw/jKuN/sbYMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162609; 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=lmYi8DtpYsJTeHd6tqjdBZ55BO04Rgs7XTcDuNkcnIc=; b=D7Rf/eL6CP7QlZVO10jhRbvFVD7jHQRTz5NEdn/F7ROG9+NaS3pn8UwxGz95EoNtfseqkgfbyaWQbscuHt6mh0o9SfbrbYZCCrQK6YnIYBBXELA3LYb8I222MqBJfzh8+cjypCKsE+883UD1hihlpOEJaU0X23MX+00Omwn3+8s= 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 1787162609047443.95813636723017; Wed, 19 Aug 2026 11:03:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcT-0004Fo-8a; Wed, 19 Aug 2026 14:02: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 1wwkcR-0004F0-2c for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:31 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcO-0007Mq-U5 for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:30 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 0FD4CC050A; Wed, 19 Aug 2026 21:02:25 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-Fb0KcTNd; Wed, 19 Aug 2026 21:02:24 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162544; bh=lmYi8DtpYsJTeHd6tqjdBZ55BO04Rgs7XTcDuNkcnIc=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=iCBEFoYMXiP5UPty7ZsMW0cPVsT/CnjuRPK1jW7tk+c4TG7rx3feUzcNwvtmi7Dj5 1tXowvXSMgQBx5I5k8hrG6mYPnBLHGcHYDrzNEzeaJMx/1qZRXxl1OFKilUDczSuLd X15JuELGTO5QIdMf93KtkjXf3IjFaA4+2uy/N9HM= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 01/16] net/tap: rework tap_parse_script Date: Wed, 19 Aug 2026 21:01:44 +0300 Message-ID: <20260819180201.1970193-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162610294158500 Content-Type: text/plain; charset="utf-8" Factor out tap_is_explicit_no_script() helper, to simplify further changes. Avoid extra copying by simpler code flow: first check for NULL / empty / "no" cases, then get default or do copying respectively. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney Reviewed-by: Markus Armbruster --- net/tap.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index 57ffb09885c..2076f5b7802 100644 --- a/net/tap.c +++ b/net/tap.c @@ -92,19 +92,35 @@ 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_value) { - g_autofree char *res =3D g_strdup(script_arg); + if (!script_arg_value) { + return false; + } + + if (script_arg_value[0] =3D=3D '\0') { + return true; + } =20 - if (!res) { - res =3D get_relocated_path(default_path); + if (strcmp(script_arg_value, "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_value, + const char *default_path) +{ + if (tap_is_explicit_no_script(script_arg_value)) { return NULL; } =20 - return g_steal_pointer(&res); + if (!script_arg_value) { + return get_relocated_path(default_path); + } + + return g_strdup(script_arg_value); } =20 static void tap_update_fd_handler(TAPState *s) --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162611; cv=none; d=zohomail.com; s=zohoarc; b=EDeOiNd+h+PHZ9qwdVxUnRmAF7JHKDsAHFqQ39avuBsW/rMhyPpSkvxTTBrQlCRNzUrdLnNrX19rr3mm1rgyCZsaWMLbiu39+vvPfW8YzxTv3qSWG+C0D79wKhS7u7d2lusxfAYetl/zMh68U+fj7oN2wbZBYx5nVkH91z0iH6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162611; 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=DaeKnaftV441pYWOLN5La1ohWjtFSUg301klU0RusmE=; b=hWIJH3uywY10RvMmlDs7PY/tCcA5PMPy4kVN6Pct2r29B9b6sxF6ArNSjmvwx7dOyLpSucLeI5nPrKc7XXtcacQHQOpREWm7PLx9N7cJq+gBOo9QVAwTathOcZ+x8ZP2PaYu5VYxZQzwPuaqexBI9gygqqu1bS1NO/a3tI/u/B4= 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 1787162611087224.12411569889787; Wed, 19 Aug 2026 11:03:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcU-0004Gu-C2; Wed, 19 Aug 2026 14:02:34 -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 1wwkcR-0004F8-Gw for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:31 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcO-0007N0-Sl for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:31 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id E6332C08AF; Wed, 19 Aug 2026 21:02:25 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-OZ4AJoq1; Wed, 19 Aug 2026 21:02:25 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162545; bh=DaeKnaftV441pYWOLN5La1ohWjtFSUg301klU0RusmE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=oj+z3/PjW1ODxH6tGciuBDi7o3Z5SyApwS6tm19Rv5vY0wwaR6SBuaktOh+L+xff9 7W+BdHfNd4Vq7SUsHESI3bdpJBwiEuqYq+GXKvR952+sa4dONun7GLBnZF1UhzNltf J6ShjaP3JLi5t+hIfO3nG5gPwoWvusp74AaH9W9s= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 02/16] net/tap: improve script/downscript options documentation Date: Wed, 19 Aug 2026 21:01:45 +0300 Message-ID: <20260819180201.1970193-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162612082158500 Content-Type: text/plain; charset="utf-8" Properly document defaults and special values of "" and "no". Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster Reviewed-by: Ben Chaney --- 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 Wed Aug 26 10:14:38 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=1787162577; cv=none; d=zohomail.com; s=zohoarc; b=QpIOsdxCulFPxB+VPl+X5lApGZhu3ASZLbczFlOUWxFrZo7H74vsGV926wywKOI0HqVCJDvhhZsHySKxLBTxS2FjvX5usEFWH/+c1UQhW+eJf9vkuGFHIH7BRU7Ul1u7PSOXvufU8/j085eE6B/jkJ8+cTnCQ4mAxe9ujjQTQxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162577; 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=CPeeLqJxqKF0PJ+VeCy5iEY5SVA2hqQkETeHHoPveXg=; b=bMogwUJVunQ5uCPMNbRwzqLuL7yXUWIEgVo/30BVc/qG7K+ZBnHrZXTKR9PYSHAtHRakK2iHlsmi883yTtow6AKmByHB9wcVBUrB0rqRqyyhaZRMMuKJ9kMup4DQhfJJD3bUvApQ1e4324KRHcf4STPoniLfOgNk3Hu4Fv0wXzc= 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 1787162576556752.263233979263; Wed, 19 Aug 2026 11:02:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1395733.1634001 (Exim 4.92) (envelope-from ) id 1wwkcS-0005pM-Sa; Wed, 19 Aug 2026 18:02:32 +0000 Received: by outflank-mailman (output) from mailman id 1395733.1634001; Wed, 19 Aug 2026 18:02:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wwkcS-0005pE-PF; Wed, 19 Aug 2026 18:02:32 +0000 Received: by outflank-mailman (input) for mailman id 1395733; Wed, 19 Aug 2026 18:02:31 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wwkcR-0005p6-1t for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 18:02:31 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wwkcQ-00HJ65-1B for xen-devel@lists.xenproject.org; Wed, 19 Aug 2026 20:02:30 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a85efa2-e002-0a2a0a5209dd-0a2a4504c5c4-40 for ; Wed, 19 Aug 2026 20:02:29 +0200 Received: from [178.154.239.72] (helo=forwardcorp1a.mail.yandex.net) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a85efb4-b57f-0a2a45040019-b29aef48ed32-3 for ; Wed, 19 Aug 2026 20:02:29 +0200 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 10899C08B2; Wed, 19 Aug 2026 21:02:28 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-qhLICAcE; Wed, 19 Aug 2026 21:02:27 +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=1787162547; bh=CPeeLqJxqKF0PJ+VeCy5iEY5SVA2hqQkETeHHoPveXg=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=X0qxl4T1N4agxXBLxlA8rsZ/MmLq7UY9J5IlIHa24kDsVWfZKc6JTYcBxqBFZGZOP 2qUpSTZ24Ca/LuB4MfyK4TL2UzXPm+ccIIjWG7Sdbnh5ORwxlpE744i/u1JLhVIMOL 51uho2cmQTw0xlbwU2PTQXiOH5jRVvv5gyc3c+Gc= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 , Conor Dooley , Sebastian Huber , 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 v21 03/16] net/tap: deprecate "no" as special value for script/downscript Date: Wed, 19 Aug 2026 21:01:46 +0300 Message-ID: <20260819180201.1970193-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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-ebf023/1787162549-C18D1B50-2840CCE6/0/0 X-purgate-type: clean X-purgate-size: 12499 X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1787162581095158500 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 Reviewed-by: Ben Chaney Reviewed-by: Markus Armbruster --- 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 | 17 +++++++++++------ qapi/net.json | 14 ++++++++++---- qemu-options.hx | 8 ++++++-- 9 files changed, 52 insertions(+), 19 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 2076f5b7802..f4051e8d4b1 100644 --- a/net/tap.c +++ b/net/tap.c @@ -92,7 +92,8 @@ static void launch_script(const char *setup_script, const= char *ifname, static void tap_send(void *opaque); static void tap_writable(void *opaque); =20 -static bool tap_is_explicit_no_script(const char *script_arg_value) +static bool tap_is_explicit_no_script(const char *script_arg_name, + const char *script_arg_value) { if (!script_arg_value) { return false; @@ -103,16 +104,19 @@ static bool tap_is_explicit_no_script(const char *scr= ipt_arg_value) } =20 if (strcmp(script_arg_value, "no") =3D=3D 0) { + warn_report("'%s=3Dno' is deprecated; use '%s=3D' instead", + script_arg_name, script_arg_name); return true; } =20 return false; } =20 -static char *tap_parse_script(const char *script_arg_value, +static char *tap_parse_script(const char *script_arg_name, + const char *script_arg_value, const char *default_path) { - if (tap_is_explicit_no_script(script_arg_value)) { + if (tap_is_explicit_no_script(script_arg_name, script_arg_value)) { return NULL; } =20 @@ -741,7 +745,7 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, qemu_set_info_str(&s->nc, "helper=3D%s", tap->helper); } else { qemu_set_info_str(&s->nc, "ifname=3D%s,script=3D%s,downscript=3D%s= ", ifname, - script ?: "no", downscript ?: "no"); + script ?: "", downscript ?: ""); =20 if (downscript) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); @@ -947,9 +951,10 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, } } else { g_autofree char *script =3D - tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); + tap_parse_script("script", tap->script, DEFAULT_NETWORK_SCRIPT= ); g_autofree char *downscript =3D - tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); + tap_parse_script("downscript", tap->downscript, + DEFAULT_NETWORK_DOWN_SCRIPT); =20 if (tap->ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); diff --git a/qapi/net.json b/qapi/net.json index 8f0915c4d86..acb8594c952 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -399,15 +399,21 @@ # @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. In a future version, "no" +# will be treated as a plain file name. # -# @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. In a future version, "no" +# will be treated as a plain file name. # # @br: bridge name (since 2.8) # diff --git a/qemu-options.hx b/qemu-options.hx index 200949655ea..1efdb8e9860 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,10 @@ 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; it disables script + execution now, but 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 Wed Aug 26 10:14:38 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=1787162644; cv=none; d=zohomail.com; s=zohoarc; b=RkxqarhKA35zDowp+rxjp45ntyscmwPwQXaGaoC8awNWhltrnmUEdxHTyDU/zTVFkzzDkFHlDtqvJrEIr4bOI/78Y0EWIkd0LaxBbMc5mE0A+ZPJUKhl0Vtu91X4MDWaRIi2BybrVjrNol5/lJVVaIJoXHkJEguZjZSLQ+Iuq+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162644; 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=7dwm1jpIwBJtMj8ZJDKQSyXcbPVHGSd3/RYqe6SKdcE=; b=TQ0hCTQDkimBzV6AVgtnBtCESpSQLZjBsWOfJ37BX7KJJ5cAy3u2JcGW4Yp5k5ENbbl/IO+48Lg+sl1dT6fO5H1/mYbug8ISnbarlNiBp4oxzCHASb6T7aZbfjlbzCESUsH0wBP3n2T3iKuQRpWZeQwrOKsscgBkwE0AjCCCHnI= 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 17871626448904.048280135371442; Wed, 19 Aug 2026 11:04:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcT-0004Fy-Es; Wed, 19 Aug 2026 14:02: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 1wwkcR-0004FG-Vb for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:31 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcQ-0007Nb-5s for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:31 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id D96D8C08B5; Wed, 19 Aug 2026 21:02:28 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-RioXLfp7; Wed, 19 Aug 2026 21:02: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=1787162548; bh=7dwm1jpIwBJtMj8ZJDKQSyXcbPVHGSd3/RYqe6SKdcE=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=1ave/KEz5BUHrAuRfecwESNWFpZjSDhaeQRhb2TXxjPWmC4YcPWJPKCfc7Rv6asq2 SKRzVGB51x2vwneI+8+nd5Fine/8e4X6D/VZDkfSEh6zH2J/EZw+k/tbEJaDptoR4B gcWyb2j4WbPBAPu/4ym375cY0z+8MFblUj9PE7MY= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 04/16] net/tap: move vhost-net open() calls to tap_parse_vhost_fds() Date: Wed, 19 Aug 2026 21:01:47 +0300 Message-ID: <20260819180201.1970193-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162646348158500 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 f4051e8d4b1..bec2cd48fd3 100644 --- a/net/tap.c +++ b/net/tap.c @@ -756,8 +756,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; @@ -767,17 +766,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; @@ -863,14 +851,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 Wed Aug 26 10:14:38 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=1787162584; cv=none; d=zohomail.com; s=zohoarc; b=LZs6AyXmJtXTlIIyFx4zKM18+BIbSho/6jY63cCE4dSWIYQ+KoSERFf+kP5p1gq6dSthxnCVeHljsH2Fk7Qz9gKm7L5HE2Snf/yPeCPO/NWTmTgH0BuLz3tMQp5nKLh0R4CoZeRzDuGGFOY/+gqZGGhzB4RWAToohQH9ZCa7ouE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162584; 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=gFmS/DTgG7tyPtgCYFw5DCDtqJUxh70iPyjnvtCIY7k=; b=V9NPJK10bHo07JgbK0j/bNTpWDeWFrbvUDSceVYw1J1ydVms3SnDO6ViVBc5KQDrqj4gjYGYB6jeMXSdkzuM9h4rdzn4qX4IDxmoFbH5hSkmvxM2MpT8JSGgSYU7PHRtct3faStE21VgJlXVBSwvQLLkCKcLgQCgv+7ITYBNVsU= 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 1787162584186371.07512901009943; Wed, 19 Aug 2026 11:03:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcT-0004GG-MX; Wed, 19 Aug 2026 14:02: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 1wwkcS-0004Fl-S2 for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:32 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcR-0007Nn-3v for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:32 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id BCAC8C08B3; Wed, 19 Aug 2026 21:02:29 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-TT7soOrS; Wed, 19 Aug 2026 21:02:29 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162549; bh=gFmS/DTgG7tyPtgCYFw5DCDtqJUxh70iPyjnvtCIY7k=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yXGy7Vm0S3vt2S1QmNIuY8xlBpS71kKl8i6qdbrzWe2bC/gvsdA1fPqXADNA1lFF8 qnNHkAmoUJyWfdAJ04A5Oy12mKPT5UQDeOyQ/LKpLQrzaDecliJxoV20cj07WAszSQ PUq4Zb7O2fCgTrBPlaACvEYuZaedN/QAyhZxlAUE= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 05/16] net/tap: move vhost initialization to tap_setup_vhost() Date: Wed, 19 Aug 2026 21:01:48 +0300 Message-ID: <20260819180201.1970193-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162585932158500 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 bec2cd48fd3..f2b571dd116 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]; @@ -722,6 +724,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, @@ -756,30 +790,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 Wed Aug 26 10:14:38 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=1787162640; cv=none; d=zohomail.com; s=zohoarc; b=kPYOs0gxxEPYwa6gelWzhBQore7+HZ2HUUQjw6U9AJe6CKw1jsI7QaTIiwG7YxdqH0SZoNApr8iqoIXIlSBsD3/bKNuGcf3VONjkFHH16ToVGTbcPMBUq9TDIW1skfVNLRpAhrDe8ueZD6u12Eq48LWNQYYXit4gpbrlPZGgNf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162640; 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=rqXLRKVB9rUlP5qhRTvWTc1Jy5XuBInjTD1aruBDXbM=; b=OiMI6880Pxttom5EZ0bJ8jkhhf4kklf9wDizbUeviHOkKBY2jwcuHHNuInXd4tDvYy4oKfduwS42BgknhHxYkZTUar8xMnVBdF0nHkMYhZlgIOZMWGY30aXsri7m8cWguvRzfRK0ejPWBasVeSSzqmCRt3qLPS8Xfx07a/FuVbQ= 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 1787162640814621.5248444238069; Wed, 19 Aug 2026 11:04:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcW-0004Ii-E5; Wed, 19 Aug 2026 14:02:36 -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 1wwkcU-0004Ge-5Y for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:34 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcS-0007OL-4l for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:33 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id B3825C08B7; Wed, 19 Aug 2026 21:02:30 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-1Sgq8Dhf; Wed, 19 Aug 2026 21:02:30 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162550; bh=rqXLRKVB9rUlP5qhRTvWTc1Jy5XuBInjTD1aruBDXbM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=P4eDqpO5MgVpANTzIZea+1WqKhewSNWvpilh4j/5HcCqFgIs2VrQQnFOrrxmtLXkd KTb0KN5WCYuhCgMrzsaPXknYCTRJQNYZemrS/XRLppeN0+I9W/hJFlpaYymCcuvIoO RKLsG1BaREvud9zKyePd8W8PvepPQ4XuL/ct42qI= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 06/16] net/tap: use container_of instead of DO_UPCAST Date: Wed, 19 Aug 2026 21:01:49 +0300 Message-ID: <20260819180201.1970193-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162642480158500 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 Reviewed-by: Ben Chaney --- net/tap.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index f2b571dd116..bfed74717e4 100644 --- a/net/tap.c +++ b/net/tap.c @@ -175,7 +175,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 { }; @@ -211,7 +211,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 @@ -271,7 +271,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 @@ -280,7 +280,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 @@ -289,7 +289,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; @@ -297,7 +297,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 @@ -311,7 +311,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 @@ -322,21 +322,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; } @@ -357,7 +357,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); @@ -381,14 +381,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; @@ -396,7 +396,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; } @@ -408,7 +408,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; } @@ -447,7 +447,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; @@ -1016,7 +1016,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) { @@ -1033,7 +1033,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 Wed Aug 26 10:14:38 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=1787162624; cv=none; d=zohomail.com; s=zohoarc; b=Y4NBmL4dZmk6T7poe31RYnl+GOOMkXcQA0Bsi5BKZkhNsK7zYZZ2HhMcV9A5uRl7TBExEWwugoEQWXjtt9dxboRGij/HMjRsBwzEHVGq7KNJYc1I+0Pok1ZXif2ISommRgCoxv3Mkqmsz7y37nF2aOFljfM9KXGpOx/Z1XjtdFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162624; 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=I4ZoNQB84kFGgyKvko11z9bKQW4aJr/0NhffXgUglew=; b=T9Y/oz3lVrsrVhrcV7A14uq5hb8KIFJvoSY9YhCYQeFQwWjxYe0X8YGcmKSWNico9oGzovSw+mQPP5HBT9hlGf54VhAj2+ufjVhfU5oFiblp0kpLRb1Y0sEgaDvtMXbM7evFihmovPFSZWrcoHFOsZII521z6si3pyexyg1rJiw= 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 1787162623958398.6629186238363; Wed, 19 Aug 2026 11:03:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkca-0004KV-9g; Wed, 19 Aug 2026 14:02:40 -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 1wwkcU-0004HN-P4 for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:34 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcS-0007Ov-Vb for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:34 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id ADD8DC0D13; Wed, 19 Aug 2026 21:02:31 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-xei66JjN; Wed, 19 Aug 2026 21:02: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=1787162551; bh=I4ZoNQB84kFGgyKvko11z9bKQW4aJr/0NhffXgUglew=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=hBsZ7UWJSqw5fqeibrSeDyLng9z87NElBh0+sWXoB0NA3SSKXwBXNoLJ2OI/3DISo SS7L79Tf29XdJkIDP9zkNHQV0Dk/nNmud7wOlw46wEkupTGYGzqrsfFj64Y7KLpg5j Qr230+VA0kzrv73Yz/kzu+BlA7zYyLSG9GA2RV+o= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 07/16] net/tap: QOMify tap backend Date: Wed, 19 Aug 2026 21:01:50 +0300 Message-ID: <20260819180201.1970193-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162626227158500 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 Reviewed-by: Ben Chaney --- 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 9edfacf827c..05d1db71eb8 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 0a30579ca4a..aba7726a6b3 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 bfed74717e4..73923442009 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); @@ -413,6 +418,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 { @@ -435,6 +453,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, @@ -442,12 +472,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; @@ -1048,3 +1073,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 Wed Aug 26 10:14:38 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=1787162584; cv=none; d=zohomail.com; s=zohoarc; b=FyfmmKmKBpS93nmATGEwpREb8EsNCIySufELwg1y2p1b21INGnhHHpgpVE/NMkpQrtlW8T/HmegnQmTekcVVQ7gR+gqhXPXXG2wwDcbwy10seu5/1RUmWS83wAv8YToeXFzE/jS4FnmfiNSpuzNs3IDqZIKAmODqUad5n0Tks8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162584; 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=oI96v0+TPIsbCm1buVmXupjL3MsG1DCG6blbQzz3fVA=; b=S71L4bCbCTQ6y4my0/4Cx2LvHzNy1+C/BUhWRRUKWXG67OmE5RYA6Mcqeo0y3VEBSZD4mv4k8GaXxP8dCpCg7PDlhaRanuPvaGQ4uNeVuO02c3cQxib/aThD3NcGMZwFK1Sy5Y7bT3eI3+wN8hLsyhcYcUrY7We3GBi97aMRLLA= 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 178716258433810.03418606083153; Wed, 19 Aug 2026 11:03:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcY-0004Je-Dy; Wed, 19 Aug 2026 14:02: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 1wwkcV-0004I1-Pg for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:35 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcU-0007PW-0t for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:35 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id ADF85C0D17; Wed, 19 Aug 2026 21:02:32 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-53GTR8ki; Wed, 19 Aug 2026 21:02:32 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162552; bh=oI96v0+TPIsbCm1buVmXupjL3MsG1DCG6blbQzz3fVA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Fqzju9FTWSYYzvnksmS2vgOgdnz/FCefPt75CeOHCkw24BLPBCg/K9ledlFa/vWcB 7GNuVnqrjaz74bVpdPgCqtkZ5dQi5Zp2/1opNKu//1RcM8+DWhOzKQ1ydpXumIc7a8 /6VWz+hkOjqk3lMwS92rfXIWfwFJNlcS720Gh7ws= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 08/16] net/tap: add TYPE_VMSTATE_IF interface Date: Wed, 19 Aug 2026 21:01:51 +0300 Message-ID: <20260819180201.1970193-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162586243158500 Content-Type: text/plain; charset="utf-8" We'll need it to implement TAP backend live migration. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/net/tap.c b/net/tap.c index 73923442009..dd0d134875b 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, @@ -419,10 +420,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) @@ -455,13 +475,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 @@ -469,10 +492,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; @@ -709,7 +733,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 @@ -785,10 +809,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; @@ -989,7 +1014,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; } } @@ -1024,7 +1049,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 Wed Aug 26 10:14:38 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=1787162618; cv=none; d=zohomail.com; s=zohoarc; b=CeCH9eeFF1P793DmJClUMw2ffaqN6KXMlKLh4NBzbOueocASR2WTh+V5AWFh5dV0kOn6k/20SBajID2d99fhtN5jotz9U7AzJpkGgXmPW3r2snIsZ2i3TMZq0npHUfG/uoNExWUlDcx+89loXsvuqvb7YKQn9mV5MS0opvcj1+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162618; 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=/9rBauyJpZa7sA9oEgvciZAppNibH2UY+hQDpFSt9ZM=; b=iegM9qtIyOqPsnm0t3NF27LBxQYP2oUDtJHzkWcbqf4bUfI0FVu4xaEO/kFXUyvgSSZ2VFQ/awbcaEQHKx5bGnxxdWmB+Je06W3opVnHh3CSiKHmzNnqJH0WsdwWZha/B5w1LS7cG74tlkrKH/H/jCVkK1cMaOxNDM1ICC8POnA= 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 1787162618306390.5372676088414; Wed, 19 Aug 2026 11:03:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcY-0004KG-Rm; Wed, 19 Aug 2026 14:02: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 1wwkcW-0004J2-SH for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:36 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcU-0007Q0-W6 for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:36 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id B3F86C08AE; Wed, 19 Aug 2026 21:02:33 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-mHkdqsrJ; Wed, 19 Aug 2026 21:02:32 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162552; bh=/9rBauyJpZa7sA9oEgvciZAppNibH2UY+hQDpFSt9ZM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vn6Cxwjs9X10EC50D27I5qgzSiFBwgxm7/MIoGdNMdyCiOZ/hL3RculBDuQqlk2/F H79wwrP7VM2+nJJ/RkoS8K1F6KJlRkogJDT432eNftwS0jZqfi68uznY73M64VStqz wN2CtShnHZnchhNyHkV7a6mPgvzVIoAnTSAVCg44= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 09/16] qapi: add local migration parameter Date: Wed, 19 Aug 2026 21:01:52 +0300 Message-ID: <20260819180201.1970193-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162620304158500 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). We can't simply auto-detect local migration by checking whether the migration channel is a UNIX domain socket: the UNIX socket may be only the first part of the transfer channel to a remote target. Hence an explicit parameter is needed. Moreover, "local" migration parameter may be useful in cpr-exec mode, when FDs are passed through exec instead of UNIX socket. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster Reviewed-by: Peter Xu --- include/migration/misc.h | 2 ++ migration/options.c | 18 +++++++++++++++++- qapi/migration.json | 21 +++++++++++++++++---- 3 files changed, 36 insertions(+), 5 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 b1eaf7b0545..f7628b55e92 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,10 +1013,20 @@ # Must be set to the same value on both source and destination # before migration starts. (Since 11.1) # +# @local: Permit the use of optimizations for local migration. This +# must only be set when either both the source and destination +# QEMU processes are directly connected with a UNIX domain socket +# as the migration channel (to enable use of file descriptor +# passing) or cpr-exec migration mode is enabled (this way file +# descriptors are inherited by new process). Individual device +# backends may need additional configuration flags set to enable +# local migration optimizations. This will be documented against +# the device backends where it applies. (Since 11.2) +# # Features: # -# @unstable: Members @x-checkpoint-delay, @x-rdma-chunk-size, and -# @x-vcpu-dirty-limit-period are experimental. +# @unstable: Members @local, @x-checkpoint-delay, @x-rdma-chunk-size, +# and @x-vcpu-dirty-limit-period are experimental. # # Since: 2.4 ## @@ -1053,7 +1064,9 @@ '*direct-io': 'bool', '*x-rdma-chunk-size': { 'type': 'uint64', 'features': [ 'unstable' ] }, - '*cpr-exec-command': [ 'str' ]} } + '*cpr-exec-command': [ 'str' ], + '*local': { 'type': 'bool', + 'features': [ 'unstable' ] } } } =20 ## # @query-migrate-parameters: --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162644; cv=none; d=zohomail.com; s=zohoarc; b=gAgbbPRzu2R/SrYVyvYOnI1c7OfbCgx5NbX//TQae+ZQ8DG1lCSBcuOY0tPSlJiItcrTss6J/P3zhx0usIndrWrbdtqzu7BntUW+IoH0GjvAuDL1ZbBWXRsLJDKJXtIZ2GMFI7XHfIJ8lO1WogtwNbSAuadec6f23uWMGLw48iE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162644; 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=jVMiYPt2Frnu4BfObGrRKjiatzSEShHfArUODPajWoM=; b=l2p8KeUdT1Yu+Q1LDX5269AprQWliNKplowphiZBSYQnrH3I0WJGGk0Js069llB/XRbmVjWEz+F4LpZQiopymdGxc2LSaoKIsYWHqtE+JvDXcoCOSybIQZ8rJBDRC8XRaLFsuayWyCXS6aIeXShC2cYh2tcAVRa+qaKH2tLtmIg= 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 1787162644872606.7590575142513; Wed, 19 Aug 2026 11:04:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkca-0004Ke-Ox; Wed, 19 Aug 2026 14:02:40 -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 1wwkcX-0004JC-8C for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:37 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcV-0007QE-Pd for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 7A24CC050A; Wed, 19 Aug 2026 21:02:34 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-tfXZjHVQ; Wed, 19 Aug 2026 21:02: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=1787162553; bh=jVMiYPt2Frnu4BfObGrRKjiatzSEShHfArUODPajWoM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=l9qvmZzIJIN7fJWzqtHU2egqSo7ShbOZ+uHfM44Adhw7jD6M2oPUGJ5TRQQHJeo8j bbKL9bk0ZisX7krbpcZimI6jLcoFC+S0nC5cSMvAmKOcPDIcL/55a1MhzePf2hDYGk DYI5+7p2jizeapvG/rEhlcDN+lTNmQoEMBKZDT1M= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 Subject: [PATCH v21 10/16] migration/fd: fix fd leak when fd is not valid for migration Date: Wed, 19 Aug 2026 21:01:53 +0300 Message-ID: <20260819180201.1970193-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162646311158500 Content-Type: text/plain; charset="utf-8" Both fd_connect_outgoing() and fd_connect_incoming() own the file descriptor after resolving it from the monitor, but forget to close it when migration_fd_valid() check fails. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Xu --- migration/fd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/fd.c b/migration/fd.c index f05f95992f8..02b39b150eb 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -62,6 +62,7 @@ QIOChannel *fd_connect_outgoing(MigrationState *s, const = char *fdname, if (!migration_fd_valid(fd)) { error_setg(errp, "fd: migration to a file is not supported." " Use file: instead."); + close(fd); goto out; } =20 @@ -97,6 +98,7 @@ void fd_connect_incoming(const char *fdname, Error **errp) if (!migration_fd_valid(fd)) { error_setg(errp, "fd: migration to a file is not supported." " Use file: instead."); + close(fd); return; } =20 --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162632; cv=none; d=zohomail.com; s=zohoarc; b=bFpRdkaKALXuGGLr5toYteQPS1vMNeJZ4t9CV9OGVxGJ+IGZAeTKWjBk4udQuinihryRuIeUV1WWReG5wyaEnW5VnlOAPdMsxW7Gfv4J9MhOFVce6BGZIARxifMBuQYab0AUMs9P3DFpz0Os8IPMRX+U3RQlDa5RuxaC/2uZXog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162632; 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=qaYQibXsMStBAjFyr2RAt6vm97uFnbe3yjAWh42yQvM=; b=Kuhhtl0j69vEo0v0mR61++6BamdXP/RPsCBLRz97ztzZI0tA4sOxkVT+czUBFkQDuqJm0I/ZRuRWAA593rW9sA+H/pXxz5DMLRBEpkNJJ/EPykr+rA953MbBXVgp+o9NGY6trHVVfBetOkmi35kIkeKnyu7kLftfpvMDoJSwmis= 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 1787162632454176.97375433376203; Wed, 19 Aug 2026 11:03:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkca-0004KW-Br; Wed, 19 Aug 2026 14:02:40 -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 1wwkcY-0004JN-5V for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:38 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcW-0007QR-JD for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:37 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 4EBA0C0D18; Wed, 19 Aug 2026 21:02:35 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-2lxIMhkT; Wed, 19 Aug 2026 21:02:34 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162554; bh=qaYQibXsMStBAjFyr2RAt6vm97uFnbe3yjAWh42yQvM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=HitzHQotkufcXUJ0rx3KEI8nAP7ROR1uJore2u6UbZlOAEz9KDqPOBh9dSYudMtLo dEpVPP9W1SPO9wIehnmhqcctiXZvExKTfrBg7uAKkrG+JG+GiAPzHvBsz38nOhlRba p0uqJq6LAMrrsR3QyGrMTV4AsbsXfhamnZK1UFVw= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 Subject: [PATCH v21 11/16] migration/fd: add errp parameter to migration_fd_valid() Date: Wed, 19 Aug 2026 21:01:54 +0300 Message-ID: <20260819180201.1970193-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162634367158501 Content-Type: text/plain; charset="utf-8" Let migration_fd_valid() report the error itself, instead of duplicating the error message in both callers. This also prepares for adding one more check (with a different error message) to the function. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Xu --- migration/fd.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index 02b39b150eb..78a27caca22 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -37,16 +37,14 @@ static bool fd_is_pipe(int fd) return S_ISFIFO(statbuf.st_mode); } =20 -static bool migration_fd_valid(int fd) +static bool migration_fd_valid(int fd, Error **errp) { - if (fd_is_socket(fd)) { - return true; - } - - if (fd_is_pipe(fd)) { + if (fd_is_socket(fd) || fd_is_pipe(fd)) { return true; } =20 + error_setg(errp, "fd: migration to a file is not supported." + " Use file: instead."); return false; } =20 @@ -59,9 +57,7 @@ QIOChannel *fd_connect_outgoing(MigrationState *s, const = char *fdname, goto out; } =20 - if (!migration_fd_valid(fd)) { - error_setg(errp, "fd: migration to a file is not supported." - " Use file: instead."); + if (!migration_fd_valid(fd, errp)) { close(fd); goto out; } @@ -95,9 +91,7 @@ void fd_connect_incoming(const char *fdname, Error **errp) return; } =20 - if (!migration_fd_valid(fd)) { - error_setg(errp, "fd: migration to a file is not supported." - " Use file: instead."); + if (!migration_fd_valid(fd, errp)) { close(fd); return; } --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162630; cv=none; d=zohomail.com; s=zohoarc; b=lGmCgm4rza92g9awn2Q6wyg553O0iSZXjfFTDo39LYvqt8MrfFJPoiRxCuPjPPWKTcQ1Gj6N51IFY2oc1Tf+49laeX6HYfugMZVZDzIVfHYmRZVpKk+ZT7TTqcNx/kRg+swjqUQ3fDNauzxQOUUkIKrwc7HpHcLMcGK+gLb5Hxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162630; 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=4J39I5MQiW15oResX/G2JSRk8nr42/jo3rCu6TGqFZQ=; b=dZG8/FQ40Qvrcn6ljpKAItMD3eqKVN5mSMpG5JTfTbZvyfAvm6S9WGn99DmeqZf7ZbFAqNyX857C22NzW3sg0lTIGfGHpMhpaZ/kY+E5UF6vN7Sg4lM8Ox/FpVib/30pl8riQtdjiOkgp3CX9PZcp1vadG2Xmw7UHnayw1DPeLo= 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 1787162629964648.1847059116776; Wed, 19 Aug 2026 11:03:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcc-0004Lz-Rv; Wed, 19 Aug 2026 14:02:42 -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 1wwkcZ-0004KI-0p for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:39 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcX-0007Qn-D8 for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:38 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 1A478C08AF; Wed, 19 Aug 2026 21:02:36 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-5ZFV58K2; Wed, 19 Aug 2026 21:02:35 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162555; bh=4J39I5MQiW15oResX/G2JSRk8nr42/jo3rCu6TGqFZQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=zSaS67O3H1HXkiywbpEApHZZhaT7OSb+WOZHntTeN+H4scoLHnFZ9A4TW8Fbn72e8 YAc1FU0mkTzpzCIijseuFSiP2pnCJUe5BtxFqnxIrDfEiPZQzQJIG22oSkzBcsTdAJ iZQ/md4R3m1t05EcYzQHFF0Q+Ou0vfJ7JPoQCsys= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 Subject: [PATCH v21 12/16] migration: check that transfer is UNIX socket when "local" set Date: Wed, 19 Aug 2026 21:01:55 +0300 Message-ID: <20260819180201.1970193-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162632245158502 Content-Type: text/plain; charset="utf-8" As documented, for "local", the migration channel must be direct UNIX socket connection from source to target (except for CPR_EXEC mode). We can't check for it being "direct", but let's at least check that we deal with UNIX socket. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Peter Xu --- migration/fd.c | 14 ++++++++++++++ migration/migration.c | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/migration/fd.c b/migration/fd.c index 78a27caca22..4a891e814a4 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -39,6 +39,20 @@ static bool fd_is_pipe(int fd) =20 static bool migration_fd_valid(int fd, Error **errp) { + if (migrate_local() && migrate_mode() !=3D MIG_MODE_CPR_EXEC) { + struct sockaddr_storage ss; + socklen_t sslen =3D sizeof(ss); + + if (getsockname(fd, (struct sockaddr *)&ss, &sslen) < 0 || + ss.ss_family !=3D AF_UNIX) { + error_setg(errp, + "local migration requires a UNIX domain socket chan= nel"); + return false; + } + + return true; + } + if (fd_is_socket(fd) || fd_is_pipe(fd)) { return true; } diff --git a/migration/migration.c b/migration/migration.c index 9df6da131ce..e30fce30a56 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -260,6 +260,19 @@ migration_capabilities_and_transport_compatible(Migrat= ionAddress *addr, errp); } =20 + if (migrate_local() && migrate_mode() !=3D MIG_MODE_CPR_EXEC && + (addr->transport !=3D MIGRATION_ADDRESS_TYPE_SOCKET || + (addr->u.socket.type !=3D SOCKET_ADDRESS_TYPE_UNIX && + addr->u.socket.type !=3D SOCKET_ADDRESS_TYPE_FD))) { + /* + * For SOCKET_ADDRESS_TYPE_FD we do check the fd itself later + * in migration_fd_valid(). + */ + error_setg(errp, + "local migration requires a UNIX domain socket channel"= ); + return false; + } + return true; } =20 --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162640; cv=none; d=zohomail.com; s=zohoarc; b=U0LPk4xuZBXSrqs/9AVghpFd+MMU0MDPWy9kLGxox6xsXvzlmCkQGvzFpHGG3hmU/4hJ+xYRF+ZbtQEm1Le1QKN/8gHNi42siZ/TCyjZ3uHscoCLFjZWBO7qPb6dQ4T+t8HLnnwC9s+d7znq6CXt4UJNUqxrdnefww+c9uzpeno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162640; 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=7RK20YNslrCWlxEAgyqrLGnjVNKJFiRRALhiNSDp1eA=; b=Uyzd+SHhcRMTB7svG6tVjhnGgbw38u/nlrz3zfKo8l9Ae47aNb7YGElS8pVMppcqKx00XfE0FUXGlqgb1YbIRi1wVSlcE7ThPceNgUvebDmFq0zAiQNBP6xYOLKxqwcbT+HWvgYMlR8nrt89zcfxWInvE4QKKhdAeGezHUoNfV8= 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 1787162640142501.8028880004405; Wed, 19 Aug 2026 11:04:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcd-0004MG-9l; Wed, 19 Aug 2026 14:02:43 -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 1wwkca-0004KX-Gk for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:40 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcY-0007RF-Dy for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 37662C0D2F; Wed, 19 Aug 2026 21:02:37 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-y4SgSE5D; Wed, 19 Aug 2026 21:02: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=1787162556; bh=7RK20YNslrCWlxEAgyqrLGnjVNKJFiRRALhiNSDp1eA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=EqW4BwtDs59WKbRkJNeyf8F378BN79Gv88qN9cKP5pfvLKBK1UHqv71LtyXy16rf8 NR7An8VlQSKlsudxhtmdGKVyr7TmiqOpCDhfTYNXAPKmZia9YlJuzRMdKThT41og+V QkiQbUvJfMCTohng+DVYDbIouiT/ut7KN6ANUzxc= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 13/16] virtio-net: support local migration of backend Date: Wed, 19 Aug 2026 21:01:56 +0300 Message-ID: <20260819180201.1970193-14-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162642520158501 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 Reviewed-by: Ben Chaney --- 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 814b99a43d2..274fbcb0d60 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" @@ -3079,7 +3080,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) @@ -3108,6 +3119,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); @@ -3204,6 +3226,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, @@ -3261,6 +3284,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 @@ -3411,6 +3448,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; @@ -3890,6 +3935,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); @@ -4027,6 +4108,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 05d1db71eb8..a606d06e46a 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 Wed Aug 26 10:14:38 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=1787162659; cv=none; d=zohomail.com; s=zohoarc; b=dyEomcO/VPMsW2zU+1xKfuC8Ykh7sHEVXkymvFYzdNjre1g2ILOyEqVqfyCbg87c1KRRG2Nl2ZfdnzrU3xNQ3pN+2u1oMN1+4uGnLNX9DVPtnGFYaW6wInA7ZL1j/qwlH6DY0i6vHnvTk8yS2fumRmZzrO6D089yQ+IKvUR9d04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162659; 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=sbGqgdN3DDYndofekR52mSHPQhxEPup54GJZHygpekk=; b=NeYy/+B37WZb1T+W61ZNJfPqTU96Tl2n5mhAtXAuBFbkAZsUaufma6ySohk4ZKtU1V4qFrHnN9bgoLSKLApQcDbbDEKUWJZ99RphxRoXHhT7KucQWWBI25vG6URqFenyCa9HiABFvpSdheH1fzowr4197GPgWK6ZNiDp2LHJ3YQ= 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 1787162659972427.8877810382586; Wed, 19 Aug 2026 11:04:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcd-0004Mf-Oo; Wed, 19 Aug 2026 14:02:43 -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 1wwkcb-0004Kt-0G for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:41 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkcZ-0007Rh-9J for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:40 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 0FA0EC08B5; Wed, 19 Aug 2026 21:02:38 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-bosuqyol; Wed, 19 Aug 2026 21:02:37 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162557; bh=sbGqgdN3DDYndofekR52mSHPQhxEPup54GJZHygpekk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=rR2S59LrH/mLnm9fMtNjOtuOA1OMZ4wB4ZBm+lzpuSpmUHnD7O7S4BbWMpSUtXpeO X+RQHK3qoE4qOmJS5YllEyux2A7+qpC/QtbGX+4Ob2BHBR52AtiXVxbC3SxuprxU0s kn64pL1ufLBf5/DGT3P4WC+IQslb1doHsIOeUGdo= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 14/16] net/tap: disable read polling for stopped VM Date: Wed, 19 Aug 2026 21:01:57 +0300 Message-ID: <20260819180201.1970193-15-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162660482158501 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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/net/tap.c b/net/tap.c index dd0d134875b..51d028d9567 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 enable_poll_on_resume; + VMChangeStateEntry *vmstate; }; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -145,10 +148,31 @@ static void tap_update_fd_handler(TAPState *s) =20 static void tap_read_poll(TAPState *s, bool enable) { + if (enable && runstate_check(RUN_STATE_FINISH_MIGRATE)) { + s->enable_poll_on_resume =3D true; + return; + } s->read_poll =3D 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->enable_poll_on_resume) { + tap_read_poll(s, true); + s->enable_poll_on_resume =3D false; + } + } else if (state =3D=3D RUN_STATE_FINISH_MIGRATE) { + if (s->read_poll) { + s->enable_poll_on_resume =3D true; + tap_read_poll(s, false); + } + } +} + static void tap_write_poll(TAPState *s, bool enable) { s->write_poll =3D enable; @@ -379,6 +403,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); @@ -818,6 +847,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->enable_poll_on_resume =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 Wed Aug 26 10:14:38 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=1787162619; cv=none; d=zohomail.com; s=zohoarc; b=em+x5GjfEzPhVTL1Yq4CUs10IYB9GGXu5R1tNYOGqBVnaLjQSnyLXjPiAp43gHEnRycj0CpFLXSrlK5EsxHU9HoC9xXJGP/bzi9gkIH9aSDnCYo8vBFTV1Nmicv7EYzhVsfCufOKNgG+misQndcown4IhUmguoMeiPw0xlIynyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162619; 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=e2rBzwUCA7XeNrK1WrokcsWbKojtljjW4a/q86xAHFk=; b=hQKDAQjnukqcTLIuaqdhbh5QD9PTenTBDvHA8nHVCMQmJRmP8B/OVcm+oKH43JAqCJovH+5EPsNYuzLZKypTMMTdjazs3PWOQaG1JElJq3Ra3YgTU8HkeKJ85M0D70+j/NGVMKedurYOEDtIa/bP9JAPe3S6WPggVEPb7oqhFXA= 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 1787162619337559.5620681539467; Wed, 19 Aug 2026 11:03:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkce-0004Ms-8H; Wed, 19 Aug 2026 14:02:44 -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 1wwkcd-0004MU-DN for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:43 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500: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 1wwkca-0007S3-NA for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:43 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id 71800C08B3; Wed, 19 Aug 2026 21:02:39 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-rooC7FPP; Wed, 19 Aug 2026 21:02: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=1787162558; bh=e2rBzwUCA7XeNrK1WrokcsWbKojtljjW4a/q86xAHFk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=pXBsnDQvpX5NgdlWrs+no4IT/8/YNT5wFrvcZxUgEeHA30Zv/zolGFu+w7OqtDiNN HGdk0SGfD9+hDJH5fAE0SyfskiI3oxtlmA/NeWJWorwx+WQM6QJbEFprnKWCCUD+WY fLX3czpKDPJk24oBToxGGI0lEeWa76Uj1EFA7cCc= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 15/16] net/tap: support local migration with virtio-net Date: Wed, 19 Aug 2026 21:01:58 +0300 Message-ID: <20260819180201.1970193-16-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1787162620365158500 Content-Type: text/plain; charset="utf-8" Support transferring of TAP state (including open fd). Add new property "x-permit-local-migration", which defines whether local migration is actually permitted for this TAP device. Note that local-migration is enabled by global "local" migration parameter, but individual devices may have additional options to enable/disable it per device. The tricky thing is that we need to know whether to call open/connect in TAP initialization code, i.e. we need to know the value of migration parameter "local" when creating the TAP device. For incoming migration, we can know only for TAP devices created with QMP after setting the migration parameter with QMP. So the full picture is: On source, to start outgoing "local" migration you need: - migration parameter "local" set to true - "x-permit-local-migration" TAP option set to true 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 "x-permit-local-migration" 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 "x-permit-local-migration" set, most of TAP options are not allowed, and script/downscript are required to be explicitly disabled. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++-- qapi/net.json | 29 ++++++++- 2 files changed, 189 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index 51d028d9567..d71e3dd1175 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 enable_poll_on_resume; VMChangeStateEntry *vmstate; + bool permit_local_migration; }; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -412,6 +420,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) @@ -448,6 +458,78 @@ 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 bool tap_pre_load(void *opaque, Error **errp) +{ + ERRP_GUARD(); + TAPState *s =3D opaque; + + if (s->fd !=3D -1) { + error_setg(errp, + "TAP is already initialized and cannot receive " + "incoming fd"); + error_append_hint(errp, + "Migration parameter 'local' must be set" + " before creating the TAP device."); + return false; + } + + return true; +} + +static bool tap_setup_vhost(TAPState *s, Error **errp); + +static bool tap_post_load(void *opaque, int version_id, Error **errp) +{ + ERRP_GUARD(); + TAPState *s =3D opaque; + + tap_read_poll(s, true); + + if (s->fd < 0) { + error_setg(errp, "FD was not loaded during incoming migration"); + return false; + } + + if (!tap_setup_vhost(s, errp)) { + error_prepend(errp, + "Failed to setup vhost during TAP post-load: "); + return false; + } + + return true; +} + +static bool tap_needed(void *opaque) +{ + TAPState *s =3D opaque; + + return s->permit_local_migration && migrate_local(); +} + +static const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .priority =3D MIG_PRI_BACKEND, + .pre_load_errp =3D tap_pre_load, + .post_load_errp =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) { @@ -456,17 +538,42 @@ static char *tap_vmstate_if_get_id(VMStateIf *obj) return res; } =20 +static bool tap_get_permit_local_migration_prop(Object *obj, Error **errp) +{ + TAPState *s =3D TAP_NETDEV(obj); + return s->permit_local_migration; +} + +static void tap_set_permit_local_migration_prop(Object *obj, bool value, + Error **errp) +{ + TAPState *s =3D TAP_NETDEV(obj); + s->permit_local_migration =3D value; +} + +static void tap_instance_init(Object *obj) +{ + TAPState *s =3D TAP_NETDEV(obj); + s->permit_local_migration =3D false; +} + 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, "x-permit-local-migration", + tap_get_permit_local_migration_prop, + tap_set_permit_local_migration_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 }, @@ -499,13 +606,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_permit_local_migration, + bool permit_local_migration) { TAPState *s =3D TAP_NETDEV(object_new(TYPE_TAP_NETDEV)); =20 @@ -514,6 +624,12 @@ static TAPState *new_tap(NetClientState *peer, =20 s->queue_index =3D queue_index; =20 + if (has_permit_local_migration) { + s->permit_local_migration =3D permit_local_migration; + } + + vmstate_register(VMSTATE_IF(s), VMSTATE_INSTANCE_ID_ANY, &vmstate_tap,= s); + return s; } =20 @@ -522,10 +638,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_permit_local_migration, + bool permit_local_migration) { NetOffloads ol =3D {}; - TAPState *s =3D new_tap(peer, model, name, queue_index); + TAPState *s =3D new_tap(peer, model, name, queue_index, + has_permit_local_migration, + permit_local_migration); =20 s->fd =3D fd; s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; @@ -762,7 +882,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 @@ -842,7 +962,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_x_permit_local_migration, + tap->x_permit_local_migration); bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; @@ -990,6 +1112,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; @@ -1012,6 +1135,23 @@ int net_init_tap(const Netdev *netdev, const char *n= ame, return -1; } =20 + incoming_fds =3D tap->x_permit_local_migration && 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("script", tap->script) || + !tap_is_explicit_no_script("downscript", tap->downscript))) { + error_setg(errp, "Local incoming migration of TAP device (-incomin= g, " + "migration parameter @local is set, " + "TAP parameter @x-permit-local-migration 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; @@ -1030,7 +1170,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_x_permit_local_migration, + tap->x_permit_local_migration); + 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 acb8594c952..a135767984b 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -437,6 +437,31 @@ # @poll-us: maximum number of microseconds that could be spent on busy # polling for tap (since 2.7) # +# @x-permit-local-migration: permit 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 a 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 @x-permit-local-migration +# parameter set) will simply fail. +# +# Moreover, when QEMU is in incoming migration state, migration +# parameter @local is set and @x-permit-local-migration is set, +# the following options are not supported and must not be set: +# @fd, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr. +# Additionally, @script and @downscript must be explicitly +# disabled then. +# (default: false, since 11.2) +# +# Features: +# +# @unstable: Member @x-permit-local-migration is experimental. +# # Since: 1.2 ## { 'struct': 'NetdevTapOptions', @@ -455,7 +480,9 @@ '*vhostfds': 'str', '*vhostforce': 'bool', '*queues': 'uint32', - '*poll-us': 'uint32'} } + '*poll-us': 'uint32', + '*x-permit-local-migration': { + 'type': 'bool', 'features' : [ 'unstable'] } } } =20 ## # @NetdevSocketOptions: --=20 2.43.0 From nobody Wed Aug 26 10:14:38 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=1787162584; cv=none; d=zohomail.com; s=zohoarc; b=h44wJPv3dsjfuWQlnMRywxqvY/W7fQeayiTz4Eu3pGPCnDMFhWEMIWPoenZq7dgDfaFnBDAYhNbzeSAtFxERYHQCivUtuTR1SuEWEuBc36wwlzchZT1LrrwwctWjW0fI8HXhhV80G5FC9lnKxnS0CYUeNUUfZvKA2CClFl0ehnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787162584; 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=1jFEXJ5gP6g9SEyIEj3BezdKrfZO8PT6nYF6N0/Kx58=; b=Rn/luR+73zYbq0PuvBCsn9E193obbvf4lAPC1ZOgxSVHzzWCNO/3aabVjfdDw2cZxVuv0cS6CZ/Keum3HJzjNPkEBjaXMNX0WAu3PDO/MrNsD3hNXU4VEe0xolpd7ePDnNXV4pXYE0zwt47wg2ydtwRcDZ3fZ4GOalv3NqkfPNI= 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 1787162584167966.1974797767735; Wed, 19 Aug 2026 11:03:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wwkcg-0004Nq-M5; Wed, 19 Aug 2026 14:02:46 -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 1wwkce-0004N4-RY for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:44 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wwkcc-0007SR-2r for qemu-devel@nongnu.org; Wed, 19 Aug 2026 14:02:44 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (postfix) with ESMTPS id C6CB1C08B7; Wed, 19 Aug 2026 21:02:40 +0300 (MSK) Received: from i115954770.yandex-team.ru (unknown [2a02:6bf:8080:c60::1:5]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id M2bUThDaVKo0-BEWSSt5d; Wed, 19 Aug 2026 21:02:39 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1787162559; bh=1jFEXJ5gP6g9SEyIEj3BezdKrfZO8PT6nYF6N0/Kx58=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Z348VjPSVVpqVnjn7DukFR1kxQSLaCK1jWz+nujthsNhPDyPRcl3ML+QGkJ97BXJR 2R/GjTp4o5t/cN0/W9A0PvJxcE0Y1Zau4bnJagOyaPopCEgPmHI/QZEFXus8DY2Rn9 TwEyjVebBHiT6O2j6LN6rjhbWlCbom5X+ePcaSjk= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.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 v21 16/16] tests/functional: add test_tap_migration Date: Wed, 19 Aug 2026 21:01:59 +0300 Message-ID: <20260819180201.1970193-17-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260819180201.1970193-1-vsementsov@yandex-team.ru> References: <20260819180201.1970193-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.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.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: 1787162586021158500 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 | 461 ++++++++++++++++++ 2 files changed, 462 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..1e0d6025185 --- /dev/null +++ b/tests/functional/x86_64/test_tap_migration.py @@ -0,0 +1,461 @@ +#!/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() + + self.require_accelerator("kvm") + self.set_machine("q35") + + self.setup_shared_memory() + + init_tap() + + self.outer_ping_proc =3D None + self.shm_path =3D None + + def tearDown(self): + with ExitStack() as stack: + stack.callback(super().tearDown) + + if self.shm_path: + stack.callback(lambda p: (os.unlink(p) if os.path.exists(p) + else None), + self.shm_path) + self.shm_path =3D None + + stack.callback(del_tap, TAP_ID2) + stack.callback(del_tap, TAP_ID) + + if self.outer_ping_proc: + self.stop_outer_ping() + + 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_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("-net", "none") + + 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") + + 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", + "x-permit-local-migration": 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): + 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 migrate(self, vm, mig_sock): + vm.cmd("migrate", uri=3Df"unix:{mig_sock}") + def do_test_tap_fd_migration(self, vhost, local=3DTrue): + socket_dir =3D self.socket_dir() + mig_sock =3D os.path.join(socket_dir.name, "mig.sock") + + # Setup second TAP if needed + if not local: + del_tap(TAP_ID2) + init_tap(TAP_ID2, with_ip=3DFalse) + + self.prepare_vm(self.shm_path, vhost, local=3Dlocal) + self.vm.launch() + self.set_migration_capabilities(self.vm, local=3Dlocal) + self.add_virtio_net(self.vm, vhost, TAP_ID, local, incoming=3DFals= e) + + 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_vm( + self.shm_path, + vhost, + incoming=3DTrue, + vm=3Dtarget_vm, + local=3Dlocal, + ) + + target_vm.launch() + if not local: + tap_name =3D TAP_ID2 + else: + tap_name =3D TAP_ID + self.set_migration_capabilities(target_vm, local=3Dlocal) + self.add_virtio_net(target_vm, vhost, tap_name, local, incoming=3D= True) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{mig_sock}"}) + + self.log.info("Starting migration") + freeze_start =3D time.time() + self.migrate(self.vm, mig_sock) + + 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