* [PATCH] s390/mm: Skip holes in identity mapping in set_memory()
@ 2026-11-29 16:53 Heiko Carstens
0 siblings, 0 replies; only message in thread
From: Heiko Carstens @ 2026-11-29 16:53 UTC (permalink / raw)
To: Alexander Gordeev, Sven Schnelle, Vasily Gorbik, Christian Borntraeger
Cc: Mike Rapoport, linux-kernel, linux-s390
With debug_pagealloc=on, vmem_map_init() panics with "Failed to set
kernel mapping permissions" if the identity mapping contains holes, e.g.
standby memory. __set_memory_4k() is called for [0, ident_map_size),
which may include holes, and change_page_attr() returns -EINVAL for the
first empty page table entry, which was silently ignored before [1].
Fix this by skipping empty entries if the range is within the identity
mapping, similar to x86.
Note: the fixes tag points to the commit which reveals this bug, but it
exists since much longer. Nobody noticed so far, since hardly anybody
uses debug_pagealloc, and also hardly anybody has configurations with
holes within the identity mapping.
Fixes: 4634f260683b ("s390/mm: Add error handling to vmem_map_init()") [1]
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/mm/pageattr.c | 53 +++++++++++++++++++++++++++++++----------
1 file changed, 41 insertions(+), 12 deletions(-)
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index 80e834e8b8e1..e744a61651b9 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -76,6 +76,13 @@ static void pgt_set(unsigned long *old, unsigned long new, unsigned long addr,
}
}
+static bool is_identity_range(unsigned long addr, unsigned long end)
+{
+ unsigned long identity_end = __identity_base + ident_map_size;
+
+ return addr >= __identity_base && end <= identity_end;
+}
+
static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,
unsigned long flags)
{
@@ -86,8 +93,11 @@ static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,
ptep = pte_offset_kernel(pmdp, addr);
do {
new = ptep_get(ptep);
- if (pte_none(new))
- return -EINVAL;
+ if (pte_none(new)) {
+ if (!is_identity_range(addr, addr + PAGE_SIZE))
+ return -EINVAL;
+ goto skip;
+ }
if (flags & SET_MEMORY_RO)
new = pte_wrprotect(new);
else if (flags & SET_MEMORY_RW)
@@ -103,6 +113,7 @@ static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,
new = set_pte_bit(new, PAGE_KERNEL);
}
pgt_set((unsigned long *)ptep, pte_val(new), addr, CRDTE_DTT_PAGE);
+skip:
ptep++;
addr += PAGE_SIZE;
} while (addr < end);
@@ -172,9 +183,12 @@ static int walk_pmd_level(pud_t *pudp, unsigned long addr, unsigned long end,
pmdp = pmd_offset(pudp, addr);
do {
pmd = pmdp_get(pmdp);
- if (pmd_none(pmd))
- return -EINVAL;
next = pmd_addr_end(addr, end);
+ if (pmd_none(pmd)) {
+ if (!is_identity_range(addr, next))
+ return -EINVAL;
+ goto skip;
+ }
if (pmd_leaf(pmd)) {
need_split = !!(flags & SET_MEMORY_4K);
need_split |= !!(addr & ~PMD_MASK);
@@ -191,6 +205,7 @@ static int walk_pmd_level(pud_t *pudp, unsigned long addr, unsigned long end,
if (rc)
return rc;
}
+skip:
pmdp++;
addr = next;
} while (addr < end);
@@ -260,9 +275,12 @@ static int walk_pud_level(p4d_t *p4d, unsigned long addr, unsigned long end,
pudp = pud_offset(p4d, addr);
do {
pud = pudp_get(pudp);
- if (pud_none(pud))
- return -EINVAL;
next = pud_addr_end(addr, end);
+ if (pud_none(pud)) {
+ if (!is_identity_range(addr, next))
+ return -EINVAL;
+ goto skip;
+ }
if (pud_leaf(pud)) {
need_split = !!(flags & SET_MEMORY_4K);
need_split |= !!(addr & ~PUD_MASK);
@@ -277,6 +295,7 @@ static int walk_pud_level(p4d_t *p4d, unsigned long addr, unsigned long end,
} else {
rc = walk_pmd_level(pudp, addr, next, flags);
}
+skip:
pudp++;
addr = next;
} while (addr < end && !rc);
@@ -292,10 +311,14 @@ static int walk_p4d_level(pgd_t *pgd, unsigned long addr, unsigned long end,
p4dp = p4d_offset(pgd, addr);
do {
- if (p4d_none(p4dp_get(p4dp)))
- return -EINVAL;
next = p4d_addr_end(addr, end);
+ if (p4d_none(p4dp_get(p4dp))) {
+ if (!is_identity_range(addr, next))
+ return -EINVAL;
+ goto skip;
+ }
rc = walk_pud_level(p4dp, addr, next, flags);
+skip:
p4dp++;
addr = next;
} while (addr < end && !rc);
@@ -308,18 +331,24 @@ static int change_page_attr(unsigned long addr, unsigned long end,
unsigned long flags)
{
unsigned long next;
- int rc = -EINVAL;
pgd_t *pgdp;
+ int rc = 0;
pgdp = pgd_offset_k(addr);
do {
- if (pgd_none(pgdp_get(pgdp)))
- break;
next = pgd_addr_end(addr, end);
+ if (pgd_none(pgdp_get(pgdp))) {
+ if (!is_identity_range(addr, next))
+ return -EINVAL;
+ goto skip;
+ }
rc = walk_p4d_level(pgdp, addr, next, flags);
if (rc)
break;
- } while (pgdp++, addr = next, addr < end && !rc);
+skip:
+ pgdp++;
+ addr = next;
+ } while (addr < end && !rc);
return rc;
}
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-29 16:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 16:53 [PATCH] s390/mm: Skip holes in identity mapping in set_memory() Heiko Carstens
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®