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 8541C2BD0B for ; Wed, 20 May 2026 10:16:29 +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=1779272196; cv=none; b=WYxnjvx6Yf3m/oUzPyO+/R34dRf7O68HfAZdNqWFwg4LGRTufSL9r3scCKqs4tIEX9W3z/zKB2n0LI+2Hlu0YVU7CaxxkAr6fyMBNVWTu7Dw7jztmWUXv3MMvY5NGSumf7IKyC4kQNyDkOEpoIAzxdxtubH7yb0AxKe5gAhIImc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779272196; c=relaxed/simple; bh=AGORkEInL9LtaHU6lvXpm/ZIk6JFkgvpf5krN1toAl4=; h=MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type; b=XX35kR8LwtxdX5dDuTuroqqUfv8mSF8Ticoezt31hVJPCw29cvvsk60GCoDsoG0eBpHqJxcAHi4mWBKnjbXcxTg23p6M1HFJHCn9VKdoOy4uowFQznpXIFwLAsYNyPScmKddRVt/vE9Zf27D6nJjMycjjJjIQ29nXF2jxAu+K5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aw1MjZl4; 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="Aw1MjZl4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B07B81F00894 for ; Wed, 20 May 2026 10:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779272187; bh=ftcrwlUHw5Gy4d+Sc3QnB5ChQd2ypzfHxdZQS9rMyXU=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=Aw1MjZl4HEDtYedfmFvnmfH/ZT6XJUYxKoKukBGpAUOR4aImkROnBqguwmxj3vimZ MKIl16Cws4sbz/twYQ1KfnjurBBqSg1z533qztfi+WwEdnX/kE/dj/X1c9POfzzS0X paUhgw1uN/XGMCQ1IfLI7T5bd26tb6zGaT/05oG6UQtVPkYek2VwEi1qmSECPNqmNS pAEnWm3iPdSPQmCUrinqCvFE8jV6mrZAzVDE3V5m//y9OfK0DViUdEJ7CHvkGjHJ3H TNhjYK7xjtK0zuI7Fld7cCDINfybNxf+c8Hf5TVYLT/G8HKBPSe1LX8wGhUjOrpnBb UsD8GtiFAnnJQ== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id F2F01F4006D; Wed, 20 May 2026 06:16:26 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-01.internal (MEProxy); Wed, 20 May 2026 06:16:26 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddugeegfeejucetufdoteggodetrf 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 D398B182007A; Wed, 20 May 2026 06:16:26 -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 12:16:06 +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: In-Reply-To: <757318e3-91df-4e39-ba44-5130626d38b8@kernel.org> References: <20260520085423.485402-1-ardb@kernel.org> <3e63e2eb-30b3-4377-9331-41445d9c8720@app.fastmail.com> <757318e3-91df-4e39-ba44-5130626d38b8@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:59, Christophe Leroy (CS GROUP) wrote: > Le 20/05/2026 =C3=A0 11:40, Ard Biesheuvel a =C3=A9crit=C2=A0: >>=20 >> 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. >>>> >>>> The use of the zero page here is completely arbitrary, and not harm= ful >>>> per se, but currently, it creates a writable mapping, and does so i= n a >>>> manner that requires that the empty_zero_page[] symbol is not >>>> const-qualified. >>>> >>>> Given that this is about to change, and that map_patch_area() now n= ever >>>> 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. >>>> >>>> This allows empty_zero_page[] to be repainted as const u8[] in a >>>> subsequent patch, without making substantial changes to this code >>>> patching logic. >>>> >>>> Cc: Madhavan Srinivasan >>>> Cc: Michael Ellerman >>>> Cc: Nicholas Piggin >>>> Cc: "Christophe Leroy (CS GROUP)" >>>> Signed-off-by: Ard Biesheuvel >>>> --- >>>> Build tested only (Clang) >>>> >>>> Resending from my non-Google email. Apologies if you are receiving = this >>>> twice. >>>> >>>> arch/powerpc/lib/code-patching.c | 11 +++++------ >>>> 1 file changed, 5 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/co= de-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-allocat= ed >>>> 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_KE= RNEL_RO); >>> >>=20 >> I think retaining the symmetry of map_patch_area() and unmap_patch_ar= ea() >> makes sense too. > > Could also drop unmap_patch_area() and use unmap_kernel_page() instead. > Good point. That way, we'll end up with arch/powerpc/lib/code-patching.c | 52 ++-------------------------------= ------- 1 file changed, 2 insertions(+), 50 deletions(- I'll spin a v2 with those changes once everyone on cc has had the opport= unity to chime in.