Skip to content

Commit 6548d36

Browse files
committed
Merge tag 'cgroup-for-6.18-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup fixes from Tejun Heo: - Fix seqcount lockdep assertion failure in cgroup freezer on PREEMPT_RT. Plain seqcount_t expects preemption disabled, but PREEMPT_RT spinlocks don't disable preemption. Switch to seqcount_spinlock_t to properly associate css_set_lock with the freeze timing seqcount. - Misc changes including kernel-doc warning fix for misc_res_type enum and improved selftest diagnostics. * tag 'cgroup-for-6.18-rc2-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup/misc: fix misc_res_type kernel-doc warning selftests: cgroup: Use values_close_report in test_cpu selftests: cgroup: add values_close_report helper cgroup: Fix seqcount lockdep assertion in cgroup freezer
2 parents 380cb5d + 0fbbcab commit 6548d36

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

include/linux/cgroup-defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ struct cgroup_freezer_state {
452452
int nr_frozen_tasks;
453453

454454
/* Freeze time data consistency protection */
455-
seqcount_t freeze_seq;
455+
seqcount_spinlock_t freeze_seq;
456456

457457
/*
458458
* Most recent time the cgroup was requested to freeze.

include/linux/misc_cgroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum misc_res_type {
1919
MISC_CG_RES_SEV_ES,
2020
#endif
2121
#ifdef CONFIG_INTEL_TDX_HOST
22-
/* Intel TDX HKIDs resource */
22+
/** @MISC_CG_RES_TDX: Intel TDX HKIDs resource */
2323
MISC_CG_RES_TDX,
2424
#endif
2525
/** @MISC_CG_RES_TYPES: count of enum misc_res_type constants */

kernel/cgroup/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5892,7 +5892,7 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name,
58925892
* if the parent has to be frozen, the child has too.
58935893
*/
58945894
cgrp->freezer.e_freeze = parent->freezer.e_freeze;
5895-
seqcount_init(&cgrp->freezer.freeze_seq);
5895+
seqcount_spinlock_init(&cgrp->freezer.freeze_seq, &css_set_lock);
58965896
if (cgrp->freezer.e_freeze) {
58975897
/*
58985898
* Set the CGRP_FREEZE flag, so when a process will be

tools/testing/selftests/cgroup/lib/include/cgroup_util.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ static inline int values_close(long a, long b, int err)
2525
return labs(a - b) <= (a + b) / 100 * err;
2626
}
2727

28+
/*
29+
* Checks if two given values differ by less than err% of their sum and assert
30+
* with detailed debug info if not.
31+
*/
32+
static inline int values_close_report(long a, long b, int err)
33+
{
34+
long diff = labs(a - b);
35+
long limit = (a + b) / 100 * err;
36+
double actual_err = (a + b) ? (100.0 * diff / (a + b)) : 0.0;
37+
int close = diff <= limit;
38+
39+
if (!close)
40+
fprintf(stderr,
41+
"[FAIL] actual=%ld expected=%ld | diff=%ld | limit=%ld | "
42+
"tolerance=%d%% | actual_error=%.2f%%\n",
43+
a, b, diff, limit, err, actual_err);
44+
45+
return close;
46+
}
47+
2848
extern ssize_t read_text(const char *path, char *buf, size_t max_len);
2949
extern ssize_t write_text(const char *path, char *buf, ssize_t len);
3050

tools/testing/selftests/cgroup/test_cpu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int test_cpucg_stats(const char *root)
219219
if (user_usec <= 0)
220220
goto cleanup;
221221

222-
if (!values_close(usage_usec, expected_usage_usec, 1))
222+
if (!values_close_report(usage_usec, expected_usage_usec, 1))
223223
goto cleanup;
224224

225225
ret = KSFT_PASS;
@@ -291,7 +291,7 @@ static int test_cpucg_nice(const char *root)
291291

292292
user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec");
293293
nice_usec = cg_read_key_long(cpucg, "cpu.stat", "nice_usec");
294-
if (!values_close(nice_usec, expected_nice_usec, 1))
294+
if (!values_close_report(nice_usec, expected_nice_usec, 1))
295295
goto cleanup;
296296

297297
ret = KSFT_PASS;
@@ -404,7 +404,7 @@ overprovision_validate(const struct cpu_hogger *children, int num_children)
404404
goto cleanup;
405405

406406
delta = children[i + 1].usage - children[i].usage;
407-
if (!values_close(delta, children[0].usage, 35))
407+
if (!values_close_report(delta, children[0].usage, 35))
408408
goto cleanup;
409409
}
410410

@@ -444,7 +444,7 @@ underprovision_validate(const struct cpu_hogger *children, int num_children)
444444
int ret = KSFT_FAIL, i;
445445

446446
for (i = 0; i < num_children - 1; i++) {
447-
if (!values_close(children[i + 1].usage, children[0].usage, 15))
447+
if (!values_close_report(children[i + 1].usage, children[0].usage, 15))
448448
goto cleanup;
449449
}
450450

@@ -573,16 +573,16 @@ run_cpucg_nested_weight_test(const char *root, bool overprovisioned)
573573

574574
nested_leaf_usage = leaf[1].usage + leaf[2].usage;
575575
if (overprovisioned) {
576-
if (!values_close(leaf[0].usage, nested_leaf_usage, 15))
576+
if (!values_close_report(leaf[0].usage, nested_leaf_usage, 15))
577577
goto cleanup;
578-
} else if (!values_close(leaf[0].usage * 2, nested_leaf_usage, 15))
578+
} else if (!values_close_report(leaf[0].usage * 2, nested_leaf_usage, 15))
579579
goto cleanup;
580580

581581

582582
child_usage = cg_read_key_long(child, "cpu.stat", "usage_usec");
583583
if (child_usage <= 0)
584584
goto cleanup;
585-
if (!values_close(child_usage, nested_leaf_usage, 1))
585+
if (!values_close_report(child_usage, nested_leaf_usage, 1))
586586
goto cleanup;
587587

588588
ret = KSFT_PASS;
@@ -691,7 +691,7 @@ static int test_cpucg_max(const char *root)
691691
expected_usage_usec
692692
= n_periods * quota_usec + MIN(remainder_usec, quota_usec);
693693

694-
if (!values_close(usage_usec, expected_usage_usec, 10))
694+
if (!values_close_report(usage_usec, expected_usage_usec, 10))
695695
goto cleanup;
696696

697697
ret = KSFT_PASS;
@@ -762,7 +762,7 @@ static int test_cpucg_max_nested(const char *root)
762762
expected_usage_usec
763763
= n_periods * quota_usec + MIN(remainder_usec, quota_usec);
764764

765-
if (!values_close(usage_usec, expected_usage_usec, 10))
765+
if (!values_close_report(usage_usec, expected_usage_usec, 10))
766766
goto cleanup;
767767

768768
ret = KSFT_PASS;

0 commit comments

Comments
 (0)