From patchwork Tue May 30 14:05:00 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: 13260144 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 8C978C77B7A for ; Tue, 30 May 2023 14:05:36 +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=lT8z0TqJWBHWta f8IdSW8/XMG2PLsecnywc5UJ/W/+MQLztQIFeIwuhbCvrJDVoqnbUeYjGRIKkD8FeqNGpNq425KR1 N61E8IyYdQjetRtspdF72Ooq/amYIu0NzQjlMjW3otyOQTEsOspOIYR4DS7McYLq5bi1YR4LabwOP b+5iCI7WVB00Ts0NW+OQVaYYg7mU+HdRNKxrUCEONMmZld4Z08xVHZuewgk3gPiCuVL6sc0Jo3XKp gTSzMHFkj/D1s3rt5h2qcSQGfzrXnOrXyxKptJXB1UGo9tnuuvrV1uG/BgKVj1eKET9GRFZCDI4Xh UfepOBlPJOULFKDN6gaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q3zyN-00E9Kd-1T; Tue, 30 May 2023 14:05:15 +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 1q3zyA-00E9Fp-2f for linux-arm-kernel@lists.infradead.org; Tue, 30 May 2023 14:05:03 +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=W7nmtbT408cEZTFXKzvM8r4hhL u0ofMJxHijW1UPdwrPW2t9bCDCfpownf0sr8OcasGxJdNzSELGxkMbB+UzjHr7rwnxdPViDUgsK/H Dh+WI8BEHEzhlX0+3EFo33Aj2AZCJlblF9m6NYDHAO7N/FEaNCYnTUMaoasejEk1krgqqB/uCGaKJ /azzEDxtBoK6UVfjBXa1433K4ISkBy/A2xJN/BCkFCWI1BQtCxOQAPbqatZweAmWRFZL3BCK9DipL aCp+jngwUFmj8FCPywcAV/ieTo20SJCbJI1bt0RLf0Ntvgxu1Xl3P3SLtqU/FX2E7LZTZfi6wCEhE Eom/9Ppw==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:59742 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 1q3zy9-0002qw-GV; Tue, 30 May 2023 15:05:01 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1q3zy8-00A5KY-SD; Tue, 30 May 2023 15:05:00 +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 06/17] arm64: text replication: add sanity checks MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 30 May 2023 15:05:00 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230530_070502_871395_10E0861D X-CRM114-Status: GOOD ( 11.13 ) 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; + } }