[PATCH 02/17] s390/pageattr: Only account direct mapping in direct map page counters
From: Heiko Carstens
Date: Thu Dec 03 2026 - 05:34:33 EST
The kernel image is not part of the direct mapping, however applying
permission changes to the kernel mapping via set_memory() incorrectly
update the direct map page counters.
Fix this and update the counters only for addresses within the direct
mapping. That is the identity mapping and the range up to max_mappable,
which includes mappings added with vmem_add_mapping(), e.g. for DCSS.
Fixes: 693d41f7c938 ("s390/mm: Restore mapping of kernel image using large pages")
Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/mm/pageattr.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index e744a61651b9..d75817d80b78 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -120,6 +120,18 @@ static int walk_pte_level(pmd_t *pmdp, unsigned long addr, unsigned long end,
return 0;
}
+static bool is_direct_map_addr(unsigned long addr)
+{
+ return addr >= __identity_base && addr - __identity_base < max_mappable;
+}
+
+/* Only the direct mapping is accounted in direct_pages_count[] */
+static void update_direct_map_count(unsigned long addr, int level, long count)
+{
+ if (is_direct_map_addr(addr))
+ update_page_count(level, count);
+}
+
static int split_pmd_page(pmd_t *pmdp, unsigned long addr)
{
unsigned long pte_addr, prot;
@@ -145,8 +157,8 @@ static int split_pmd_page(pmd_t *pmdp, unsigned long addr)
}
new = __pmd(__pa(pt_dir) | _SEGMENT_ENTRY);
pgt_set((unsigned long *)pmdp, pmd_val(new), addr, CRDTE_DTT_SEGMENT);
- update_page_count(PG_DIRECT_MAP_4K, PTRS_PER_PTE);
- update_page_count(PG_DIRECT_MAP_1M, -1);
+ update_direct_map_count(addr, PG_DIRECT_MAP_4K, PTRS_PER_PTE);
+ update_direct_map_count(addr, PG_DIRECT_MAP_1M, -1);
return 0;
}
@@ -237,8 +249,8 @@ int split_pud_page(pud_t *pudp, unsigned long addr)
}
new = __pud(__pa(pm_dir) | _REGION3_ENTRY);
pgt_set((unsigned long *)pudp, pud_val(new), addr, CRDTE_DTT_REGION3);
- update_page_count(PG_DIRECT_MAP_1M, PTRS_PER_PMD);
- update_page_count(PG_DIRECT_MAP_2G, -1);
+ update_direct_map_count(addr, PG_DIRECT_MAP_1M, PTRS_PER_PMD);
+ update_direct_map_count(addr, PG_DIRECT_MAP_2G, -1);
return 0;
}
--
2.53.0