From: Thomas Richter <tmricht@linux.ibm.com>
To: linux-s390@vger.kernel.org
Cc: Thomas Richter <tmricht@linux.ibm.com>
Subject: [PATCH] s390/pai: Handle CPU hotplug add for PAI PMU
Date: Fri, 31 Jul 2026 10:40:11 +0200 [thread overview]
Message-ID: <20260731084011.2568310-1-tmricht@linux.ibm.com> (raw)
The command 'perf stat -e pai_crypto/CRYPTO_ALL/ -- <command>
crashes the kernel when CPUs are hotplug added during that run.
Root cause is the allocation of struct pai_mapptr at first
event initialization. The allocation is dynamic and the first
event that has task context creates such a structure for
each online CPU. This is not sufficient. CPUs may be offline
during event creation and can be set online during the
perf run time. For example commands
# echo 0 > /sys/devices/system/cpu/cpu1/online
# perf stat -e pai_crypto/CRYPTO_ALL/ -i -- stress-ng -t10s --matrix X
# sleep 1
# echo 1 > /sys/devices/system/cpu/cpu1/online
create an event for CPUs 0,2-X. Since the events are created with
task-context, the scheduler will eventually schedule the program
on CPU1. This CPU has not created and initialized any per
CPU event infrastructure as that CPU was not online at the time
of the perf invocation. Thus when the scheduler runs stress-ng
on CPU1, the function pai_add() refers to a NULL pointer:
struct pai_mapptr *mp = this_cpu_ptr(pai_root[idx].mapptr);
This function call is invoked after the task stress-ng has been
made runnable on CPU1. And variable mp is a NULL pointer.
The result is a panic.
Allocate the necessary per CPU event handling infrastructure for all
possible CPUs, not just the ones currently online.
Fixes: 92ea686840ac ("s390/pai_crypto: Enable per-task counting event")
Cc: <Stable@vger.kernel.org> # v6.11+
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
---
arch/s390/kernel/perf_pai.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
index cdb8006220ca..793bda20df14 100644
--- a/arch/s390/kernel/perf_pai.c
+++ b/arch/s390/kernel/perf_pai.c
@@ -325,7 +325,7 @@ static int pai_alloc(struct perf_event *event)
if (!maskptr)
goto out;
- for_each_online_cpu(cpu) {
+ for_each_possible_cpu(cpu) {
rc = pai_alloc_cpu(event, cpu);
if (rc) {
for_each_cpu(cpu, maskptr)
--
2.55.0
next reply other threads:[~2026-07-31 8:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 8:40 Thomas Richter [this message]
2026-07-31 8:47 ` [PATCH] s390/pai: Handle CPU hotplug add for PAI PMU sashiko-bot
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=20260731084011.2568310-1-tmricht@linux.ibm.com \
--to=tmricht@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox