Skip to content

Commit 731bdd9

Browse files
inwardvesselhtejun
authored andcommitted
cgroup: avoid per-cpu allocation of size zero rstat cpu locks
Subsystem rstat locks are dynamically allocated per-cpu. It was discovered that a panic can occur during this allocation when the lock size is zero. This is the case on non-smp systems, since arch_spinlock_t is defined as an empty struct. Prevent this allocation when !CONFIG_SMP by adding a pre-processor conditional around the affected block. Signed-off-by: JP Kobryn <inwardvessel@gmail.com> Reported-by: Klara Modin <klarasmodin@gmail.com> Fixes: 748922d ("cgroup: use subsystem-specific rstat locks to avoid contention") Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent dc9f08b commit 731bdd9

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

kernel/cgroup/rstat.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,20 @@ int __init ss_rstat_init(struct cgroup_subsys *ss)
510510
{
511511
int cpu;
512512

513+
#ifdef CONFIG_SMP
514+
/*
515+
* On uniprocessor machines, arch_spinlock_t is defined as an empty
516+
* struct. Avoid allocating a size of zero by having this block
517+
* excluded in this case. It's acceptable to leave the subsystem locks
518+
* unitialized since the associated lock functions are no-ops in the
519+
* non-smp case.
520+
*/
513521
if (ss) {
514522
ss->rstat_ss_cpu_lock = alloc_percpu(raw_spinlock_t);
515523
if (!ss->rstat_ss_cpu_lock)
516524
return -ENOMEM;
517525
}
526+
#endif
518527

519528
spin_lock_init(ss_rstat_lock(ss));
520529
for_each_possible_cpu(cpu)

0 commit comments

Comments
 (0)