]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cgroup/cpuset: Account for boot time isolated CPUs
authorWaiman Long <longman@redhat.com>
Tue, 20 Aug 2024 19:55:35 +0000 (15:55 -0400)
committerTejun Heo <tj@kernel.org>
Fri, 30 Aug 2024 19:23:39 +0000 (09:23 -1000)
With the "isolcpus" boot command line parameter, we are able to
create isolated CPUs at boot time. These isolated CPUs aren't fully
accounted for in the cpuset code. For instance, the root cgroup's
"cpuset.cpus.isolated" control file does not include the boot time
isolated CPUs. Fix that by looking for pre-isolated CPUs at init time.

The prstate_housekeeping_conflict() function does check the
HK_TYPE_DOMAIN housekeeping cpumask to make sure that CPUs outside of it
can only be used in isolated partition. Given the fact that we are going
to make housekeeping cpumasks dynamic, the current check may not be right
anymore. Save the boot time HK_TYPE_DOMAIN cpumask and check against
it instead of the upcoming dynamic HK_TYPE_DOMAIN housekeeping cpumask.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cpuset.c

index 7db55eed63cf95f8254cfa0919d2b49ccf4a5cfd..8b40df89c3c135e0654b3f1d5db336ed90773b4a 100644 (file)
@@ -224,6 +224,12 @@ static cpumask_var_t       subpartitions_cpus;
  */
 static cpumask_var_t   isolated_cpus;
 
+/*
+ * Housekeeping (HK_TYPE_DOMAIN) CPUs at boot
+ */
+static cpumask_var_t   boot_hk_cpus;
+static bool            have_boot_isolcpus;
+
 /* List of remote partition root children */
 static struct list_head remote_children;
 
@@ -1823,15 +1829,15 @@ static void remote_partition_check(struct cpuset *cs, struct cpumask *newmask,
  * @new_cpus: cpu mask
  * Return: true if there is conflict, false otherwise
  *
- * CPUs outside of housekeeping_cpumask(HK_TYPE_DOMAIN) can only be used in
- * an isolated partition.
+ * CPUs outside of boot_hk_cpus, if defined, can only be used in an
+ * isolated partition.
  */
 static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus)
 {
-       const struct cpumask *hk_domain = housekeeping_cpumask(HK_TYPE_DOMAIN);
-       bool all_in_hk = cpumask_subset(new_cpus, hk_domain);
+       if (!have_boot_isolcpus)
+               return false;
 
-       if (!all_in_hk && (prstate != PRS_ISOLATED))
+       if ((prstate != PRS_ISOLATED) && !cpumask_subset(new_cpus, boot_hk_cpus))
                return true;
 
        return false;
@@ -4345,6 +4351,13 @@ int __init cpuset_init(void)
 
        BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL));
 
+       have_boot_isolcpus = housekeeping_enabled(HK_TYPE_DOMAIN);
+       if (have_boot_isolcpus) {
+               BUG_ON(!alloc_cpumask_var(&boot_hk_cpus, GFP_KERNEL));
+               cpumask_copy(boot_hk_cpus, housekeeping_cpumask(HK_TYPE_DOMAIN));
+               cpumask_andnot(isolated_cpus, cpu_possible_mask, boot_hk_cpus);
+       }
+
        return 0;
 }