mbox series

[net-next,v4,00/13] net: xps: improve the xps maps handling

Message ID 20210318183752.2612563-1-atenart@kernel.org (mailing list archive)
Headers show
Series net: xps: improve the xps maps handling | expand

Message

Antoine Tenart March 18, 2021, 6:37 p.m. UTC
Hello,

This series aims at fixing various issues with the xps code, including
out-of-bound accesses and use-after-free. While doing so we try to
improve the xps code maintainability and readability.

The main change is moving dev->num_tc and dev->nr_ids in the xps maps, to
avoid out-of-bound accesses as those two fields can be updated after the
maps have been allocated. This allows further reworks, to improve the
xps code readability and allow to stop taking the rtnl lock when
reading the maps in sysfs. The maps are moved to an array in net_device,
which simplifies the code a lot.

One future improvement may be to remove the use of xps_map_mutex from
net/core/dev.c, but that may require extra care.

Thanks!
Antoine

Since v3:
  - Removed the 3 patches about the rtnl lock and __netif_set_xps_queue
    as there are extra issues. Those patches were not tied to the
    others, and I'll see want can be done as a separate effort.
  - One small fix in patch 12.

Since v2:
  - Patches 13-16 are new to the series.
  - Fixed another issue I found while preparing v3 (use after free of
    old xps maps).
  - Kept the rtnl lock when calling netdev_get_tx_queue and
    netdev_txq_to_tc.
  - Use get_device/put_device when using the sb_dev.
  - Take the rtnl lock in mlx5 and virtio_net when calling
    netif_set_xps_queue.
  - Fixed a coding style issue.

Since v1:
  - Reordered the patches to improve readability and avoid introducing
    issues in between patches.
  - Use dev_maps->nr_ids to allocate the mask in xps_queue_show but
    still default to nr_cpu_ids/dev->num_rx_queues in xps_queue_show
    when dev_maps hasn't been allocated yet for backward
    compatibility.:w


Antoine Tenart (13):
  net-sysfs: convert xps_cpus_show to bitmap_zalloc
  net-sysfs: store the return of get_netdev_queue_index in an unsigned
    int
  net-sysfs: make xps_cpus_show and xps_rxqs_show consistent
  net: embed num_tc in the xps maps
  net: embed nr_ids in the xps maps
  net: remove the xps possible_mask
  net: move the xps maps to an array
  net: add an helper to copy xps maps to the new dev_maps
  net: improve queue removal readability in __netif_set_xps_queue
  net-sysfs: move the rtnl unlock up in the xps show helpers
  net-sysfs: move the xps cpus/rxqs retrieval in a common function
  net: fix use after free in xps
  net: NULL the old xps map entries when freeing them

 drivers/net/virtio_net.c  |   2 +-
 include/linux/netdevice.h |  27 ++++-
 net/core/dev.c            | 247 ++++++++++++++++++++------------------
 net/core/net-sysfs.c      | 177 +++++++++++----------------
 4 files changed, 222 insertions(+), 231 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org March 18, 2021, 11:10 p.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Thu, 18 Mar 2021 19:37:39 +0100 you wrote:
> Hello,
> 
> This series aims at fixing various issues with the xps code, including
> out-of-bound accesses and use-after-free. While doing so we try to
> improve the xps code maintainability and readability.
> 
> The main change is moving dev->num_tc and dev->nr_ids in the xps maps, to
> avoid out-of-bound accesses as those two fields can be updated after the
> maps have been allocated. This allows further reworks, to improve the
> xps code readability and allow to stop taking the rtnl lock when
> reading the maps in sysfs. The maps are moved to an array in net_device,
> which simplifies the code a lot.
> 
> [...]

Here is the summary with links:
  - [net-next,v4,01/13] net-sysfs: convert xps_cpus_show to bitmap_zalloc
    https://git.kernel.org/netdev/net-next/c/ea4fe7e842f6
  - [net-next,v4,02/13] net-sysfs: store the return of get_netdev_queue_index in an unsigned int
    https://git.kernel.org/netdev/net-next/c/d9a063d207f0
  - [net-next,v4,03/13] net-sysfs: make xps_cpus_show and xps_rxqs_show consistent
    https://git.kernel.org/netdev/net-next/c/73f5e52b15e3
  - [net-next,v4,04/13] net: embed num_tc in the xps maps
    https://git.kernel.org/netdev/net-next/c/255c04a87f43
  - [net-next,v4,05/13] net: embed nr_ids in the xps maps
    https://git.kernel.org/netdev/net-next/c/5478fcd0f483
  - [net-next,v4,06/13] net: remove the xps possible_mask
    https://git.kernel.org/netdev/net-next/c/6f36158e0584
  - [net-next,v4,07/13] net: move the xps maps to an array
    https://git.kernel.org/netdev/net-next/c/044ab86d431b
  - [net-next,v4,08/13] net: add an helper to copy xps maps to the new dev_maps
    https://git.kernel.org/netdev/net-next/c/402fbb992e13
  - [net-next,v4,09/13] net: improve queue removal readability in __netif_set_xps_queue
    https://git.kernel.org/netdev/net-next/c/132f743b01b8
  - [net-next,v4,10/13] net-sysfs: move the rtnl unlock up in the xps show helpers
    https://git.kernel.org/netdev/net-next/c/d7be87a687cc
  - [net-next,v4,11/13] net-sysfs: move the xps cpus/rxqs retrieval in a common function
    https://git.kernel.org/netdev/net-next/c/2db6cdaebac8
  - [net-next,v4,12/13] net: fix use after free in xps
    https://git.kernel.org/netdev/net-next/c/2d05bf015308
  - [net-next,v4,13/13] net: NULL the old xps map entries when freeing them
    https://git.kernel.org/netdev/net-next/c/75b2758abc35

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