Skip to content

Commit ccba9f6

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: update NAPI threaded config even for disabled NAPIs
We have to make sure that all future NAPIs will have the right threaded state when the state is configured on the device level. We chose not to have an "unset" state for threaded, and not to wipe the NAPI config clean when channels are explicitly disabled. This means the persistent config structs "exist" even when their NAPIs are not instantiated. Differently put - the NAPI persistent state lives in the net_device (ncfg == struct napi_config): ,--- [napi 0] - [napi 1] [dev] | | `--- [ncfg 0] - [ncfg 1] so say we a device with 2 queues but only 1 enabled: ,--- [napi 0] [dev] | `--- [ncfg 0] - [ncfg 1] now we set the device to threaded=1: ,---------- [napi 0 (thr:1)] [dev(thr:1)] | `---------- [ncfg 0 (thr:1)] - [ncfg 1 (thr:?)] Since [ncfg 1] was not attached to a NAPI during configuration we skipped it. If we create a NAPI for it later it will have the old setting (presumably disabled). One could argue if this is right or not "in principle", but it's definitely not how things worked before per-NAPI config.. Fixes: 2677010 ("Add support to set NAPI threaded for individual NAPI") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Joe Damato <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent bda053d commit ccba9f6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/linux/netdevice.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,8 @@ enum netdev_reg_state {
20712071
* @max_pacing_offload_horizon: max EDT offload horizon in nsec.
20722072
* @napi_config: An array of napi_config structures containing per-NAPI
20732073
* settings.
2074+
* @num_napi_configs: number of allocated NAPI config structs,
2075+
* always >= max(num_rx_queues, num_tx_queues).
20742076
* @gro_flush_timeout: timeout for GRO layer in NAPI
20752077
* @napi_defer_hard_irqs: If not zero, provides a counter that would
20762078
* allow to avoid NIC hard IRQ, on busy queues.
@@ -2482,8 +2484,9 @@ struct net_device {
24822484

24832485
u64 max_pacing_offload_horizon;
24842486
struct napi_config *napi_config;
2485-
unsigned long gro_flush_timeout;
2487+
u32 num_napi_configs;
24862488
u32 napi_defer_hard_irqs;
2489+
unsigned long gro_flush_timeout;
24872490

24882491
/**
24892492
* @up: copy of @state's IFF_UP, but safe to read with just @lock.

net/core/dev.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6999,7 +6999,7 @@ int netif_set_threaded(struct net_device *dev,
69996999
enum netdev_napi_threaded threaded)
70007000
{
70017001
struct napi_struct *napi;
7002-
int err = 0;
7002+
int i, err = 0;
70037003

70047004
netdev_assert_locked_or_invisible(dev);
70057005

@@ -7021,6 +7021,10 @@ int netif_set_threaded(struct net_device *dev,
70217021
list_for_each_entry(napi, &dev->napi_list, dev_list)
70227022
WARN_ON_ONCE(napi_set_threaded(napi, threaded));
70237023

7024+
/* Override the config for all NAPIs even if currently not listed */
7025+
for (i = 0; i < dev->num_napi_configs; i++)
7026+
dev->napi_config[i].threaded = threaded;
7027+
70247028
return err;
70257029
}
70267030

@@ -11873,6 +11877,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1187311877
goto free_all;
1187411878
dev->cfg_pending = dev->cfg;
1187511879

11880+
dev->num_napi_configs = maxqs;
1187611881
napi_config_sz = array_size(maxqs, sizeof(*dev->napi_config));
1187711882
dev->napi_config = kvzalloc(napi_config_sz, GFP_KERNEL_ACCOUNT);
1187811883
if (!dev->napi_config)

0 commit comments

Comments
 (0)