From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796308243; b=VU81OKjRyEWpwL1hJ4kWpzsOb4YfK01cX1FpZD0oUSD1meI8RdGKtjSOUs9Zd3nbOqNu q+TcZGaF25ROlQEHQfswxu8EKJwF3qfWq/e0DCWj5NM8LOaM8JrRymSixN6kmE8TLaHUc 1a0Kf5LclOxC3Wffdu4H0zcJC5cNPPjQodSoZM7b9prQ2JmYuaJGvshORPTZakfc4y99n zqZrXhP+oHxrSanDQcml5WLWlweit2spsBZ6ys3w4PSwDCH+kWf8LaWhamX6YcD6WUyzB 5St9fC59jUzG/qCnB4Actqwj9LZ9OC60IoAsNm7UZfciKk21xKwjVEdUXWVUxjk7itQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796308243; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ZHdPH/f1VPGjr5HPHUURofmaMuqWOo/jXPcBpK0KInQ=; b=LKjWbA3t3kcjVhB0uMaoPlAceKQfEV2sKQDDKIklcP3w9INEzVEVsyOi9dwm7ybosVwG 6YknPi98i7JrARQbR6Sxb70wpAlesX927H5n5WoiLWaKktTWLenygpIyDPtqsgVL/K1SQ /igqUWI41h6UV7NDcWg/iHScBJq6AnQFDPMnZUE1KsbHavOI8l6OX/ubDmD9Bnj4IgHFf ZnSnLphBPc6r7HFudL4mHJ8oo8m2pr1dHqaAoH/9QNpYg0dQ/VT+X/EuXhuNYfbtuiwhQ jZM5dI9nMcx/VyduKuaZjPWA8NgrB0RNlODl3DKxJOobAcUcyw0QG47gT78aO3z49cQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NiQrur7T; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6F86606A322; Thu, 3 Dec 2026 14:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NiQrur7T Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC6621F00893; Thu, 3 Dec 2026 14:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796308243; bh=ZHdPH/f1VPGjr5HPHUURofmaMuqWOo/jXPcBpK0KInQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=NiQrur7ThAApmq+vySzZX3s2Wlc0jaSeT27ToY8sug1nS4bx0ihy9294bkFkEPkgy CmrqlhFwFmcvBb64eFrUGIXvUCZSnHzytf23FwPUFYDWsoJetzVQBT9r485+hVuKtl 8Saay1kuPhlNfbVag0tgF0q2LigX96NVq5f9HTtenvrGPgkBXb3cwyZ2oH+C25TiYu JVYdPgBhjKvXY1jqe8BWwdpfFfD2q2oFn0xU/aVAmQZ2lai3qoer4M6j7pHWnL1cze Cc1EkyZG9nxtPAwma1ACbPeen8crbEiiVEsDJD86EWPpF1t4LxLHkgNMR1wxNxIaSq aPrepM1P2DhDw== Date: Thu, 3 Dec 2026 16:30:28 +0200 From: Mike Rapoport To: Heiko Carstens Cc: linux-mm@kvack.org, Adrian =?utf-8?Q?Barna=C5=9B?= , Alexander Gordeev , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Brendan Jackman , Catalin Marinas , Dave Hansen , David Hildenbrand , Gerald Schaefer , Huacai Chen , Ingo Molnar , Kevin Brodsky , "Liam R. Howlett" , Lorenzo Stoakes , Madhavan Srinivasan , Michal Hocko , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Russell King , Suren Baghdasaryan , Thomas Gleixner , Vasily Gorbik , Vlastimil Babka , Will Deacon , 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() Message-ID: References: <20261126-generic-set-memory-v0-1-v2-0-723f1e33c3d8@kernel.org> <20261126-generic-set-memory-v0-1-v2-46-723f1e33c3d8@kernel.org> <20261203104925.77590A0b-hca@linux.ibm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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) > > --- > > 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.