From patchwork Tue May 30 14:05:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13260156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E4C3C7EE23 for ; Tue, 30 May 2023 14:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:Message-Id:MIME-Version:Subject:Cc :To:From:References:In-Reply-To:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HcE+XS3zfIodd4DQeeiYFVRcs4PdFF8+ypelPoA4r5w=; b=26svy38CD2axxl yeIY4JYhtKUFofsCv+2iQtMT1o4URZSJCvQ5o63TmSiE/K1tu6unjF4OeU7PISOuEtTt6kDQYNBF1 tpNoONgkaZLuIdp0pn1jmcjyr32siIIudloMbfBLEe168Pdm/sJcNVUgo91SoQvJzf8SXS74dPMaa Bc7ga1Ja9GcRoHVRIUGYNx5HXxi15hv/5JY4YaDbNlUSYCaYh2lYLFZJvCRdQwaDO/Wyk5XHWJjtY yjF5SnjIEaIXcqNkLJoFLbZ983oBk1f0dZ2Wx4Qg8ebn2TmbvmcGs+mEAYGCfUX1hdN4fKSGjaani r0/cU/bSkJXn9tAlrIOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q3zz7-00E9jy-1f; Tue, 30 May 2023 14:06:01 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q3zyu-00E9cE-2X for linux-arm-kernel@lists.infradead.org; Tue, 30 May 2023 14:05:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=j73sK6spBSnIr1eNE6vGhJALNwM1f6fBM4G1hUkLttA=; b=unJutXRiCGHwGOdig5Y2+g+y4u cvzjOTL9NH/I5W6AWOt955Qzq8ypMcoEx4IXpoklX9piKIJXI6LbZ03RHWCiE2R4GkpSEoo0W1h3X UV6yhD8S78OkfEkLWm58o6rVV0tuoiIlztYe9bOGGcbwoJQ8kBxOA1dNIFx/bW/aUNEz9kxrRG+UM LK9fD/qX1I2S2JD/sPuXC2wl/kb7zzWFItH1hQrSkg+SEXmZ0Mu2NQlrN6D6NcO0cVZ48Kz3mU6Ee zinw5X2ub0Kz7CCdpxLBZhvC44T04cNSVHXR//ZYCBrBLE5qNQQbXhRzaft+0QorcFK8nNEUBSJnJ BjFMPWWw==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:48868 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q3zyt-0002sp-CG; Tue, 30 May 2023 15:05:47 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1q3zys-00A5Lw-QO; Tue, 30 May 2023 15:05:46 +0100 In-Reply-To: References: From: "Russell King (Oracle)" To: Catalin Marinas , Jonathan Corbet , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org Subject: [PATCH RFC 15/17] arm64: text replication: include most of read-only data as well MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 30 May 2023 15:05:46 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230530_070548_823110_DE066C48 X-CRM114-Status: GOOD ( 15.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Include as much of the read-only data in the replication as we can without needing to move away from the generic RO_DATA() macro in the linker script. Unfortunately, the read-only data section is immedaitely followed by the read-only after init data with no page alignment, which means we can't have separate mappings for the read-only data section and everything else. Changing that would mean replacing the generic RO_DATA() macro which increases the maintenance burden. however, this is likely not worth the effort as the majority of read-only data will be covered. Signed-off-by: Russell King (Oracle) --- arch/arm64/mm/ktext.c | 2 +- arch/arm64/mm/mmu.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/ktext.c b/arch/arm64/mm/ktext.c index 11eba88fdd49..f64a649f06a4 100644 --- a/arch/arm64/mm/ktext.c +++ b/arch/arm64/mm/ktext.c @@ -101,7 +101,7 @@ void ktext_replication_patch_alternative(__le32 *src, int nr_inst) /* Allocate page tables and memory for the replicated kernel texts. */ void __init ktext_replication_init(void) { - size_t size = _etext - _stext; + size_t size = __end_rodata - _stext; int kidx = pgd_index((phys_addr_t)KERNEL_START); int nid; diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 2ba5cdfa28ce..5e4cb28f3e5f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -753,11 +753,26 @@ static pgprot_t __init kernel_text_pgprot(void) #ifdef CONFIG_REPLICATE_KTEXT void __init create_kernel_nid_map(pgd_t *pgdp, void *ktext) { + phys_addr_t pa_ktext; + size_t ro_offset; + void *ro_end; pgprot_t text_prot = kernel_text_pgprot(); - create_kernel_mapping(pgdp, __pa(ktext), _stext, _etext, text_prot, 0); - create_kernel_mapping(pgdp, __pa_symbol(__start_rodata), - __start_rodata, __inittext_begin, + pa_ktext = __pa(ktext); + ro_offset = __pa_symbol(__start_rodata) - __pa_symbol(_stext); + /* + * We must not cover the read-only data after init, since this + * is written to during boot, and thus must be shared between + * the NUMA nodes. + */ + ro_end = PTR_ALIGN_DOWN((void *)__start_ro_after_init, PAGE_SIZE); + + create_kernel_mapping(pgdp, pa_ktext, _stext, _etext, text_prot, 0); + create_kernel_mapping(pgdp, pa_ktext + ro_offset, + __start_rodata, ro_end, + PAGE_KERNEL, NO_CONT_MAPPINGS); + create_kernel_mapping(pgdp, __pa_symbol(ro_end), + ro_end, __inittext_begin, PAGE_KERNEL, NO_CONT_MAPPINGS); create_kernel_mapping(pgdp, __pa_symbol(__inittext_begin), __inittext_begin, __inittext_end,