Commit 88df16f8 authored by Eric Dumazet's avatar Eric Dumazet Committed by Paolo Abeni
Browse files

net: sched: calls synchronize_net() only when needed



dev_deactivate_many() role is to remove the qdiscs
of a network device.

When/if a qdisc is dismantled, an rcu grace period
is needed to make sure all outstanding qdisc enqueue
are done before we proceed with a qdisc reset.

Most virtual devices do not have a qdisc.

We can call the expensive synchronize_net() only
if needed.

Note that dev_deactivate_many() does not have to deal
with qdisc-less dev_queue_xmit, as an old comment
was claiming.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250109171850.2871194-1-edumazet@google.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent a833fb85
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -1277,15 +1277,17 @@ static void qdisc_deactivate(struct Qdisc *qdisc)

static void dev_deactivate_queue(struct net_device *dev,
				 struct netdev_queue *dev_queue,
				 void *_qdisc_default)
				 void *_sync_needed)
{
	struct Qdisc *qdisc_default = _qdisc_default;
	bool *sync_needed = _sync_needed;
	struct Qdisc *qdisc;

	qdisc = rtnl_dereference(dev_queue->qdisc);
	if (qdisc) {
		if (qdisc->enqueue)
			*sync_needed = true;
		qdisc_deactivate(qdisc);
		rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
		rcu_assign_pointer(dev_queue->qdisc, &noop_qdisc);
	}
}

@@ -1352,23 +1354,21 @@ static bool some_qdisc_is_busy(struct net_device *dev)
 */
void dev_deactivate_many(struct list_head *head)
{
	bool sync_needed = false;
	struct net_device *dev;

	list_for_each_entry(dev, head, close_list) {
		netdev_for_each_tx_queue(dev, dev_deactivate_queue,
					 &noop_qdisc);
					 &sync_needed);
		if (dev_ingress_queue(dev))
			dev_deactivate_queue(dev, dev_ingress_queue(dev),
					     &noop_qdisc);
					     &sync_needed);

		netdev_watchdog_down(dev);
	}

	/* Wait for outstanding qdisc-less dev_queue_xmit calls or
	 * outstanding qdisc enqueuing calls.
	 * This is avoided if all devices are in dismantle phase :
	 * Caller will call synchronize_net() for us
	 */
	/* Wait for outstanding qdisc enqueuing calls. */
	if (sync_needed)
		synchronize_net();

	list_for_each_entry(dev, head, close_list) {