Commit 5bfbcd1
committed
tracing/timerlat: Add interface_lock around clearing of kthread in stop_kthread()
The timerlat interface will get and put the task that is part of the
"kthread" field of the osn_var to keep it around until all references are
released. But here's a race in the "stop_kthread()" code that will call
put_task_struct() on the kthread if it is not a kernel thread. This can
race with the releasing of the references to that task struct and the
put_task_struct() can be called twice when it should have been called just
once.
Take the interface_lock() in stop_kthread() to synchronize this change.
But to do so, the function stop_per_cpu_kthreads() needs to change the
loop from for_each_online_cpu() to for_each_possible_cpu() and remove the
cpu_read_lock(), as the interface_lock can not be taken while the cpu
locks are held. The only side effect of this change is that it may do some
extra work, as the per_cpu variables of the offline CPUs would not be set
anyway, and would simply be skipped in the loop.
Remove unneeded "return;" in stop_kthread().
Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Tomas Glozar <tglozar@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com>
Link: https://lore.kernel.org/20240905113359.2b934242@gandalf.local.home
Fixes: e88ed22 ("tracing/timerlat: Add user-space interface")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>1 parent e6a5348 commit 5bfbcd1
1 file changed
Lines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1953 | 1953 | | |
1954 | 1954 | | |
1955 | 1955 | | |
| 1956 | + | |
1956 | 1957 | | |
1957 | 1958 | | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
1958 | 1962 | | |
1959 | 1963 | | |
1960 | 1964 | | |
| |||
1967 | 1971 | | |
1968 | 1972 | | |
1969 | 1973 | | |
1970 | | - | |
1971 | 1974 | | |
| 1975 | + | |
1972 | 1976 | | |
1973 | 1977 | | |
1974 | 1978 | | |
1975 | 1979 | | |
1976 | 1980 | | |
1977 | 1981 | | |
1978 | 1982 | | |
1979 | | - | |
1980 | 1983 | | |
1981 | 1984 | | |
1982 | 1985 | | |
| |||
1991 | 1994 | | |
1992 | 1995 | | |
1993 | 1996 | | |
1994 | | - | |
1995 | | - | |
1996 | | - | |
| 1997 | + | |
1997 | 1998 | | |
1998 | | - | |
1999 | | - | |
2000 | 1999 | | |
2001 | 2000 | | |
2002 | 2001 | | |
| |||
0 commit comments