From: sashiko-bot@kernel.org
To: "Wenwu Hou" <hwenwur@gmail.com>, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing/hwlat: Bind the sampler kthread instead of setting its affinity
Date: Wed, 11 Nov 2026 02:54:09 +0000 [thread overview]
Message-ID: <sashiko-outbox-208125@kernel.org> (raw)
In-Reply-To: <20261111020755.1422284-1-hwenwur@gmail.com>
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 <hwenwur@gmail.com>
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.
> 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
prev parent reply other threads:[~2026-11-11 2:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 2:07 [PATCH] tracing/hwlat: Bind the sampler kthread instead of setting its affinity Wenwu Hou
2026-11-11 2:54 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-208125@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hwenwur@gmail.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.