From patchwork Wed Dec 4 05:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13893214 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 8746517F4F6 for ; Wed, 4 Dec 2024 05:08:01 +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=1733288883; cv=none; b=AaLmSrhWUmexARziEd7gNIdF5nyARLI/oreKvePLkoV+5ldQoqmskaO/eC5ZVuCLx5yWEO4S42XHr6W0/fvVINz3VfrPn0oCJkdmLYs0S95RnscTffkmDXZcQKTfkke6cPz1z4lv3tlN0EVmdqlLnnByvkxrlt5KDnqTmqwdkq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288883; c=relaxed/simple; bh=hM3TSWI+eWAZK1GQuQ4ljeW5GtUNvTvSlHAiQfkse1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qSEgclW9gOhOnM1uErmPOfzSw2ZbuBFOkmdTq78O0btnaKLhlKBP9Q4FBLXLz7353vAFbSjUkCVu7rXESIumuSEZC8NPHayoMNL5KJduwowynlA5yHTSRE6iN0iR3h5VqPGMiTFOB8sNAUYu7PPEg/luWG5h6L8QJPKiVqsisfE= 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=I6baVxVz; 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="I6baVxVz" Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 B5BB13F851 for ; Wed, 4 Dec 2024 05:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288879; bh=rn0yafvxR+rgXFWM/3BvoQL8ErZXVisWsjUhy9aKjNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I6baVxVzaJoROpEDsE/3ey2a/MR95NEYvdS2ZbXTchMDbkaTPeXujg6bd/MDD6xav 1iZzK7EHwTXDtiuvbrujMULmu5770LJbqMfYZ6PPRbb9halC0FIR3LMDeKLH2ebqAH G2veu2XGTH+KJDCXSZd0E7eQH2swHOeDVZPQ3l1T6m/6IzimOMoxNHi4d3inziN2io Opq5CNH2FPaG2kSSUkNysJyLU0GBLlJeMZLPxx/47yehdWdJSqnKLIF6RQ1E/v+QLm O5twUyLgsf0eyDaQHbnmJnM/Dav00udrIZgh66ukhOh0iteDRZuCshyqhV+8QvSErh 6ejeoQXR147eQ== Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-7ea8c2b257bso4516103a12.1 for ; Tue, 03 Dec 2024 21:07:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288878; x=1733893678; 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=eTSFKCvINpqxjQmTIOxxxfiWPofgbRFw7YUKq4y3ZvUfQiKD7U1KpzbilKn1MLkVps zkA79RCkrJfi8bQRfcW08MTZ57hW7ocVSs1bo0pcta+HiPFJqJjvD+pCXeiWk9+GKrC1 7yfgMSdeBc4EQYNzhzdkeyzkyLLMfJpPOKcbBbDd1E/Pk+KTvpNKMK5lZyHBSZ4jC/sI aAzhskkgVMW+27iRR4FusOQCfZIKK7cwa/Zwso2pGDWOxhrw3gxizSX4YR5LznUoVByP ZgoNFwP2EiXfmE+J1dcG3IWDQkxZWyyQn6e7T2E0Z5ePdO7owFB7HSmMc7aWPA9svlZu wvMg== X-Forwarded-Encrypted: i=1; AJvYcCUOt1GsnsB9ij+h5XSvyH2PHyWVD1bo3abbGsfsNm2uz5QUrPhVh4Ac3W6U896M6kCJ3lk0qo0=@vger.kernel.org X-Gm-Message-State: AOJu0YxZMySQODDteGqjFzw/AJs3vfRpfj9Izxa9vymMrAR/q2wQKwPD dhOczk89GiKlqpciYnzR9KZgijqHVUEZP8P949Zo1Gvtw6RnGvHBVo4d9NQGfNLBkQYvLMSYG4f sxdZdr7WNQjhgLxzTbK3AnfYqmA3fBMRzWQO8sTsMrlEwcBBM977sN5hSVSRq0KdpQsy1uA== X-Gm-Gg: ASbGnct7yOekslNPeK5X9FfzHmmrDO99Fv1PCQclgRAwHawEhjwgUplS10l6BqmFO+g g8MruH2LLC5Vx8x/zHtrk6tMoJuraC9s3e3mSnwdXo88gnyd4G+B0phNwg7yXH5J48t3/OMlTHB EP/KLh78D5PUuFNXTyPnOZWD2qRbeTH6xV0RSIg88TuqiYK7QxDMFHRgiM2KCNGSR1QAwOvQYQe 2NbBUDQ1xskAl7rki6CEO2/hvQ4NxMYpEi28746dVoa6USuUDz1G7XN0GEheOkGaSFo X-Received: by 2002:a05:6a21:99a7:b0:1e0:cfc0:df34 with SMTP id adf61e73a8af0-1e1653b7b73mr7608970637.16.1733288878287; Tue, 03 Dec 2024 21:07:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEysp0HtOVqClK9sw+sZa+rGz782YX2HQNluIEnhdoS3IDFDXbm7mTKBDtu+0lCElrabYClkw== X-Received: by 2002:a05:6a21:99a7:b0:1e0:cfc0:df34 with SMTP id adf61e73a8af0-1e1653b7b73mr7608940637.16.1733288877916; Tue, 03 Dec 2024 21:07:57 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:07:57 -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 v3 1/7] virtio_net: correct netdev_tx_reset_queue() invocation point Date: Wed, 4 Dec 2024 14:07:18 +0900 Message-ID: <20241204050724.307544-2-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 --- 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 Wed Dec 4 05:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13893215 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 4D02618787F for ; Wed, 4 Dec 2024 05:08:05 +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=1733288886; cv=none; b=BhlHTeeiknJzye6wIvTXu11lvKWGF/V7zkwphNb6OX2++mJxJj6cSqnJw6iTNRY+IYNsfgW3xS4o49z4AOKWstHLXngjDwAPJyyMoDB51E8PD0g538Ni3CvPxIYv+klDkM9xPGiuo04PsKKS5zYNU15ozJXSasPpkJJdQca/u/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288886; c=relaxed/simple; bh=QyB99KR/E5dyuun3oXDM9y/WJ8QG5my98H0Do5AE/aY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RySxPXt/UPeNpXb73qgawIbEY1GRZXVFzIx7CWYpc2axCfyRGRpr58SbYDTd2wJh3na2x8G25uuAv0jPO+g+HQOp1j0KYTZZ5zMzi2wY/K5mBbrLDLdAKgiBTuYYqk4WzO7Fnu1TlNE+UmOs65LiliNlSTPZ7aXlEDRwjhoNMtI= 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=AwhOnM8K; 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="AwhOnM8K" Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (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 E33103F763 for ; Wed, 4 Dec 2024 05:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288883; bh=/pCx9eaXWcL4ixwAWHstQXvOGcUbbmljwAztWY9crP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AwhOnM8Kkfe0D69Kjh5oJnX/zXegdfKc5fWXWGPU1SOZjs/of9VZhyYHtOOi8MWOD Fpt7tO/O62qlHN73+OjwtLILC/tOQUGQ3BrE/ZCoId18nbNOnE+3np/Tv80FArDaFk 8Mgg9xcgLJ5pkDbpmX7D7nZuq11qpHGTa5zqYXGtPkbDgAeyw+wmUS4H0RajFr5Gz1 YpRXyZRpWe8yHZx3UXnPZzNwDloxgOxjDHVdbFjMRWdoPMVxjo8NGaimqPfMzxAoVB 1eyEiuLJSouqekeKJ0gcJlvrqD3UjIkht04p6kmtwKdwQz6eXhiS6t2zJSRt3Ll4OZ qctgxt8YPbRrw== Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-71d40608b16so3890255a34.1 for ; Tue, 03 Dec 2024 21:08:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288882; x=1733893682; 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=/pCx9eaXWcL4ixwAWHstQXvOGcUbbmljwAztWY9crP4=; b=PoI3h2cPiOuWArKdtuwLgddDz3fVVuh3Btx7qy5/SsKC03tfAuLPsbRMAKsYu1GD7Q 6Qe92KMCiPHylF+6O13reeQxdv8GM2k2ojZJmh9mQg9VeJSy0vqBBdnAq2Nstz3aNO6I KY1GVtnjpV9IItX9TBbGdkVlKb9VYtR9N4LJUfoUYPiZRrMxhbFsxswKvLf49nEU7K+x RK4GJ9K7KYVPBhtAQBQq/uIEn2JIKl8zJrAD5lMH9uWPonFPWS4n5V5Of8fAtl1IxYmx y9HtlhCQUXO5nQS9VHhAsGdiXptEBJ1XSl6e+tRtvBhr79qhLXSKMkLswl+I/3XSm4l9 DXcg== X-Forwarded-Encrypted: i=1; AJvYcCWUsGfbUs7sho1iRLJPOXnqytoZFKSk4ZeSpf6daWsq7fqtNgbVmI4KNTF7TF4eSM7mCjMMuY8=@vger.kernel.org X-Gm-Message-State: AOJu0YxlbxOxF+Byuje8A8selYL4a/V3c4lsOl4Qs/4oPi+oS2Q4lX/J B/b61myqMr2RUp5QGxRoR8S2esi3NgGFbs50nd4WQvEKxyAG4+K9914qmVdI2OO442tkqN98G0Q uko2PBadeTTA/pQxRBIIP9KIMv5kVmpLqNBmogWN0vphwVBQlPmIjjSoLIh31FOwRQrghEQ== X-Gm-Gg: ASbGncvEjZEv8r6FbP2e+OolPHzrLYTwHRmiRAel57iOPs/IyKXm2ZIMcO/Wwa6zgIN hHUblo1pxylPsLclkFDepW7T1+FgMCWjESuO/+kJia1ago/aG/1oZpK3iW7D2lB0lYho3OJwSTZ o4yOeow62Gi8mvbQtMUJudGJfiXkdlOG9QrZlsT8QhMDyt0YUsltrHYcZUU8+KZNxj6L2ZBdGwv boouQMruin8CcwBrzjOQOYlPXxI3aUVDtQng2mAhhQodKUlR3PYiJXm3xcztmDRqMqy X-Received: by 2002:a05:6359:5f8b:b0:1c3:38a:2143 with SMTP id e5c5f4694b2df-1caea790375mr503388355d.0.1733288882540; Tue, 03 Dec 2024 21:08:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEs3DkY/VwOKGPPt8+iJ+sQPX2t2a1HIu9jL1g2fxiv2RrXsi55RCQsiq+IatRf8oAeRlGmPQ== X-Received: by 2002:a05:6359:5f8b:b0:1c3:38a:2143 with SMTP id e5c5f4694b2df-1caea790375mr503387455d.0.1733288882234; Tue, 03 Dec 2024 21:08:02 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:01 -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 v3 2/7] virtio_net: replace vq2rxq with vq2txq where appropriate Date: Wed, 4 Dec 2024 14:07:19 +0900 Message-ID: <20241204050724.307544-3-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 While not harmful, using vq2rxq where it's always sq appears odd. Replace it with the more appropriate vq2txq for clarity and correctness. Fixes: 89f86675cb03 ("virtio_net: xsk: tx: support xmit xsk buffer") Signed-off-by: Koichiro Den --- 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 48ce8b3881b6..1b7a85e75e14 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -6213,7 +6213,7 @@ static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf) { struct virtnet_info *vi = vq->vdev->priv; struct send_queue *sq; - int i = vq2rxq(vq); + int i = vq2txq(vq); sq = &vi->sq[i]; From patchwork Wed Dec 4 05:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koichiro Den X-Patchwork-Id: 13893216 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 C4B9E155398 for ; Wed, 4 Dec 2024 05:08:09 +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=1733288891; cv=none; b=r2Qvcepr+Gqc3Vl0v/EZB2PnipyBG3fmvy69ev09aPq4ulUAwQAOGQlkOhuhvfOfxpIfRd5rupQkbJSjxSYJ6m1RTv8HzIqdkA0Mi7gBJOCBm1ckcns4KOp9HzVLleS9YmsgTzI5Ce9qD6OB8EgkmmEO6VZvaZENskUQRi+5YdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288891; c=relaxed/simple; bh=hqMbrbaYzCq+7XyNHSdUPNm5e7GvSWtAGjiRKisOUa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dK9GVK6wGSKWgC80WYjLtwMYwECu52pHEYWgGWjmiNpxT+tqbSRR+6QvOhKnJRcTP8TY4eYDG7vNfj+MnNEgoiBVSAKD/mmJTJr31LmNr63nr6eBs6iaYy/PMwpeFxGCKi4slXaXIkhqn0GtlrQkNwobGA56HH+8Mg304CFIFxg= 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=Qyu9S9mC; 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="Qyu9S9mC" Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.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 438D740CE4 for ; Wed, 4 Dec 2024 05:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288888; bh=FIgKTk0jFKfzwEEyDT2sgiCPxqET1PFOW7qhpD89ECQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qyu9S9mCnx4pcYekkU190n1p39grb+EJu7YtPUBXvKPEUShglzziXTqE2DTDMYUA0 9KQssvONmiVWaFF/Txt8pUnMeMcTVZvmxNjtl8TDpKcf4c+sryIvfqE+VewwuoFGNg I8s16N5y/sMzX4k0awSmBLtAtJuAQWIu4O5eZFsDDelJfubJtnvZIKa71pZy9KPZ4P nce9h9hGCprVU+bh6nJhkYs+sEpyLpirAGKijXectYyUN6/ld8UDyspgMy+RbgMElT DueY2B/N1dm5QYMYNhvxgXXy8HaTT0tkefBtOqCRoEdPOkdshnjs6Q9oqhzGFhmSgo DpNBwmCvKEIqw== Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-724efa5d35bso5278897b3a.3 for ; Tue, 03 Dec 2024 21:08:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288887; x=1733893687; 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=FIgKTk0jFKfzwEEyDT2sgiCPxqET1PFOW7qhpD89ECQ=; b=Pelx+H33/AT4KhdE3CXw+4QtX2c68hBNOYzdvOqq15EQw6VAMGhPffBiqHkCQnrVDb iA1rUpzTeK3IzAovb8CLojMpekbjHBYbh7DS15bhTpyWlPkiDZCpXZsI7tYG9Tze8K/6 lAJjiU4mCaDFS0ht/eB4Sz+pRR0+LJ51IhIWHXfUnMg8vFWj0+wjhcDJclo1NneO5/eg g/Zvcp9Gk1EZlzuCJgZH4fWb0GqDyrT45A3slJyVj+yl71VNKa0WPIobSs7MBPIFHsJr VEm44L6x2/purOiU80m5hlkiAmcB4K1D4uIRQw+C5Y042VqINxeY8dmslkZZfS30LzgW vDSQ== X-Forwarded-Encrypted: i=1; AJvYcCV8pT0203H7elXAirPq255bAJx4wVzYxWaK0f4pGsUaRb2UyHX++MJCJqO6N/HjhCJd1i5jqQU=@vger.kernel.org X-Gm-Message-State: AOJu0YxBjQFnB+xGkNDO3oE+oqzAXXhzTAacwByVJ6S0ltkO9a1JGo5Z N6LUOgIZCK4rREhQFa73wzfzjcevHgQjy7HNEGfZQI7zXUTYrN4SgCsdUiPGcwL+YUWHG/tLZ+0 Pr6g2VIDoR3rs6BPl+KOfPiFe33xzFt43xQxBsV+OH2BHKDqmtldAgnzrhtHWnplbT4TFkw== X-Gm-Gg: ASbGncsPENY+HmUwroHZVBQrGE8aD/Qb9lAPADSye3avQlPZq4Fhi3UAz2MERSHjTca mZI1kvMAnSA+1BDSHvdvydOGbO33jyCwyTg9DyAw7dUW3nPPpGuCsZYWebP83TVgS8IdA5H2lTm Og1VVdUTNRQ2JhH9ZOAo6EUC8icBgfvKy9UXmYH9pJ8utj54yvZClEhvPA6vtkdqc2WtYg7U1oT Qzo5p4VwOkIGJUCeqe4rIWTadT0c9+hFISHUXsD6SDtVW5bY2C9SZMNAe6NeeZ/G1ce X-Received: by 2002:a05:6a20:9149:b0:1e0:d1c3:97d1 with SMTP id adf61e73a8af0-1e16bee16efmr4965549637.29.1733288886654; Tue, 03 Dec 2024 21:08:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPKUJ5bAB237DtTojPXFWcCu5gDgXnbdRSrhZV9hCNjaygoT5Of7Xd97gtubjWTrohnL5HSg== X-Received: by 2002:a05:6a20:9149:b0:1e0:d1c3:97d1 with SMTP id adf61e73a8af0-1e16bee16efmr4965473637.29.1733288885901; Tue, 03 Dec 2024 21:08:05 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:05 -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 v3 3/7] virtio_net: introduce virtnet_sq_free_unused_buf_done() Date: Wed, 4 Dec 2024 14:07:20 +0900 Message-ID: <20241204050724.307544-4-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 This will be used in the following commits, to ensure DQL reset occurs iff. all unused buffers are actually recycled. Cc: # v6.11+ Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 1b7a85e75e14..b3cbbd8052e4 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -503,6 +503,7 @@ struct virtio_net_common_hdr { static struct virtio_net_common_hdr xsk_hdr; static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf); +static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq); static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp, struct net_device *dev, unsigned int *xdp_xmit, @@ -6233,6 +6234,14 @@ static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf) } } +static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq) +{ + struct virtnet_info *vi = vq->vdev->priv; + int i = vq2txq(vq); + + netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i)); +} + static void free_unused_bufs(struct virtnet_info *vi) { void *buf; From patchwork Wed Dec 4 05:07: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: 13893217 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 E7AEF17ADE1 for ; Wed, 4 Dec 2024 05:08:12 +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=1733288894; cv=none; b=FsbfH1Lidtlfvda8YKHh9zJqBEHx5GUjKde52rTcIyUt/n6sD43/VcT9cQU4RJnQAXFR08EhnQfgNlAJ31Erpw4b/0xhU3xBqf5Ie0ZGr1JnET6TbmIo3oGPQX8SOqzJzQwm29vNBdjHN0H6OGVs0ceVzRVGB27ZO8H5MZPhnp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288894; c=relaxed/simple; bh=2ASVmnmBrwinuHv7OjI+NZQNnMWFB6cMYc65eRQREgE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y2g8PyEkiWSTf3eaZhvR+xUQmy7+L/GnXkQ4WS7lIykduq13EP7HqfQ+5bdt6KS6lHZThyohrYp2QVAZPtRKmaziOZRf8kYbeLmxi7j+PFhEEnJHzoRpi0Mh9czTTC+pRitbukDWZxYVhLnHGuoJ98d+oBcp9dldLtlq4RQjTPk= 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=X3v5EWDA; 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="X3v5EWDA" Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.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 969203FDB1 for ; Wed, 4 Dec 2024 05:08:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288891; bh=jXyAuQfUujhNr4ebdBlKeTENPgCp2kxqJe5b1p/AGHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X3v5EWDAa0MwCpdWfDi+A14OMjFHEtYsPBMZYwZk6Z7wSHLeMiXIjUqkV3fjJtXlp WAqcouuL4a9ScOFitUbx6dLEVI8dZFv8uqiMCws4WaSqvAP4TQhEP1gvdqMU4AJIUk VOsA3RmQVAXqC56VJEqBFs/+3Ef1h4/Ju/Yb4uUlab/+Rq44tlnWzrRV3XhLRsx4Lp 1mhYrXymkWtWATfI7PgxtcqrcwkgWXW0itp0KZ8SxstwlOFsKrjJYQTbKrGOgdznrj sh7PwdbJhvzQK4uBS6VH9u3Eg0rrjlGZJfvv3SNo+w4JPIFur+As7DcQ4rgzOxGP0x ffFmjDDhWktCw== Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a7e39b48a2so57481375ab.0 for ; Tue, 03 Dec 2024 21:08:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288890; x=1733893690; 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=jXyAuQfUujhNr4ebdBlKeTENPgCp2kxqJe5b1p/AGHc=; b=lnCJ84EEqpw5smj7mrSv/3WOjhQ+JroIiZIrZHySaQysVp+JkVpOMkKJC+6uSe80aq g/rfuplXTSHFo2kCdkAK/7bFyOc2tFS/pLYl3hptfjr83EGk1koGwfLh37S+TtDM0ZNN pc+VHp4w/rbafl+cYIsuqISMbwjHIeT/zAmbBDVmqxBYF2dUTDV6IPUj0Ak6ZstHYfTV bvMne8Jcz+YEOD4+9kN8QFDAHPuFiPHbFPqYrAIpBX71nS2pzIP7Y62Z9cRzGSlWUbFH oSSph7vDod2bgIeCb5KuXcFtP7AdmL65Ukgo5qKdxmWZdWqtGuTVL3xM3a4J1Z2PAUFd gS6Q== X-Forwarded-Encrypted: i=1; AJvYcCUUTrSHH9WB6cEeGIGEDumpFroQa9q6cJ1n5g45+Y24/QBaHG5IdGQwAVsN6uId7gVQ1pV6rW4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0zLkkpBsgLGOD29ei48HGZHK+wYMR54zvpPXp+fbOKvyB7ijD 0t7D+A8RxM5QABxFpGDoKVfELO7qhbvOd+ZHVNsuUtZpUNA/p+Pj8czaM5AAyvtdefgLzV+fED0 ecuiGcK9KvqpFm5nWyXt4tmI2P5MUP7jyT1U/jcg0cpHNyd7AmVMODBSO1PWCFneRqXidOg== X-Gm-Gg: ASbGncuP2JwjZj1y/iiTDy4bzUkKumlsdZ7QQvLVrEkI23+r70kNU4CHY6y/LVH2W8O 4neTWw6iOREJQOme9HyfrsjQKEyCGdgJxTBG9cj3OWSe9Lhdxv1YPL2297MdE6aRT7IyfUjaAZF 4/zEX+FC0uZLukBbQveA59F2H8mc4CdCYKr9ykhGTW0MiORQv4HqCm0nuMswt4EzpAA1o3AUaFo q1fUJ2gqs5SzmElJSnst6oWXdHiLs9tRU3FZWhc59vD9T1q5Os5XhH85lKEDPs6/Wxe X-Received: by 2002:a05:6e02:1a0f:b0:3a7:e147:812f with SMTP id e9e14a558f8ab-3a7f9a4df8fmr55453085ab.12.1733288890459; Tue, 03 Dec 2024 21:08:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSreo3edKtytlX2/z1lj+Ztcj1hPgmrTHi1doqfmXw3O4HnfIfLBPg3ea8ZceTG86gSX4Msg== X-Received: by 2002:a05:6e02:1a0f:b0:3a7:e147:812f with SMTP id e9e14a558f8ab-3a7f9a4df8fmr55453005ab.12.1733288890200; Tue, 03 Dec 2024 21:08:10 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:09 -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 v3 4/7] virtio_ring: add a func argument 'recycle_done' to virtqueue_resize() Date: Wed, 4 Dec 2024 14:07:21 +0900 Message-ID: <20241204050724.307544-5-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 function argument 'recycle_done', which is invoked when the recycle really occurs. Cc: # v6.11+ Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 4 ++-- drivers/virtio/virtio_ring.c | 6 +++++- include/linux/virtio.h | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index b3cbbd8052e4..2a90655cfa4f 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3332,7 +3332,7 @@ static int virtnet_rx_resize(struct virtnet_info *vi, 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, NULL); if (err) netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); @@ -3395,7 +3395,7 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *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, NULL); 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..6af8cf6a619e 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 + * @recycle_done: callback to be invoked when recycle for all unused buffers done * * 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,7 +2793,8 @@ 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), + void (*recycle_done)(struct virtqueue *vq)) { struct vring_virtqueue *vq = to_vvq(_vq); int err; @@ -2809,6 +2811,8 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num, err = virtqueue_disable_and_recycle(_vq, recycle); if (err) return err; + if (recycle_done) + recycle_done(_vq); if (vq->packed_ring) err = virtqueue_resize_packed(_vq, num); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 57cc4b07fd17..0aa7df4ed5ca 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), + void (*recycle_done)(struct virtqueue *vq)); int virtqueue_reset(struct virtqueue *vq, void (*recycle)(struct virtqueue *vq, void *buf)); From patchwork Wed Dec 4 05:07: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: 13893218 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 0115F18D65F for ; Wed, 4 Dec 2024 05:08:16 +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=1733288899; cv=none; b=UIoY4JQJFaxINdsVgtijJRu4uUp1eIczmB+oyN14MYjQeUSKtR0SypGvb2V0uNYkomPTE13ufkeopIeYjpvAyB/I3YFMYAK3ggygQdc9PuXYHaMKamlVieS2UzICPhBYJRGrD9K0sev2BPDjC1xENyqFL/74B8K7vU2KYRSMdCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288899; c=relaxed/simple; bh=gLYoI15BjmtBU7oAvSpTarPfyfyGSgvB72KHD0BKUnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LjcU7dj3TJFKXHF1FsYdvuFJhmlV/cMidML4B2Vug22bz3whk2B5PF2SN/oRfNt2z6QpwelS/DOg2g8yBeOJBBwlphb2E5t8DXtx9y9svZDQ0xONozWpu43lH45xbVvTG5F8AOWGZpZs7F/obsyZ5phFjiJfQM1uTKJfcS/68VA= 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=nDC+V+XV; 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="nDC+V+XV" Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.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-1.canonical.com (Postfix) with ESMTPS id C5BCE40CD4 for ; Wed, 4 Dec 2024 05:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288895; bh=ObVc7Whi17Pu6UUwsCZaDHkuVEONGWJHt7EBpIl7aAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nDC+V+XVcAD7b1H+1pBB2uwhAywejnQ/hMRFp+/jG23uEQ8xcyCd7DNJrJB5NRwup pvzi+glCd2gAoKxP0vu813xGDVgcIFujukFGUtEpnFIZKnW7Cy0vQITQoxXgl6btHo 4Sx585rAL4o+J0zI9xb34fZHydysrUaDjQ8VywfhtJAmfOXOlLaKYo7Ynlaj6bb4el mczlFqveJECYWvEtov3SuxjDvDtmgt9NdFgRrloBTcWfYA5ey1YGTC4w5+CpsxJ+og LJps9Cvx3XxGE4mN5wyK3zv2rmUcvxGqy278oTtB0KT82YJiU8kmNmGTNBaxQdEgLA bDX+oXzAcSLOg== Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-7fcd0eff40cso2399016a12.0 for ; Tue, 03 Dec 2024 21:08:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288894; x=1733893694; 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=ObVc7Whi17Pu6UUwsCZaDHkuVEONGWJHt7EBpIl7aAs=; b=QIsu1zqdAeolmmPXzBZgwKftArRdRkkm6xpmBzojuo4i7JgZC/KlsxR18y+FbXsnyQ 6rUDnvaWVnoifS2l01lB4RfscYjBWScTvux30LejJLSpHmAwYoeaGBlPHOYLWllvev7h PfLV0RtSQbOyL42hlTFFS4Z6HitOFDUiwjbvVtd7NJSNLJL025EGCtN+sRFsYPjI/k4h 22xnBP5MU1Fzp+HLMQwOUN3Sib7/80QRV6/JHXbc68wVaJ9LOvR0Q9QWSd4DpajqoUdq ujzonTIxYyRCqBDxMWyO5r3b+tiLKUQ2R+3vAn3RcFTBeAE5Nhl1eq5RQJHfEE3rwJDd NwVA== X-Forwarded-Encrypted: i=1; AJvYcCXFb3SIb3RuSply8mM2mmGLdfXdcsIoflTU+g/ZDepCz87auBXwMtFEo31XqbhhQMU/bJtqCEY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1gBMatB/+lZppWWAD5CQ2G9tDZWggj6G5gfiPc7DPZ78DFd3R dUdVTKhqRiH6P9YToZGMQcY+Ci2k4xdYFHS8tJ+chgL3GpUYprHzzHNfIzVio+xbNXH9lUpIpd+ TUNeCfy4rV3c0QgFGQDlLu3ORCwYyFJnQ9zjx5BWXs68W6HzJatIdsaid7VGLwQ0ZO7YViA== X-Gm-Gg: ASbGncv93uPcRwgYDPcHz8eVVxxqP+exFUuRwFAkhe/op/sgcRRxVAyiDBRC4sv8LAJ NhBo1qJbhdNjC2tg9DEYT7ZhglA5Wc64kdMDIKYDO374gF8Vo95G0jvLjd66rGcyr+283sYV9Ij dOrFV/mC7y5YoFuKpLx4auq093nqOzeaKMQNZCjgrhtnpsUiHO7vmlscUHOsr5pQHW+/yStgkK3 /qHQ4VaqPPHUxrs7dMS/CtCShvJVc/yRriTLTnLWSBLk6NumVrijNma43fFG2r4Yhqo X-Received: by 2002:a05:6a20:3948:b0:1e0:c7cf:bc2d with SMTP id adf61e73a8af0-1e16bdd328amr5699739637.3.1733288894403; Tue, 03 Dec 2024 21:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj+uUlyY1C0BsWmALoxtojbbY8sLNjryjJ+hUDmswkw3F7P+vqgijj+KJpqRsQ36IWx1WReA== X-Received: by 2002:a05:6a20:3948:b0:1e0:c7cf:bc2d with SMTP id adf61e73a8af0-1e16bdd328amr5699705637.3.1733288894118; Tue, 03 Dec 2024 21:08:14 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:13 -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 v3 5/7] virtio_net: ensure netdev_tx_reset_queue is called on tx ring resize Date: Wed, 4 Dec 2024 14:07:22 +0900 Message-ID: <20241204050724.307544-6-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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, requiring DQL counters to be reset when flushing has actually occurred. Add virtnet_sq_free_unused_buf_done() as a callback for virtqueue_reset() to handle this. Fixes: c8bd1f7f3e61 ("virtio_net: add support for Byte Queue Limits") Cc: # v6.11+ Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 2a90655cfa4f..d0cf29fd8255 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3395,7 +3395,8 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq, virtnet_tx_pause(vi, sq); - err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf, NULL); + err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf, + virtnet_sq_free_unused_buf_done); if (err) netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); From patchwork Wed Dec 4 05:07: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: 13893219 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 2C8FE18FC70 for ; Wed, 4 Dec 2024 05:08:20 +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=1733288903; cv=none; b=T84uncNJxaQP+aiyO1++HFhL0tY0IaX+G7iolSpJHv2ub9QJc4nSiIz7wS7iYepHPNJCx4yZPQ/oPPYFx9D11AQ8KWQv7DSs+tvSr4spH3M1EuGJJBlO9yEbxZMw1dX2/ospLM9ym+v8SJQcirS+uYkwTMUTXYVK8S+tHaQ4M74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288903; c=relaxed/simple; bh=/hxsPKXVZNwPj0FSFmTo2DxSrpBL+nEcvnadMx1VMr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L/24ISbgyd+xQFXSr4VP3lZnZxmnjhLoaQxghpPVwOT+vdBJsaO9w94iyoS8NJzH0guQUftWHKQTzh29K3MEEAf5WR1kx5On/XwcfmUHpfA/IsurlNMl2Eu+7Uh/av3Jwvj1HlF55XQp8QoAm3OV+RkUTuAG5oSkhR9zVsv9+xs= 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=e+Z/auLe; 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="e+Z/auLe" Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (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 C4F7A3F763 for ; Wed, 4 Dec 2024 05:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288899; bh=cMQ1mn6QkKh++9sVefHm/YQARbeGOPYVwGZmbPvclzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+Z/auLe4VrP/HY06rKtp4J1/jkJ7IlDoYUNgfe9m6hcDPyfvAqUkpUh1MApIMp1x B/xbSuhQvt5tDzT2mfCU1UzZ8vWgOukWp/G3D9C31OP5jf25txTbADO0R3R67EL4H0 kgveLAt9mbzvRdFWnVOvXH+RsDakydwksvuu75NjQaZOeyoFnPyWfTwy9vCMaTnB4c dwJxaZmcxQqHEaJ9nmTnW16BrBvSVe/APU3EfiJyS6h8N7U0axEjJQCqSQ3nFisLrX XPRWdT7QVUr6ggUahYlKmAXXMix0L8WwSNDhsG1K05bJg126qBncDQYAKQ5apNe13z /ck584pR0Nkhw== Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-724e57da443so8417940b3a.1 for ; Tue, 03 Dec 2024 21:08:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288898; x=1733893698; 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=cMQ1mn6QkKh++9sVefHm/YQARbeGOPYVwGZmbPvclzE=; b=ZEICPfRexC4wPfA6rgiPVKbAsqT3z4E1HNl9RDBR9+DkMdzTQ9/Xdp5b959jXfxCCc Bm4lJ7YQhHmoPTtCi6ZykzRS8aYQsX6JUuve35uhL+SznqVxHamIctOjb3sOFjyPM5p9 Cex0Pz3NyYCmNjwsDG4w5j7Lny5tLHKjYFc4XA6Rc/Ovz8ODmqwkBo3m5Xao/8mxDOzY 6iD0ywNz2SoJ1YeW+vFZroC6KS8QWC8LdB2fIlGLw9Oh8LRUoCQXRB3FZpRQ9cFrKeDD ucaLWwnBq+w9sHOmJBU5otLOAt+vGIou42d3sVxIIhjeEpSApBxVybJBYiGUmkowo2cM rcbg== X-Forwarded-Encrypted: i=1; AJvYcCW1LieSR8jj/wM5mwPcinH1seOFsrdIMv4kFVeD94BrHrx84JaiAaP2lnp3dR+SQp09Bq3YTyw=@vger.kernel.org X-Gm-Message-State: AOJu0YyYCQBH7w7np4/it2H061CmZgLRBQ3moakLv/64+rxRqCzo9nAh rMKecMUGrJ7PApq1HdCqj6GXvC6hGCiHr2jbqinWz814wa+2PGfJgY6PS5W7MSgVI4G8L4gd7oo pSUaYyPxL/kldBzsaTMe+Sp3pmy9cVoOYhMlCIZfdcU1gFK4nnGbx5sUD+gCj5bBm8Bx4SA== X-Gm-Gg: ASbGncs6e0OwHeKEwumNx0Rg+g3M+/Rj37CYjkXFsQov8Kv4gk/+wKhHSi4SwY0MiVA eurIzftVXXEJwFD3P09Tt6JUKovgC2Y31ciw3nfuKUVzscTdODU4C+enWyz7xugL9ctvXyEJyE5 m2cHdb3Szkw9A15jCwXDD4S5heACfcrtaadwmiOQfPDxzxkGmJNMJeMMBRU9PCtxgyvFm5gjbMF p5xsWIDp3s3pzim+HmsVtqKLdfx4quD+bgLJ50Z8IgOlgmbox+hUttIpNNDAu+JeS1P X-Received: by 2002:a05:6a00:3c8a:b0:71e:5fa1:d3e4 with SMTP id d2e1a72fcca58-7257fa45248mr6730704b3a.2.1733288898387; Tue, 03 Dec 2024 21:08:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzK4BK1oktH3ckDZBRjHOokufY6SEBLhJ5DJ7e1vYZicOqoakq+cqHgepP7ZCNIOpN0Nx7ew== X-Received: by 2002:a05:6a00:3c8a:b0:71e:5fa1:d3e4 with SMTP id d2e1a72fcca58-7257fa45248mr6730677b3a.2.1733288898066; Tue, 03 Dec 2024 21:08:18 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:17 -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 v3 6/7] virtio_ring: add a func argument 'recycle_done' to virtqueue_reset() Date: Wed, 4 Dec 2024 14:07:23 +0900 Message-ID: <20241204050724.307544-7-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 function argument 'recycle_done', which is invoked when it really occurs. Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 4 ++-- drivers/virtio/virtio_ring.c | 6 +++++- include/linux/virtio.h | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index d0cf29fd8255..5eaa7a2884d5 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -5711,7 +5711,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, NULL); if (err) { netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err); @@ -5740,7 +5740,7 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi, 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, NULL); 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 6af8cf6a619e..fdd2d2b07b5a 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2827,6 +2827,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 + * @recycle_done: callback to be invoked when recycle for all unused buffers done * * Caller must ensure we don't call this with other virtqueue operations * at the same time (except where noted). @@ -2838,7 +2839,8 @@ 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), + void (*recycle_done)(struct virtqueue *vq)) { struct vring_virtqueue *vq = to_vvq(_vq); int err; @@ -2846,6 +2848,8 @@ int virtqueue_reset(struct virtqueue *_vq, err = virtqueue_disable_and_recycle(_vq, recycle); if (err) return err; + if (recycle_done) + recycle_done(_vq); if (vq->packed_ring) virtqueue_reinit_packed(vq); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 0aa7df4ed5ca..dd88682e27e3 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), void (*recycle_done)(struct virtqueue *vq)); int virtqueue_reset(struct virtqueue *vq, - void (*recycle)(struct virtqueue *vq, void *buf)); + void (*recycle)(struct virtqueue *vq, void *buf), + void (*recycle_done)(struct virtqueue *vq)); struct virtio_admin_cmd { __le16 opcode; From patchwork Wed Dec 4 05:07: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: 13893220 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 5867818FDC8 for ; Wed, 4 Dec 2024 05:08:25 +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=1733288906; cv=none; b=olCceRm3lxFpptMyAVbOPiaGAmhZTX82limsTtFdMKL0hQjC1IAs5QyJ4s5u1ytMoprr7hSf40/rnaXpm5zAw6h+jVCMhEHdjc04SCnxTL/06MKq8GJom47rXpdUT5A/mUfZdLcYk7qWuVdNWwK/LhmzPuXHsphX46iHNtVz6L8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733288906; c=relaxed/simple; bh=pJkC/sg81thrf+L+DBV2A5EohoZuMx0x87sK8yW3WmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwC+wmJq5KkG7a0RNjo8a8I87rXt0iwZX9YtdYueYj49zG73/jNNsOuI6DU9NqhqtsS9Hz7TGTnWwKXE7ttowHI1CuourtoCzRUYL9GKnqX8m2UfED/MXycX1Dz2Tmh0YLjeHsl5LZp0KFfcl7Ed1GiTnG6O301CFnDAmZ4m9QY= 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=b6Pa6F09; 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="b6Pa6F09" Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.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 D3E0A3F28B for ; Wed, 4 Dec 2024 05:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1733288903; bh=9uM+qY4J1GQbqjmyDa0r1OVtoI70UH7O4H6kctiyohw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b6Pa6F09cluQnkUQzZZx8ma8BaEhBbv1cHN9CcKbEGyopffc+i2SxVLgYqh4nDv22 clW7iuq46Nikl8Ce4EPLhaocWinp0p5rYB00pFjtdKWd75iF6TG3z4qVogEtinG5VM NSQ1ozqVz6B5PYF6zBMG0VMjXStwklZR8N7HnEcRoWRKwVbCjE1UOzVGcOwmFBxnog wQKS1rXwfLB5aoJB29At79iY2lZiwMyCeO9Oq3seqTRXaLAits1ks4RTQPHigf/s27 dW0jE0UOxkP0Nxx7DKbxVh1YW3JeWaLHtJpjT2vLEdBy2oBwB1XDxvSXu1/g1o0Ty9 2NBT4i1duioiw== Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-7fc99b41679so5616037a12.3 for ; Tue, 03 Dec 2024 21:08:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733288902; x=1733893702; 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=9uM+qY4J1GQbqjmyDa0r1OVtoI70UH7O4H6kctiyohw=; b=DzCDS17eAGXefNNmDLEWoUpxrnyKO8Wa65vujSRVzkoQBGbBeiH1PD0KnZGg/B/JW6 bAdBpbxAzpCXd8unKIsJz97Dx+CB+E0JScEqMCHVZSNfEvLAb0hb9EGRqGqpUumbh5CC vINJU5Jw1vYFmhC4lCPE39Mh1jl6MWQnckyIW/gPZm37WoziyrTlZEQpy1SfdW/zbl9A nwMX0bYGnQAgO0anPY9G/aGZ5oJJTMtloi366odhEPOptCQVSZi1wK0CAMRRFc70jIh7 oDk5z2gb6nlbfBB2/K37x5l206IIc/yvE1C7+sR4e/ZsO9rLEvxuhfvSu5isJrOZFj2e kbNg== X-Forwarded-Encrypted: i=1; AJvYcCVFzWyN81B0hP3lyYQy94w8Ap+fHuDglnAXFGvwMdaVuwySGT6Sit8Ah85d43O4G8RW1umgEBU=@vger.kernel.org X-Gm-Message-State: AOJu0YwxQnihYZCpIfq4+Kmq0lkhf2u12J0lZb638Rz5hqQZneqxciEj nyjkKrwNkYpywXus745jjz6FItCr0rxS5dMZwXkJuyKRPebjy2c3XkreYhn8F0cqQnjNPqa/euI Yzj5Yau2FS9v3DpjSg9kXIqTNdt3d7fDnCcG6m58NejmWSfFRLPlGR1LAe+RsJysWZPwHEw== X-Gm-Gg: ASbGncug0h7bmpVu73pm6GeqrugNaLifWiQi5ZuJmRCf87TSPo4NM/yRun3K4BSSz8/ oERdc71Fru8dK4p2kXtJu4l12MjSlSQ60DGzfFJGn4RbwtUfgGtL/7UNdRE28WCxB+IwYAjqX70 qn7iaz5jilu2k+63y9Q42+OskCqMmH4/z/rwv4S5er5WHUibdVL6wMlk3eX8scMHr1kPVIbruNP 5uiZKEEpIIV1G2YE6Brd324dws3yD0HsWVtRSxUP1Z/C7uhbiUpiaPZIn5Fw9W4L7hy X-Received: by 2002:a05:6a20:9144:b0:1e0:d796:b079 with SMTP id adf61e73a8af0-1e1653bb99dmr8288073637.17.1733288902454; Tue, 03 Dec 2024 21:08:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtD8y79hadaHZvvNeugnEdk8crgadqfqLkx2GLITOJPtd6W8UtDItN+uiyqRlDo7jPSUc/FA== X-Received: by 2002:a05:6a20:9144:b0:1e0:d796:b079 with SMTP id adf61e73a8af0-1e1653bb99dmr8288032637.17.1733288902122; Tue, 03 Dec 2024 21:08:22 -0800 (PST) Received: from localhost.localdomain ([240f:74:7be:1:9c88:3d14:cbea:e537]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd0a0682d6sm145466a12.10.2024.12.03.21.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 21:08:21 -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 v3 7/7] virtio_net: ensure netdev_tx_reset_queue is called on bind xsk for tx Date: Wed, 4 Dec 2024 14:07:24 +0900 Message-ID: <20241204050724.307544-8-koichiro.den@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204050724.307544-1-koichiro.den@canonical.com> References: <20241204050724.307544-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 when flushing has actually occurred, Add virtnet_sq_free_unused_buf_done() as a callback for virtqueue_resize() to handle this. Fixes: 21a4e3ce6dc7 ("virtio_net: xsk: bind/unbind xsk for tx") Signed-off-by: Koichiro Den --- drivers/net/virtio_net.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 5eaa7a2884d5..177705a56812 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -5740,7 +5740,8 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi, virtnet_tx_pause(vi, sq); - err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, NULL); + err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, + virtnet_sq_free_unused_buf_done); if (err) { netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err); pool = NULL;