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>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Muhammad Usama Anjum <usama.anjum@arm.com>,
linux-s390@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com
Subject: [PATCH v8 15/15] s390/mm: Lazy MMU mode sanitizer
Date: Wed, 7 Oct 2026 13:41:58 +0200 [thread overview]
Message-ID: <1890ee88ced60e0d03d88e681b7e6dde6a6158fa.1791365932.git.agordeev@linux.ibm.com> (raw)
In-Reply-To: <cover.1791365932.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 decce76fac74..47f0adfc1029 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1063,6 +1063,12 @@ static inline void set_pte(hw_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(hw_pte_t *ptep)
+{
+ return __pte_from_hw(READ_ONCE(*ptep));
+}
+
static inline pte_t __ptep_get(hw_pte_t *ptep)
{
return __pte_from_hw(READ_ONCE(*ptep));
diff --git a/arch/s390/mm/lazy_mmu.c b/arch/s390/mm/lazy_mmu.c
index 8c1a62f23736..e29afa081061 100644
--- a/arch/s390/mm/lazy_mmu.c
+++ b/arch/s390/mm/lazy_mmu.c
@@ -65,10 +65,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,
- hw_pte_t *ptep, hw_pte_t *end, pte_t *cache)
+ hw_pte_t *start, hw_pte_t *end, pte_t *cache)
{
- int i, nr_ptes;
+ int nr_ptes, nr_total = end - start;
+ hw_pte_t *ptep = start;
+ int i;
+ kasan_unpoison_pte(start, nr_total);
while (ptep < end) {
nr_ptes = invalidate_pte_range(mm, addr, ptep, end);
@@ -79,6 +82,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)
@@ -98,6 +102,7 @@ static void enter_ipte_range(struct mm_struct *mm,
unsigned long addr, unsigned long end, hw_pte_t *pte)
{
struct ipte_range *range;
+ unsigned int nr_ptes;
if (!static_branch_likely(&lazy_mmu_enabled))
return;
@@ -116,6 +121,9 @@ static void enter_ipte_range(struct mm_struct *mm,
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);
+
local_bh_enable();
}
@@ -125,6 +133,7 @@ static void leave_ipte_range(void)
pte_t *start_cache, *cache;
hw_pte_t *ptep, *start;
struct ipte_range *range;
+ unsigned int nr_ptes;
int start_idx;
if (!static_branch_likely(&lazy_mmu_enabled))
@@ -163,6 +172,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;
@@ -244,10 +256,17 @@ static void __ipte_range_set_pte(struct ipte_range *range, hw_pte_t *ptep, pte_t
static pte_t __ipte_range_ptep_get(struct ipte_range *range, hw_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-10-07 11:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 11:41 [PATCH v8 00/15] s390/mm: Batch PTE updates in lazy MMU mode Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 01/15] mm: introduce hw_pte_t for PTE table storage Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 02/15] mm: rename pointers to software PTE values as ptentp Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 03/15] mm: use hw_pte_t for generic PTE table storage Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 04/15] mm: convert PTE table entries in ptep_get() Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 05/15] mm: convert PTE table entry to pte Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 06/15] mm: add hw_pte_val for HW PTE storage Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 07/15] mm/kasan: use hw_pte_t for the early shadow PTE table Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 08/15] drm/i915: use hw_pte_t for PTE range callbacks Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 09/15] xen: " Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 10/15] s390/mm: Cleanup pXXp_flush_lazy() routines Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 11/15] s390: Distinguish hardware and software PTEs Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 12/15] mm: Make lazy MMU mode context-aware Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 13/15] s390/mm: Batch PTE updates in lazy MMU mode Alexander Gordeev
2026-10-07 11:41 ` [PATCH v8 14/15] mm/kasan: Introduce helpers for lazy MMU mode sanitizer Alexander Gordeev
2026-10-07 20:24 ` kernel test robot
2026-10-07 20:35 ` kernel test robot
2026-10-07 11:41 ` 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=1890ee88ced60e0d03d88e681b7e6dde6a6158fa.1791365932.git.agordeev@linux.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=usama.anjum@arm.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
all inboxes | Powered by JetHome®