From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Aboorva Devarajan <aboorvad@linux.ibm.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
linuxppc-dev@lists.ozlabs.org
Cc: Aboorva Devarajan <aboorvad@linux.ibm.com>,
Christophe Leroy <chleroy@kernel.org>,
Kajol Jain <kjain@linux.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/hv-gpci: fix preempt count leak in sysfs show paths
Date: Mon, 11 May 2026 07:07:32 +0530 [thread overview]
Message-ID: <5x4usp43.ritesh.list@gmail.com> (raw)
In-Reply-To: <20260508041256.3447113-1-aboorvad@linux.ibm.com>
Aboorva Devarajan <aboorvad@linux.ibm.com> writes:
> Four sysfs show() callbacks in hv-gpci take get_cpu_var(hv_gpci_reqb)
> (which calls preempt_disable()) but only call the matching put_cpu_var()
> on the error path under the 'out:' label. Every successful read leaks
> one preempt_disable():
>
> processor_bus_topology_show()
> processor_config_show()
> affinity_domain_via_virtual_processor_show()
> affinity_domain_via_domain_show()
>
> (affinity_domain_via_partition_show() was already correct.)
>
> On a CONFIG_PREEMPT=y kernel, repeated reads raise preempt_count and
> eventually return to userspace with preemption still disabled. The
> next user-mode page fault then hits faulthandler_disabled() == 1,
> gets forced to SIGSEGV, and the resulting coredump trips
> 'BUG: scheduling while atomic' in call_usermodehelper_exec ->
> wait_for_completion_state -> schedule:
>
> BUG: scheduling while atomic: <task>/<pid>/0x00000004
> ...
> __schedule_bug+0x6c/0x90
> __schedule+0x58c/0x13a0
> schedule+0x48/0x1a0
> schedule_timeout+0x104/0x170
> wait_for_completion_state+0x16c/0x330
> call_usermodehelper_exec+0x254/0x2d0
> vfs_coredump+0x1050/0x2590
> get_signal+0xb9c/0xc80
> do_notify_resume+0xf8/0x470
>
> Add an out_success label that calls put_cpu_var() before returning
> the byte count, mirroring affinity_domain_via_partition_show().
Yup. That seems like the right thing to do otherwise we leak preempt
count.
I guess, these would be the other kind of issues which might show up now,
since powerpc is moved to CONFIG_PREEMPTION=y with lazy preempt as the
default preemption mode. It will be nice to have some mechanism to catch
these error handling paths where preempt counts might be getting leaked.
Nice Catch! As for this patch, it looks to me.
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
prev parent reply other threads:[~2026-05-11 1:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 4:12 [PATCH] powerpc/hv-gpci: fix preempt count leak in sysfs show paths Aboorva Devarajan
2026-05-11 1:37 ` Ritesh Harjani [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=5x4usp43.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=aboorvad@linux.ibm.com \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=chleroy@kernel.org \
--cc=kjain@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
/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