From patchwork Thu Jul 27 15:30:20 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: 13330298 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 AE794C001DC for ; Thu, 27 Jul 2023 15:31:06 +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=AU1Sd5wzrFWxr+3Zv+LuOVQROZYurxd8H3YEK+p9/Zo=; b=QX0Tl8NjvskflS jyETzzCOzOhG9MzyBhZdTnFyFRUjP25GCBJaCY8J7vz6sN96MGmT69+5h92NzkSOvCWsEHv9k9Eux lxCfE1umrHocDHVmvoLd6TTMFK2SYoD1LPABChGUbm8igxhmJbEeyeHxrR4JciZAsTi56EL2b5Nqj m/ur4SBaLtDfJogCn8Og1vPwZ+DZ0PKUlB4AUb7AJlnEHayw6S5BDBbQxPyBv7bi0N8CUt5UXZeqV 2SYVE4BuEcWwJz3ul7fZIlHQkEeR0IktZhnAltjPjmarVLK357ZOg4GEZ5Bl9Yo49nXem3M/ihEiY 4OEngLZw8wbdIlRVgCaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qP2wr-00FudU-2r; Thu, 27 Jul 2023 15:30:41 +0000 Received: from [2001:4d48:ad52:32c8:5054:ff:fe00:142] (helo=pandora.armlinux.org.uk) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qP2wZ-00FuNG-1n for linux-arm-kernel@lists.infradead.org; Thu, 27 Jul 2023 15:30:25 +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=nyj2l8PY3qAzzBlei2fGIlbkY3GLY8pUVEJtHA0LwRE=; b=bVgJGDhGTIg5HdLjMLDsEtxgmv m3DvR2CYMo8YKaU+1N089+ohCZTsM9XponAqRuB5zRKUw+nvNie0fjBreSNKyyGDYVrkHgfk2fA+p 0dRJxVeniunsHnyiGtCUc+Y9qHqTOYqGRBa3z1bGZPxWprHv8qtaOOFZOUfb2vkm6WafgAvJYnTIG QX/dGIM8FYiWJTFDVhy/pmnTaAIKXjxeOsHPMUUVrkXptOfaXdny0a4J8gzMrSReHggcFYDhv8Xo4 4RYutcI8bwGwR+HHl35qIgAImZbjkM2pjS26YrTIqtktPa4AF84a8ce97paGka0wJ0BBryO5aFHD6 7lxHSueg==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:49446 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.96) (envelope-from ) id 1qP2wW-00062v-2i; Thu, 27 Jul 2023 16:30:20 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qP2wW-001CXK-WB; Thu, 27 Jul 2023 16:30:21 +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 v2 05/16] arm64: text replication: add sanity checks MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Thu, 27 Jul 2023 16:30:20 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230727_083023_611212_ECC6F099 X-CRM114-Status: GOOD ( 11.37 ) 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 The kernel text and modules must be in separate L0 page table entries. Signed-off-by: Russell King (Oracle) --- arch/arm64/mm/ktext.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/mm/ktext.c b/arch/arm64/mm/ktext.c index 3a8d37c9abc4..901f159c65e6 100644 --- a/arch/arm64/mm/ktext.c +++ b/arch/arm64/mm/ktext.c @@ -3,6 +3,27 @@ * Copyright (C) 2022, Oracle and/or its affiliates. */ +#include +#include + +#include +#include + void __init ktext_replication_init(void) { + int kidx = pgd_index((phys_addr_t)KERNEL_START); + + /* + * If we've messed up and the kernel shares a L0 entry with the + * module or vmalloc area, then don't even attempt to use text + * replication. + */ + if (pgd_index(MODULES_VADDR) == kidx) { + pr_warn("Kernel is located in the same L0 index as modules - text replication disabled\n"); + return; + } + if (pgd_index(VMALLOC_START) == kidx) { + pr_warn("Kernel is located in the same L0 index as vmalloc - text replication disabled\n"); + return; + } }