From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Kevin Brodsky <kevin.brodsky@arm.com>,
David Hildenbrand <david@redhat.com>
Subject: [PATCH -next v4 4/4] s390/mm: Lazy MMU mode sanitizer
Date: Thu, 18 Jun 2026 16:47:28 +0200 [thread overview]
Message-ID: <638d47ee200c586a119ac725864f381fe75eefa9.1781789772.git.agordeev@linux.ibm.com> (raw)
In-Reply-To: <cover.1781789772.git.agordeev@linux.ibm.com>
Detect PTE entries access in lazy MMU mode by means other
than set_pte() and ptep_get() primitives, which would be
a read hazard.
The access to kasan shadow memory from ptep_get_lockless()
mistakenly hits invalid access in case a concurrent lazy
MMU access to the same PTE is happening. To avoid that
disable instrumentation for ptep_get_lockless() altogether.
Suggested-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
arch/s390/include/asm/pgtable.h | 6 ++++++
arch/s390/mm/lazy_mmu.c | 27 +++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 2b6659d61fa5..a93e7e786457 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1047,6 +1047,12 @@ static inline void set_pte(pte_t *ptep, pte_t pte)
__set_pte(ptep, pte);
}
+#define ptep_get_lockless ptep_get_lockless
+static inline __no_sanitize_address pte_t ptep_get_lockless(pte_t *ptep)
+{
+ return READ_ONCE(*ptep);
+}
+
static inline pte_t __ptep_get(pte_t *ptep)
{
return READ_ONCE(*ptep);
diff --git a/arch/s390/mm/lazy_mmu.c b/arch/s390/mm/lazy_mmu.c
index d75b93d9b0de..ee2385897bc7 100644
--- a/arch/s390/mm/lazy_mmu.c
+++ b/arch/s390/mm/lazy_mmu.c
@@ -63,10 +63,13 @@ static int invalidate_pte_range(struct mm_struct *mm, unsigned long addr,
}
static void set_pte_range(struct mm_struct *mm, unsigned long addr,
- pte_t *ptep, pte_t *end, pte_t *cache)
+ pte_t *start, pte_t *end, pte_t *cache)
{
- int i, nr_ptes;
+ int nr_ptes, nr_total = end - start;
+ pte_t *ptep = start;
+ int i;
+ kasan_unpoison_pte(start, nr_total);
while (ptep < end) {
nr_ptes = invalidate_pte_range(mm, addr, ptep, end);
@@ -77,6 +80,7 @@ static void set_pte_range(struct mm_struct *mm, unsigned long addr,
addr += nr_ptes * PAGE_SIZE;
}
+ kasan_poison_pte(start, nr_total);
}
static void enter_ipte_norange(void)
@@ -94,6 +98,7 @@ static void enter_ipte_range(struct mm_struct *mm,
unsigned long addr, unsigned long end, pte_t *pte)
{
struct ipte_range *range;
+ unsigned int nr_ptes;
if (!test_facility(13))
return;
@@ -105,6 +110,9 @@ static void enter_ipte_range(struct mm_struct *mm,
range->base_addr = addr;
range->base_end = end;
range->base_pte = pte;
+
+ nr_ptes = (range->base_end - range->base_addr) / PAGE_SIZE;
+ kasan_poison_pte(range->base_pte, nr_ptes);
}
static void leave_ipte_range(void)
@@ -112,6 +120,7 @@ static void leave_ipte_range(void)
pte_t *ptep, *start, *start_cache, *cache;
unsigned long start_addr, addr;
struct ipte_range *range;
+ unsigned int nr_ptes;
int start_idx;
if (!test_facility(13))
@@ -148,6 +157,9 @@ static void leave_ipte_range(void)
range->end_pte = NULL;
done:
+ nr_ptes = (range->base_end - range->base_addr) / PAGE_SIZE;
+ kasan_unpoison_pte(range->base_pte, nr_ptes);
+
range->mm = NULL;
range->base_addr = 0;
range->base_end = 0;
@@ -227,10 +239,17 @@ static void __ipte_range_set_pte(struct ipte_range *range, pte_t *ptep, pte_t pt
static pte_t __ipte_range_ptep_get(struct ipte_range *range, pte_t *ptep)
{
unsigned int idx = ptep - range->base_pte;
+ pte_t pte;
lockdep_assert_preemption_disabled();
- if (pte_val(range->cache[idx]) == PTE_POISON)
- return __ptep_get(ptep);
+ if (pte_val(range->cache[idx]) == PTE_POISON) {
+ kasan_unpoison_pte(ptep, 1);
+ pte = __ptep_get(ptep);
+ kasan_poison_pte(ptep, 1);
+
+ return pte;
+ }
+
return range->cache[idx];
}
--
2.53.0
prev parent reply other threads:[~2026-06-18 14:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 14:47 [PATCH -next v4 0/4] s390/mm: Batch PTE updates in lazy MMU mode Alexander Gordeev
2026-06-18 14:47 ` [PATCH -next v4 1/4] mm: Make lazy MMU mode context-aware Alexander Gordeev
2026-06-18 14:47 ` [PATCH -next v4 2/4] s390/mm: Batch PTE updates in lazy MMU mode Alexander Gordeev
2026-06-18 14:47 ` [PATCH -next v4 3/4] mm/kasan: Introduce helpers for lazy MMU mode sanitizer Alexander Gordeev
2026-06-18 14:47 ` Alexander Gordeev [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=638d47ee200c586a119ac725864f381fe75eefa9.1781789772.git.agordeev@linux.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kevin.brodsky@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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
all inboxes | Powered by JetHome®