Skip to contentSkip to conversation

cgroup: fix psi monitor for root cgroup

PATCH Applied Odin Ugedal 4 participants 8 messages Jan 16, 2021 – Jan 19, 2021

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

v2 cover cgroup: fix psi monitor for root cgroup

This patchset fixes PSI monitors on the root cgroup, as they currently only works on the non-root cgroups. Reading works for all, since that was fixed when adding support for the root PSI files. It also contains a doc update to reflect the current implementation.

Changes since v1:
- Added Reviewed-by tag on the original patch (Suren)
- Updated patch title
- Added a separate patch to update doc

Odin Ugedal (2):
cgroup: fix psi monitor for root cgroup
cgroup: update PSI file description in docs

 Documentation/admin-guide/cgroup-v2.rst | 6 +++---
 kernel/cgroup/cgroup.c                  | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.0
#1 lore raw

PATCH v2 1/2 cgroup: fix psi monitor for root cgroup

Fix NULL pointer dereference when adding new psi monitor to the root cgroup. PSI files for root cgroup was introduced in df5ba5be742 by using system wide psi struct when reading, but file write/monitor was not properly fixed. Since the PSI config for the root cgroup isn't initialized, the current implementation tries to lock a NULL ptr, resulting in a crash.

Can be triggered by running this as root:

$ tee /sys/fs/cgroup/cpu.pressure <<< "some 10000 1000000"
---
 kernel/cgroup/cgroup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/cgroup/cgroup.c +3 -1
index 613845769103..1ea995f801ec 100644
@@ -3564,6 +3564,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
 {
 	struct psi_trigger *new;
 	struct cgroup *cgrp;
+	struct psi_group *psi;
 
 	cgrp = cgroup_kn_lock_live(of->kn, false);
 	if (!cgrp)
@@ -3572,7 +3573,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
 	cgroup_get(cgrp);
 	cgroup_kn_unlock(of->kn);
 
-	new = psi_trigger_create(&cgrp->psi, buf, nbytes, res);
+	psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
+	new = psi_trigger_create(psi, buf, nbytes, res);
 	if (IS_ERR(new)) {
 		cgroup_put(cgrp);
 		return PTR_ERR(new);
Signature · 1 line
2.30.0
maintainer Acked-by on v2 1/2
#2 lore raw
Quoted 7 lines · Odin Ugedal

Fix NULL pointer dereference when adding new psi monitor to the root cgroup. PSI files for root cgroup was introduced in df5ba5be742 by using system wide psi struct when reading, but file write/monitor was not properly fixed. Since the PSI config for the root cgroup isn't initialized, the current implementation tries to lock a NULL ptr, resulting in a crash.

Quoted 5 lines

Can be triggered by running this as root:

$ tee /sys/fs/cgroup/cpu.pressure <<< "some 10000 1000000"
Fixes df5ba5be7425 ("kernel/sched/psi.c: expose pressure metrics on root cgroup")

Since this is a userspace-triggerable NULL ptr crash, we should probably also

#3 lore raw

PATCH v2 2/2 cgroup: update PSI file description in docs

In reply to Odin Ugedal

Update PSI file description in cgroup-v2 docs to reflect the current implementation.

---
 Documentation/admin-guide/cgroup-v2.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +3 -3
index 63521cd36ce5..f638c9d3d9f2 100644
@@ -1029,7 +1029,7 @@ All time durations are in microseconds.
 	one number is written, $MAX is updated.
 
   cpu.pressure
-	A read-only nested-key file which exists on non-root cgroups.
+	A read-only nested-keyed file.
 
 	Shows pressure stall information for CPU. See
 	:ref:`Documentation/accounting/psi.rst <psi>` for details.
@@ -1475,7 +1475,7 @@ PAGE_SIZE multiple when read back.
 	reduces the impact on the workload and memory management.
 
   memory.pressure
-	A read-only nested-key file which exists on non-root cgroups.
+	A read-only nested-keyed file.
 
 	Shows pressure stall information for memory. See
 	:ref:`Documentation/accounting/psi.rst <psi>` for details.
@@ -1714,7 +1714,7 @@ IO Interface Files
 	  8:16 rbps=2097152 wbps=max riops=max wiops=max
 
   io.pressure
-	A read-only nested-key file which exists on non-root cgroups.
+	A read-only nested-keyed file.
 
 	Shows pressure stall information for IO. See
 	:ref:`Documentation/accounting/psi.rst <psi>` for details.
Signature · 1 line
2.30.0
maintainer Acked-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] cgroup: update PSI file description in docs

Quoted 13 lines · Odin Ugedal

Update PSI file description in cgroup-v2 docs to reflect the current implementation.

---
 Documentation/admin-guide/cgroup-v2.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +0 -0
index 63521cd36ce5..f638c9d3d9f2 100644

Documentation/admin-guide/cgroup-v2.rst All time durations are in microseconds. · line 1032

Quoted 5 lines
Documentation/admin-guide/cgroup-v2.rst +1 -1
@@ -1029,7 +1029,7 @@ All time durations are in microseconds.
 	one number is written, $MAX is updated.
 
   cpu.pressure
-	A read-only nested-key file which exists on non-root cgroups.
+	A read-only nested-keyed file.

Could you please also change the 'read-only' to 'read-write'?

With that, please feel free to add:

maintainer
#5 lore raw

Re: [PATCH v2 2/2] cgroup: update PSI file description in docs

Quoted 16 lines · Johannes Weiner
Quoted 15 lines · Odin Ugedal

Update PSI file description in cgroup-v2 docs to reflect the current implementation.

---
 Documentation/admin-guide/cgroup-v2.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +0 -0
index 63521cd36ce5..f638c9d3d9f2 100644
@@ -1029,7 +1029,7 @@ All time durations are in microseconds.
 	one number is written, $MAX is updated.
 
Quoted 8 lines

Documentation/admin-guide/cgroup-v2.rst All time durations are in microseconds. · line 1032

Quoted 3 lines
Documentation/admin-guide/cgroup-v2.rst +1 -1
   cpu.pressure
-	A read-only nested-key file which exists on non-root cgroups.
+	A read-only nested-keyed file.

Could you please also change the 'read-only' to 'read-write'?

With that, please feel free to add:

Applied w/ the suggested change.

Thanks.

Signature · 1 line
tejun
Acked-by on the v2 series
#6 lore raw
In reply to Odin Ugedal
Quoted 11 lines

This patchset fixes PSI monitors on the root cgroup, as they currently only works on the non-root cgroups. Reading works for all, since that was fixed when adding support for the root PSI files. It also contains a doc update to reflect the current implementation.

Changes since v1:
 - Added Reviewed-by tag on the original patch (Suren)
 - Updated patch title
 - Added a separate patch to update doc

Quoted 7 lines

Odin Ugedal (2):
  cgroup: fix psi monitor for root cgroup
  cgroup: update PSI file description in docs

 Documentation/admin-guide/cgroup-v2.rst | 6 +++--- kernel/cgroup/cgroup.c                  | 4 +++-

 2 files changed, 6 insertions(+), 4 deletions(-)

Both patches look good.

maintainer Applied
#7 lore raw
In reply to Odin Ugedal
Quoted 4 lines · Odin Ugedal

This patchset fixes PSI monitors on the root cgroup, as they currently only works on the non-root cgroups. Reading works for all, since that was fixed when adding support for the root PSI files. It also contains a doc update to reflect the current implementation.

Applied to cgroup/for-5.11-fixes with acks and stable tag added.

Thanks.

Signature · 1 line
tejun