[PATCH net-next 0/2] net: track the queue count at unregistration

STALE1774d LANDED

Landed in mainline as 28a0a044fbe9 on 2021-12-09.

4 messages, 2 authors, 2021-12-09 · open the first message on its own page

[PATCH net-next 0/2] net: track the queue count at unregistration

From: Antoine Tenart <atenart@kernel.org>
Date: 2021-12-07 14:57:34

Hello,

Those two patches allow to track the Rx and Tx queue count at
unregistration and help in detecting illegal addition of Tx queues after
unregister (a warning is added).

This follows discussions on the following thread,
https://lore.kernel.org/all/20211122162007.303623-1-atenart@kernel.org/T/

A patch fixing one issue linked to this was merged ealier,
https://lore.kernel.org/all/20211203101318.435618-1-atenart@kernel.org/T/

Thanks,
Antoine

Antoine Tenart (2):
  net-sysfs: update the queue counts in the unregistration path
  net-sysfs: warn if new queue objects are being created during device
    unregistration

 net/core/net-sysfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

-- 
2.33.1

[PATCH net-next 1/2] net-sysfs: update the queue counts in the unregistration path

From: Antoine Tenart <atenart@kernel.org>
Date: 2021-12-07 14:57:36

When updating Rx and Tx queue kobjects, the queue count should always be
updated to match the queue kobjects count. This was not done in the net
device unregistration path, fix it. Tracking all queue count updates
will allow in a following up patch to detect illegal updates.

Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 net/core/net-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 3b2cdbbdc858..33f408c24205 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1808,6 +1808,9 @@ static void remove_queue_kobjects(struct net_device *dev)
 
 	net_rx_queue_update_kobjects(dev, real_rx, 0);
 	netdev_queue_update_kobjects(dev, real_tx, 0);
+
+	dev->real_num_rx_queues = 0;
+	dev->real_num_tx_queues = 0;
 #ifdef CONFIG_SYSFS
 	kset_unregister(dev->queues_kset);
 #endif
-- 
2.33.1

[PATCH net-next 2/2] net-sysfs: warn if new queue objects are being created during device unregistration

From: Antoine Tenart <atenart@kernel.org>
Date: 2021-12-07 14:57:38

Calling netdev_queue_update_kobjects is allowed during device
unregistration since commit 5c56580b74e5 ("net: Adjust TX queue kobjects
if number of queues changes during unregister"). But this is solely to
allow queue unregistrations. Any path attempting to add new queues after
a device started its unregistration should be fixed.

This patch adds a warning to detect such illegal use.

Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 net/core/net-sysfs.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 33f408c24205..53ea262ecafd 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1694,6 +1694,13 @@ netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
 	int i;
 	int error = 0;
 
+	/* Tx queue kobjects are allowed to be updated when a device is being
+	 * unregistered, but solely to remove queues from qdiscs. Any path
+	 * adding queues should be fixed.
+	 */
+	WARN(dev->reg_state == NETREG_UNREGISTERING && new_num > old_num,
+	     "New queues can't be registered after device unregistration.");
+
 	for (i = old_num; i < new_num; i++) {
 		error = netdev_queue_add_kobject(dev, i);
 		if (error) {
-- 
2.33.1

Re: [PATCH net-next 0/2] net: track the queue count at unregistration

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-12-09 02:50:15

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski [off-list ref]:

On Tue,  7 Dec 2021 15:57:23 +0100 you wrote:
Hello,

Those two patches allow to track the Rx and Tx queue count at
unregistration and help in detecting illegal addition of Tx queues after
unregister (a warning is added).

This follows discussions on the following thread,
https://lore.kernel.org/all/20211122162007.303623-1-atenart@kernel.org/T/

[...]
Here is the summary with links:
  - [net-next,1/2] net-sysfs: update the queue counts in the unregistration path
    https://git.kernel.org/netdev/net-next/c/d7dac083414e
  - [net-next,2/2] net-sysfs: warn if new queue objects are being created during device unregistration
    https://git.kernel.org/netdev/net-next/c/5f1c802ca69b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help