Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing/hwlat: start_single_kthread() leaves
PF_NO_SETAFFINITY set on hwlatd
--
commit 649d99e25afc0a134fd743f085f8409aa8adb366
Author: Wenwu Hou [off-list ref]
tracing/hwlat: Bind the sampler kthread instead of setting its affinity
This commit replaces set_cpus_allowed_ptr() with kthread_bind_mask() in
start_single_kthread() and validates that tracing_cpumask overlaps with
cpu_online_mask before creating the hwlatd kthread.
quoted hunk ↗ jump to hunk
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 3fe274b84f1c2..65e184d800ff1 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -440,7 +437,14 @@ static int start_single_kthread(struct trace_array *tr)
}
- set_cpus_allowed_ptr(kthread, current_mask);
+ kthread = kthread_create(kthread_fn, NULL, "hwlatd");
+ if (IS_ERR(kthread)) {
+ pr_err(BANNER "could not start sampling thread\n");
+ cpus_read_unlock();
+ return -ENOMEM;
+ }
+
+ kthread_bind_mask(kthread, current_mask);
[Severity: Medium]
Does leaving PF_NO_SETAFFINITY set on hwlatd prevent userspace from
changing its CPU affinity or moving it into a cgroup?
kthread_bind_mask() sets PF_NO_SETAFFINITY, which kthread() only checks on
initial wake-up before calling kthread_fn(). Because kthread_fn() never
clears the flag, sched_setaffinity() and cgroup_attach_permissions()
reject hwlatd with -EINVAL in both round-robin and none modes. That also
makes the user-affinity override check in move_to_next_cpu() unreachable
from sched_setaffinity():
kernel/trace/trace_hwlat.c:move_to_next_cpu() {
/*
* If for some reason the user modifies the CPU affinity
* of this thread, then stop migrating for the duration
* of the current test.
*/
if (!cpumask_equal(current_mask, current->cpus_ptr))
goto change_mode;
...
}
Clearing PF_NO_SETAFFINITY in kthread_fn() once the thread has started, as
done in 4998e7fda149 ("tracing/osnoise: Switch from PF_NO_SETAFFINITY to
migrate_disable"), would avoid this regression while still skipping
kthread_affine_node() on the initial wake-up.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111020755.1422284-1-hwenwur@gmail.com?part=1