Message ID | 20230307140522.2311461-39-ardb@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org> 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 3247EC678D5 for <linux-arm-kernel@archiver.kernel.org>; Tue, 7 Mar 2023 14:42:24 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JyFhIYMOokFvm9cIdCre25Dl1mt+GqCzsxy2ue7bUWk=; b=F2H/lG14rOmmIr d8DKpcvL5+siUmBkduMycvZ443/25sJ9Z/7eKytksP2xYi3hAwR/+6GEdhZ/7+A6/W+qd0YCEWzUB x/QGGRcWYJK64qCOPGXMazzOPUKh/btImNYxmgvl+1XJwIn2dkPwoHlrTsVZt452uj2bJV2j+aHnl x3+Tqf/chBHtmx2k784Ha6ihETOtDWI5ddaPGMq/6T5LJcT7G8ZOHFvsM2qnrhuT+buecNaQwBTo8 GrYHxyD1nsDzIwOLoidkrtx1bcFzyGKoRo2iUf1PSE9DH7BJWPkL/u0ePdsBCBKSg7/sqEavbCNqq uriMJZ/xHKQaYqODH2ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZYV7-000tFw-Ru; Tue, 07 Mar 2023 14:41:14 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXz8-000edz-Px for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 14:08:14 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3C06D61458; Tue, 7 Mar 2023 14:08:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD895C433D2; Tue, 7 Mar 2023 14:08:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198089; bh=uWLIu3yqNCwcrGkRr50TGOXKaa6P6eE4gao1D3xoCEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iwFAh6VGmHFEMKpps+Sndm/kF/KFeIpQ5F+mfHpWHoLpyPyy0AIil6DnL38nbFaz0 V/32tC5/+fBAMEk+RZ2/vg0XSKJbkhKBcFX4YPu+k4wvmV92qSFaqhmqVq0LD4IFWw LEz8nRAndNcOb+gm8NBBZOR9KnCTMz4YpytDpORhYCJnjgXVnu7nLFbuuEL3wRByBf XZsOO9mpXMsv//CgtIK+BHVsC/zfucJu1GAEXsTPGKjNqYN9nM12m63Z10/NW2k83E ZqG56RV2YbmVmRIKZXlDQyogUck/gpMYJF4ubL0xk1S5EJ4mIkHLqq2CHFyeOApyxJ wUXmsvFEEUf2A== From: Ard Biesheuvel <ardb@kernel.org> To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel <ardb@kernel.org>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Ryan Roberts <ryan.roberts@arm.com>, Anshuman Khandual <anshuman.khandual@arm.com>, Kees Cook <keescook@chromium.org> Subject: [PATCH v3 38/60] arm64: mm: avoid fixmap for early swapper_pg_dir updates Date: Tue, 7 Mar 2023 15:05:00 +0100 Message-Id: <20230307140522.2311461-39-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2146; i=ardb@kernel.org; h=from:subject; bh=uWLIu3yqNCwcrGkRr50TGOXKaa6P6eE4gao1D3xoCEo=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdJengQ+5ILZ+4yZ9msfx3jPXdZhPU7u7Ol/7ZgPlZy TbFj3wdJSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCIz6xi+afk8mqa8y2apu9bv Wx7fft8tTHfYlfzF7qrwPS+Nls1KDH/lNktwyi7Z2i/UPnWCSf+SHNYd0mekTDTrvptY1De4LOI CAA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_060810_974161_80D63D1E X-CRM114-Status: GOOD ( 16.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: <linux-arm-kernel.lists.infradead.org> List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe> List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/> List-Post: <mailto:linux-arm-kernel@lists.infradead.org> List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help> List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org> Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org |
Series |
arm64: Add support for LPA2 at stage1 and WXN
|
expand
|
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 13f46c911558f21f..3f631f3bc2f80b2b 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -53,6 +53,8 @@ EXPORT_SYMBOL(kimage_voffset); u32 __boot_cpu_mode[] = { BOOT_CPU_MODE_EL2, BOOT_CPU_MODE_EL1 }; +static bool rodata_is_rw __ro_after_init = true; + /* * The booting CPU updates the failed status @__early_cpu_boot_status, * with MMU turned off. @@ -73,10 +75,21 @@ static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; static DEFINE_SPINLOCK(swapper_pgdir_lock); static DEFINE_MUTEX(fixmap_lock); -void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) +void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd) { pgd_t *fixmap_pgdp; + /* + * Don't bother with the fixmap if swapper_pg_dir is still mapped + * writable in the kernel mapping. + */ + if (rodata_is_rw) { + WRITE_ONCE(*pgdp, pgd); + dsb(ishst); + isb(); + return; + } + spin_lock(&swapper_pgdir_lock); fixmap_pgdp = pgd_set_fixmap(__pa_symbol(pgdp)); WRITE_ONCE(*fixmap_pgdp, pgd); @@ -614,6 +627,7 @@ void mark_rodata_ro(void) * to cover NOTES and EXCEPTION_TABLE. */ section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata; + WRITE_ONCE(rodata_is_rw, false); update_mapping_prot(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, section_size, PAGE_KERNEL_RO);
Early in the boot, when .rodata is still writable, we can poke swapper_pg_dir entries directly, and there is no need to go through the fixmap. After a future patch, we will enter the kernel with swapper_pg_dir already active, and early swapper_pg_dir updates for creating the fixmap page table hierarchy itself cannot go through the fixmap for obvious reaons. So let's keep track of whether rodata is writable, and update the descriptor directly in that case. As the same reasoning applies to early KASAN init, make the function noinstr as well. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> --- arch/arm64/mm/mmu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)