Skip to content

Commit cc61d20

Browse files
committed
net-shapers: implement shaper cleanup on queue deletion
JIRA: https://issues.redhat.com/browse/RHEL-89973 commit ff7d4de Author: Paolo Abeni <pabeni@redhat.com> Date: Wed Oct 9 10:09:53 2024 +0200 net-shapers: implement shaper cleanup on queue deletion hook into netif_set_real_num_tx_queues() to cleanup any shaper configured on top of the to-be-destroyed TX queues. Reviewed-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Link: https://patch.msgid.link/6da4ee03cae2b2a757d7b59e88baf09cc94c5ef1.1728460186.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
1 parent 6bfcdf1 commit cc61d20

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

net/core/dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,8 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
30063006
if (dev->num_tc)
30073007
netif_setup_tc(dev, txq);
30083008

3009+
net_shaper_set_real_num_tx_queues(dev, txq);
3010+
30093011
dev_qdisc_change_real_num_tx(dev, txq);
30103012

30113013
dev->real_num_tx_queues = txq;

net/core/dev.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ int dev_addr_init(struct net_device *dev);
4141

4242
#if IS_ENABLED(CONFIG_NET_SHAPER)
4343
void net_shaper_flush_netdev(struct net_device *dev);
44+
void net_shaper_set_real_num_tx_queues(struct net_device *dev,
45+
unsigned int txq);
4446
#else
4547
static inline void net_shaper_flush_netdev(struct net_device *dev) {}
48+
static inline void net_shaper_set_real_num_tx_queues(struct net_device *dev,
49+
unsigned int txq) {}
4650
#endif
4751

4852
/* sysctls not referred to from outside net/core/ */

net/shaper/shaper.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,54 @@ void net_shaper_flush_netdev(struct net_device *dev)
11571157
net_shaper_flush(&binding);
11581158
}
11591159

1160+
void net_shaper_set_real_num_tx_queues(struct net_device *dev,
1161+
unsigned int txq)
1162+
{
1163+
struct net_shaper_hierarchy *hierarchy;
1164+
struct net_shaper_binding binding;
1165+
int i;
1166+
1167+
binding.type = NET_SHAPER_BINDING_TYPE_NETDEV;
1168+
binding.netdev = dev;
1169+
hierarchy = net_shaper_hierarchy(&binding);
1170+
if (!hierarchy)
1171+
return;
1172+
1173+
/* Only drivers implementing shapers support ensure
1174+
* the lock is acquired in advance.
1175+
*/
1176+
lockdep_assert_held(&dev->lock);
1177+
1178+
/* Take action only when decreasing the tx queue number. */
1179+
for (i = txq; i < dev->real_num_tx_queues; ++i) {
1180+
struct net_shaper_handle handle, parent_handle;
1181+
struct net_shaper *shaper;
1182+
u32 index;
1183+
1184+
handle.scope = NET_SHAPER_SCOPE_QUEUE;
1185+
handle.id = i;
1186+
shaper = net_shaper_lookup(&binding, &handle);
1187+
if (!shaper)
1188+
continue;
1189+
1190+
/* Don't touch the H/W for the queue shaper, the drivers already
1191+
* deleted the queue and related resources.
1192+
*/
1193+
parent_handle = shaper->parent;
1194+
index = net_shaper_handle_to_index(&handle);
1195+
xa_erase(&hierarchy->shapers, index);
1196+
kfree_rcu(shaper, rcu);
1197+
1198+
/* The recursion on parent does the full job. */
1199+
if (parent_handle.scope != NET_SHAPER_SCOPE_NODE)
1200+
continue;
1201+
1202+
shaper = net_shaper_lookup(&binding, &parent_handle);
1203+
if (shaper && !--shaper->leaves)
1204+
__net_shaper_delete(&binding, shaper, NULL);
1205+
}
1206+
}
1207+
11601208
static int __init shaper_init(void)
11611209
{
11621210
return genl_register_family(&net_shaper_nl_family);

0 commit comments

Comments
 (0)