linux-s390.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS
@ 2026-08-06 15:53 Heiko Carstens
  2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Heiko Carstens @ 2026-08-06 15:53 UTC (permalink / raw)
  To: Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger
  Cc: linux-s390

Enable CONTEXT_ANALYSYS for s390/char drivers.

Static code checking for acquiring and releasing locks used to be done
with sparse. That was removed with [1] and replaced with a clang based
approach [2]. The new approach requires that each subsystem needs to be
explicitly enabled for checking.

Do that for drivers/s390/char. Add a __must_hold() attribute to
raw3215_make_room() to address the only valid warning.
Then enable CONTEXT_ANALYSIS.

Thanks,
Heiko

[1] 5b63d0ae94cc ("compiler-context-analysis: Remove Sparse support")
[2] 3269701cb256 ("compiler-context-analysis: Add infrastructure for Context Analysis with Clang")

Heiko Carstens (2):
  s390/con3215: Add __must_hold() attribute to raw3215_make_room()
  s390/char: Enable CONTEXT_ANALYSIS

 drivers/s390/char/Makefile  | 2 ++
 drivers/s390/char/con3215.c | 1 +
 2 files changed, 3 insertions(+)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room()
  2026-08-06 15:53 [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
@ 2026-08-06 15:53 ` Heiko Carstens
  2026-08-06 16:12   ` sashiko-bot
  2026-08-07  9:23   ` Sven Schnelle
  2026-08-06 15:53 ` [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
  2026-08-07 10:49 ` [PATCH 0/2] " Heiko Carstens
  2 siblings, 2 replies; 8+ messages in thread
From: Heiko Carstens @ 2026-08-06 15:53 UTC (permalink / raw)
  To: Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger
  Cc: linux-s390

Add __must_hold() attribute to raw3215_make_room() in order to let
clang's context analysis know that "get_ccwdev_lock(raw->cdev)" must be
held on function entry. This can also be easily verified when inspecting
the function.

Without this annotation this leads to a valid warning when context
analysis is enabled:

drivers/s390/char/con3215.c:485:9: warning:
  expecting spinlock 'raw->cdev->ccwlock' to be held at start of each loop [-Wthread-safety-analysis]
  485 |         while (RAW3215_BUFFER_SIZE - raw->count < length) {

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 drivers/s390/char/con3215.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 46265f4fbfd8..57fefa8986d6 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -481,6 +481,7 @@ static unsigned int raw3215_drop(struct raw3215_info *raw)
  */
 static unsigned int raw3215_make_room(struct raw3215_info *raw,
 				      unsigned int length, bool drop)
+	__must_hold(get_ccwdev_lock(raw->cdev))
 {
 	while (RAW3215_BUFFER_SIZE - raw->count < length) {
 		if (drop)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS
  2026-08-06 15:53 [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
  2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
@ 2026-08-06 15:53 ` Heiko Carstens
  2026-08-06 16:06   ` sashiko-bot
  2026-08-07  9:23   ` Sven Schnelle
  2026-08-07 10:49 ` [PATCH 0/2] " Heiko Carstens
  2 siblings, 2 replies; 8+ messages in thread
From: Heiko Carstens @ 2026-08-06 15:53 UTC (permalink / raw)
  To: Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger
  Cc: linux-s390

All character drivers pass clang's compile time context analysis.
Therefore enable CONTEXT_ANALYSIS.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 drivers/s390/char/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
index 126a87c3c6f8..0ad960d000a2 100644
--- a/drivers/s390/char/Makefile
+++ b/drivers/s390/char/Makefile
@@ -3,6 +3,8 @@
 # S/390 character devices
 #
 
+CONTEXT_ANALYSIS := y
+
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early setup code
 CFLAGS_REMOVE_sclp_early_core.o	= $(CC_FLAGS_FTRACE)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS
  2026-08-06 15:53 ` [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
@ 2026-08-06 16:06   ` sashiko-bot
  2026-08-07  9:23   ` Sven Schnelle
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-08-06 16:06 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Heiko Carstens, linux-s390, Vasily Gorbik, Alexander Gordeev

> All character drivers pass clang's compile time context analysis.
> Therefore enable CONTEXT_ANALYSIS.
> 
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806155303.2675932-1-hca@linux.ibm.com?part=2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room()
  2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
@ 2026-08-06 16:12   ` sashiko-bot
  2026-08-07  9:23   ` Sven Schnelle
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-08-06 16:12 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Heiko Carstens, Vasily Gorbik, linux-s390, Alexander Gordeev

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Use-After-Free during device removal due to concurrent lock dropping and missing console unregistration.
- [High] Sleeping in atomic context during panic/reboot on PREEMPT_RT.
--

--- Patch [1]: [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() ---
commit bdab109aec8f8a62fc73654df5f2f42b168ab432
Author: Heiko Carstens <hca@linux.ibm.com>

s390/con3215: Add __must_hold() attribute to raw3215_make_room()
    
Add __must_hold() attribute to raw3215_make_room() in order to let
clang's context analysis know that "get_ccwdev_lock(raw->cdev)" must be
held on function entry.

> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index 46265f4fbfd80..57fefa8986d6b 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -481,6 +481,7 @@ static unsigned int raw3215_drop(struct raw3215_info *raw)
>   */
>  static unsigned int raw3215_make_room(struct raw3215_info *raw,
>  				      unsigned int length, bool drop)
> +	__must_hold(get_ccwdev_lock(raw->cdev))
>  {
>  	while (RAW3215_BUFFER_SIZE - raw->count < length) {
>  		if (drop)

[Severity: Critical]
This is a pre-existing issue, but can this sequence lead to a use-after-free
if a concurrent device unbind occurs?

When raw3215_make_room() yields the lock and sleeps, it does so without any
reference counting:

drivers/s390/char/con3215.c:raw3215_make_room() {
    ...
		/* there might be another cpu waiting for the lock */
		spin_unlock(get_ccwdev_lock(raw->cdev));
		udelay(100);
		spin_lock(get_ccwdev_lock(raw->cdev));
    ...
}

If con3215_write() calls raw3215_make_room() and drops the lock here,
could a concurrent sysfs unbind invoke raw3215_remove(), which nullifies
raw3215[0] and calls kfree(raw) without unregistering the console or
synchronizing with the ccwlock?

When raw3215_make_room() wakes up from the udelay, it appears it would
directly dereference the freed raw pointer when calling spin_lock().

[Severity: High]
This is also a pre-existing issue, but does this spin_lock() introduce a
sleepable lock acquisition into an atomic panic context on PREEMPT_RT?

When the system panics or reboots, con3215_notify() uses
spin_trylock_irqsave() to avoid sleeping, as local IRQs are disabled.

If it then calls raw3215_make_room() and the buffer is full, the code drops
the lock and unconditionally calls spin_lock(). On PREEMPT_RT kernels,
spin_lock() maps to a sleepable rt_mutex.

Could calling this with hardware interrupts disabled violate wait-context
rules and trigger a sleeping-in-atomic bug?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806155303.2675932-1-hca@linux.ibm.com?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room()
  2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
  2026-08-06 16:12   ` sashiko-bot
@ 2026-08-07  9:23   ` Sven Schnelle
  1 sibling, 0 replies; 8+ messages in thread
From: Sven Schnelle @ 2026-08-07  9:23 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Alexander Gordeev, Vasily Gorbik, Christian Borntraeger,
	linux-s390

Heiko Carstens <hca@linux.ibm.com> writes:

> Add __must_hold() attribute to raw3215_make_room() in order to let
> clang's context analysis know that "get_ccwdev_lock(raw->cdev)" must be
> held on function entry. This can also be easily verified when inspecting
> the function.
>
> Without this annotation this leads to a valid warning when context
> analysis is enabled:
>
> drivers/s390/char/con3215.c:485:9: warning:
>   expecting spinlock 'raw->cdev->ccwlock' to be held at start of each loop [-Wthread-safety-analysis]
>   485 |         while (RAW3215_BUFFER_SIZE - raw->count < length) {
>
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
>  drivers/s390/char/con3215.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index 46265f4fbfd8..57fefa8986d6 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -481,6 +481,7 @@ static unsigned int raw3215_drop(struct raw3215_info *raw)
>   */
>  static unsigned int raw3215_make_room(struct raw3215_info *raw,
>  				      unsigned int length, bool drop)
> +	__must_hold(get_ccwdev_lock(raw->cdev))
>  {
>  	while (RAW3215_BUFFER_SIZE - raw->count < length) {
>  		if (drop)

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS
  2026-08-06 15:53 ` [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
  2026-08-06 16:06   ` sashiko-bot
@ 2026-08-07  9:23   ` Sven Schnelle
  1 sibling, 0 replies; 8+ messages in thread
From: Sven Schnelle @ 2026-08-07  9:23 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Alexander Gordeev, Vasily Gorbik, Christian Borntraeger,
	linux-s390

Heiko Carstens <hca@linux.ibm.com> writes:

> All character drivers pass clang's compile time context analysis.
> Therefore enable CONTEXT_ANALYSIS.
>
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
>  drivers/s390/char/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
> index 126a87c3c6f8..0ad960d000a2 100644
> --- a/drivers/s390/char/Makefile
> +++ b/drivers/s390/char/Makefile
> @@ -3,6 +3,8 @@
>  # S/390 character devices
>  #
>  
> +CONTEXT_ANALYSIS := y
> +
>  ifdef CONFIG_FUNCTION_TRACER
>  # Do not trace early setup code
>  CFLAGS_REMOVE_sclp_early_core.o	= $(CC_FLAGS_FTRACE)

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS
  2026-08-06 15:53 [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
  2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
  2026-08-06 15:53 ` [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
@ 2026-08-07 10:49 ` Heiko Carstens
  2 siblings, 0 replies; 8+ messages in thread
From: Heiko Carstens @ 2026-08-07 10:49 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Alexander Gordeev, Sven Schnelle, Vasily Gorbik,
	Christian Borntraeger, linux-s390

On Thu, Aug 06, 2026 at 05:53:01PM +0200, Heiko Carstens wrote:
> Enable CONTEXT_ANALYSYS for s390/char drivers.
...
> Heiko Carstens (2):
>   s390/con3215: Add __must_hold() attribute to raw3215_make_room()
>   s390/char: Enable CONTEXT_ANALYSIS
> 
>  drivers/s390/char/Makefile  | 2 ++
>  drivers/s390/char/con3215.c | 1 +
>  2 files changed, 3 insertions(+)

Applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-07 10:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 15:53 [PATCH 0/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
2026-08-06 15:53 ` [PATCH 1/2] s390/con3215: Add __must_hold() attribute to raw3215_make_room() Heiko Carstens
2026-08-06 16:12   ` sashiko-bot
2026-08-07  9:23   ` Sven Schnelle
2026-08-06 15:53 ` [PATCH 2/2] s390/char: Enable CONTEXT_ANALYSIS Heiko Carstens
2026-08-06 16:06   ` sashiko-bot
2026-08-07  9:23   ` Sven Schnelle
2026-08-07 10:49 ` [PATCH 0/2] " Heiko Carstens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).