From nobody Mon May 25 00:55:35 2026 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 549443B19AA for ; Wed, 20 May 2026 08:54:33 +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=1779267274; cv=none; b=IK+4zcsdYZiLapa6gJZjbgZ/ZnlQmXEjdflGups05Qog9/F6KSrgokq8+SCVgAfBr6cHrXgIkpPKU5Nz0AL1erpYVsMT0S6dh1dhZ6bZ+ZJxbGM5rXDdEXr2yqKjqR0+7Xz9yQSXGK2QWFL3aUNlq4jG84Lgbm6pw7cM99b9V0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779267274; c=relaxed/simple; bh=JA7OGbftdtH8ZMQWXeZvyJp5+mUkYbne5EIXZIJwddw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CT2cjkqbydAaStcp7/FR/ElRHCRIxKwtSL9gghrbbLMyWH0sa1JS2IAQjzgtRETO+VAAJ4b/JPsYPpgyhq7S+XJhAgE4ozIDSeKdrEBeQMnTIRA2IFirn1Rn1k2YF+7P3QltRP4P44hQnGBkeX9geOf0ahs3Cl17rp8FVBnkaHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nsYunww/; 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="nsYunww/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A95071F000E9; Wed, 20 May 2026 08:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779267273; bh=SJbvQCeYYGK31no0UiRJJfovB9239W4R99+29etyJMU=; h=From:To:Cc:Subject:Date; b=nsYunww/wNRisO2TgDK+NnVSxFs1l7ZnC4Cr1l+Mv8AdN0N49rj5GjBZEza3sAx7e 6BzLM08hEytZZaqwT/hG2gaouG9wwGCLXzjJ1VtTRp1PbPlGIgWmkWT8OC8+wuOvol Umsz3HVbfb1s7phBZGumKda2+n97tSR0EnnNbsRHmaNfEcl6Sul27o6Eh42efiCnO5 +MzvGAo67z/1QpbmS00ePYqARLlz43ZZuQB65TqVdo2aq714OtfnAsawZerHDkPthE 0WJBYxD1w5mdAmEDNlhOz5joxLnEqejRILGOZ0EIGti2J6GpJ+Ih4Rw8+DPxxZKs/s aX/x1RqwCYINA== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Ard Biesheuvel , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" Subject: [PATCH resend] powerpc/code-patching: Avoid r/w mapping of the zero page Date: Wed, 20 May 2026 10:54:23 +0200 Message-ID: <20260520085423.485402-1-ardb@kernel.org> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2580; i=ardb@kernel.org; h=from:subject; bh=oY6gtKVWNTBx6UhZYZ8J5F7bWJKDdqkgNGPUoOyRHTg=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIYs3RWD7P9O9sip+nxa8t3i22u1c9+ypXxduWjaj6mv8v Ad5y6codpSyMIhxMciKKbIIzP77bufpiVK1zrNkYeawMoEMYeDiFICJhBox/M94/XbBEb45a0sm T0iw2eXcuyKvVOt/YIzwzZp7x18VHdrC8E/zmjyPpZ+xlEKMw/TfJ/4sXjvrUTTvgvztfF9NHeL uS7ECAA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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. Given that this is about to change, and that map_patch_area() now never 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/code-patch= ing.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); if (err) return err; =20 @@ -236,11 +236,10 @@ static unsigned long get_patch_pfn(void *addr) /* * This can be called for kernel text or a module. */ -static int map_patch_area(void *addr, unsigned long text_poke_addr) +static int map_patch_area(unsigned long text_poke_addr) { - unsigned long pfn =3D get_patch_pfn(addr); - - return map_kernel_page(text_poke_addr, (pfn << PAGE_SHIFT), PAGE_KERNEL); + return map_kernel_page(text_poke_addr, __pa_symbol(empty_zero_page), + PAGE_KERNEL_RO); } =20 static void unmap_patch_area(unsigned long addr) --=20 2.54.0.631.ge1b05301d1-goog