From nobody Fri Dec 19 22:06:03 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1753597461477349.94757726226896; Sat, 26 Jul 2025 23:24:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ufunS-0007Bh-3Q; Sun, 27 Jul 2025 02:23:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ufun0-0006vi-50; Sun, 27 Jul 2025 02:23:20 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ufumv-0006eR-P2; Sun, 27 Jul 2025 02:23:17 -0400 Received: from h205.csg.ci.i.u-tokyo.ac.jp (h205.csg.ci.i.u-tokyo.ac.jp [133.11.54.205]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 56R6Ml3s093507 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 27 Jul 2025 15:22:54 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=Akdb0YA3jwzUaEHtZ7YvqK6+migMLbF4VDzJ6CtcXI0=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Date:Subject:Message-Id:To; s=rs20250326; t=1753597374; v=1; b=PR4nWHnn+dOnW0hrKyhD6P5aXYAbmzEeKQFIyM4scb8zRrhizr3knYy5+EgJYd3F aah7CIs/VMSoX5ZW/S0fDMicPGZgAabSEkq7m4oMyHkck/2hWpziyGu98mMHovfb 2vXr6wuPJWI+8sObSZZg/IDfAhbU9vfOwxpd4QojRFlZ1gcammG7Ui/+3Tmm5I4u CgZbWGAGzRXd2q/XPXQlqvVmsr1pNalJgD5v03PcrqyvLLkjgLpibluZXGpODXo8 22Ll81t02Q+ZWpCXK2QjUh3e2Wk1cDvh7PLI7rt6fjILwroh/r2p+hjeoUK6swQZ GXbpG2i7lGhRhPB7567vwQ== From: Akihiko Odaki Date: Sun, 27 Jul 2025 15:22:36 +0900 Subject: [PATCH v3] virtio-net: Fix VLAN filter table reset timing MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250727-vlan-v3-1-bbee738619b1@rsg.ci.i.u-tokyo.ac.jp> X-B4-Tracking: v=1; b=H4sIAKvFhWgC/3XMSwrCMBSF4a1IxiY0j74cuQ9xcJuk7VVpSlKDp XTvpsWBCA7/w+FbSLAebSCnw0K8jRjQDSnk8UB0D0NnKZrURGQiz0ouaXzAQCvNsxKKHEzNSbq O3rb42pnLNXWPYXJ+3tXIt/UHiJxyClK3WaNbKJQ6+9AxjQzZk07uPjsGmt1GsmlRfAvqI4gkC JNXdQPKaCP/Cuu6vgEiBzpQ5wAAAA== X-Change-ID: 20250713-vlan-8c107a65ad91 To: Konstantin Shkolnyy , qemu-devel@nongnu.org Cc: yin31149@gmail.com, eperezma@redhat.com, mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux.dev, qemu-stable@nongnu.org, Akihiko Odaki , Lei Yang X-Mailer: b4 0.14.2 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=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1753597464896116600 Problem Reported-by: Konstantin Shkolnyy Tested-by: Konstantin Shkolnyy Tested-by: Lei Yang ------- The expected initial state of the table depends on feature negotiation: With VIRTIO_NET_F_CTRL_VLAN: The table must be empty in accordance with the specification. Without VIRTIO_NET_F_CTRL_VLAN: The table must be filled to permit all VLAN traffic. Prior to commit 06b636a1e2ad ("virtio-net: do not reset vlan filtering at set_features"), virtio_net_set_features() always reset the VLAN table. That commit changed the behavior to skip table reset when VIRTIO_NET_F_CTRL_VLAN was negotiated, assuming the table would be properly cleared during device reset and remain stable. However, this assumption breaks when a driver renegotiates features: 1. Initial negotiation without VIRTIO_NET_F_CTRL_VLAN (table filled) 2. Renegotiation with VIRTIO_NET_F_CTRL_VLAN (table will not be cleared) The problem was exacerbated by commit 0caed25cd171 ("virtio: Call set_features during reset"), which triggered virtio_net_set_features() during device reset, exposing the bug whenever VIRTIO_NET_F_CTRL_VLAN was negotiated after a device reset. Solution -------- Fix the issue by initializing the table when virtio_net_set_features() is called to change the VIRTIO_NET_F_CTRL_VLAN bit of vdev->guest_features. This approach ensures the correct table state regardless of feature negotiation sequence by performing initialization in virtio_net_set_features() as QEMU did prior to commit 06b636a1e2ad ("virtio-net: do not reset vlan filtering at set_features"). This change still preserves the goal of the commit, which was to avoid resetting the table during migration, by checking whether the VIRTIO_NET_F_CTRL_VLAN bit of vdev->guest_features is being changed; vdev->guest_features is set before virtio_net_set_features() gets called during migration. It also avoids resetting the table when the driver sets a feature bitmask with no change for the VIRTIO_NET_F_CTRL_VLAN bit, which makes the operation idempotent and its semantics cleaner. Additionally, this change ensures the table is initialized after feature negotiation and before the DRIVER_OK status bit being set for compatibility with the Linux driver before commit 50c0ada627f5 ("virtio-net: fix race between ndo_open() and virtio_device_ready()"), which did not ensure to set the DRIVER_OK status bit before modifying the table. Fixes: 06b636a1e2ad ("virtio-net: do not reset vlan filtering at set_featur= es") Cc: qemu-stable@nongnu.org Reported-by: Konstantin Shkolnyy Signed-off-by: Akihiko Odaki Tested-by: Konstantin Shkolnyy Tested-by: Lei Yang --- Not tested. Konstantin, I would also want you to test this new version. Please also give it Tested-by, and, if possible, Reviewed-by. --- Changes in v3: - Dropped RFC. - Rebased. - Link to v2: https://lore.kernel.org/qemu-devel/20250714-vlan-v2-1-2d589ba= 4dcd3@rsg.ci.i.u-tokyo.ac.jp Changes in v2: - Addressed a concern with old drivers that do not properly set DRIVER_OK (pointed out by Michael S. Tsirkin). - Noted that this change does not simply revert commit 06b636a1e2ad ("virtio-net: do not reset vlan filtering at set_features") but preserves its goal. - Added Cc: qemu-stable@nongnu.org. - Link to v1: https://lore.kernel.org/qemu-devel/20250713-vlan-v1-1-a3cf0bc= fa644@rsg.ci.i.u-tokyo.ac.jp --- hw/net/virtio-net.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c4c49b0f9caa1e8f26fa2e03acc8786936877eba..6b5b5dace334af12e9b77a8a276= 5c88443cee235 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -929,8 +929,9 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) vhost_net_save_acked_features(nc->peer); } =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) { - memset(n->vlans, 0xff, MAX_VLAN >> 3); + if (virtio_has_feature(vdev->guest_features ^ features, VIRTIO_NET_F_C= TRL_VLAN)) { + bool vlan =3D virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN); + memset(n->vlans, vlan ? 0 : 0xff, MAX_VLAN >> 3); } =20 if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { @@ -3942,6 +3943,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) n->mac_table.macs =3D g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); =20 n->vlans =3D g_malloc0(MAX_VLAN >> 3); + memset(n->vlans, 0xff, MAX_VLAN >> 3); =20 nc =3D qemu_get_queue(n->nic); nc->rxfilter_notify_enabled =3D 1; @@ -4041,7 +4043,6 @@ static void virtio_net_reset(VirtIODevice *vdev) memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac)); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); - memset(n->vlans, 0, MAX_VLAN >> 3); =20 /* Flush any async TX */ for (i =3D 0; i < n->max_queue_pairs; i++) { --- base-commit: 9e601684dc24a521bb1d23215a63e5c6e79ea0bb change-id: 20250713-vlan-8c107a65ad91 Best regards, --=20 Akihiko Odaki