Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Aleksei Nikiforov <aleksei.nikiforov@linux.ibm.com>
To: linux-s390@vger.kernel.org
Cc: aleksei.nikiforov@linux.ibm.com
Subject: [PATCH] kmsan: fix false warnings in return_address on s390
Date: Mon, 31 Aug 2026 17:28:12 +0200	[thread overview]
Message-ID: <20260831152811.3817938-2-aleksei.nikiforov@linux.ibm.com> (raw)

Function return_address manually traverses stack frames
using backchain on s390.
Stack frames are written to stack in function prologues
and are not marked as written for kmsan.
This may lead to previous mark being used.

Let's assume that there was an unitialized area on stack.
Later backchain and other information is written there
in function prologue.
kmsan markings are unchanged in prologue.
That means data is actually initialized but incorrectly marked.
And when data is read, a false warning is emitted.

It might be possible to fix marking data written in prologue of function,
but it may be somewhat complex, especially in leaf functions
where no stack for next function call is allocated yet
and new function call would be required for kmsan helper function.

Other approach is to mark return_address function as noinstr
to skip kmsan checks there. That's approach in this patch.

When kmsan is enabled, a special noinstr wrapper function is used.
Since one more function call is introduced,
depth n of backtrace is incremented to account for this function call.

Fix false warnings like following one:

[    1.017151] =====================================================
[    1.017218] BUG: KMSAN: uninit-value in trace_hardirqs_off+0x134/0x5e0
[    1.017280]  trace_hardirqs_off+0x134/0x5e0
[    1.017330]  _raw_spin_lock_irqsave+0x74/0xc0
[    1.017375]  get_from_partial_node+0x112/0x1df0
[    1.017424]  ___slab_alloc+0x27c/0x29a0
[    1.017466]  __kmalloc_noprof+0x442/0x1cb0
[    1.017507]  alloc_workqueue_va+0x188/0x3f30
[    1.017552]  alloc_workqueue_noprof+0x236/0x260
[    1.017595]  kmem_cache_init_late+0x44/0xe0
[    1.017648]  start_kernel+0x57a/0xcd0
[    1.017689]  startup_continue+0x2e/0x40
[    1.017724]
[    1.017732] Local variable old created at:
[    1.017747]  get_from_partial_node+0x35c/0x1df0
[    1.017790]
[    1.017804] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.2.0 #54 PREEMPT
[    1.017859] Hardware name: IBM 8561 T01 703 (KVM/Linux)
[    1.017877] =====================================================

Signed-off-by: Aleksei Nikiforov <aleksei.nikiforov@linux.ibm.com>
---
 arch/s390/include/asm/ftrace.h | 6 ++++++
 arch/s390/kernel/stacktrace.c  | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/arch/s390/include/asm/ftrace.h b/arch/s390/include/asm/ftrace.h
index 692c484ec163..9a9f7f2f2c36 100644
--- a/arch/s390/include/asm/ftrace.h
+++ b/arch/s390/include/asm/ftrace.h
@@ -23,7 +23,13 @@ static __always_inline unsigned long return_address(unsigned int n)
 	} while (--n);
 	return sf->gprs[8];
 }
+
+#ifdef CONFIG_KMSAN
+unsigned long return_address_noinstr(unsigned int n);
+#define ftrace_return_address(n) return_address_noinstr(n)
+#else
 #define ftrace_return_address(n) return_address(n)
+#endif
 
 void ftrace_caller(void);
 
diff --git a/arch/s390/kernel/stacktrace.c b/arch/s390/kernel/stacktrace.c
index 18520d333058..db458050d8bf 100644
--- a/arch/s390/kernel/stacktrace.c
+++ b/arch/s390/kernel/stacktrace.c
@@ -146,3 +146,11 @@ void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
 {
 	arch_stack_walk_user_common(consume_entry, cookie, NULL, regs, false);
 }
+
+#ifdef CONFIG_KMSAN
+noinstr unsigned long return_address_noinstr(unsigned int n)
+{
+	/* Add 1 to account for call of uninlined function return_address_noinstr */
+	return return_address(n+1);
+}
+#endif
-- 
2.43.7


             reply	other threads:[~2026-08-31 15:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 15:28 Aleksei Nikiforov [this message]
2026-08-31 18:48 ` [PATCH] kmsan: fix false warnings in return_address on s390 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=20260831152811.3817938-2-aleksei.nikiforov@linux.ibm.com \
    --to=aleksei.nikiforov@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