net: embed num_tc in the xps maps
authorAntoine Tenart <atenart@kernel.org>
Thu, 18 Mar 2021 18:37:43 +0000 (19:37 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 18 Mar 2021 21:56:22 +0000 (14:56 -0700)
commit255c04a87f4381849fce9ed81e5efabf78a71a30
tree702d869692566f7ba3bfde4907d51f0f78921e5e
parent73f5e52b15e3aa4ef641264228cd9069b1948149
net: embed num_tc in the xps maps

The xps cpus/rxqs map is accessed using dev->num_tc, which is used when
allocating the map. But later updates of dev->num_tc can lead to having
a mismatch between the maps and how they're accessed. In such cases the
map values do not make any sense and out of bound accesses can occur
(that can be easily seen using KASAN).

This patch aims at fixing this by embedding num_tc into the maps, using
the value at the time the map is created. This brings two improvements:
- The maps can be accessed using the embedded num_tc, so we know for
  sure we won't have out of bound accesses.
- Checks can be made before accessing the maps so we know the values
  retrieved will make sense.

We also update __netif_set_xps_queue to conditionally copy old maps from
dev_maps in the new one only if the number of traffic classes from both
maps match.

Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
net/core/dev.c
net/core/net-sysfs.c