Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Mike Rapoport <rppt@kernel.org>,
	linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH] s390/mm: Skip holes in identity mapping in set_memory()
Date: Sun, 29 Nov 2026 17:53:27 +0100	[thread overview]
Message-ID: <20261129165327.1188117-1-hca@linux.ibm.com> (raw)

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


             reply	other threads:[~2026-11-29 16:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 16:53 Heiko Carstens [this message]
2026-11-29 16:59 ` [PATCH] s390/mm: Skip holes in identity mapping in set_memory() 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=20261129165327.1188117-1-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=rppt@kernel.org \
    --cc=svens@linux.ibm.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