From patchwork Tue Dec 3 07:30:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13891811 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 954B918595B for ; Tue, 3 Dec 2024 07:30:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211061; cv=none; b=VozdZqgcsQLv5tdxf9uh2zreK51N0+Yr3vcE8g+QC8LkPYIVEZhmnRkEGuALtpVGxXS+E3V8NDKtImbQP8cavzf2v/zsvTFW9jY5zP7SK4Hq3xe6bdeFQPkGhfsFE9YcAP2Kjks/Hkfo210HqBejGZpv6/0yCPs8M1jOE2UkzbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211061; c=relaxed/simple; bh=hM3TSWI+eWAZK1GQuQ4ljeW5GtUNvTvSlHAiQfkse1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ct+Ag3+NGCwj9qVdUKsDQuzCkewzZ8d1wUoFI+dSQnTVNX09qV6YJpqVCIVhgbP0E0s06n5LCV63nXgbe/OgKbnY7/C8tGaSoceq0oKX74qWS8KwLPHmSfTFvGi6yiYaHZEc0o9FIw9wJpHSYwqvrZnHlvNkrtlDC3fi9mEn2PU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=eLylPdfC; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="eLylPdfC" Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id EF8C83FD49 for ; Tue, 3 Dec 2024 07:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733211057; bh=rn0yafvxR+rgXFWM/3BvoQL8ErZXVisWsjUhy9aKjNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eLylPdfCPhiV1N1U4BnwTPiks3Cahm9jHCg1BNTld7pk2v7yIb05L14xihxGssrMH sY4agVdUgDdmrcGL6BsR/X/DeZKkpJSFs+v9ffK+wNPdujR/7u27Etp0K+UWNJx72P XxHYQZTDbk13EIE5b6JnY2ZX2HBNOlwGhV7RZG/ZFCwfK9l4q38Hv3p/3/BUXYDg8B QGRdPnVVHS41Errntq0xGbOfw1JidVoUxsFLeefo84tfeMVHyn9WT0d1yXATe/cEr+ 8flhVRaK6Dfcw7vqrJsXGbU+obNRtOfyMV4WmnL1Go1CQ2UU8xfuKJTrafH04PVuFY ttnTpb5IFEFdw== Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2153861c470so37432895ad.2 for ; Mon, 02 Dec 2024 23:30:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733211056; x=1733815856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rn0yafvxR+rgXFWM/3BvoQL8ErZXVisWsjUhy9aKjNw=; b=RY2V2X5JEBhVvDuDnZNVtll9cHcaLlB53MZhWgMH+4zGFcMs4R3Wj1GOHFujtI0rDF honkkQvoKsk+mSRVqBa/xNV+Gd1fT/4KGhxwEXJm8MEQbFyuXXhUUSDxLpl8zbUJC/cl EtLlR+SuxSraIYKO+37AoJq15XRqiteob7NB1GmUGOxV9oi/qDuGDXDiNqs2/9DFG2xc h+UXuRcudXIqHp4A8AmONPgyS8kRTWTRsRC+7Hrb/QQSzIc/+QsS/ws5yV/J41XW9cOx 7LkqzDU871JzvYJX7c7w735VHCvX7TGVbhBcl6KRUrPexZoAJcXX0phP/Dsg3VQbWt2Y WkMw== X-Forwarded-Encrypted: i=1; AJvYcCUBBZmtgUnbOTWyh/0srFJiHEeFjGi53yGWAHCnw9gWi/AuporqzUZoMLrBQiPSDmtLmmophS8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz15/BiWYgzeadCOocaSmbJn+fK8AL0Pu+itqp+G/VZdX+dBFXu 9vAj7lvPA6M9Z6meFn5RFxYWsP23hNlDI0fgMH/AdG+dNRJc8oBBwpdeRDlat0aWEKebczLWZSj TqsR00odulskVD+4jF5dTpJ0I3n/xzMGy9gchuyD3zvtj52Ov/kGMRty75QbWPvsvsDYlGw== X-Gm-Gg: ASbGnctxqUkmLIC3zK7un0JDPExR8/H38KFvV2finJ594loQADsKXtDM4IdgRKty5eJ ePtJcZw0mU/G1reW7sDCsF8k3EMeQQfsP5sB+jTyxcahF9VEJ/VDM3fGn1ZdYO3XyH46Uwngnc8 kQtAfBA4SuOPCh3nXMhpDkVBRJflzy8/BpTKX+2bwwK6Cn8aeS8hP1EP3b2Np+Sh9FnulsURwCY nix7TQPYGhbWoE6hSARd2u4szfcom5fzGdYIMfI9Xhe9Ryg99b9HZT1TaSgNC1l7NSj X-Received: by 2002:a17:903:191:b0:215:7cd2:1132 with SMTP id d9443c01a7336-215bd0e7d81mr19717715ad.29.1733211056443; Mon, 02 Dec 2024 23:30:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7gi3gIAf+lQKauh1LZNO6nUm9eJREawvVeJIpAEFisTXFFb5l8sD9JG8LDx7etuoxazJyYg== X-Received: by 2002:a17:903:191:b0:215:7cd2:1132 with SMTP id d9443c01a7336-215bd0e7d81mr19717435ad.29.1733211056018; Mon, 02 Dec 2024 23:30:56 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:b2b6:e8c2:50d0:c558]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21586d40afasm35735165ad.270.2024.12.02.23.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 23:30:55 -0800 (PST) From: Koichiro Den To: virtualization@lists.linux.dev Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net-next v2 1/5] virtio_net: correct netdev_tx_reset_queue() invocation point Date: Tue, 3 Dec 2024 16:30:21 +0900 Message-ID: <20241203073025.67065-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203073025.67065-1-koichiro.den@canonical.com> References: <20241203073025.67065-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When virtnet_close is followed by virtnet_open, some TX completions can possibly remain unconsumed, until they are finally processed during the first NAPI poll after the netdev_tx_reset_queue(), resulting in a crash [1]. Commit b96ed2c97c79 ("virtio_net: move netdev_tx_reset_queue() call before RX napi enable") was not sufficient to eliminate all BQL crash cases for virtio-net. This issue can be reproduced with the latest net-next master by running: `while :; do ip l set DEV down; ip l set DEV up; done` under heavy network TX load from inside the machine. netdev_tx_reset_queue() can actually be dropped from virtnet_open path; the device is not stopped in any case. For BQL core part, it's just like traffic nearly ceases to exist for some period. For stall detector added to BQL, even if virtnet_close could somehow lead to some TX completions delayed for long, followed by virtnet_open, we can just take it as stall as mentioned in commit 6025b9135f7a ("net: dqs: add NIC stall detector based on BQL"). Note also that users can still reset stall_max via sysfs. So, drop netdev_tx_reset_queue() from virtnet_enable_queue_pair(). This eliminates the BQL crashes. Note that netdev_tx_reset_queue() is now explicitly required in freeze/restore path, so this patch adds it to free_unused_bufs(). [1]: ------------[ cut here ]------------ kernel BUG at lib/dynamic_queue_limits.c:99! Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 7 UID: 0 PID: 1598 Comm: ip Tainted: G N 6.12.0net-next_main+ #2 Tainted: [N]=TEST Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), \ BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 RIP: 0010:dql_completed+0x26b/0x290 Code: b7 c2 49 89 e9 44 89 da 89 c6 4c 89 d7 e8 ed 17 47 00 58 65 ff 0d 4d 27 90 7e 0f 85 fd fe ff ff e8 ea 53 8d ff e9 f3 fe ff ff <0f> 0b 01 d2 44 89 d1 29 d1 ba 00 00 00 00 0f 48 ca e9 28 ff ff ff RSP: 0018:ffffc900002b0d08 EFLAGS: 00010297 RAX: 0000000000000000 RBX: ffff888102398c80 RCX: 0000000080190009 RDX: 0000000000000000 RSI: 000000000000006a RDI: 0000000000000000 RBP: ffff888102398c00 R08: 0000000000000000 R09: 0000000000000000 R10: 00000000000000ca R11: 0000000000015681 R12: 0000000000000001 R13: ffffc900002b0d68 R14: ffff88811115e000 R15: ffff8881107aca40 FS: 00007f41ded69500(0000) GS:ffff888667dc0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000556ccc2dc1a0 CR3: 0000000104fd8003 CR4: 0000000000772ef0 PKRU: 55555554 Call Trace: ? die+0x32/0x80 ? do_trap+0xd9/0x100 ? dql_completed+0x26b/0x290 ? dql_completed+0x26b/0x290 ? do_error_trap+0x6d/0xb0 ? dql_completed+0x26b/0x290 ? exc_invalid_op+0x4c/0x60 ? dql_completed+0x26b/0x290 ? asm_exc_invalid_op+0x16/0x20 ? dql_completed+0x26b/0x290 __free_old_xmit+0xff/0x170 [virtio_net] free_old_xmit+0x54/0xc0 [virtio_net] virtnet_poll+0xf4/0xe30 [virtio_net] ? __update_load_avg_cfs_rq+0x264/0x2d0 ? update_curr+0x35/0x260 ? reweight_entity+0x1be/0x260 __napi_poll.constprop.0+0x28/0x1c0 net_rx_action+0x329/0x420 ? enqueue_hrtimer+0x35/0x90 ? trace_hardirqs_on+0x1d/0x80 ? kvm_sched_clock_read+0xd/0x20 ? sched_clock+0xc/0x30 ? kvm_sched_clock_read+0xd/0x20 ? sched_clock+0xc/0x30 ? sched_clock_cpu+0xd/0x1a0 handle_softirqs+0x138/0x3e0 do_softirq.part.0+0x89/0xc0 __local_bh_enable_ip+0xa7/0xb0 virtnet_open+0xc8/0x310 [virtio_net] __dev_open+0xfa/0x1b0 __dev_change_flags+0x1de/0x250 dev_change_flags+0x22/0x60 do_setlink.isra.0+0x2df/0x10b0 ? rtnetlink_rcv_msg+0x34f/0x3f0 ? netlink_rcv_skb+0x54/0x100 ? netlink_unicast+0x23e/0x390 ? netlink_sendmsg+0x21e/0x490 ? ____sys_sendmsg+0x31b/0x350 ? avc_has_perm_noaudit+0x67/0xf0 ? cred_has_capability.isra.0+0x75/0x110 ? __nla_validate_parse+0x5f/0xee0 ? __pfx___probestub_irq_enable+0x3/0x10 ? __create_object+0x5e/0x90 ? security_capable+0x3b/0x70 rtnl_newlink+0x784/0xaf0 ? avc_has_perm_noaudit+0x67/0xf0 ? cred_has_capability.isra.0+0x75/0x110 ? stack_depot_save_flags+0x24/0x6d0 ? __pfx_rtnl_newlink+0x10/0x10 rtnetlink_rcv_msg+0x34f/0x3f0 ? do_syscall_64+0x6c/0x180 ? entry_SYSCALL_64_after_hwframe+0x76/0x7e ? __pfx_rtnetlink_rcv_msg+0x10/0x10 netlink_rcv_skb+0x54/0x100 netlink_unicast+0x23e/0x390 netlink_sendmsg+0x21e/0x490 ____sys_sendmsg+0x31b/0x350 ? copy_msghdr_from_user+0x6d/0xa0 ___sys_sendmsg+0x86/0xd0 ? __pte_offset_map+0x17/0x160 ? preempt_count_add+0x69/0xa0 ? __call_rcu_common.constprop.0+0x147/0x610 ? preempt_count_add+0x69/0xa0 ? preempt_count_add+0x69/0xa0 ? _raw_spin_trylock+0x13/0x60 ? trace_hardirqs_on+0x1d/0x80 __sys_sendmsg+0x66/0xc0 do_syscall_64+0x6c/0x180 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f41defe5b34 Code: 15 e1 12 0f 00 f7 d8 64 89 02 b8 ff ff ff ff eb bf 0f 1f 44 00 00 f3 0f 1e fa 80 3d 35 95 0f 00 00 74 13 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 4c c3 0f 1f 00 55 48 89 e5 48 83 ec 20 89 55 RSP: 002b:00007ffe5336ecc8 EFLAGS: 00000202 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f41defe5b34 RDX: 0000000000000000 RSI: 00007ffe5336ed30 RDI: 0000000000000003 RBP: 00007ffe5336eda0 R08: 0000000000000010 R09: 0000000000000001 R10: 00007ffe5336f6f9 R11: 0000000000000202 R12: 0000000000000003 R13: 0000000067452259 R14: 0000556ccc28b040 R15: 0000000000000000 [...] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]--- Fixes: c8bd1f7f3e61 ("virtio_net: add support for Byte Queue Limits") Cc: # v6.11+ Signed-off-by: Koichiro Den Acked-by: Jason Wang --- drivers/net/virtio_net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 64c87bb48a41..48ce8b3881b6 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3054,7 +3054,6 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) if (err < 0) goto err_xdp_reg_mem_model; - netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, qp_index)); virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); @@ -6243,6 +6242,7 @@ static void free_unused_bufs(struct virtnet_info *vi) struct virtqueue *vq = vi->sq[i].vq; while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) virtnet_sq_free_unused_buf(vq, buf); + netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i)); cond_resched(); } From patchwork Tue Dec 3 07:30:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13891812 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFF671AC42C for ; Tue, 3 Dec 2024 07:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211065; cv=none; b=FDMN6Rxl6WV6nnLlS+uAkDRnXwqlnG9QBCYIgwLSP8FfaouQLSDRX2TNSOoscsq5Qxhlam0nEm1fLnAfqS752JUeWUv1GxJ6rCuR4Yr1BkjYEcW9IwWOI7SB2ujHOUmjblmOtXZynCXgW5Fhh3cQEF3hz+kY/ZWcrlHO99wwNfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211065; c=relaxed/simple; bh=w5AGnCRzxvkv5uIQocaLa71YmtI6LxwVdo9vgigsjyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D9R7UK3WOfKE5THzMzk30tQRJ8EfNvcda7WJ9VYfoitqQMeUzquvviPv4BypCBU+P+jbia020I8KqokiAl5ibBtc/6uXFX/GYvM6erh067S6cgMoGWAy6E5JdmmWWxPsArWGjHL6qWyfqRJbLaQV+EcvnCAz+MfyTuX96mMLPTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=QoSkUbSG; arc=none smtp.client-ip=185.125.188.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="QoSkUbSG" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 724E53F626 for ; Tue, 3 Dec 2024 07:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733211061; bh=fW9S3ivOx/vCR/Vpb6zGlhQWyPtyKwj/7WKI3Nel5z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QoSkUbSG4sn0AdiFfXD0l9vSJzLdEnz5weCkV+IhLUyhySqlIuzFD9x6EXuCkjbot iHMhpGpaAPjBwZaHOWgjclclDBJwNRzPUCwpgpBXc4Asgx5EtSIB0LiRQDKVHCnBMz CQVvJSizHFDNLR2ZTZYm91IsB3qnXgctPZj2Um3lMYtX8LfMb8G8TANLPcSULUArfs j9j04/CLmUniB3i2jwufIFiVszieQjX6E0TMa4XN5PKcV2sehraAS4H01/OmYV024c ExB14VxSSb+dl8lIsF5yhwMmckM7foLzaxAN+1hI3ns7X37VwmGJXmrFnjpCLygK5c 8oxitsmza5UwA== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-215576aca41so23173515ad.0 for ; Mon, 02 Dec 2024 23:31:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733211060; x=1733815860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fW9S3ivOx/vCR/Vpb6zGlhQWyPtyKwj/7WKI3Nel5z4=; b=b8kycLe+J12KlC+IBsqv4RMUrAuJTfu3UvRnxbLPNvRdskAWreWNjw83l0XpKQLe8e 7ybp9HyfwsMoySUy9Vvq2m1B/3Kp/cjjM+6unGesv3eoLtI3hIbwjc0hojDHzqriSRPd nRMUH7JtQMkDpEm8luhEsMReWqrCTEfspjLfMtdhLTnL8JoUfv/HYWeHF4yVVcXw5XDx 96fd0Oeacr649XQiOC8OKjofMGTtKSU/Fbv76RD/1h1hhE6tcikDcsXwFHpiszZgYXVk +uT0DQyrvop2QexeH4GJJQe51W8IE4v1zxkuJFp0xIpuVzhqkGRchcSPf1GgxIdEVVQ6 mhUQ== X-Forwarded-Encrypted: i=1; AJvYcCWD6dRl5qMhUfJu2iYd1ZgVBozi6V2pyMrOhXc9W7w2QR9LRNeY60Xql7noRh3CkWMh/2/qVIQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8BgoB4ckVQUubulqRbVtTc8U7yxAVxr/vo5lXaDszd9MSvZbA W318jnkNWM0RRRs9953A4MNaYi8vSU9e0ogqNVWA/Jl+nns2op8789RLS4sGhV6IzNQ86Rj36gl X0TiFipOCj30m+IoaxhbHmW4+clPIZ0nL+m4NjtlJcyl2TbA9B8GAsgcvs/Qv9TcftCszfQ== X-Gm-Gg: ASbGncvuMBUBmlt4hGjw/W5mHeJgrbOFRu8ey20257o6VZWzKNknt+VXMlh29p9Tqcs /9LFV2vGpIcvulsNzLFe4Q5tNwlCbA6nf8mzK1GkRXgSkfRyQbWIyASAq+8DOxnM1RSxRv1/4gX G8bLGYyapjuNCs88S+itF/xx8CmaM8ddzRIhOaHZ3YWaYdyOXSKpWiOKpFurvkFuriOnWJ8Ygry AugTOIVIJh6vO9KWd57ss9f1GL7Z9lVTvwpMikMywQIlxCmpoj7clPzlG+3Ou3jnsjY X-Received: by 2002:a17:902:cec7:b0:215:a3e4:d26b with SMTP id d9443c01a7336-215a3e4dc89mr79434775ad.0.1733211060066; Mon, 02 Dec 2024 23:31:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwtFDsd1WSbUlFVtINv5gpljD9oqMcZ9HvNspEp3AWCkY/mGPNDUp8oHCemJTryvY2p/FvlA== X-Received: by 2002:a17:902:cec7:b0:215:a3e4:d26b with SMTP id d9443c01a7336-215a3e4dc89mr79434565ad.0.1733211059765; Mon, 02 Dec 2024 23:30:59 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:b2b6:e8c2:50d0:c558]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21586d40afasm35735165ad.270.2024.12.02.23.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 23:30:59 -0800 (PST) From: Koichiro Den To: virtualization@lists.linux.dev Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net-next v2 2/5] virtio_ring: add 'flushed' as an argument to virtqueue_resize() Date: Tue, 3 Dec 2024 16:30:22 +0900 Message-ID: <20241203073025.67065-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203073025.67065-1-koichiro.den@canonical.com> References: <20241203073025.67065-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When virtqueue_resize() has actually recycled all unused buffers, additional work may be required in some cases. Relying solely on its return status is fragile, so introduce a new argument 'flushed' to explicitly indicate whether it has really occurred. Signed-off-by: Koichiro Den Acked-by: Jason Wang --- drivers/net/virtio_net.c | 6 ++++-- drivers/virtio/virtio_ring.c | 7 ++++++- include/linux/virtio.h | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 48ce8b3881b6..df9bfe31aa6d 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3326,12 +3326,13 @@ static int virtnet_rx_resize(struct virtnet_info *vi, struct receive_queue *rq, u32 ring_num) { int err, qindex; + bool flushed; qindex = rq - vi->rq; virtnet_rx_pause(vi, rq); - err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf); + err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf, &flushed); if (err) netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); @@ -3389,12 +3390,13 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq, u32 ring_num) { int qindex, err; + bool flushed; qindex = sq - vi->sq; virtnet_tx_pause(vi, sq); - err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf); + err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf, &flushed); if (err) netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 82a7d2cbc704..34a068d401ec 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2772,6 +2772,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma); * @_vq: the struct virtqueue we're talking about. * @num: new ring num * @recycle: callback to recycle unused buffers + * @flushed: whether or not unused buffers are all flushed * * When it is really necessary to create a new vring, it will set the current vq * into the reset state. Then call the passed callback to recycle the buffer @@ -2792,11 +2793,14 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma); * */ int virtqueue_resize(struct virtqueue *_vq, u32 num, - void (*recycle)(struct virtqueue *vq, void *buf)) + void (*recycle)(struct virtqueue *vq, void *buf), + bool *flushed) { struct vring_virtqueue *vq = to_vvq(_vq); int err; + *flushed = false; + if (num > vq->vq.num_max) return -E2BIG; @@ -2809,6 +2813,7 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, err = virtqueue_disable_and_recycle(_vq, recycle); if (err) return err; + *flushed = true; if (vq->packed_ring) err = virtqueue_resize_packed(_vq, num); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 57cc4b07fd17..878feda08af9 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -109,7 +109,8 @@ dma_addr_t virtqueue_get_avail_addr(const struct virtqueue *vq); dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq); int virtqueue_resize(struct virtqueue *vq, u32 num, - void (*recycle)(struct virtqueue *vq, void *buf)); + void (*recycle)(struct virtqueue *vq, void *buf), + bool *flushed); int virtqueue_reset(struct virtqueue *vq, void (*recycle)(struct virtqueue *vq, void *buf)); From patchwork Tue Dec 3 07:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13891813 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CB2F1B85EB for ; Tue, 3 Dec 2024 07:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211068; cv=none; b=oN2QLdQ0JuRZIbj4OEk8eVlwqhAm3ZXF/5A2UgwrMJVAXmrUvhEweSgJFN1fFl9szOoWVBlhgwtKtAXqPcrOinmZcO1nczpR8l+t8Bfp3EHDKgvDhTUqHeKFDXI3ZhhTUartAdwfhY0SJ/KQ4xgIHx2SiOboBenVBE7+/A6deUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211068; c=relaxed/simple; bh=ONGQeGV/Lo+dvZaz/MxmBnTpy+k0yha3gjPk1y+HOIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dwFfo9Hj8+PTWK/qskzIPO4vH2n+Je2GlQx+rwQW7IIetVEFVMcWuoyyVq8+/mWCEpwr6Hu+0Tdij42YkOdZrk47vjksJDpHu28yQAq+iIs4cEO0z2BozaUQ3kAbx0YkTZ/u6cs7jf0z7nlEy5Rjqz7lMRe9qNVZNLgE9ZtuU7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=og5pTrpR; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="og5pTrpR" Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id F3A443FD8B for ; Tue, 3 Dec 2024 07:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733211065; bh=5NLMnu2Z46KkDgOBwjL355ay2S58qzCZBNzBIFOkdbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=og5pTrpRvLJr0XSW2GAPqyptSvzFiPq9P25nRwiD6RklmYc4qDy4rvVU9T3KAfj/x Kof18ZoRu2x9ict/CHI2zJFFgFlnisNZJDC5EBmFIvzAp3IyH/I6AnGj6wQFPR8q1w zbXemcHYEdDkJS1yXV2fTgikPPjukJndYPlIPy866fkR8/bemteoziajT0nGS1brC+ Ih4il8+C72+0fyb+YPTyc5qnsfMHHI4OkkyFX3QeTY3HbQ1wShBkEjDA58NiYyloHw ng8xxkWAkYp3nJ7RNl8RLA7S/ixHNBID+0F0F7RXLwqWJMomQZt58oZk2zSkT7n41Y fhH5R9zpnNlbA== Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-21567f825d2so25688965ad.3 for ; Mon, 02 Dec 2024 23:31:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733211063; x=1733815863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5NLMnu2Z46KkDgOBwjL355ay2S58qzCZBNzBIFOkdbw=; b=CNBy5h8Y68vO7WMeTKmpybPGeJ39vu9vfi1o/njGlezDlzLESXmGfYhoRpmKLwBAr4 5QSae56UbErI+6m4IGY0YUD7sidnb7Dxl3n1X8vQ/qk79J5qD41IZaAiFJ6kQ1+iCzFf LCjXiryL3/WKVkerhm7TMtd8CkXDYPS+oJ8ssjEK9zpkoWMVDG596qWYHItuiBcYYXak 5zFPn/G19OzSWAzUd6sqZkQVEdag95/R73Pze3wdr/SJIqax+sI/xduiUHkjdP8fo06J 7m/Fnjl3WfbnVaWyPHDnq+Sy0VZg629KN3gw7XntQf/+ppJeGoguBLUhDuHmCFYFRRlD 2rhA== X-Forwarded-Encrypted: i=1; AJvYcCU4ukNGaXPuA3OYJg8S2iPVGkHfxsegO1FVICexL0uDYQAGiYjr+T1qSpzq9EnWjkI6w63PqP0=@vger.kernel.org X-Gm-Message-State: AOJu0YwxgGLD0QrfGwdZqqA3FrVbhNoqqb+47JiLsSoMI15AH3tUFgwl Y1wJeMpuH/1dhVFC7uIpYwjMCMMWyWLGGtRFdE58vxW3asPC3c+0rtLt3UHJHAfGAQ5n0d4ihtu cYcDWxulgvcAEfL1aMXiqpCQU5cs4m2rL24eyU8+HYSLbD2IpQhfDpwcdIyKSylcq81+lPQ== X-Gm-Gg: ASbGnctKR8MjPHPk07TKtqdn27FuzIUNXSrueR15CX4yP3PDqFiC9tB6RJRsJFP0gJm uMNswVKh13TrHsB5gEk8o/9VplR8L8UDuLD9evO6P/v1WqBBiEstzp8Nl9fY3Kbs1mmaUEC0f/s 3UQ96ag9J0HT3fmU3DC3m2D36bKmJgHcLwYxMHi46/HtQf9E6orCLBMJku7meEMsgKhOT5Peej0 +l/DNlAHVk9Z/jqnvtgMJKTxSwP3KPfD7gN2c4TLN91Rm7UmvhSKKMDKRTO4kyJTGp2 X-Received: by 2002:a17:903:32cc:b0:215:6e07:e0c9 with SMTP id d9443c01a7336-215bd25580bmr20893655ad.53.1733211063422; Mon, 02 Dec 2024 23:31:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEeKLM2ys5e0Q3udqn6af/fNUMQYdUmFkZT/mCzd4RS2FR0h2mYZFsi+zEkr90jaY94M2UwGw== X-Received: by 2002:a17:903:32cc:b0:215:6e07:e0c9 with SMTP id d9443c01a7336-215bd25580bmr20893465ad.53.1733211063136; Mon, 02 Dec 2024 23:31:03 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:b2b6:e8c2:50d0:c558]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21586d40afasm35735165ad.270.2024.12.02.23.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 23:31:02 -0800 (PST) From: Koichiro Den To: virtualization@lists.linux.dev Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net-next v2 3/5] virtio_net: add missing netdev_tx_reset_queue() to virtnet_tx_resize() Date: Tue, 3 Dec 2024 16:30:23 +0900 Message-ID: <20241203073025.67065-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203073025.67065-1-koichiro.den@canonical.com> References: <20241203073025.67065-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org virtnet_tx_resize() flushes remaining tx skbs, so DQL counters need to be reset. Fixes: c8bd1f7f3e61 ("virtio_net: add support for Byte Queue Limits") Cc: # v6.11+ Signed-off-by: Koichiro Den Acked-by: Jason Wang --- drivers/net/virtio_net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index df9bfe31aa6d..0103d7990e44 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3399,6 +3399,8 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq, err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf, &flushed); if (err) netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); + if (flushed) + netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, qindex)); virtnet_tx_resume(vi, sq); From patchwork Tue Dec 3 07:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13891814 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52D001D5AC0 for ; Tue, 3 Dec 2024 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211071; cv=none; b=F/Wrpe3/n5OT8bcAUmEY6YcGeM9auNVQdntyEUed3z7maqL1xBMmUkARAUyCTRW8K1VvNCflgKLTVW16S9ZzyeQSTiR4vDj12Y0HdEpY8zTv4LAcmBX4/Mf2VIdyzezHBFVIy9YfGTRwri3LvAXRpE07I4K1F+/H0ed0oDEpXOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211071; c=relaxed/simple; bh=B35FJqtVrA6/g3cRJDtf6i8TWPwah/QahNofj7yw7FU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tIj1V2JZSuRwkfB8HjtOnY+I1VkH5FWcs9yL2fOdLPZoYRW4gV88kTWz848FvMZ/oB+mq149/toT2RfpC8PRIQTwSwggF5vR3OwZyDj3E9PFUACMLd3ZjVhy/akMUoGKVLtwOIkDdzSeol8dLZArtMRJffk3GroJZ0reH50M0g8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=LKpRDxmZ; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="LKpRDxmZ" Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 78B543FD49 for ; Tue, 3 Dec 2024 07:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733211068; bh=0tIoR4M/e1hC8XWEPJavp463x0u2oxmCDdWZ8pN4UWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LKpRDxmZRdRR+v13SSCn6JGZ2d/jh0meD7tb5qxZtwWBP8TX39Hi2RMvdSPIerkDq eU9epCYO46m5JaKvRktGXooROdY+o2ukLXNSQYO/F8294xVruHxUotb8PpUjseYv+/ azkjBbBKVv1emvQRnH+xYOQzvZx/Qey0auKjDplpXwjjJ6d9ac6UkeHCAbrulYW+6Q lluCdy/HCT8YfXWwV4rN2u1rwRPxK1jIOjnrUoom8hbYDRXVVClswsiI7yI6D4l3gA NkiUnEys5eh2T1cloHRdz1cPuqboVTZMP5tpIkA31MVSFNKkHBuNFFTTYdl0bLrdbN NhI6jbJJ+UNQw== Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2157b83f656so29821595ad.0 for ; Mon, 02 Dec 2024 23:31:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733211067; x=1733815867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0tIoR4M/e1hC8XWEPJavp463x0u2oxmCDdWZ8pN4UWM=; b=I+wWH9RUG6YkBSyevvKQutVuqKXqKxPhipdsk4HdR28erJe97Os1gCU+Pb+UVsBMfN iSKmDOOCllnlatrFXJeCY7OJAPuVPSTgYJTgGCKYTz0FYveDO6/Ld4zrAMaFEeF5oUmq d2KzLio71m0m1d0m4U4B/15vh/R54QIH6fjwuQ0TCYmB/hoWZRo1RuR3JoJOlVDIkxxH gse/bxsWGjA0U1iBYXuRMpYdFKSq1xCWynQ67tI192I6D0o45ZJD/vekhnFlip2NSxmL 6dQ0hMvRLrys132ouM3Sf3DnDucEVIgKcySkQssFnrFc9F3t/0iQWHiPDcHSQDdry9Mv F97Q== X-Forwarded-Encrypted: i=1; AJvYcCVztm1SmSEUsKi8pzUqmPFRvcOJ6igyRx9xNJTrRCsfgWqKCDqrpGMwHDcrCWvGbOXgD1PkIrM=@vger.kernel.org X-Gm-Message-State: AOJu0YysafCAq4i5bVdxEHKkv+t04RRFNDqF055+5QF84BhYGiN82nKz PEgQsEdQPrvvbt2mjcedztVGprTHngmLVV5YP1Qz3lefQ0CyLafr2ooys3LctrNSmUzo7dY9gMr 9PDfMBb+rXDS2s3JMs493+DfX1IJEVrj3PiXbNxciG5lN18719FjNpbzhbYEe5LZuyo331g== X-Gm-Gg: ASbGnctyWVjgHcHs6J3My+WzUyuGZlYcuq+pEdA08Gk5KCTkPgD40FzuBNUOkxLV/Wx dil3BtZ1e4cSjHfp332fRDTonaRjAqqy62c2s/cUMJJK6ZapjHX2FyWOVHYvaDCZO3Fr3lqOBvl lI4gZZ98u1wJh/MIZzvn0cG83MieZ9lOJyDIRjSfbaM9jcccw/NT82iEQXSiYn9IUGSfOKvXRsL 81GpTbNvikaGR1tKgzSWe27gjCLzpjua/Q9mCITuj7hhvoF1DkrO/86Uqrs2Ycirlq8 X-Received: by 2002:a17:902:c945:b0:215:a57e:88e7 with SMTP id d9443c01a7336-215bd1b46b0mr13127565ad.3.1733211067089; Mon, 02 Dec 2024 23:31:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHP4XjzXdT7YSH9p2iSEiXeF4vQERCA9UmM9iKOMdbRsv+ACtukLlabl71vKcQSJKNxhflm3g== X-Received: by 2002:a17:902:c945:b0:215:a57e:88e7 with SMTP id d9443c01a7336-215bd1b46b0mr13127345ad.3.1733211066776; Mon, 02 Dec 2024 23:31:06 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:b2b6:e8c2:50d0:c558]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21586d40afasm35735165ad.270.2024.12.02.23.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 23:31:06 -0800 (PST) From: Koichiro Den To: virtualization@lists.linux.dev Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net-next v2 4/5] virtio_ring: add 'flushed' as an argument to virtqueue_reset() Date: Tue, 3 Dec 2024 16:30:24 +0900 Message-ID: <20241203073025.67065-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203073025.67065-1-koichiro.den@canonical.com> References: <20241203073025.67065-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When virtqueue_reset() has actually recycled all unused buffers, additional work may be required in some cases. Relying solely on its return status is fragile, so introduce a new argument 'flushed' to explicitly indicate whether it has really occurred. Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 6 ++++-- drivers/virtio/virtio_ring.c | 6 +++++- include/linux/virtio.h | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0103d7990e44..d5240a03b7d6 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -5695,6 +5695,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu struct xsk_buff_pool *pool) { int err, qindex; + bool flushed; qindex = rq - vi->rq; @@ -5713,7 +5714,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu virtnet_rx_pause(vi, rq); - err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf); + err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf, &flushed); if (err) { netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err); @@ -5737,12 +5738,13 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi, struct xsk_buff_pool *pool) { int err, qindex; + bool flushed; qindex = sq - vi->sq; virtnet_tx_pause(vi, sq); - err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf); + err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, &flushed); if (err) { netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err); pool = NULL; diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 34a068d401ec..b522ef798946 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2828,6 +2828,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize); * virtqueue_reset - detach and recycle all unused buffers * @_vq: the struct virtqueue we're talking about. * @recycle: callback to recycle unused buffers + * @flushed: whether or not unused buffers are all flushed * * Caller must ensure we don't call this with other virtqueue operations * at the same time (except where noted). @@ -2839,14 +2840,17 @@ EXPORT_SYMBOL_GPL(virtqueue_resize); * -EPERM: Operation not permitted */ int virtqueue_reset(struct virtqueue *_vq, - void (*recycle)(struct virtqueue *vq, void *buf)) + void (*recycle)(struct virtqueue *vq, void *buf), + bool *flushed) { struct vring_virtqueue *vq = to_vvq(_vq); int err; + *flushed = false; err = virtqueue_disable_and_recycle(_vq, recycle); if (err) return err; + *flushed = true; if (vq->packed_ring) virtqueue_reinit_packed(vq); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 878feda08af9..e5072d64a364 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -112,7 +112,8 @@ int virtqueue_resize(struct virtqueue *vq, u32 num, void (*recycle)(struct virtqueue *vq, void *buf), bool *flushed); int virtqueue_reset(struct virtqueue *vq, - void (*recycle)(struct virtqueue *vq, void *buf)); + void (*recycle)(struct virtqueue *vq, void *buf), + bool *flushed); struct virtio_admin_cmd { __le16 opcode; From patchwork Tue Dec 3 07:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13891815 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8986019CC3A for ; Tue, 3 Dec 2024 07:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211077; cv=none; b=JeFxPg4Nrbilj0UWaj3uUw4bURoa5WUSGOmiDVd3ROEhaliMoyKeBvIRR6xwlJb1U7Nawwm/+SFbABDUB7eY5t/Wy3j57x8+62jvBSSeo9L/hjtRznj9tNodvtZLSglWE2W2mZd3Lv0E2ZGuB36+O44eQ6LFE1DwVBY9nCwwUBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733211077; c=relaxed/simple; bh=Hk5ke9nzypkJaxk8bCoKEHSofdwMIA0X2l10CVp/tS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h8/ZyxvIppFPKDw65aqwrHRc1OdYa9Gkn2UD701aw3RoViJlEMvEdlpsRRuG6LzRgT01vfeucvm2O10doytKWL//ODBRTWY+F14+JFTEjRnDEbSaCWvwuBYDiC9SxIhS/SbuSDe1yVGQNdYkP81ARsXE8q+AY+Jo9qcCPxw8r7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=C3Xzh+5c; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="C3Xzh+5c" Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 351AA3F84C for ; Tue, 3 Dec 2024 07:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733211073; bh=pP1rcV8yFT6KeAKHqqLHhUue0tX/F8YDnxUvKh8M2mo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C3Xzh+5cpzLeAi6lG7ybJMSWsp5dzoQkCzf849O+aduNhIk2dM5EFSvI3fSumTC6D I7+Ym/Z9xKubRQbT5hGSgzVvOVTndqqbh+CpnOSu2R8f/V0O9o+E5+kNhoC4vjXm9N k5WeYn5iYmOZzN72l50Lz4fDwyb637xf1RlQoD5nPcXLn1NpnSHTzC6nRzaoWeBVBw mF2we6PCvdR0nJAUoK3Hy3cKYQohxIssz8vz7MXqxHxFuoTpcUewN24z1iq7hd31Bx aLUmfMd0kFDPZ8GwqjNtuivX6InY7VyBdbyQxQEh4jXItSo5XSOsT+4k+Ck8baJsyl K/BPuc+yzf9pA== Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-7250863ae6dso5077904b3a.0 for ; Mon, 02 Dec 2024 23:31:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733211071; x=1733815871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pP1rcV8yFT6KeAKHqqLHhUue0tX/F8YDnxUvKh8M2mo=; b=mgT9yoh6Xwy1s77FYJYoOcWnldUjvkbB8UZsKNXKUOE4ZSS8diUOByJgdMdp7FBRRr 0UvchHdj9oiU25CMKZt367YRhTJCOvUTjcxO+SukjvBQBV/ycGNOo/rFj0tF4k+8GZQZ VElPI5xqvZ2G0q4avDzY4t2c3AFBfJfPRpYm20lrYh5c7BQwi8Hd2pNA2J88SXQilmI/ 5j3nE4DLHB5JHB1g+fWPRCogEPEMoM0v93Yq34vFu/bJexuuebI8lyqVK7DQcHkLUhce odkpxpJFMAQcgQTyM4eyTF072tnakQRsJyj4xNTPga3L87D3hvlQAMx7mVLodtW/erY2 Ov/A== X-Forwarded-Encrypted: i=1; AJvYcCUtOCW1OqbjnH2kBMqgUAVaxUT0f7raunLb7f6lMQtrnHwcpO73zxrueUgu1y1T0ysWwMB4GRk=@vger.kernel.org X-Gm-Message-State: AOJu0YwC09MfN7Miuh+nhWRTc/YvNuOwxMwyMpU+BnZOA0PJ1vpqFBbL 1pEeMHfPP7ctaaxgkLMnfRtQ9zlaEEtEX8q0nhk/vAEuVe5Fx6cyfFAahRCISRm+OFBFKJv2UoX BVjaOr0O+qWpYl78Iy9gMyZzjXFe2nbcBJfyRVysyThP6jDxYw+r50SDQ7xLhRNluhetIhQ== X-Gm-Gg: ASbGncuZdH7NI8DSlPG7vZHF8jRhkNGDxo9MWiPOYmmpPgzjoPc/qT0z8TPEmZ99Opk Rlz6rwpsRetxd4/sGtKdmcNjq/TUMh+0IlXeuvFk1hoborZtGut5B5JrEXN5lc9ydcGHWQy5WJK mIpZ2nGfVg4hs74t0V2VlJ408duMI3dS4/w5lJDVBY4vA95YMGnaxzsUZY6uitpC1xAVhayFTDM 2upHKQLUtZq60uNUmedJZz8dCk2ZJGp1ChXoTBySrwN4Ryh2R5Ys84CFI34G5ol7d1s X-Received: by 2002:a17:902:e88b:b0:215:6816:6333 with SMTP id d9443c01a7336-215bd1c4a4cmr18393885ad.15.1733211070592; Mon, 02 Dec 2024 23:31:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEND0UzhbAQRYul9CwlhlE8NsG8OZop+RaB8RyNyzhSiQjfU17kWK9qXqZeOdr2+snjte5ZcQ== X-Received: by 2002:a17:902:e88b:b0:215:6816:6333 with SMTP id d9443c01a7336-215bd1c4a4cmr18393625ad.15.1733211070289; Mon, 02 Dec 2024 23:31:10 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:b2b6:e8c2:50d0:c558]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21586d40afasm35735165ad.270.2024.12.02.23.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 23:31:10 -0800 (PST) From: Koichiro Den To: virtualization@lists.linux.dev Cc: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net-next v2 5/5] virtio_net: add missing netdev_tx_reset_queue to virtnet_sq_bind_xsk_pool() Date: Tue, 3 Dec 2024 16:30:25 +0900 Message-ID: <20241203073025.67065-6-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203073025.67065-1-koichiro.den@canonical.com> References: <20241203073025.67065-1-koichiro.den@canonical.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org virtnet_sq_bind_xsk_pool() flushes tx skbs and then resets tx queue, so DQL counters need to be reset. Fixes: 21a4e3ce6dc7 ("virtio_net: xsk: bind/unbind xsk for tx") Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index d5240a03b7d6..27d58fb47b07 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -5749,6 +5749,8 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi, netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err); pool = NULL; } + if (flushed) + netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, qindex)); sq->xsk_pool = pool;