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>,
Mike Rapoport <rppt@kernel.org>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 03/17] s390/mm: Serialize kernel page table changes with init_mm mmap lock
Date: Thu, 3 Dec 2026 11:33:31 +0100 [thread overview]
Message-ID: <20261203103345.1206548-4-hca@linux.ibm.com> (raw)
In-Reply-To: <20261203103345.1206548-1-hca@linux.ibm.com>
s390 serializes kernel mapping changes with two unrelated mutexes:
cpa_mutex for pageattr and vmem_mutex for memory hotplug.
Both modify the kernel direct mapping, and can split e.g. the same
2GB region-third table concurrently, which can lead to an inconsistent
mapping.
Use mmap_write_lock(&init_mm) everywhere, and drop the old locks.
This also matches riscv, loongarch and what the generic page table
walkers and ptdump expect.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/include/asm/set_memory.h | 4 ----
arch/s390/mm/dump_pagetables.c | 2 --
arch/s390/mm/pageattr.c | 6 ++----
arch/s390/mm/vmem.c | 26 ++++++++++++--------------
4 files changed, 14 insertions(+), 24 deletions(-)
diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h
index 036295215a1a..b453dd2d6a8e 100644
--- a/arch/s390/include/asm/set_memory.h
+++ b/arch/s390/include/asm/set_memory.h
@@ -2,10 +2,6 @@
#ifndef _ASMS390_SET_MEMORY_H
#define _ASMS390_SET_MEMORY_H
-#include <linux/mutex.h>
-
-extern struct mutex cpa_mutex;
-
enum {
_SET_MEMORY_RO_BIT,
_SET_MEMORY_RW_BIT,
diff --git a/arch/s390/mm/dump_pagetables.c b/arch/s390/mm/dump_pagetables.c
index a23a0bd4d8a8..7533dc22e0e9 100644
--- a/arch/s390/mm/dump_pagetables.c
+++ b/arch/s390/mm/dump_pagetables.c
@@ -247,9 +247,7 @@ static int ptdump_show(struct seq_file *m, void *v)
.marker = markers,
};
- mutex_lock(&cpa_mutex);
ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
- mutex_unlock(&cpa_mutex);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(ptdump);
diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c
index d75817d80b78..9ca30ed46179 100644
--- a/arch/s390/mm/pageattr.c
+++ b/arch/s390/mm/pageattr.c
@@ -337,8 +337,6 @@ static int walk_p4d_level(pgd_t *pgd, unsigned long addr, unsigned long end,
return rc;
}
-DEFINE_MUTEX(cpa_mutex);
-
static int change_page_attr(unsigned long addr, unsigned long end,
unsigned long flags)
{
@@ -413,13 +411,13 @@ int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags
return 0;
addr &= PAGE_MASK;
end = addr + numpages * PAGE_SIZE;
- mutex_lock(&cpa_mutex);
+ mmap_write_lock(&init_mm);
rc = change_page_attr(addr, end, flags);
if (rc)
goto out;
rc = change_page_attr_alias(addr, end, flags);
out:
- mutex_unlock(&cpa_mutex);
+ mmap_write_unlock(&init_mm);
return rc;
}
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index 317bd01dca86..66071085f5a3 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -26,8 +26,6 @@
#include <asm/set_memory.h>
#include <asm/physmem_info.h>
-static DEFINE_MUTEX(vmem_mutex);
-
static void __ref *vmem_alloc_pages(unsigned int order)
{
unsigned long size = PAGE_SIZE << order;
@@ -513,12 +511,12 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
{
int ret;
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
/* We don't care about the node, just use NUMA_NO_NODE on allocations */
ret = add_pagetable(start, end, false, altmap);
if (ret)
remove_pagetable(start, end, false, altmap);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
return ret;
}
@@ -527,18 +525,18 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
void vmemmap_free(unsigned long start, unsigned long end,
struct vmem_altmap *altmap)
{
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
remove_pagetable(start, end, false, altmap);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
}
#endif
void vmem_remove_mapping(unsigned long start, unsigned long size)
{
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
vmem_remove_range(start, size);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
}
struct range arch_get_mappable_range(void)
@@ -560,11 +558,11 @@ int vmem_add_mapping(unsigned long start, unsigned long size)
start + size < start)
return -ERANGE;
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
ret = vmem_add_range(start, size);
if (ret)
vmem_remove_range(start, size);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
return ret;
}
@@ -652,9 +650,9 @@ int vmem_map_4k_page(unsigned long addr, unsigned long phys, pgprot_t prot)
{
int rc;
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
rc = __vmem_map_4k_page(addr, phys, prot, true);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
return rc;
}
@@ -662,11 +660,11 @@ void vmem_unmap_4k_page(unsigned long addr)
{
pte_t *ptep;
- mutex_lock(&vmem_mutex);
+ mmap_write_lock(&init_mm);
ptep = virt_to_kpte(addr);
__ptep_ipte(addr, ptep, 0, 0, IPTE_GLOBAL);
pte_clear(&init_mm, addr, ptep);
- mutex_unlock(&vmem_mutex);
+ mmap_write_unlock(&init_mm);
}
void __init vmem_map_init(void)
--
2.53.0
next prev parent reply other threads:[~2026-12-03 10:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 10:33 [PATCH 00/17] s390/mm: Large kernel mappings for vmalloc and execmem ROX cache Heiko Carstens
2026-12-03 10:33 ` [PATCH 01/17] s390/boot: Initialize asce_limit for init_mm properly Heiko Carstens
2026-12-03 10:33 ` [PATCH 02/17] s390/pageattr: Only account direct mapping in direct map page counters Heiko Carstens
2026-12-03 10:33 ` Heiko Carstens [this message]
2026-12-03 10:33 ` [PATCH 04/17] s390/vmem: Use generic page table allocators for vmem page tables Heiko Carstens
2026-12-03 10:33 ` [PATCH 05/17] s390/mm: Show write-combining attribute in page table dump Heiko Carstens
2026-12-03 10:33 ` [PATCH 06/17] s390/mm: Implement HAVE_ARCH_HUGE_VMAP Heiko Carstens
2026-12-03 10:33 ` [PATCH 07/17] s390/mm: Implement HAVE_ARCH_HUGE_VMALLOC Heiko Carstens
2026-12-03 10:33 ` [PATCH 08/17] s390/pageattr: Add helpers to replace kernel page table entries Heiko Carstens
2026-12-03 10:33 ` [PATCH 09/17] s390/mm: Add _SEGMENT_ENTRY_TYPE Heiko Carstens
2026-12-03 10:33 ` [PATCH 10/17] s390/pageattr: Use common helper to change kernel page table permissions Heiko Carstens
2026-12-03 10:33 ` [PATCH 11/17] s390/pageattr: Avoid splitting mappings if permissions do not change Heiko Carstens
2026-12-03 10:33 ` [PATCH 12/17] s390/pageattr: Mark intentional 4k kernel mappings Heiko Carstens
2026-12-03 10:33 ` [PATCH 13/17] s390/pageattr: Collapse kernel mappings after changing page attributes Heiko Carstens
2026-12-03 10:33 ` [PATCH 14/17] s390/mm: Add PAGE_KERNEL_ROX Heiko Carstens
2026-12-03 10:33 ` [PATCH 15/17] s390/execmem: Add EXECMEM_KPROBES range Heiko Carstens
2026-12-03 10:33 ` [PATCH 16/17] s390/execmem: Add EXECMEM_FTRACE range Heiko Carstens
2026-12-03 10:33 ` [PATCH 17/17] s390/execmem: Enable EXECMEM_ARCH_ROX Heiko Carstens
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=20261203103345.1206548-4-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gerald.schaefer@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
all inboxes | Powered by JetHome®