Skip to contentSkip to conversation

cgroup: Fix seqcount lockdep assertion in cgroup freezer

PATCH Applied Nirbhay Sharma 4 participants 5 messages Oct 3, 2025 – Oct 4, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: Fix seqcount lockdep assertion in cgroup freezer

The commit afa3701c0e45 ("cgroup: cgroup.stat.local time accounting") introduced a seqcount to track freeze timing but initialized it as a plain seqcount_t using seqcount_init().

However, the write-side critical section in cgroup_do_freeze() holds the css_set_lock spinlock while calling write_seqcount_begin(). On PREEMPT_RT kernels, spinlocks do not disable preemption, causing the lockdep assertion for a plain seqcount_t, which checks for preemption being disabled, to fail.

This triggers the following warning:

  WARNING: CPU: 0 PID: 9692 at include/linux/seqlock.h:221

Fix this by changing the type to seqcount_spinlock_t and initializing it with seqcount_spinlock_init() to associate css_set_lock with the seqcount. This allows lockdep to correctly validate that the spinlock is held during write operations, resolving the assertion failure on all kernel configurations.

Reported-by [email protected]
Fixes afa3701c0e45 ("cgroup: cgroup.stat.local time accounting")
---
 include/linux/cgroup-defs.h | 2 +-
 kernel/cgroup/cgroup.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/cgroup-defs.h +1 -1
index 539c64eeef38..933c4487a846 100644
@@ -435,7 +435,7 @@ struct cgroup_freezer_state {
 	int nr_frozen_tasks;
 
 	/* Freeze time data consistency protection */
-	seqcount_t freeze_seq;
+	seqcount_spinlock_t freeze_seq;
 
 	/*
 	 * Most recent time the cgroup was requested to freeze.
kernel/cgroup/cgroup.c +1 -1
index ab096b884bbc..fe175326b155 100644
@@ -5789,7 +5789,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
 	 * if the parent has to be frozen, the child has too.
 	 */
 	cgrp->freezer.e_freeze = parent->freezer.e_freeze;
-	seqcount_init(&cgrp->freezer.freeze_seq);
+	seqcount_spinlock_init(&cgrp->freezer.freeze_seq, &css_set_lock);
 	if (cgrp->freezer.e_freeze) {
 		/*
 		 * Set the CGRP_FREEZE flag, so when a process will be
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Nirbhay Sharma

The commit afa3701c0e45 ("cgroup: cgroup.stat.local time accounting") introduced a seqcount to track freeze timing but initialized it as a plain seqcount_t using seqcount_init().

However, the write-side critical section in cgroup_do_freeze() holds the css_set_lock spinlock while calling write_seqcount_begin(). On PREEMPT_RT kernels, spinlocks do not disable preemption, causing the lockdep assertion for a plain seqcount_t, which checks for preemption being disabled, to fail.

This triggers the following warning:

  WARNING: CPU: 0 PID: 9692 at include/linux/seqlock.h:221

Fix this by changing the type to seqcount_spinlock_t and initializing it with seqcount_spinlock_init() to associate css_set_lock with the seqcount. This allows lockdep to correctly validate that the spinlock is held during write operations, resolving the assertion failure on all kernel configurations.

Quoted 4 lines
Reported-by [email protected]
Fixes afa3701c0e45 ("cgroup: cgroup.stat.local time accounting")

Yes, this is what was discussed yesterday. Thanks.

maintainer
#2 lore raw
Quoted 25 lines · Michal Koutný
Quoted 19 lines · Nirbhay Sharma

The commit afa3701c0e45 ("cgroup: cgroup.stat.local time accounting") introduced a seqcount to track freeze timing but initialized it as a plain seqcount_t using seqcount_init().

However, the write-side critical section in cgroup_do_freeze() holds the css_set_lock spinlock while calling write_seqcount_begin(). On PREEMPT_RT kernels, spinlocks do not disable preemption, causing the lockdep assertion for a plain seqcount_t, which checks for preemption being disabled, to fail.

This triggers the following warning:

  WARNING: CPU: 0 PID: 9692 at include/linux/seqlock.h:221

Fix this by changing the type to seqcount_spinlock_t and initializing it with seqcount_spinlock_init() to associate css_set_lock with the seqcount. This allows lockdep to correctly validate that the spinlock is held during write operations, resolving the assertion failure on all kernel configurations.

Quoted 4 lines
Reported-by [email protected]
Fixes afa3701c0e45 ("cgroup: cgroup.stat.local time accounting")
Quoted 5 lines

Yes, this is what was discussed yesterday. Thanks.

Okay, reverting that one and applying this one.

Thanks.

Signature · 1 line
tejun
#4 lore raw
In reply to Nirbhay Sharma
Quoted 54 lines · Nirbhay Sharma

The commit afa3701c0e45 ("cgroup: cgroup.stat.local time accounting") introduced a seqcount to track freeze timing but initialized it as a plain seqcount_t using seqcount_init().

However, the write-side critical section in cgroup_do_freeze() holds the css_set_lock spinlock while calling write_seqcount_begin(). On PREEMPT_RT kernels, spinlocks do not disable preemption, causing the lockdep assertion for a plain seqcount_t, which checks for preemption being disabled, to fail.

This triggers the following warning:

   WARNING: CPU: 0 PID: 9692 at include/linux/seqlock.h:221

Fix this by changing the type to seqcount_spinlock_t and initializing it with seqcount_spinlock_init() to associate css_set_lock with the seqcount. This allows lockdep to correctly validate that the spinlock is held during write operations, resolving the assertion failure on all kernel configurations.

Reported-by [email protected]
Fixes afa3701c0e45 ("cgroup: cgroup.stat.local time accounting")
---
  include/linux/cgroup-defs.h | 2 +-
  kernel/cgroup/cgroup.c      | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/cgroup-defs.h +1 -1
index 539c64eeef38..933c4487a846 100644
@@ -435,7 +435,7 @@ struct cgroup_freezer_state {
  	int nr_frozen_tasks;
 
  	/* Freeze time data consistency protection */
-	seqcount_t freeze_seq;
+	seqcount_spinlock_t freeze_seq;
 
  	/*
  	 * Most recent time the cgroup was requested to freeze.
kernel/cgroup/cgroup.c +1 -1
index ab096b884bbc..fe175326b155 100644
@@ -5789,7 +5789,7 @@ static struct cgroup *cgroup_create(struct cgroup  
 *parent, const char *name,
  	 * if the parent has to be frozen, the child has too.
  	 */
  	cgrp->freezer.e_freeze = parent->freezer.e_freeze;
-	seqcount_init(&cgrp->freezer.freeze_seq);
+	seqcount_spinlock_init(&cgrp->freezer.freeze_seq, &css_set_lock);
  	if (cgrp->freezer.e_freeze) {
  		/*
Quoted 1 line

* Set the CGRP_FREEZE flag, so when a process will be

Thanks for this fix, Nirbhay!

Signature · 1 line
Tiffany Y. Yang