Skip to content

cpumask: fix invalid uniprocessor assumptions

Sander Vanheule lkml 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 8 repliesIn review
  2. v45 patches 16 repliesApplied 5/5
  3. v34 patches 8 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v24 patches2 repliesSuperseded
v12 patches2 repliesSuperseded

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5x86/cacheinfo: move shared cache map definitionsarch/x86/kernel/cpu/cacheinfo.c arch/x86/kernel/smpboot.c+6 -41 reply
2/5cpumask: add UP optimised for_each_*_cpu versionsinclude/linux/cpumask.h+7 -00 replies
3/5cpumask: fix invalid uniprocessor mask assumptioninclude/linux/cpumask.h lib/Makefile lib/cpumask.c+22 -822 replies
4/5lib/test: introduce cpumask KUnit test suitelib/Kconfig.debug lib/Makefile lib/cpumask_test.c+160 -04 replies
5/5cpumask: update cpumask_next_wrap() signatureinclude/linux/cpumask.h+1 -10 replies

Reviews trailers per patch

4 of 5 patches have a Reviewed-by or Acked-by.

PatchYury NorovAndy ShevchenkoMaíra CanalIngo Molnar
1/5R-b
2/5A-b
3/5
4/5R-b T-b
5/5R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v5 thread

Cover letter [PATCH v5 0/5] cpumask: fix invalid uniprocessor assumptions

On uniprocessor builds, it is currently assumed that any cpumask will contain the single CPU: cpu0. This assumption is used to provide optimised implementations.

The current assumption also appears to be wrong, by ignoring the fact that users can provide empty cpumasks. This can result in bugs as explained in [1] - for_each_cpu() will run one iteration of the loop even when passed an empty cpumask.

This series introduces some basic tests, and updates the optimisations for uniprocessor builds.

The x86 patch was written after the kernel test robot [2] ran into a failed build. I have tried to list the files potentially affected by the changes to cpumask.h, in an attempt to find any other cases that fail on !SMP. I've gone through some of the files manually, and ran a few cross builds, but nothing else popped up. I (build) checked about half of the potientally affected files, but I do not have the resources to do them all. I hope we can fix other issues if/when they pop up later.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Changes since v4:

- Move new for_each_*_cpu() optimisations ahead, so they come before the fixes.
- Update test cases for cpu_possible_mask for nr_cpu_ids < CONFIG_NR_CPUS
- Improve KUnit style compliance on tests
- Collect tags and add Cc: tags

Changes since v3:

- Guard against CPU hotplugging while testing cpu online/present masks
- Add fix for cpu_llc_shared_map on x86

Changes since v2:

- Put new tests after patch fixes
- Update for_each_* macros

Changes since v1:

- Place tests in lib/test_cpumask.c
- Drop the modified UP code in favor of the generic SMP implementation
- Update declaration of cpumask_next_wrap()

Sander Vanheule (5):
x86/cacheinfo: move shared cache map definitions
cpumask: add UP optimised for_each_*_cpu versions
cpumask: fix invalid uniprocessor mask assumption lib/test: introduce cpumask KUnit test suite
cpumask: update cpumask_next_wrap() signature

 arch/x86/kernel/cpu/cacheinfo.c |   6 ++
 arch/x86/kernel/smpboot.c       |   4 -
 include/linux/cpumask.h         | 108 ++++++-----------------
 lib/Kconfig.debug               |  12 +++
 lib/Makefile                    |   4 +-
 lib/cpumask.c                   |   2 +
 lib/cpumask_test.c              | 147 ++++++++++++++++++++++++++++++++
 7 files changed, 196 insertions(+), 87 deletions(-)
 create mode 100644 lib/cpumask_test.c
Signature · 1 line
2.37.1