From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30204606A322 for ; Thu, 3 Dec 2026 14:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=wZN0vnh1; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NiQrur7T DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=ZHdPH/f1VPGjr5HPHUURofmaMuqWOo/jXPcBpK0KInQ=; b=wZN0vnh1CV4R7Uywd9s20Lk6kI 5RNkN2mUCqUyI2HamKu0HnmUYBGXng4a/gb7lVqL0Gxv4tZSwKJU3yruXxKIq4qlo8d1qwoe2bMrN M0Eq5Tjfe52hNdIv+yoPFzMpAZwiiHZD2gGG3RankGkTrldcYX9gSZ3SQDbAdwdYWG6GB+tJeNN5k OgxlGZ4qjOdqjarI0GAQBtUhlDzS20TDXTLtF9iOMiNs1+iMAwSAstgS91ELNGYEWHNh9rPKKBcPC mLFsxBsIgCXPa6WD0Chera70x6tFPIxh4vCFBWQAhLpRT1yvdGrm93TcoiWenmUaFVG9VKCuzZWC4 cI2ei22A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ7pf-0000000ExDm-21rB; Thu, 03 Dec 2026 14:30:47 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZ7pd-0000000ExDV-1YwP; Thu, 03 Dec 2026 14:30:45 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8C7EB44988; Thu, 3 Dec 2026 14:30:43 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261203104925.77590A0b-hca@linux.ibm.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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.