Skip boot CPU or don't allow it from being used in isolcpus and isolated partitions
Subsystems (6)
Waiman Long
maintainercover Skip boot CPU or don't allow it from being used in isolcpus and isolated partitions
It is reported that having CPU 0 being domain isolated can cause problems in the some kernel subystems which don't take into account that the boot CPU (CPU 0) may not be a HK_TYPE_DOMAIN housekeeping CPU. As a result, it makes sense to just disallow CPU 0 from being used in the isolcpus=domain boot parameter as well as in cpuset isolated partitions instead of trying to fix the problems when they show up.
The first patch fixes the inconsistency problems between tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask.
The second patch removes the boot CPU from the isolcpus=domain parameter if set.
The third patch disallows isolated partitions from being created if CPU 0 is specified in its effective exclusive cpumask.
Waiman Long (3):
tick/sched: Make tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask
consistent
sched/isolation: Forbid the boot CPU from being isolated cgroup/cpuset: Disallow CPU 0 from being used in isolated partition
Documentation/admin-guide/cgroup-v2.rst | 1 + .../admin-guide/kernel-parameters.txt | 7 +-- include/linux/sched/isolation.h | 2 + kernel/cgroup/cpuset-internal.h | 1 + kernel/cgroup/cpuset.c | 6 +++ kernel/sched/isolation.c | 31 ++++++++++--- kernel/time/tick-sched.c | 8 +++- .../selftests/cgroup/test_cpuset_prs.sh | 43 ++++++++++++------- 8 files changed, 74 insertions(+), 25 deletions(-)
Signature · 1 line
2.56.1
Waiman Long
maintainerPATCH 1/3 tick/sched: Make tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask consistent
When the nohz_full boot parameter is first set, the cpu list parameter is passed directly to tick_nohz_full_setup() to set up tick_nohz_full_mask cpumask. Then the HK_TYPE_KERNEL_NOISE cpumask will be set up as the inverse of given cpu list parameter. Some of the timer code and RCU uses tick_nohz_full_mask directly while other timer code, scheduler and other subsystems use the HK_TYPE_KERNEL_NOISE cpumask.
There are two problems that can cause inconsistency between tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask. First of all, if there are more than one nohz_full boot parameters in the boot command line, only the first one is passed to tick_nohz_full_setup() while the setting of HK_TYPE_KERNEL_NOISE cpumask is controlled by the last nohz_full parameter.
Secondly, with CONFIG_PM_SLEEP_SMP && !CONFIG_PM_SLEEP_SMP_NONZERO_CPU config options, the boot CPU will be cleared from tick_nohz_full_mask if set while the corresponding HK_TYPE_KERNEL_NOISE cpumask isn't touched. The nohz_full entry in kernel-parameters.txt does state that the boot CPU will be forced outside the range to maintain the timekeeping. So it makes sense that the HK_TYPE_KERNEL_NOISE should be modified accordingly.
PM_SLEEP_SMP_NONZERO_CPU depends on ARCH_SUSPEND_NONZERO_CPU which can only be set for the PowerPC architecture. Moreover CONFIG_PM_SLEEP_SMP is on by default, it means most kernels will not allow CPU 0 to be set in the tick_nohz_full_mask and hence should be set in HK_TYPE_KERNEL_NOISE cpumask.
The first inconsistency problem is fixed by calling tick_nohz_full_setup() every time a nohz_full parameter is hit with tick_nohz_full_setup() modified to allow multiple calls. The second problem is fixed by adding a new cpumask_set_cpu() init function to be called by tick_nohz_init() when the boot CPU is cleared from tick_nohz_full_mask.
--- include/linux/sched/isolation.h | 2 ++ kernel/sched/isolation.c | 14 +++++++++++++- kernel/time/tick-sched.c | 8 ++++++-- 3 files changed, 21 insertions(+), 3 deletions(-)
include/linux/sched/isolation.h +2 -0
@@ -44,6 +44,7 @@ extern bool housekeeping_enabled(enum hk_type type);extern void housekeeping_affine (struct task_struct *t,enum hk_type type);extern bool housekeeping_test_cpu (int cpu,enum hk_type type);extern int housekeeping_update (struct cpumask *isol_mask); +extern void __init housekeeping_set_cpu (int cpu,enum hk_type type);extern void __init housekeeping_init (void );#else
@@ -72,6 +73,7 @@ static inline bool housekeeping_test_cpu(int cpu, enum hk_type type) }static inline int housekeeping_update (struct cpumask *isol_mask) {return 0 ; } +static inline void housekeeping_set_cpu (int cpu,enum hk_type type) { }static inline void housekeeping_init (void ) { }#endif /* CONFIG_CPU_ISOLATION */
kernel/sched/isolation.c +13 -1
@@ -120,6 +120,18 @@ bool housekeeping_test_cpu(int cpu, enum hk_type type) }EXPORT_SYMBOL_GPL (housekeeping_test_cpu); +void __init housekeeping_set_cpu (int cpu,enum hk_type type) +{ +/* Only CPU setting of HK_TYPE_KERNEL_NOISE is currently supported */ +if (type !=HK_TYPE_KERNEL_NOISE ) +return ; + +if (static_branch_unlikely (&housekeeping_overridden) && +READ_ONCE (housekeeping.flags) &BIT (type)) +cpumask_set_cpu (cpu, housekeeping.cpumasks[type]); +} +EXPORT_SYMBOL_GPL (housekeeping_set_cpu); +int housekeeping_update (struct cpumask *isol_mask) {struct cpumask *trial, *old =NULL ;
@@ -301,7 +313,7 @@ static int __init housekeeping_setup(char *str, unsigned long flags)housekeeping_setup_type (type, housekeeping_staging); } -if ((flags &HK_FLAG_KERNEL_NOISE ) && !(housekeeping.flags &HK_FLAG_KERNEL_NOISE )) +if (flags &HK_FLAG_KERNEL_NOISE )tick_nohz_full_setup (non_housekeeping_mask); housekeeping.flags |= flags;
kernel/time/tick-sched.c +6 -2
@@ -22,6 +22,7 @@#include <linux/sched/stat.h> #include <linux/sched/nohz.h> #include <linux/sched/loadavg.h> +#include <linux/sched/isolation.h> #include <linux/module.h> #include <linux/irq_work.h> #include <linux/posix-timers.h>
@@ -634,9 +635,11 @@ void __tick_nohz_task_switch(void)/* Get the boot-time nohz CPU list from the kernel parameters. */ void __init tick_nohz_full_setup (cpumask_var_t cpumask) { -alloc_bootmem_cpumask_var (&tick_nohz_full_mask); +if (!tick_nohz_full_running) { +alloc_bootmem_cpumask_var (&tick_nohz_full_mask); + tick_nohz_full_running = true; + }cpumask_copy (tick_nohz_full_mask, cpumask); - tick_nohz_full_running = true; }bool tick_nohz_cpu_hotpluggable (unsigned int cpu)
@@ -683,6 +686,7 @@ void __init tick_nohz_init(void)pr_warn ("NO_HZ: Clearing %d from nohz_full range " "for timekeeping\n" , cpu);cpumask_clear_cpu (cpu, tick_nohz_full_mask); +housekeeping_set_cpu (cpu,HK_TYPE_KERNEL_NOISE ); } }
Signature · 1 line
2.56.1
kernel test robot
build botRe: [PATCH-next 1/3] tick/sched: Make tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask consistent
kernel test robot noticed the following build warnings:
Hi Waiman,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tj-cgroup/for-next]
[also build test WARNING on tip/sched/core tip/timers/nohz linus/master v7.4-rc3 next-20261119] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Waiman-Long/tick-sched-Make-tick_nohz_full_mask-and-HK_TYPE_KERNEL_NOISE-cpumask-consistent/20261120-221327 base: https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git for-next patch link: https://lore.kernel.org/r/20261121031329.240177-2-longman%40redhat.com patch subject: [PATCH-next 1/3] tick/sched: Make tick_nohz_full_mask and HK_TYPE_KERNEL_NOISE cpumask consistent config: powerpc-akebono_defconfig (https://download.01.org/0day-ci/archive/20261121/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 3b14d7c370558b46e5f0c6494a05c492e59bf32c) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261121/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux: EXPORT_SYMBOL used for init symbol 'housekeeping_set_cpu'. Remove __init or EXPORT_SYMBOL.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Waiman Long
maintainerPATCH 2/3 sched/isolation: Forbid the boot CPU from being isolated
In reply to Waiman LongIt is reported that with CONFIG_CPUSETS=n, a kernel booted with isolcpus=domain,0 hits the BUG() in select_fallback_rq() during boot [1]. At boot time, cpu 0 is the only CPU online and an unbound kworker cannot be run on a domain isolated CPU causing kernel panic.
Sashiko also reports that domain isolating the boot CPU can break system suspend and trigger a BUG_ON() [2]. So it is problematic if the boot CPU is domain isolated.
There may be other kernel subsystems that have problem if the boot CPU is domain isolated as most of them won't take into account the fact that boot CPU is currently allowed to be domain isolated. The current housekeeping code enforces the rule that if both isolcpus and nohz_full boot parameters are set, they should match each other. Given the fact that the boot CPU is likely to be disallowed from the nohz_full list, it makes sense that we should not allow the boot CPU from being set in the isolcpus boot parameter as well. This will also avoid the above problems due to boot CPU being domain isolated.
Do that by clearing the boot CPU from the isolcpus range when it is specified in the boot command line. A warning will also be printed when that happens.
This is indeed a change in behavior which is customer visible. So the kernel-paremeters.txt is updated to mention the fact that boot CPU cannot be isolated.
[1] https://lore.kernel.org/lkml/[email protected]
[2] https://sashiko.dev/#/patchset/20261108180849.1268263-1-longman%40redhat.com
--- Documentation/admin-guide/kernel-parameters.txt | 7 ++++--- kernel/sched/isolation.c | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -3
@@ -2954,11 +2954,12 @@ Kernel parameters You can move a process onto or off an "isolated" CPU via the CPU affinity syscalls or cpuset. - <cpu number> begins at 0 and the maximum value is - "number of CPUs in system - 1". + <cpu number> begins at 0 and the maximum value + is "number of CPUs in system - 1". However boot + CPU (cpu 0) cannot be domain isolated as it + may cause problem with some kernel subsystems. managed_irq - Isolate from being targeted by managed interrupts which have an interrupt mask containing isolated CPUs. The affinity of managed interrupts is
kernel/sched/isolation.c +12 -4
@@ -232,6 +232,7 @@ static int __init housekeeping_setup(char *str, unsigned long flags) {cpumask_var_t non_housekeeping_mask, housekeeping_staging;unsigned int first_cpu; +int boot_cpu =smp_processor_id ();int err =0 ;if ((flags &HK_FLAG_KERNEL_NOISE ) && !(housekeeping.flags &HK_FLAG_KERNEL_NOISE )) {
@@ -254,14 +255,21 @@ static int __init housekeeping_setup(char *str, unsigned long flags) first_cpu =cpumask_first_and (cpu_present_mask, housekeeping_staging);if (first_cpu >= nr_cpu_ids || first_cpu >= setup_max_cpus) { -__cpumask_set_cpu (smp_processor_id (), housekeeping_staging); -__cpumask_clear_cpu (smp_processor_id (), non_housekeeping_mask); +__cpumask_set_cpu (boot_cpu, housekeeping_staging); +__cpumask_clear_cpu (boot_cpu, non_housekeeping_mask);if (!housekeeping.flags) { -pr_warn ("Housekeeping: must include one present CPU, " -"using boot CPU:%d\n" ,smp_processor_id ()); +pr_warn ("Housekeeping: must include one present CPU, using boot CPU:%d\n" , + boot_cpu); } } +if ((flags &HK_FLAG_DOMAIN ) &&cpumask_test_cpu (boot_cpu, non_housekeeping_mask)) { +pr_warn ("Housekeeping: Boot CPU must not be isolated, clearing %d from isolcpus range\n" , + boot_cpu); +__cpumask_set_cpu (boot_cpu, housekeeping_staging); +__cpumask_clear_cpu (boot_cpu, non_housekeeping_mask); + } +if (cpumask_empty (non_housekeeping_mask)) goto free_housekeeping_staging;
Signature · 1 line
2.56.1
Waiman Long
maintainerPATCH 3/3 cgroup/cpuset: Disallow CPU 0 from being used in isolated partition
In reply to Waiman LongDomain isolating CPU 0 can be problematic and may even cause panic in some cases. So it is better to disable its use in an isolated partition.
Add a new partition error code to indicate to the users that CPU 0 cannot be used in an isolated partition.
Some existing test cases in test_cpuset_prs.sh are modified to remove the use of CPU 0 in isolated partition setup and explicit new test cases are added to test that. The NOHZ_FULL test cases also modified to run if the "nohz_full" parameters includes all the CPUs except CPU 1-7 instead of 0-7. Though it is not recommended to put CPU 0 in the nohz_full boot parameter, it is the only way we can test that the cpuset code is able to correctly disallow isolating the last nohz_full/domain housekeeping CPU.
With CPU 0 likely not allowed in the nohz_full list and with CPU 0 also disallowed from being domain isolated and offline, we will likely have CPU 0 being an always present online housekeeping CPU for most kernels. For those kernels, we will not be able to trigger partition invalidation due to using up the last nohz_full/domain housekeeping CPU in an isolated partition and the NOHZ_FULL test cases in test_cpuset_prs.sh will not be run.
The cgroup-v2.rst documentation file is also modified to indicate that CPU 0 cannot be used in an isolated partition.
--- Documentation/admin-guide/cgroup-v2.rst | 1 + kernel/cgroup/cpuset-internal.h | 1 + kernel/cgroup/cpuset.c | 6 +++ .../selftests/cgroup/test_cpuset_prs.sh | 43 ++++++++++++------- 4 files changed, 36 insertions(+), 15 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +1 -0
@@ -2771,6 +2771,7 @@ Cpuset Interface Files and excluded from the unbound workqueues. Tasks placed in such a partition with multiple CPUs should be carefully distributed and bound to each of the individual CPUs for optimal performance. + The boot CPU (CPU 0) cannot be used in an isolated partition. A partition root ("root" or "isolated") can be in one of the two possible states - valid or invalid. An invalid partition
kernel/cgroup/cpuset-internal.h +1 -0
@@ -36,6 +36,7 @@ enum prs_errcode {PERR_ACCESS ,PERR_REMOTE ,PERR_ISOPARENT , + PERR_ISOLCPU0, };/* bits in struct cpuset flags field */
kernel/cgroup/cpuset.c +6 -0
@@ -61,6 +61,7 @@ static const char * const perr_strings[] = { [PERR_ACCESS] = "Enable partition not permitted", [PERR_REMOTE] = "Have remote partition underneath", [PERR_ISOPARENT] = "Root partition is not allowed with isolated parent", + [PERR_ISOLCPU0] = "Boot CPU (cpu 0) cannot be isolated", };/*
@@ -1453,6 +1454,9 @@ static enum prs_errcode validate_partition(struct cpuset *cs,if (tasks_nocpu_error (parent, cs, new_excpus))return PERR_NOCPUS ; +if ((new_prs ==PRS_ISOLATED ) &&cpumask_test_cpu (0 , new_excpus)) +return PERR_ISOLCPU0 ; +return PERR_NONE ; }
@@ -3002,6 +3006,8 @@ static int update_prstate(struct cpuset *cs, int new_prs) err =PERR_HKEEPING ; else if (parent_prs == PRS_ISOLATED) err =PERR_ISOPARENT ;/* old_prs should be isolated */ + else if ((new_prs == PRS_ISOLATED) && cpumask_test_cpu(0, cs->effective_xcpus)) + err = PERR_ISOLCPU0;if (err) { disable_partition = true;
tools/testing/selftests/cgroup/test_cpuset_prs.sh +28 -15
92 lines not on this page · raw message
Signature · 1 line
2.56.1