From: Mike Rapoport <rppt@kernel.org>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: linux-mm@kvack.org, "Adrian Barnaś" <abarnas@google.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andy Lutomirski" <luto@kernel.org>,
"Arnd Bergmann" <arnd@arndb.de>, "Borislav Petkov" <bp@alien8.de>,
"Brendan Jackman" <brendan.jackman@linux.dev>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"David Hildenbrand" <david@kernel.org>,
"Gerald Schaefer" <gerald.schaefer@linux.ibm.com>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Ingo Molnar" <mingo@kernel.org>,
"Kevin Brodsky" <kevin.brodsky@arm.com>,
"Liam R. Howlett" <liam@infradead.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Madhavan Srinivasan" <maddy@linux.ibm.com>,
"Michal Hocko" <mhocko@suse.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Paul Walmsley" <pjw@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Russell King" <linux@armlinux.org.uk>,
"Suren Baghdasaryan" <surenb@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Will Deacon" <will@kernel.org>,
linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
loongarch@lists.linux.dev, x86@kernel.org
Subject: Re: [PATCH RFC v2 46/54] s390: remove set_memory_rwnx()
Date: Thu, 3 Dec 2026 16:30:28 +0200 [thread overview]
Message-ID: <axF9BESVLl_aMnLm@kernel.org> (raw)
In-Reply-To: <20261203104925.77590A0b-hca@linux.ibm.com>
On Thu, Dec 03, 2026 at 11:49:25AM +0100, Heiko Carstens wrote:
> On Thu, Nov 26, 2026 at 01:14:59PM +0200, Mike Rapoport (Microsoft) wrote:
> > set_memory_rwnx() has no users since commit 33bd8d153c33 ("s390: Keep
> > inittext section writable").
> >
> > Remove it.
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> > arch/s390/include/asm/set_memory.h | 1 -
> > 1 file changed, 1 deletion(-)
>
> I'd rather keep it, since it would be useful for execmem_force_rw(), which
> is doing set_memory_nx() + set_memory_rw(), which could be replaced with
> set_memory_rwnx().
>
> set_memory*() calls are quite expensive on s390 (I guess that's true for all
> architectures). Collapsing calls doesn't seem to be the worst idea.
I agree that it makes sense. riscv also has set_memory_rwnx() and it can be
added on x86 and maybe others as well.
Since the rework is going to be slow, I can take it from here and post
a more general patch that updates other architectures too.
> Something like the below maybe?
>
> diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h
> index b453dd2d6a8e..580d81324e82 100644
> --- a/arch/s390/include/asm/set_memory.h
> +++ b/arch/s390/include/asm/set_memory.h
> @@ -23,6 +23,7 @@ enum {
> int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags);
>
> #define set_memory_rox set_memory_rox
> +#define set_memory_rwnx set_memory_rwnx
>
> /*
> * Generate two variants of each set_memory() function:
> diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h
> index 27c32fbabfec..0bbdb63a406d 100644
> --- a/include/linux/set_memory.h
> +++ b/include/linux/set_memory.h
> @@ -100,6 +100,30 @@ static inline int set_memory_rox(unsigned long addr, int numpages)
> }
> #endif
>
> +#ifndef set_memory_rwnx
> +/**
> + * set_memory_rwnx - make a kernel mapping writable and non-executable
> + * @addr: page aligned start of the kernel virtual address range
> + * @numpages: number of pages in the range
> + *
> + * The mapping is made non-executable before it is made writable so that it is
> + * never writable and executable at the same time. A failure may leave the range
> + * non-executable but not writable.
Heh, it is never writable and executable at the same time indeed, but a
failure in the middle of set_memory_nx() just leaves the old permissions :/
> + *
> + * Flushes the TLB for the range.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +static inline int set_memory_rwnx(unsigned long addr, int numpages)
> +{
> + int ret = set_memory_nx(addr, numpages);
> +
> + if (ret)
> + return ret;
> + return set_memory_rw(addr, numpages);
> +}
> +#endif
> +
> #ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP
> /**
> * set_direct_map_invalid_noflush - remove pages from the direct map
> diff --git a/mm/execmem.c b/mm/execmem.c
> index 349cadd87486..16d795097878 100644
> --- a/mm/execmem.c
> +++ b/mm/execmem.c
> @@ -118,13 +118,8 @@ static int execmem_force_rw(void *ptr, size_t size)
> {
> unsigned int nr = PAGE_ALIGN(size) >> PAGE_SHIFT;
> unsigned long addr = (unsigned long)ptr;
> - int ret;
>
> - ret = set_memory_nx(addr, nr);
> - if (ret)
> - return ret;
> -
> - return set_memory_rw(addr, nr);
> + return set_memory_rwnx(addr, nr);
And this is lovely :)
> }
>
> int execmem_restore_rox(void *ptr, size_t size)
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-12-03 14:30 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:14 [PATCH RFC v2 00/54] arch, mm: create a generic set_memory/change_page_attr core Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 01/54] riscv: do not use P4D entries for the linear mapping Mike Rapoport (Microsoft)
2026-12-03 5:01 ` Rik van Riel
2026-11-26 11:14 ` [PATCH RFC v2 02/54] riscv: test for Svnapot in pte_napot() Mike Rapoport (Microsoft)
2026-12-03 5:29 ` Rik van Riel
2026-11-26 11:14 ` [PATCH RFC v2 03/54] s390/boot: parse boolean parameters like the kernel Mike Rapoport (Microsoft)
2026-12-03 5:32 ` Rik van Riel
2026-12-03 5:39 ` Rik van Riel
2026-11-26 11:14 ` [PATCH RFC v2 04/54] s390/boot: stop parsing the command line at "--" Mike Rapoport (Microsoft)
2026-12-03 5:40 ` Rik van Riel
2026-11-26 11:14 ` [PATCH RFC v2 05/54] s390/boot: treat dashes and underscores alike in parameter names Mike Rapoport (Microsoft)
2026-12-03 5:41 ` Rik van Riel
2026-11-26 11:14 ` [PATCH RFC v2 06/54] x86/mm/pat: don't count kernel image splits as direct map splits Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 07/54] x86/mm/pat: drop KERN_WARNING from the WARN() in __cpa_process_fault() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 08/54] x86/mm/pat: fail a split at an unexpected level with -EINVAL Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 09/54] x86/mm/pat: separate CPA request flags from internal state Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 10/54] x86/mm/pat: stop using CPA for debug_pagealloc Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 11/54] x86/mm/pat: drop the init_mm read lock from change_page_attr_set_clr() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 12/54] x86/mm/pat: introduce change_page_attr_pages() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 13/54] x86/mm/pat: make the direct map counters atomic Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 14/54] x86/mm/pat: take pgd_lock only around the pgd_list walks Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 15/54] x86/mm/pat: look up the effective NX/RW bits in verify_rwx() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 16/54] x86/mm/pat: look up a large page again only after dropping cpa_lock Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 17/54] x86/mm/pat: drop the check of existing mappings against static protections Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 18/54] x86/mm/pat: consolidate encoding of page table entries Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 19/54] x86/mm/pat: use enum pgtable_level in CPA Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 20/54] x86/mm/pat: index the CPA statistics by page table level Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 22/54] x86/mm/pat: consolidate calculation of the new protection Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 23/54] x86/mm/pat: allocate the page tables for a split by level Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 24/54] x86/mm/pat: detect unchanged mappings by comparing protections Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 25/54] x86/mm/pat: add cpa_is_direct_map() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 26/54] x86/mm/pat: implement set_memory_*() with a table of operations Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 27/54] x86/mm/pat: prepare the direct map counters for the generic code Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 28/54] x86/mm/pat: separate the generic part of CPA from the x86 hooks Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 29/54] x86/mm/pat, mm: pull CPA core to mm/ Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 30/54] mm/pageattr: introduce arch_cpa_can_split() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 31/54] mm/pageattr: introduce cpa_flush_tlb_kernel_range() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 32/54] asm-generic: add an empty pageattr.h Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 33/54] LoongArch: use pfn_is_nosave() to exclude firmware ranges from hibernation Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 34/54] LoongArch: stop pretending LoongArch supports set_direct_map APIs Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 35/54] LoongArch: drop the huge page handling from set_memory() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 36/54] LoongArch: use the generic CPA core Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 37/54] ARM: mm: " Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 38/54] mm/pageattr: let a leaf cover a contiguous block of entries Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 39/54] powerpc: use the generic CPA core Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 40/54] riscv: replace set_memory_rw_nx() with set_memory_nx() and set_memory_rw() Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 41/54] riscv: use the generic CPA core Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 42/54] riscv: count the mappings of the linear map Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 43/54] mm/pageattr: let an architecture allocate the page tables for a split Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 44/54] mm/pageattr: derive direct map counter updates from the level sizes Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 45/54] s390/boot: map the identity map with 4K pages for debug_pagealloc Mike Rapoport (Microsoft)
2026-11-26 11:14 ` [PATCH RFC v2 46/54] s390: remove set_memory_rwnx() Mike Rapoport (Microsoft)
2026-12-03 10:49 ` Heiko Carstens
2026-12-03 14:30 ` Mike Rapoport [this message]
2026-11-26 11:15 ` [PATCH RFC v2 47/54] s390: use the generic CPA core Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 48/54] mm/pageattr: let an architecture bracket the set_memory() entry points Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 49/54] arm64: mm: allocate page tables in the callers of split_p{mu}d() Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 50/54] arm64: use the generic CPA core Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 51/54] arm64: let the generic CPA core split large mappings Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 52/54] arm64: count the mappings of the linear map Mike Rapoport (Microsoft)
2026-12-01 20:43 ` Yang Shi
2026-12-02 7:26 ` Mike Rapoport
2026-11-26 11:15 ` [PATCH RFC v2 53/54] arch, mm: enable the generic CPA core with ARCH_HAS_SET_MEMORY Mike Rapoport (Microsoft)
2026-11-26 11:15 ` [PATCH RFC v2 54/54] mm/pageattr: document CPA core and the architecture hooks Mike Rapoport (Microsoft)
2026-12-02 0:09 ` [PATCH RFC v2 00/54] arch, mm: create a generic set_memory/change_page_attr core Dave Hansen
2026-12-02 7:52 ` Mike Rapoport
2026-12-03 11:13 ` Heiko Carstens
2026-12-03 14:19 ` Mike Rapoport
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=axF9BESVLl_aMnLm@kernel.org \
--to=rppt@kernel.org \
--cc=abarnas@google.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=brendan.jackman@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kevin.brodsky@arm.com \
--cc=liam@infradead.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ljs@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/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