From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EDA73CAE61 for ; Wed, 20 May 2026 09:40:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779270037; cv=none; b=rqMEaJFZALvAX90x6pKFagCpjyT2ltfjOtEq/A1oMZo7zGfKsawPUp0j34150yQneYYyPAPNDKT0OjEHp4K2yQmKJUFa57W4Qcny0i1m/snlOUb3snR5jPaXrAaUnotIkl0l4VnF6b7lB6e6B+T5OGwhMlBjZ5xpp2kJRUb4z54= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779270037; c=relaxed/simple; bh=fsDplnJ0UkqUbgVAEzZE3yHTGI8sGZzdWQJtneeU1kI=; h=MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type; b=PP6F6+f1+6taFyhz4GHc68KDSSJV71BWvWKzq7+8IgRQvL8WmZA1V8qytg4+NZr3L2dJecHBM+4KQi1dcAcQP+VNPtK7RAJlGJF1aPCcofI2r4563MnLDZyzJpOnZm235u+6ITc4oo0YMjUUbFqexvAwx4c0+S1q/zrIVvCYVAU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XU6bBNmz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XU6bBNmz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 826DD1F00894; Wed, 20 May 2026 09:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779270033; bh=O/TEx4FDc/EtlNCU5OdX56vjPLrz6XpixMikUKfrvxM=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=XU6bBNmzeY4C8OKQ+1UzT55ZvZtTG8CeX/UdS1IiVTEpWXJFWZ9Jm0+KUo/XbKBsW ZYDKgbyzVhsKpzTTC1ANzEOw/xh2VwE+3fUbVndf81VctqIoJitPfP2vkjtPKcXKO3 UMVeQCCvtD9YBmZ0CEpfjyEsIu9hO/Cy/DXqOWUfW423blNYM/vmhgV58lISRywS6Z cVrj6Oe9hDhcqJRiDBhclX8pcQODMMjzQNCrN+aw1ihNH4uKDqVdRXdyk9aOzwXf9z mYw08B2AXR8Esfx+2wLiXZVqm+bCn/9tRRBGDnP7EVcjFYk+pWKmt7me6nqwPt0PSu 8t2OyKPg/aFQw== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id A6D41F4007C; Wed, 20 May 2026 05:40:32 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-01.internal (MEProxy); Wed, 20 May 2026 05:40:32 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddugeegvdelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvfevkfgjfhfutgfgsehtqhertdertdejnecuhfhrohhmpedftehrugcu uehivghshhgvuhhvvghlfdcuoegrrhgusgeskhgvrhhnvghlrdhorhhgqeenucggtffrrg htthgvrhhnpeeuteeiudeigeekjedvheduieehteetgfdtuefghfejgffhfedtleehvdeh fffhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grrhguodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduieejtdehtddtjeel qdeffedvudeigeduhedqrghruggspeepkhgvrhhnvghlrdhorhhgseifohhrkhhofhgrrh gurdgtohhmpdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtphht thhopehmphgvsegvlhhlvghrmhgrnhdrihgurdgruhdprhgtphhtthhopehnphhighhgih hnsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptghhlhgvrhhohieskhgvrhhnvghlrdho rhhgpdhrtghpthhtohepmhgrugguhieslhhinhhugidrihgsmhdrtghomhdprhgtphhtth hopehlihhnuhigphhptgdquggvvheslhhishhtshdrohiilhgrsghsrdhorhhgpdhrtghp thhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: ice86485a:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 84095182007A; Wed, 20 May 2026 05:40:32 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 20 May 2026 11:40:12 +0200 From: "Ard Biesheuvel" To: "Christophe Leroy (CS GROUP)" , linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, "Madhavan Srinivasan" , "Michael Ellerman" , "Nicholas Piggin" Message-Id: <3e63e2eb-30b3-4377-9331-41445d9c8720@app.fastmail.com> In-Reply-To: References: <20260520085423.485402-1-ardb@kernel.org> Subject: Re: [PATCH resend] powerpc/code-patching: Avoid r/w mapping of the zero page Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, 20 May 2026, at 11:36, Christophe Leroy (CS GROUP) wrote: > Le 20/05/2026 =C3=A0 10:54, Ard Biesheuvel a =C3=A9crit=C2=A0: >> The only remaining use of map_patch_area() is mapping the zero page, = and >> immediately unmapping it again so that the intermediate page table >> levels are all guaranteed to be populated. >>=20 >> The use of the zero page here is completely arbitrary, and not harmful >> per se, but currently, it creates a writable mapping, and does so in a >> manner that requires that the empty_zero_page[] symbol is not >> const-qualified. >>=20 >> Given that this is about to change, and that map_patch_area() now nev= er >> maps anything other than the zero page, let's simplify the code and >> - take the PA of empty_zero_page directly >> - create a read-only temporary mapping. >>=20 >> This allows empty_zero_page[] to be repainted as const u8[] in a >> subsequent patch, without making substantial changes to this code >> patching logic. >>=20 >> Cc: Madhavan Srinivasan >> Cc: Michael Ellerman >> Cc: Nicholas Piggin >> Cc: "Christophe Leroy (CS GROUP)" >> Signed-off-by: Ard Biesheuvel >> --- >> Build tested only (Clang) >>=20 >> Resending from my non-Google email. Apologies if you are receiving th= is >> twice. >>=20 >> arch/powerpc/lib/code-patching.c | 11 +++++------ >> 1 file changed, 5 insertions(+), 6 deletions(-) >>=20 >> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code= -patching.c >> index f84e0337cc02..13a8acf851f1 100644 >> --- a/arch/powerpc/lib/code-patching.c >> +++ b/arch/powerpc/lib/code-patching.c >> @@ -60,7 +60,7 @@ struct patch_context { >> =20 >> static DEFINE_PER_CPU(struct patch_context, cpu_patching_context); >> =20 >> -static int map_patch_area(void *addr, unsigned long text_poke_addr); >> +static int map_patch_area(unsigned long text_poke_addr); >> static void unmap_patch_area(unsigned long addr); >> =20 >> static bool mm_patch_enabled(void) >> @@ -117,7 +117,7 @@ static int text_area_cpu_up(unsigned int cpu) >> =20 >> // Map/unmap the area to ensure all page tables are pre-allocated >> addr =3D (unsigned long)area->addr; >> - err =3D map_patch_area(empty_zero_page, addr); >> + err =3D map_patch_area(addr); > > I would get rid of map_patch_area() completely and just do: > > err =3D map_kernel_page(addr, __pa_symbol(empty_zero_page), PAGE_KERN= EL_RO); > I think retaining the symmetry of map_patch_area() and unmap_patch_area() makes sense too. > > By the way I don't know how vital it is to map in read-only but in cas= e=20 > it is see commit da3a3b0a0e38 ("powerpc/32s: map kasan zero shadow wit= h=20 > PAGE_READONLY instead of PAGE_KERNEL_RO") > In the end, it doesn't make any difference, given that the mapping is re= moved again immediately. It is just neater to use _RO to map a const object, r= ather than explicitly creating a read-write mapping of something that should r= eally never be written to.