From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080330; cv=none; d=zohomail.com; s=zohoarc; b=aBQCsh9EaqrVkRcxQVF8FRh+CNlwNNmHcO3UF3mlzn34jIgU6If78mf6Tc9VfoS+qZDw9vZrgP8h5ExF4iRZ3TbNZ05xplI+zVTK/O8QmLBKEpazO1nXhQlATN2+Db/qBEeXgvkAjSYZRsXusXnGcaWEcqejkRPQVrzzYh+lRDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080330; 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=M+LwSX/uuPa2gM4twysLBZZ64QwQ6Num9jQnfd3A3y8=; b=HzMhZXQn1VHWPiLacAWaAdgW+IesY4IQEvL6HLXzfX3wKE5buduT/X4l4Fvyqb4uQar2VM4aAnsPmRBq9shCP0dNkCLTErDfzjIzC1kXuY5p5whs2uJtm8hMPq2vze61e6DOu2v5kC69urM1cAkaX455WRazoP8a4Ry/DNpbNeg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17570803297611019.7957126909172; Fri, 5 Sep 2025 06:52:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqH-0001gl-IG; Fri, 05 Sep 2025 09:51:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqD-0001et-0Z for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:01 -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 1uuWq2-0006XD-MW for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:00 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 8846FC108E; Fri, 05 Sep 2025 16:50:43 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-sl5GhG6P; Fri, 05 Sep 2025 16:50:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080243; bh=M+LwSX/uuPa2gM4twysLBZZ64QwQ6Num9jQnfd3A3y8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=V6lAPmdt+NFWWRJxYDVZdclezaHe8WZ4qVVSYd+NXtJ2W37tDoePm2FrGo7/UyVoB Uc+psfaKCxhUfwx8AT/ieBKBgqifvB+V7n1s23PeAOm3XXbSNaNZY+tk02KkqhiN1T 9VPmna1m5ipUG2oMjx+S34J8W21Uo+vMEXu2wNTY= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 1/9] net/tap: add some trace points Date: Fri, 5 Sep 2025 16:50:31 +0300 Message-ID: <20250905135039.2202924-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080334021124100 Content-Type: text/plain; charset="utf-8" Add trace points to simplify debugging migration. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 10 ++++++++++ net/trace-events | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/net/tap.c b/net/tap.c index 2530627a9a..151fb73820 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 "trace.h" =20 #include "net/tap.h" =20 @@ -148,6 +149,9 @@ static ssize_t tap_receive_iov(NetClientState *nc, cons= t struct iovec *iov, g_autofree struct iovec *iov_copy =3D NULL; struct virtio_net_hdr hdr =3D { }; =20 + trace_tap_receive_iov(s->using_vnet_hdr, s->host_vnet_hdr_len, iovcnt, + iov->iov_len); + if (s->host_vnet_hdr_len && !s->using_vnet_hdr) { iov_copy =3D g_new(struct iovec, iovcnt + 1); iov_copy[0].iov_base =3D &hdr; @@ -199,6 +203,8 @@ static void tap_send(void *opaque) break; } =20 + trace_tap_send_packet(s->using_vnet_hdr, s->host_vnet_hdr_len, siz= e); + if (s->host_vnet_hdr_len && size <=3D s->host_vnet_hdr_len) { /* Invalid packet */ break; @@ -980,6 +986,8 @@ int tap_enable(NetClientState *nc) TAPState *s =3D DO_UPCAST(TAPState, nc, nc); int ret; =20 + trace_tap_enable(); + if (s->enabled) { return 0; } else { @@ -997,6 +1005,8 @@ int tap_disable(NetClientState *nc) TAPState *s =3D DO_UPCAST(TAPState, nc, nc); int ret; =20 + trace_tap_disable(); + if (s->enabled =3D=3D 0) { return 0; } else { diff --git a/net/trace-events b/net/trace-events index cda960f42b..a8921763ab 100644 --- a/net/trace-events +++ b/net/trace-events @@ -29,3 +29,9 @@ vhost_vdpa_set_address_space_id(void *v, unsigned vq_grou= p, unsigned asid_num) " vhost_vdpa_net_load_cmd(void *s, uint8_t class, uint8_t cmd, int data_num,= int data_size) "vdpa state: %p class: %u cmd: %u sg_num: %d size: %d" vhost_vdpa_net_load_cmd_retval(void *s, uint8_t class, uint8_t cmd, int r)= "vdpa state: %p class: %u cmd: %u retval: %d" vhost_vdpa_net_load_mq(void *s, int ncurqps) "vdpa state: %p current_qpair= s: %d" + +# tap.c +tap_receive_iov(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int iovcn= t, size_t iov_len) "using_vnet_hdr:%d host_vnet_hdr_len:%u iovcnt:%d iov_le= n:%zu" +tap_send_packet(bool using_vnet_hdr, uint32_t host_vnet_hdr_len, int size)= "using_vnet_hdr:%d host_vnet_hdr_len:%u size:%d" +tap_enable(void) "" +tap_disable(void) "" --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080430; cv=none; d=zohomail.com; s=zohoarc; b=nCt2oj+lop53ziXN/jSsy7mAw5mPvx4smhYezneveX21ss3Skmr6Ws9QCaalgUfqoERARKXM3R6dhV8BB4NBdwExsEMRuWJqreluLRFH2/AdY9wGzSIUfLCr8/nv1joF2AyrvpWqZCJv4wxGgF4951zssSQq0nAsmUTHSHvwNhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080430; 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=Eu31Z84cv7HW21LtKBhasXjdiIYgRYFKi7HX9Rx+K30=; b=RqCLGx0LNIuQ2eOOuOAPXuyIrBNi9y1lNYpsfcJenF5SFbzfHXLI0BAq1eCBAAZjtpa3oeM7Mb9yfIbVfdlQvBd+ksbck00GLvaf+2f7izCU1MMbwBLt6A1lpKy3vyu+6Vggqh3pGgq13H3hDY59FJEXCS/qTJI2AI4OUiG61ag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175708043059140.718263233874836; Fri, 5 Sep 2025 06:53:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqN-0001jh-EX; Fri, 05 Sep 2025 09:51:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqK-0001iB-QG for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:09 -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 1uuWq2-0006XE-Mz for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:07 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 224AEC108F; Fri, 05 Sep 2025 16:50:44 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-5dQR3RFv; Fri, 05 Sep 2025 16:50:43 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080243; bh=Eu31Z84cv7HW21LtKBhasXjdiIYgRYFKi7HX9Rx+K30=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=AziRMqq4QwEcPwXORTUOAUDMw9mG9z12zfp2fS1LKD0HJW3toMI5QlyptkhrfypNH IT3gohqYj6mpRaDFLbEcS/5cxltcCcm6+s+iZxaLz8X9geLtJZvncj7vNFfu156IpM 1AHSxCZ+ikj5ld1qK331EirAhHJhPG1g1ksXY/LY= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 2/9] net/tap: keep exit notifier only when downscript set Date: Fri, 5 Sep 2025 16:50:32 +0300 Message-ID: <20250905135039.2202924-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080432435116601 Content-Type: text/plain; charset="utf-8" The notifier is used only to call the downscript. Avoid extra notifier for other cases. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 151fb73820..4f3512a831 100644 --- a/net/tap.c +++ b/net/tap.c @@ -336,8 +336,10 @@ static void tap_cleanup(NetClientState *nc) =20 qemu_purge_queued_packets(nc); =20 - tap_exit_notify(&s->exit, NULL); - qemu_remove_exit_notifier(&s->exit); + if (s->exit.notify) { + tap_exit_notify(&s->exit, NULL); + qemu_remove_exit_notifier(&s->exit); + } =20 tap_read_poll(s, false); tap_write_poll(s, false); @@ -727,9 +729,7 @@ static int net_tap_fd_init_common(const Netdev *netdev,= NetClientState *peer, } tap_read_poll(s, true); s->vhost_net =3D NULL; - - s->exit.notify =3D tap_exit_notify; - qemu_add_exit_notifier(&s->exit); + s->exit.notify =3D NULL; =20 if (netdev->type =3D=3D NET_CLIENT_DRIVER_BRIDGE) { const NetdevBridgeOptions *bridge =3D &netdev->u.bridge; @@ -757,6 +757,8 @@ static int net_tap_fd_init_common(const Netdev *netdev,= NetClientState *peer, snprintf(s->down_script, sizeof(s->down_script), "%s", downscr= ipt); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); + s->exit.notify =3D tap_exit_notify; + qemu_add_exit_notifier(&s->exit); } } =20 --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080377; cv=none; d=zohomail.com; s=zohoarc; b=awQuKgtRxPfBoFp+VwoqdQZiXPeBY7g9hQjLJUZHxw8+WJmbjJbbqKPFJfslmGMxVzMCPBzkJhyeSi+B5ZoPe/gLR4b/Fz11GjThsMiFKUqlBU22x82yfsrzNE7Y0h6WN+0SLU80SNZ05M0ycrThYW4b+sj3WfSDN/VUFSUuhWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080377; 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=dec+tS+435t4X7GDxrUR1YNWlwcVjqv8PqWOjR5ue+w=; b=Kw4yiHHr/NotpjjOOZ9usTnx6IQQeRXXJE8ehqMv8FVKpaOl+Pfr790ji/vM1wc5Bu7bti3SArRqnLYweGdtcYs2VCYjhxS5betCi1zlvxkbL3elxogvZmGAgCN3jNc8ZO0NrdQv8cFUbF/aabVk4TPJTfggoNQAL7agTSObGuw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080377715774.0252440920137; Fri, 5 Sep 2025 06:52:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqG-0001gR-TN; Fri, 05 Sep 2025 09:51:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqB-0001eQ-Sj for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:59 -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 1uuWq2-0006XH-Ri for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:59 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id B4E80C1090; Fri, 05 Sep 2025 16:50:44 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-XkdiTCsX; Fri, 05 Sep 2025 16:50:44 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080244; bh=dec+tS+435t4X7GDxrUR1YNWlwcVjqv8PqWOjR5ue+w=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=awZXidPnAL91P+3bnFe1U/4fAYNS3VRtFYF9h2JiFBS0SWOSX/1YlhOuCVTZ8gnft rqo0eeifDwAeAgik0D31IFkMjEwT21jpeF6yEmd+Eo2L0qTm3CpMwUZGKkix6f5Fj2 vtxablYtjXcrSKzl6XBx7CHhvX//j6QuVwn3l05M= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 3/9] net/tap: refactor net_tap_setup_vhost() Date: Fri, 5 Sep 2025 16:50:33 +0300 Message-ID: <20250905135039.2202924-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080379702116600 Content-Type: text/plain; charset="utf-8" 1. Move function higher. (we anyway want to split it into two functions, and change the code a lot, so take an opportunity to get rid of extra declaration). 2. Split into _set_options() and _init_vhost(): we'll need it later to implement TAP local migration feature. 3. Split requires to store options somewhere, and to be able to call _init_vhost() later (from migriation _load() in later commit), store options in the TAPState. 4. So, take an opportunity to zero-initialize options: - be safe (avoid uninitialized options) - don't care to initialize half of the options to zero by hand 5. Also, don't worry too much about poll_us: absent option should be zero-initialized anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 124 +++++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/net/tap.c b/net/tap.c index 4f3512a831..cf7f704a92 100644 --- a/net/tap.c +++ b/net/tap.c @@ -78,6 +78,7 @@ typedef struct TAPState { bool has_ufo; bool has_uso; bool enabled; + VhostNetOptions *vhost_options; VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; @@ -95,8 +96,6 @@ static int net_tap_fd_init_common(const Netdev *netdev, N= etClientState *peer, const char *downscript, const char *vhostfdname, int vnet_hdr, int fd, Error **errp); -static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, Error **errp); =20 static void tap_update_fd_handler(TAPState *s) { @@ -334,6 +333,8 @@ static void tap_cleanup(NetClientState *nc) s->vhost_net =3D NULL; } =20 + g_free(s->vhost_options); + qemu_purge_queued_packets(nc); =20 if (s->exit.notify) { @@ -697,6 +698,64 @@ static int net_tap_open_one(const Netdev *netdev, =20 #define MAX_TAP_QUEUES 1024 =20 +static int net_tap_set_vhost_options(TAPState *s, const NetdevTapOptions *= tap, + const char *vhostfdname, Error **errp) +{ + int vhostfd; + bool vhost_on =3D tap->has_vhost ? tap->vhost : + vhostfdname || (tap->has_vhostforce && tap->vhostforce); + + if (!vhost_on) { + return 0; + } + + if (vhostfdname) { + vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); + if (vhostfd =3D=3D -1) { + return -1; + } + } else { + vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (vhostfd < 0) { + error_setg_errno(errp, errno, + "tap: open vhost char device failed"); + return -1; + } + } + + if (!qemu_set_blocking(vhostfd, false, errp)) { + return -1; + } + + s->vhost_options =3D g_new(VhostNetOptions, 1); + *s->vhost_options =3D (VhostNetOptions) { + .backend_type =3D VHOST_BACKEND_TYPE_KERNEL, + .net_backend =3D &s->nc, + .busyloop_timeout =3D tap->poll_us, + .opaque =3D (void *)(uintptr_t)vhostfd, + .nvqs =3D 2, + .feature_bits =3D kernel_feature_bits, + }; + + return 0; +} + +static int net_tap_init_vhost(TAPState *s, Error **errp) +{ + if (!s->vhost_options) { + return 0; + } + + s->vhost_net =3D vhost_net_init(s->vhost_options); + if (!s->vhost_net) { + error_setg(errp, + "vhost-net requested but could not be initialized"); + return -1; + } + + return 0; +} + static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *pe= er, const char *model, const char *name, const char *ifname, const char *script, @@ -762,7 +821,12 @@ static int net_tap_fd_init_common(const Netdev *netdev= , NetClientState *peer, } } =20 - ret =3D net_tap_setup_vhost(s, tap, vhostfdname, errp); + ret =3D net_tap_set_vhost_options(s, tap, vhostfdname, errp); + if (ret < 0) { + goto failed; + } + + ret =3D net_tap_init_vhost(s, errp); if (ret < 0) { goto failed; } @@ -774,60 +838,6 @@ failed: return -1; } =20 -static int net_tap_setup_vhost(TAPState *s, const NetdevTapOptions *tap, - const char *vhostfdname, Error **errp) -{ - if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { - VhostNetOptions options; - int vhostfd; - - options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; - options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - return -1; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return -1; - } - } else { - vhostfd =3D open("/dev/vhost-net", O_RDWR); - if (vhostfd < 0) { - error_setg_errno(errp, errno, - "tap: open vhost char device failed"); - return -1; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - return -1; - } - } - 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"); - return -1; - } - } - - return 0; -} - static int net_tap_from_monitor_fd(const Netdev *netdev, NetClientState *p= eer, const char *name, const char *vhostfdna= me, int *pvnet_hdr, const char *fdname, --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080375; cv=none; d=zohomail.com; s=zohoarc; b=bkGesVaGmXR9smGWgT0pNF+Ufo9x3loCkWvllG82ZZDnopffEZHAYa7JdocY2NjvxRRCS4l8yysTMT7rAVi17RFgRbdM1qLG6kT6E0LWSjf9NjR8luTceTG+ruJ3wgzjyd4IpHArRrA+A6Xo445v6+QVb5cAkPSnXhBQyxcfgTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080375; 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=ZIuITB1rd17BNdWGYUy9N1rTVr/YhJCJKjPp4gE6akA=; b=KmqBek5YmGviUBDn+/OY/NlFS0pFp87eHPghj9gXBNVH7YfcjNt88eDfBFFIAHZpnvFt3ikFF+UCX1UrbVaz0qSEplAqJoaaTPaiLgp6gvRNYmAItx1UIy0ixyRtwSEisTy4nslJ3ZvYDlU6L1mWU9riG2SBarQFcs16ebmfbqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080375510153.0610872931985; Fri, 5 Sep 2025 06:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqA-0001db-Pk; Fri, 05 Sep 2025 09:50:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWq7-0001cx-Tw for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:55 -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 1uuWq2-0006XI-MV for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:55 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 4C2E1C1091; Fri, 05 Sep 2025 16:50:45 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-Mvpm3ELe; Fri, 05 Sep 2025 16:50:44 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080244; bh=ZIuITB1rd17BNdWGYUy9N1rTVr/YhJCJKjPp4gE6akA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yhRw2dEvlKrHEAVI8Bb8+b8z5K30+KldaEYJmXz06TXw9j6D/OPEPBR8B7JNxab5l nYtlZxDDxm71iDmxy8AVbblymqkt5Jm+lNC0crs5sNYCFgt71QSON4uKJT0S7BfGr/ mGaJbZNaDeDW9Kr+N7WNt2qaXZqUE3QU6mAFiUk4= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 4/9] qapi: add interface for local TAP migration Date: Fri, 5 Sep 2025 16:50:34 +0300 Message-ID: <20250905135039.2202924-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080377945116600 Content-Type: text/plain; charset="utf-8" To migrate TAP device (including open fds) locally, user should: 1. enable local-tap migration capability both on source and target 2. use additional local-incoming=3Dtrue option for tap on target Why capability is not enough? We need an option to modify early initialization of TAP, to avoid opening new fds. The capability may not be set at the moment of netdev initialization. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/options.c | 7 +++++++ migration/options.h | 1 + qapi/migration.json | 9 ++++++++- qapi/net.json | 12 +++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/migration/options.c b/migration/options.c index 4e923a2e07..6f5af52a5c 100644 --- a/migration/options.c +++ b/migration/options.c @@ -262,6 +262,13 @@ bool migrate_mapped_ram(void) return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM]; } =20 +bool migrate_local_tap(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->capabilities[MIGRATION_CAPABILITY_LOCAL_TAP]; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/options.h b/migration/options.h index 82d839709e..08c0606072 100644 --- a/migration/options.h +++ b/migration/options.h @@ -30,6 +30,7 @@ bool migrate_colo(void); bool migrate_dirty_bitmaps(void); bool migrate_events(void); bool migrate_mapped_ram(void); +bool migrate_local_tap(void); bool migrate_ignore_shared(void); bool migrate_late_block_activate(void); bool migrate_multifd(void); diff --git a/qapi/migration.json b/qapi/migration.json index 2387c21e9c..992a5b1e2b 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -517,6 +517,12 @@ # each RAM page. Requires a migration URI that supports seeking, # such as a file. (since 9.0) # +# @local-tap: Migrate TAPs locally, keeping backend alive. Open file +# descriptors and TAP-related state are migrated. Only may be +# used when migration channel is unix socket. For target device +# also @local-incoming option must be specified (since 10.2) +# (since 10.2) +# # Features: # # @unstable: Members @x-colo and @x-ignore-shared are experimental. @@ -536,7 +542,8 @@ { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', 'zero-copy-send', 'postcopy-preempt', 'switchover-ack', - 'dirty-limit', 'mapped-ram'] } + 'dirty-limit', 'mapped-ram', + { 'name': 'local-tap', 'features': [ 'unstable' ] } ] } =20 ## # @MigrationCapabilityStatus: diff --git a/qapi/net.json b/qapi/net.json index 78bcc9871e..8f53549d58 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -353,6 +353,15 @@ # @poll-us: maximum number of microseconds that could be spent on busy # polling for tap (since 2.7) # +# @local-incoming: Do load open file descriptor for that TAP +# on incoming migration. May be used only if QEMU is started +# for incoming migration. Will work only together with local-tap +# migration capability enabled (default: false) (Since: 10.2) +# +# Features: +# +# @unstable: Member @local-incoming is experimental +# # Since: 1.2 ## { 'struct': 'NetdevTapOptions', @@ -371,7 +380,8 @@ '*vhostfds': 'str', '*vhostforce': 'bool', '*queues': 'uint32', - '*poll-us': 'uint32'} } + '*poll-us': 'uint32', + '*local-incoming': { 'type': 'bool', 'features': [ 'unstable' ] } } } =20 ## # @NetdevSocketOptions: --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080350; cv=none; d=zohomail.com; s=zohoarc; b=MMEd6wcKriX7H0RGWnVcK58nGwtx8AdXZcrijGhJUhiIwJnZTRavlUx6JTD6DwVkzGkTrVLh9cpUVpSHxSwjzEzgcOWU/aD6B4f8+n0cb7ZJIdr9sHlF03z/VU1hxc1gqEd71RTl5GBIK2PZrNleO1ZQ9h6d8jm0XQqAA6jdeVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080350; 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=9BRBRN4FugsQSiwFKEkHemuvQEzD3v1rNDoVEakXDW8=; b=mlNcTmtO3PusWLF6zHyjYD4coKbU7IbU6A8UjAw+LH9Kojf+DPntQD9yr+WYc/QIHnIOkMz1z2qOlfCuzYZ5GsS62Nt15CiW/fkUdqlfzlmBFUR/1+9TtYGDRJyQQ2SJKalSQ808eNHjx6+5CFn9WyM6+OiNe9/5ujDUgwjr4Xs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175708035090174.92016254114617; Fri, 5 Sep 2025 06:52:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqD-0001fD-UZ; Fri, 05 Sep 2025 09:51:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqC-0001dU-2E for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:00 -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 1uuWq3-0006XN-9N for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:56 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 04A9FC1093; Fri, 05 Sep 2025 16:50:46 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-2g50U4kW; Fri, 05 Sep 2025 16:50:45 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080245; bh=9BRBRN4FugsQSiwFKEkHemuvQEzD3v1rNDoVEakXDW8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=DurQy7uM9nCHn7vczOe7dFX5he/8OWdeKzd/m2NFIW34csUeUu3Tho1DJApdJArTC 1AAlraf1Mb5NKVF4Z7+T4PW+7yRccIKzgvKHdjlT3rmpABxdW9b8gWoyMMeQbjYayE stzXw4iXe45ySRZ3jPIrt6GWevAiWDxFF+l8kBFo= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 5/9] net/tap: implement interfaces for local migration Date: Fri, 5 Sep 2025 16:50:35 +0300 Message-ID: <20250905135039.2202924-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080353883116600 Content-Type: text/plain; charset="utf-8" Handle local-incoming option: Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/net/tap.h | 4 ++ net/tap.c | 139 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 122 insertions(+), 21 deletions(-) diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..3ef2e2dbae 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -30,7 +30,11 @@ =20 int tap_enable(NetClientState *nc); int tap_disable(NetClientState *nc); +bool tap_local_incoming(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); =20 +int tap_load(NetClientState *nc, QEMUFile *f); +int tap_save(NetClientState *nc, QEMUFile *f); + #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap.c b/net/tap.c index cf7f704a92..0fd7a7671c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -35,6 +35,7 @@ #include "net/eth.h" #include "net/net.h" #include "clients.h" +#include "migration/vmstate.h" #include "monitor/monitor.h" #include "system/system.h" #include "qapi/error.h" @@ -44,6 +45,7 @@ #include "qemu/sockets.h" #include "hw/virtio/vhost.h" #include "trace.h" +#include "system/runstate.h" =20 #include "net/tap.h" =20 @@ -82,6 +84,7 @@ typedef struct TAPState { VHostNetState *vhost_net; unsigned host_vnet_hdr_len; Notifier exit; + bool local_incoming; } TAPState; =20 static void launch_script(const char *setup_script, const char *ifname, @@ -756,6 +759,43 @@ static int net_tap_init_vhost(TAPState *s, Error **err= p) return 0; } =20 +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + + tap_read_poll(s, true); + + return net_tap_init_vhost(s, NULL); +} + +static const VMStateDescription vmstate_tap =3D { + .name =3D "virtio-net-device", + .post_load =3D tap_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_FD(fd, TAPState), + VMSTATE_BOOL(using_vnet_hdr, TAPState), + VMSTATE_BOOL(has_ufo, TAPState), + VMSTATE_BOOL(has_uso, TAPState), + VMSTATE_BOOL(enabled, TAPState), + VMSTATE_UINT32(host_vnet_hdr_len, TAPState), + VMSTATE_END_OF_LIST() + } +}; + +int tap_save(NetClientState *nc, QEMUFile *f) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return vmstate_save_state(f, &vmstate_tap, s, 0); +} + +int tap_load(NetClientState *nc, QEMUFile *f) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return vmstate_load_state(f, &vmstate_tap, s, 0); +} + static int net_tap_fd_init_common(const Netdev *netdev, NetClientState *pe= er, const char *model, const char *name, const char *ifname, const char *script, @@ -763,30 +803,40 @@ static int net_tap_fd_init_common(const Netdev *netde= v, NetClientState *peer, const char *vhostfdname, int vnet_hdr, int fd, Error **errp) { - const NetdevTapOptions *tap; + const NetdevTapOptions *tap =3D NULL; int ret; NetClientState *nc; TAPState *s; + bool local_incoming =3D false; + + if (netdev->type =3D=3D NET_CLIENT_DRIVER_TAP) { + tap =3D &netdev->u.tap; + local_incoming =3D tap->local_incoming; + } =20 nc =3D qemu_new_net_client(&net_tap_info, peer, model, name); =20 s =3D DO_UPCAST(TAPState, nc, nc); - - s->fd =3D fd; - s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) : 0; - s->using_vnet_hdr =3D false; - s->has_ufo =3D tap_probe_has_ufo(s->fd); - s->has_uso =3D tap_probe_has_uso(s->fd); - s->enabled =3D true; - tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); - /* - * Make sure host header length is set correctly in tap: - * it might have been modified by another instance of qemu. - */ - if (vnet_hdr) { - tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); + s->local_incoming =3D local_incoming; + + if (!local_incoming) { + s->fd =3D fd; + s->host_vnet_hdr_len =3D vnet_hdr ? sizeof(struct virtio_net_hdr) = : 0; + s->using_vnet_hdr =3D false; + s->has_ufo =3D tap_probe_has_ufo(s->fd); + s->has_uso =3D tap_probe_has_uso(s->fd); + s->enabled =3D true; + tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); + /* + * Make sure host header length is set correctly in tap: + * it might have been modified by another instance of qemu. + */ + if (vnet_hdr) { + tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); + } + tap_read_poll(s, true); } - tap_read_poll(s, true); + s->vhost_net =3D NULL; s->exit.notify =3D NULL; =20 @@ -798,9 +848,8 @@ static int net_tap_fd_init_common(const Netdev *netdev,= NetClientState *peer, } =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); - tap =3D &netdev->u.tap; =20 - if (tap_set_sndbuf(s->fd, tap, errp) < 0) { + if (!local_incoming && tap_set_sndbuf(s->fd, tap, errp) < 0) { goto failed; } =20 @@ -826,9 +875,11 @@ static int net_tap_fd_init_common(const Netdev *netdev= , NetClientState *peer, goto failed; } =20 - ret =3D net_tap_init_vhost(s, errp); - if (ret < 0) { - goto failed; + if (!local_incoming) { + ret =3D net_tap_init_vhost(s, errp); + if (ret < 0) { + goto failed; + } } =20 return 0; @@ -895,6 +946,38 @@ static int net_tap_open(const Netdev *netdev, return 0; } =20 +static int net_init_local_incoming(const Netdev *netdev, + const char *name, + NetClientState *peer, + Error **errp) +{ + const NetdevTapOptions *tap =3D &netdev->u.tap; + const char *downscript =3D tap->downscript; + int queues =3D tap->has_queues ? tap->queues : 1; + g_autofree char *default_downscript =3D NULL; + int i, ret; + + assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); + assert(!tap->script); + + if (!downscript) { + downscript =3D default_downscript =3D + get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIP= T); + } + + for (i =3D 0; i < queues; i++) { + ret =3D net_tap_fd_init_common(netdev, peer, "tap", name, + tap->ifname ?: "", + "no", downscript, + tap->vhostfd, -1, -1, errp); + if (ret < 0) { + return -1; + } + } + + return 0; +} + static int net_init_tap_fds(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -983,6 +1066,13 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } =20 return net_init_bridge(netdev, name, peer, errp); + } else if (tap->local_incoming) { + if (tap->script) { + error_setg(errp, "script=3D is invalid with local-incoming"); + return -1; + } + + return net_init_local_incoming(netdev, name, peer, errp); } =20 if (tap->vhostfds) { @@ -1031,3 +1121,10 @@ int tap_disable(NetClientState *nc) return ret; } } + +bool tap_local_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + return s->local_incoming && runstate_check(RUN_STATE_INMIGRATE); +} --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080331; cv=none; d=zohomail.com; s=zohoarc; b=BY5MTzRO2jOQ0qF5UxLJ0BcLl/euB5rtKzNRLIvaVX56p+ImmTBieOpX3GsiosxOPN1tzqduS5cVgEVop9AbueJpn/BH92FSuRI+PfqXhZhreuzhFLTvspwe1Odnf44dEklZ43V1jtCzuX54kxBCQlWzIlgSfaeIixhaAh2bPyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080331; 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=GftTvKuCJ/20RJKBye2/TezLhjc0gyXvfMSFYxlvOO8=; b=Aa9tBOCXc2+qXax4Iyzrcmgby4TymjaR/RtkU2KL2xppwYHL3gtTjHbprkKvfeUlZBfsDxSDNH8rVdEARtsNtdXIIHhTSLBj5zBYPUulKYejEe0zclfYW6bWw7DTbUk2PUhFB7RQ681DSbBxi7FNBzSdhBPdJJ3ZxLgIK8+oq5Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080331797636.3019716466055; Fri, 5 Sep 2025 06:52:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqA-0001dT-6B; Fri, 05 Sep 2025 09:50:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWq8-0001cy-29 for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:56 -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 1uuWq2-0006XT-Mr for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:50:55 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9D1DBC108D; Fri, 05 Sep 2025 16:50:46 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-0rVyDtvL; Fri, 05 Sep 2025 16:50:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080246; bh=GftTvKuCJ/20RJKBye2/TezLhjc0gyXvfMSFYxlvOO8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=PMTQpLivBqSYjdGE6wFzF5PUKqArKM0+7IuDL1mnXNCuWRI7zlAts2WrwJKu1mBmT mmFFu4bFliteaePrbsSyLIu7G/SjbyDkfcXjVgSlcQFCKB+ZeyPQSsDoieuJqlQSvT C1wX5fjZ60TO0ppy4Cgn5JSbjx+pRIzKYk/I3dqg= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 6/9] virtio-net: support local tap migration Date: Fri, 5 Sep 2025 16:50:36 +0300 Message-ID: <20250905135039.2202924-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080334374116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 100 ++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6b5b5dace3..874e349fee 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -38,6 +38,8 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/migration.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -2999,7 +3001,13 @@ 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); + /* + * Called from set_features(0) on reset, when on target we + * doesn't have fds yet + */ + if (!n->tap_wait_incoming) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3009,6 +3017,19 @@ static int virtio_net_pre_load_queues(VirtIODevice *= vdev, uint32_t n) return 0; } =20 +static int virtio_net_pre_save_device(void *opaque) +{ + VirtIONet *n =3D opaque; + int i, r; + + for (i =3D 0; i < n->curr_queue_pairs; i++) { + r =3D peer_detach(n, i); + assert(!r); + } + + return 0; +} + static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t featu= res, Error **errp) { @@ -3028,6 +3049,11 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, =20 virtio_add_feature(&features, VIRTIO_NET_F_MAC); =20 + if (n->tap_wait_incoming) { + /* Excessive feature set is OK for early initialization */ + return features; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); @@ -3494,11 +3520,69 @@ static const VMStateDescription vhost_user_net_back= end_state =3D { } }; =20 +static int virtio_net_tap_save(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, + JSONWriter *vmdesc) +{ + VirtIONet *n =3D pv; + int i; + + for (i =3D 0; i < n->max_queue_pairs; i++) { + NetClientState *nc =3D qemu_get_subqueue(n->nic, i); + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + tap_save(nc->peer, f); + } + + return 0; +} + +static int virtio_net_tap_load(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + VirtIONet *n =3D pv; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + Error *local_err =3D NULL; + int i; + + for (i =3D 0; i < n->max_queue_pairs; i++) { + NetClientState *nc =3D qemu_get_subqueue(n->nic, i); + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + tap_load(nc->peer, f); + } + + peer_test_vnet_hdr(n); + n->tap_wait_incoming =3D false; + + vdev->host_features =3D vdc->get_features(vdev, vdev->host_features, + &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static bool virtio_net_is_tap_local(void *opaque, int version_id) +{ + VirtIONet *n =3D opaque; + NetClientState *nc; + + nc =3D qemu_get_queue(n->nic); + + return migrate_local_tap() && nc->peer && + nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP; +} + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, .minimum_version_id =3D VIRTIO_NET_VM_VERSION, .post_load =3D virtio_net_post_load_device, + .pre_save =3D virtio_net_pre_save_device, .fields =3D (const VMStateField[]) { VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), VMSTATE_STRUCT_POINTER(vqs, VirtIONet, @@ -3525,6 +3609,15 @@ static const VMStateDescription vmstate_virtio_net_d= evice =3D { * but based on the uint. */ VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + { + .name =3D "tap", + .info =3D &(const VMStateInfo) { + .name =3D "virtio-net vhost-user backend state", + .get =3D virtio_net_tap_load, + .put =3D virtio_net_tap_save, + }, + .field_exists =3D virtio_net_is_tap_local, + }, VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -3954,6 +4047,11 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEN= D); } + + if (nc->peer && nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { + n->tap_wait_incoming =3D tap_local_incoming(nc->peer); + } + QTAILQ_INIT(&n->rsc_chains); n->qdev =3D dev; =20 diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 73fdefc0dc..04ae0e4c06 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -231,6 +231,8 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; uint32_t nr_ebpf_rss_fds; char **ebpf_rss_fds; + + bool tap_wait_incoming; }; =20 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080383; cv=none; d=zohomail.com; s=zohoarc; b=PedQeam6qUCNjgJMRubYYWIB2f34ERDLTmHGLLCt+odQX+Bttn9HDYn4rrOKDjT/ovuDstCjJE+iDpniKIU1EqRzTaYFyjsQW14t21hhMQX1H+rs03H0LREghucJJ4u6QhrqUQNcVgSZZh3CWY7Oup27mPPRtdPCHFwsoouQGk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080383; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xzcdYCb73x3t/fdZEEKsSgOBm4tobZHvOXDAvGXSlv0=; b=IoQR3qAggxXrPvQABDEt8u4A+YR/7GwgpOmsqVdC/JPgKvCAAzIxhTHHCXtRCTRyuLirWIgrpEtqtvxDcRnHHYy59KRhBhe189I9Q+7PF5ZIgGgOPcibamFQVGX8XdExmaahAF/9ZGgTBcydsJWkGDwjXNsP06LkfMbZRhpo0yk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080383119626.9685401648851; Fri, 5 Sep 2025 06:53:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqK-0001hw-9L; Fri, 05 Sep 2025 09:51:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqG-0001gI-KU for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:04 -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 1uuWq5-0006Xa-03 for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:04 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 31FF3C1094; Fri, 05 Sep 2025 16:50:47 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-ItYgjn4o; Fri, 05 Sep 2025 16:50:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080246; bh=xzcdYCb73x3t/fdZEEKsSgOBm4tobZHvOXDAvGXSlv0=; h=Cc:Message-ID:References:Date:In-Reply-To:Subject:To:From; b=ouDFlx2Wa2zxYjQtwKTRzMjMjRYdZyl9fOhacMz9TdGZGGSQzPo855d8E4MHCG0LR RP7WUbQnOpubVGEvyUUSB+iYkl2SnQNrxRtfFQur2K8U65wYSaSIxbxFnVnSoda0kb zz1AfFrnWh7i5S8jeGF/zLoJ5aMa/EJzeXjtSE2M= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 7/9] tests/functional: exec_command_and_wait_for_pattern: add vm arg Date: Fri, 5 Sep 2025 16:50:37 +0300 Message-ID: <20250905135039.2202924-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080383807116600 Allow to specify non default vm for the command. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth --- tests/functional/qemu_test/cmd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test= /cmd.py index dc5f422b77..28b36a3a54 100644 --- a/tests/functional/qemu_test/cmd.py +++ b/tests/functional/qemu_test/cmd.py @@ -172,7 +172,8 @@ def exec_command(test, command): _console_interaction(test, None, None, command + '\r') =20 def exec_command_and_wait_for_pattern(test, command, - success_message, failure_message=3DN= one): + success_message, failure_message=3DN= one, + vm=3DNone): """ Send a command to a console (appending CRLF characters), then wait for success_message to appear on the console, while logging the. @@ -184,9 +185,11 @@ def exec_command_and_wait_for_pattern(test, command, :param command: the command to send :param success_message: if this message appears, test succeeds :param failure_message: if this message appears, test fails + :param vm: the VM to use (defaults to test.vm if None) """ assert success_message - _console_interaction(test, success_message, failure_message, command += '\r') + _console_interaction(test, success_message, failure_message, command += '\r', + vm=3Dvm) =20 def get_qemu_img(test): test.log.debug('Looking for and selecting a qemu-img binary') --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080366; cv=none; d=zohomail.com; s=zohoarc; b=DmSKsK6Nyht5W8m5PmtMPtMVha/2rOEVyYbhmEBk25ce+NXdwObnTO8JFJqmAN1NKxcUu5zYgV7Wot42Tjod+ddc58RdJO5l5MD727zP7WGxibhHyT80JBOHRkBxQpmsUHW5/O/DQ7A59DGueTqRPVRkW06esVTugQ5Bn4/OSMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080366; 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=rSuCXQoWhEDa3lClRsRosmYTTtalG282XpTtVGlPEX8=; b=apdCAU0VCwhP5MdTsPjrnv9EtP+KQ3CnbCeLZbahqPKN7uVd/dO5+4ha3iO8WAKu78+P3ppa/RpEQ4mNvaTnIDVV5zcS8IuShnd7W9rKcsTCl1I2r67n3Wg4xRDR15ONpAbeOFf2EKMLPY5VFYKYkNEeOZfbcX5iFYFtU2uTjtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080365822474.77363004818574; Fri, 5 Sep 2025 06:52:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqI-0001h9-CQ; Fri, 05 Sep 2025 09:51:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqF-0001ft-BK for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:03 -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 1uuWq3-0006Xc-23 for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:03 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id BE027C1089; Fri, 05 Sep 2025 16:50:47 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-mmvTNMEX; Fri, 05 Sep 2025 16:50:47 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080247; bh=rSuCXQoWhEDa3lClRsRosmYTTtalG282XpTtVGlPEX8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=yShOKByCRrXrK90LW+SiPRGLCfrzVNz0EvFvw2e6R8IEqNSv2feE8TditLoOcq/H3 MwYTcXOjeSceVK4Cq9MNT75IE7zMMaamMpIFl3YV5APpCRON9cYiHZ8RG1qq859ksP qq5aZvZA/PLrOr8wQVuH/5iNFjcJfgxov1JnRN/Y= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 8/9] tests/functional: add skipUnlessPasswordlessSudo() decorator Date: Fri, 5 Sep 2025 16:50:38 +0300 Message-ID: <20250905135039.2202924-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080368332124100 Content-Type: text/plain; charset="utf-8" To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/qemu_test/decorators.py b/tests/functional/qe= mu_test/decorators.py index c0d1567b14..4b332804ef 100644 --- a/tests/functional/qemu_test/decorators.py +++ b/tests/functional/qemu_test/decorators.py @@ -6,6 +6,7 @@ import os import platform import resource +import subprocess from unittest import skipIf, skipUnless =20 from .cmd import which @@ -149,3 +150,18 @@ def skipLockedMemoryTest(locked_memory): ulimit_memory =3D=3D resource.RLIM_INFINITY or ulimit_memory >=3D = locked_memory * 1024, f'Test required {locked_memory} kB of available locked memory', ) + +''' +Decorator to skip execution of a test if passwordless +sudo command is not available. +''' +def skipUnlessPasswordlessSudo(): + proc =3D subprocess.run(["sudo", "-n", "/bin/true"], + stdin=3Dsubprocess.PIPE, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue, + check=3DFalse) + + return skipUnless(proc.returncode =3D=3D 0, + f'requires password-less sudo access: {proc.stdout}') --=20 2.48.1 From nobody Sat Sep 6 14:41:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1757080399; cv=none; d=zohomail.com; s=zohoarc; b=m8+r0OGd2UGzI3CrYJZM8+1cKsf2XexUQKe/E8Du+kWtchDb62TmYNT64IR8msV8IEVvhuK7KSEITp1nGjKrznrNFq30m4CMf5FrLO4jyKrgw6luIzACmnptd5YV0Bf1O7369xeXsLSEn9AZV1bt7ua+vE224kUV/Bee5xdzJc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757080399; 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=GspJw+jNZMf/qcEM6sv+qXWY9PKMq0Hh2OhEwGiDIAA=; b=kVjj8GBakBxOGySljaDO6jP2pWqqYiQv5b6n0uuXeibbY5PRDYCilZDHu9FMteZR26oy2QzNAscfNgCAWiNdf2IGd2y9PvE91cyQmsYdTx4BPUJwHqtuMyaF4xs1XUIICTBFmrcz/ESMOfrfJuLjXrEK1eKpfUj4Z/rPqa0voO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757080399728152.38749975394194; Fri, 5 Sep 2025 06:53:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuWqM-0001jc-Vd; Fri, 05 Sep 2025 09:51:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuWqI-0001h4-7r for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:07 -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 1uuWq6-0006Xk-TU for qemu-devel@nongnu.org; Fri, 05 Sep 2025 09:51:05 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:3a87:0:640:845c:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9F795C1092; Fri, 05 Sep 2025 16:50:48 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id foiXcl3Gh8c0-KF7XumK2; Fri, 05 Sep 2025 16:50:47 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1757080247; bh=GspJw+jNZMf/qcEM6sv+qXWY9PKMq0Hh2OhEwGiDIAA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=gQ/vAz16y9OXXtnrOBBLQChvDHC5K4rpuLbzDA/HP+Ob8uSBIvZGNDxr7nfoC5fwq 6jNaYaa9+YLX99NcKe5KLmHgezZ54iaX0RWekCnZ2nNYRk+eW0C9h3WNVhqthDZR/X yhjkoewhiRIBlFr+JIQrFwt/2KxiPQ2ZU066DQow= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v3 9/9] tests/functional: add test_x86_64_tap_fd_migration Date: Fri, 5 Sep 2025 16:50:39 +0300 Message-ID: <20250905135039.2202924-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250905135039.2202924-1-vsementsov@yandex-team.ru> References: <20250905135039.2202924-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1757080400520116600 Content-Type: text/plain; charset="utf-8" Add test for a new feature of local TAP migration with fd passing through unix socket. Signed-off-by: Vladimir Sementsov-Ogievskiy --- .../test_x86_64_tap_fd_migration.py | 345 ++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 tests/functional/test_x86_64_tap_fd_migration.py diff --git a/tests/functional/test_x86_64_tap_fd_migration.py b/tests/funct= ional/test_x86_64_tap_fd_migration.py new file mode 100644 index 0000000000..a38dba39fe --- /dev/null +++ b/tests/functional/test_x86_64_tap_fd_migration.py @@ -0,0 +1,345 @@ +#!/usr/bin/env python3 +# +# Functional test that tests TAP local migration +# with fd passing +# +# Copyright (c) Yandex +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import time +import subprocess +from subprocess import run +import signal +from typing import Tuple + +from qemu_test import ( + LinuxKernelTest, + Asset, + exec_command_and_wait_for_pattern, +) +from qemu_test.decorators import skipUnlessPasswordlessSudo + +GUEST_IP =3D "10.0.1.2" +GUEST_IP_MASK =3D f"{GUEST_IP}/24" +GUEST_MAC =3D "d6:0d:75:f8:0f:b7" +HOST_IP =3D "10.0.1.1" +HOST_IP_MASK =3D f"{HOST_IP}/24" +TAP_ID =3D "tap0" +TAP_MAC =3D "e6:1d:44:b5:03:5d" + + +def del_tap() -> None: + run( + ["sudo", "ip", "tuntap", "del", TAP_ID, "mode", "tap", "multi_queu= e"], + check=3DTrue, + ) + + +def init_tap() -> None: + run( + ["sudo", "ip", "tuntap", "add", "dev", TAP_ID, "mode", "tap", "mul= ti_queue"], + check=3DTrue, + ) + run(["sudo", "ip", "link", "set", "dev", TAP_ID, "address", TAP_MAC], = check=3DTrue) + run(["sudo", "ip", "addr", "add", HOST_IP_MASK, "dev", TAP_ID], check= =3DTrue) + run(["sudo", "ip", "link", "set", TAP_ID, "up"], check=3DTrue) + + +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}""" + + +@skipUnlessPasswordlessSudo() +class VhostUserBlkFdMigration(LinuxKernelTest): + + ASSET_KERNEL =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/vmlinuz" + ), + "d4738d03dbbe083ca610d0821d0a8f1488bebbdccef54ce33e3adb35fda00129", + ) + + ASSET_INITRD =3D Asset( + ( + "https://archives.fedoraproject.org/pub/archive/fedora/linux/r= eleases" + "/31/Server/x86_64/os/images/pxeboot/initrd.img" + ), + "277cd6c7adf77c7e63d73bbb2cded8ef9e2d3a2f100000e92ff1f8396513cd8b", + ) + + ASSET_ALPINE_ISO =3D Asset( + ( + "https://dl-cdn.alpinelinux.org/" + "alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.is= o" + ), + "96d1b44ea1b8a5a884f193526d92edb4676054e9fa903ad2f016441a0fe13089", + ) + + def setUp(self): + super().setUp() + + init_tap() + + self.outer_ping_proc =3D None + + def tearDown(self): + del_tap() + + if self.outer_ping_proc: + self.stop_outer_ping() + + super().tearDown() + + def start_outer_ping(self) -> None: + assert self.outer_ping_proc is None + self.outer_ping_log =3D self.scratch_file("ping.log") + with open(self.outer_ping_log, "w") as f: + self.outer_ping_proc =3D subprocess.Popen( + ["ping", "-i", "0", "-O", "-D", GUEST_IP], + text=3DTrue, + stdout=3Df, + ) + + def stop_outer_ping(self) -> str: + assert self.outer_ping_proc + self.outer_ping_proc.send_signal(signal.SIGINT) + + self.outer_ping_proc.communicate(timeout=3D5) + self.outer_ping_proc =3D None + + with open(self.outer_ping_log) as f: + return f.read() + + def stop_ping_and_check(self, stop_time, resume_time): + ping_res =3D self.stop_outer_ping() + + discon, a, b =3D parse_ping_output(ping_res) + + if not discon: + text =3D f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: = {a} - {b}" + if a > stop_time or b < resume_time: + self.fail(f"PING failed: {text}") + self.log.info(f"PING: no packets lost: {text}") + return + + text =3D ( + f"STOP: {stop_time}, RESUME: {resume_time}," f"PING: disconnec= t: {a} - {b}" + ) + self.log.info(text) + eps =3D 0.01 + if a < stop_time - eps or b > resume_time + eps: + self.fail(text) + + def one_ping_from_guest(self, vm) -> None: + exec_command_and_wait_for_pattern( + self, + f"ping -c 1 -W 1 {HOST_IP}", + "1 packets transmitted, 1 packets received", + "1 packets transmitted, 0 packets received", + vm=3Dvm, + ) + self.wait_for_console_pattern("# ", vm=3Dvm) + + def one_ping_from_host(self) -> None: + run(["ping", "-c", "1", "-W", "1", GUEST_IP]) + + def setup_shared_memory(self): + shm_path =3D f"/dev/shm/qemu_test_{os.getpid()}" + + try: + with open(shm_path, "wb") as f: + f.write(b"\0" * (1024 * 1024 * 1024)) # 1GB + except Exception as e: + self.fail(f"Failed to create shared memory file: {e}") + + return shm_path + + def prepare_and_launch_vm(self, shm_path, vhost, incoming=3DFalse, vm= =3DNone): + if not vm: + vm =3D self.vm + + vm.set_console() + vm.add_args("-accel", "kvm") + vm.add_args("-device", "pcie-pci-bridge,id=3Dpci.1,bus=3Dpcie.0") + vm.add_args("-m", "1G") + + vm.add_args( + "-object", + f"memory-backend-file,id=3Dram0,size=3D1G,mem-path=3D{shm_path= },share=3Don", + ) + vm.add_args("-machine", "memory-backend=3Dram0") + + vm.add_args( + "-drive", f"file=3D{self.ASSET_ALPINE_ISO.fetch()},media=3Dcdr= om,format=3Draw" + ) + + vm.add_args("-S") + + if incoming: + vm.add_args("-incoming", "defer") + + vm_s =3D "target" if incoming else "source" + self.log.info(f"Launching {vm_s} VM") + vm.launch() + + self.set_migration_capabilities(vm) + self.add_virtio_net(vm, vhost, incoming) + + def add_virtio_net(self, vm, vhost: bool, incoming: bool =3D False): + netdev_params =3D { + "id": "netdev.1", + "vhost": vhost, + "type": "tap", + "ifname": "tap0", + "downscript": "no", + "queues": 4, + } + + if incoming: + netdev_params["local-incoming"] =3D True + else: + netdev_params["script"] =3D "no" + + 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): + capabilities =3D [ + {"capability": "events", "state": True}, + {"capability": "x-ignore-shared", "state": True}, + {"capability": "local-tap", "state": True}, + ] + vm.cmd("migrate-set-capabilities", {"capabilities": capabilities}) + + def setup_guest_network(self) -> None: + exec_command_and_wait_for_pattern(self, "ip addr", "# ") + exec_command_and_wait_for_pattern( + self, + f"ip addr add {GUEST_IP_MASK} dev eth0 && ip link set eth0 up = && echo OK", + "OK", + ) + self.wait_for_console_pattern("# ") + + def do_test_tap_fd_migration(self, vhost): + self.require_accelerator("kvm") + self.set_machine("q35") + + socket_dir =3D self.socket_dir() + migration_socket =3D os.path.join(socket_dir.name, "migration.sock= ") + + shm_path =3D self.setup_shared_memory() + + self.prepare_and_launch_vm(shm_path, vhost) + self.vm.cmd("cont") + self.wait_for_console_pattern("login:") + exec_command_and_wait_for_pattern(self, "root", "# ") + + self.setup_guest_network() + + self.one_ping_from_guest(self.vm) + self.one_ping_from_host() + self.start_outer_ping() + + # Get some successful pings before migration + time.sleep(0.5) + + target_vm =3D self.get_vm(name=3D"target") + self.prepare_and_launch_vm(shm_path, vhost, incoming=3DTrue, vm=3D= target_vm) + + target_vm.cmd("migrate-incoming", {"uri": f"unix:{migration_socket= }"}) + + self.log.info("Starting migration") + freeze_start =3D time.time() + self.vm.cmd("migrate", {"uri": f"unix:{migration_socket}"}) + + self.log.info("Waiting for migration completion") + wait_migration_finish(self.vm, target_vm) + + 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) + + +if __name__ =3D=3D "__main__": + LinuxKernelTest.main() --=20 2.48.1