From: Thomas Richter <tmricht@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-s390@vger.kernel.org, Heiko Carstens <hca@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH] s390/pai: Prevent ioctl(PERF_EVENT_IOC_REFRESH)
Date: Mon, 31 Aug 2026 11:45:57 +0200 [thread overview]
Message-ID: <d3ad41b1-909d-48a7-af89-2234a9a84627@linux.ibm.com> (raw)
In-Reply-To: <20260827065709.D6E561F000E9@smtp.kernel.org>
On 8/27/26 08:57, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] Unprotected modification of core perf_event state (pending_kill, event_limit) causes data races, dropped signals, and silently breaks the PERF_EVENT_IOC_REFRESH API.
> --
>
> commit ae843d6ca679921720078776be6911f36a1931c1
> Author: Thomas Richter <tmricht@linux.ibm.com>
>
> s390/pai: Prevent ioctl(PERF_EVENT_IOC_REFRESH)
>
> This commit prevents ioctl(fd, PERF_EVENT_IOC_REFRESH, XXX) from taking effect
> on PAI PMU events by clearing event->pending_kill and event->event_limit. The
> intention is to prevent counter resets that conflict with the schedule-out
> readouts these PMUs are designed for.
>
>> diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
>> index cdb8006220ca0..e43b2f1c94471 100644
>> --- a/arch/s390/kernel/perf_pai.c
>> +++ b/arch/s390/kernel/perf_pai.c
>> @@ -658,6 +658,8 @@ static void pai_have_sample(struct perf_event *event, struct pai_map *cpump)
>>
>> if (!event) /* No event active */
>> return;
>> + event->pending_kill = 0; /* prevent ioctl(IOC_REFRESH) */
>> + atomic_set(&event->event_limit, 0);
>
> [Severity: High]
> Does this unprotected modification of core perf_event state (pending_kill,
> event_limit) cause data races, dropped signals, and silently break the
> PERF_EVENT_IOC_REFRESH API?
>
> Bypassing core perf locking rules to directly mutate event_limit and
> pending_kill causes data races, silently drops pending SIGIO signals, and
> breaks the API contract. The ioctl will return success, but userspace will
> never receive the requested signal, leading to application hangs.
A: The PERF_EVENT_IOC_REFRESH API is disabled on purpose. The PAI PMU
relies on data collection on schedule out of a task. This is
done by design. Invoking ioctl(fd, PERF_EVENT_IOC_REFRESH API, X)
breaks this behavior and should be blocked.
The modifications of members perf_event::event_limit and
perf_event::pending_kill are protected. The invocation
is triggered by the schedule out path and protected via
perf_pmu_sched_task()
+--> __perf_pmu_sched_task()
+--> perf_ctx_lock()
This locks the event and protects the states of the event.
>
> If a userspace application calls ioctl(fd, PERF_EVENT_IOC_REFRESH, N) on a
> PAI event, and concurrently, a context switch calls pai_have_sample(),
> writing to event_limit will race with atomic_add() in the core subsystem,
> and clearing pending_kill will race with perf_event_wakeup().
This requires a common code change to block an ioctl(fd, PERF_EVENT_IOC_REFRESH, N)
similar to the PMU check_period call back function.
>
> PMU drivers should not directly mutate these core fields to implicitly break
> an ioctl. This approach creates cross-CPU data races because it lacks the
> synchronization (ctx->mutex for limits, irq_work execution order for signals)
> used by the core subsystem. Any user with access to the PAI PMU can trigger
> this state corruption.
>
>> pp = &pai_pmu[PAI_PMU_IDX(event)];
>> rawsize = pai_copy(cpump->save, cpump->area, pp,
>> (unsigned long *)PAI_SAVE_AREA(event),
>
--
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
next prev parent reply other threads:[~2026-08-31 9:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 6:46 [PATCH] s390/pai: Prevent ioctl(PERF_EVENT_IOC_REFRESH) Thomas Richter
2026-08-27 6:57 ` sashiko-bot
2026-08-31 9:45 ` Thomas Richter [this message]
2026-08-31 13:49 ` Heiko Carstens
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=d3ad41b1-909d-48a7-af89-2234a9a84627@linux.ibm.com \
--to=tmricht@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox