netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Abhinav Jain <jain.abhinav177@gmail.com>
To: mst@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
	eperezma@redhat.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com,
	virtualization@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com,
	jain.abhinav177@gmail.com
Subject: [PATCH] virtio_net: Eliminate OOO packets during switching
Date: Fri, 14 Jun 2024 22:04:22 +0000	[thread overview]
Message-ID: <20240614220422.42733-1-jain.abhinav177@gmail.com> (raw)

Disable the network device & turn off carrier before modifying the
number of queue pairs.
Process all the in-flight packets and then turn on carrier, followed
by waking up all the queues on the network device.

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 drivers/net/virtio_net.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 61a57d134544..d0a655a3b4c6 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -3447,7 +3447,6 @@ static void virtnet_get_drvinfo(struct net_device *dev,
 
 }
 
-/* TODO: Eliminate OOO packets during switching */
 static int virtnet_set_channels(struct net_device *dev,
 				struct ethtool_channels *channels)
 {
@@ -3471,6 +3470,15 @@ static int virtnet_set_channels(struct net_device *dev,
 	if (vi->rq[0].xdp_prog)
 		return -EINVAL;
 
+	/* Disable network device to prevent packet processing during
+	 * the switch.
+	 */
+	netif_tx_disable(dev);
+	netif_carrier_off(dev);
+
+	/* Make certain that all in-flight packets are processed. */
+	synchronize_net();
+
 	cpus_read_lock();
 	err = virtnet_set_queues(vi, queue_pairs);
 	if (err) {
@@ -3482,7 +3490,12 @@ static int virtnet_set_channels(struct net_device *dev,
 
 	netif_set_real_num_tx_queues(dev, queue_pairs);
 	netif_set_real_num_rx_queues(dev, queue_pairs);
- err:
+
+	/* Restart the network device */
+	netif_carrier_on(dev);
+	netif_tx_wake_all_queues(dev);
+
+err:
 	return err;
 }
 
-- 
2.34.1


             reply	other threads:[~2024-06-14 22:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 22:04 Abhinav Jain [this message]
2024-06-17  1:51 ` [PATCH] virtio_net: Eliminate OOO packets during switching Jason Wang
2024-06-17 13:25 ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614220422.42733-1-jain.abhinav177@gmail.com \
    --to=jain.abhinav177@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=skhan@linuxfoundation.org \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).