From patchwork Tue Sep 12 14:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13381806 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 22C01CA0EEC for ; Tue, 12 Sep 2023 14:20:54 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=krFINH6Ql5ogfKtZFYV62IKjb3nILkyPhyuyWq9KK9s=; b=flvqHMy+bys9E+OiTvJrTRxuAF 2mwxs5d1F8vUmCLxNQZ/9cbMqk7zRz9Cby15Vo5R9i7IZtRs0SUHY6l+iGkWn1VgRqNfnQs9db9g4 qe2b9C65wcB3c2m6/uIIjKFiY5LA1YzXF95ByqpYgiRJpfvl40t0DjwAgAianPuqjHZPV7u7OSvR1 hCfVNTroR1/xmfGGf83mb1tiwlKwy60J652O8RjWD0BEvr2hggGqlmpvNgq9pkjDT3Rwo0GkVzir1 Ktx1cZ5601QTwrMgy1HqIdjBtd9aSSw5EoWkThK//l9jvC68C6Ic4Q/rxE48AAHf67/w0xUw5U5nk UOdAxlHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qg4Fa-003YDY-0G; Tue, 12 Sep 2023 14:20:22 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qg4EM-003XBW-2j for linux-arm-kernel@lists.infradead.org; Tue, 12 Sep 2023 14:19:17 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-597f461adc5so62618427b3.1 for ; Tue, 12 Sep 2023 07:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694528345; x=1695133145; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YuFo+zhrlHBQxtpOYSqLrGv0YPox19bH/VMTVW3OMKk=; b=4TLUIqUW1xld3HI23Klmtv2eTGKTX/tuBW8cfMi68O4E4U3Ddmdok9MOTHFNkW3fgd X9gIb+Eiot4GKjRDDU3dTtRI3BuR77noRFRr4ST7j6/i3COjIMNSrRliTBN5yWKZePa+ uZHa3DwglvHxHXiKCnf5G0u3S7VmOVjntvpql1jw4Nm+UqoUTiehQ2Ecuf248WfVYwM1 L+9tVjuFKgOVHi8QmaPi7EPrV06if8I5QJLA/cnQQk1+GgT81MMUltcDp3KdY4ov6zGA Z3bIvTE9SaHf0A/8WGQzO08B2H230rQnoE/+u4i+PdAK0QYrT52kXaSg1l2t2kdw3YzL 83yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694528345; x=1695133145; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YuFo+zhrlHBQxtpOYSqLrGv0YPox19bH/VMTVW3OMKk=; b=iX0fwxD4zUBPp4XUg6M2FLyGDUFApC/7nbcyP8qMcpwcSSEwJ+RMF+tsRdt/ctC1Cg LncU9fM0MWFFfpAMOUKM47TNdWosxPDh7XziLcgi26+W11IB9vsEcKU0npxhZ/QW/BPg FD4c1Ms9BSaG0p2uWRxBaTpxfUILle1c4R1RunKr7jq/U3PBa8bPcAseVmMNWLufpSTZ 7ZoQxfRz0DJaEvxeWS60ySambNdAPgECBTDMCBQEncaUId77/BG+24E5CEIl0EUT7hL2 vYjPm8AdkYhAytBnWU7AFVYw90/FSPLdCfK7fXArYCiH3uiRxOb7YEr/KRI2IRSCo3Ai unLg== X-Gm-Message-State: AOJu0YzRZruuYMBx4L9yQvRzxbPsRfZiFNloF3IoXCmMpTI59TwRotDJ 0lPWzqLVHr17Ucx5JPfXqr1a+cLKNetnhUzJM6cSDDOW5aqii3Uf80PVbQUhtEonSSSnF8T4K+n XQOCfAIi50Ty17q2RJKb3XR39EoX/PGRYCGou4vN0rg3S8elaeKObUEbFRNM8itYNdyRwCW58NC c= X-Google-Smtp-Source: AGHT+IFKQgO4I6kmwuanNWsfDjwN5Tu5o/8KzSYmnaUqgNrAF1UrDmu3cnsKXG71vVUwdOh1zF+Xm5HH X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:c84a:0:b0:584:3d8f:a423 with SMTP id k10-20020a81c84a000000b005843d8fa423mr299933ywl.8.1694528344992; Tue, 12 Sep 2023 07:19:04 -0700 (PDT) Date: Tue, 12 Sep 2023 14:16:35 +0000 In-Reply-To: <20230912141549.278777-63-ardb@google.com> Mime-Version: 1.0 References: <20230912141549.278777-63-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2581; i=ardb@kernel.org; h=from:subject; bh=V6DZobgx0PLonWJdeZENIUbjbbfoYLLezxmlwMLfJ2U=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIZWh6OgBhziF/KqzHAoSsvo5gk3LRBaGX/J/8Gyvvv5Nj 2Vbq1d2lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgImYuTEyPCh7+Ltr6utpnsrv HO/MP6N7z038wrXCZyzZC90LnVWtAhkZ+hM9f4olZXk+f/TuT8NNriqnPzc3sFz3kp7aq6d1Wn8 NKwA= X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230912141549.278777-108-ardb@google.com> Subject: [PATCH v4 45/61] arm64/mm: Avoid #define'ing PTE_MAYBE_NG to 0x0 for asm use From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook , Joey Gouly X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230912_071906_929662_4F9318E5 X-CRM114-Status: GOOD ( 16.93 ) 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 From: Ard Biesheuvel The PROT_* macros resolve to expressions that are only valid in C and not in assembler, and so they are only usable from C code. Currently, we make an exception for the permission indirection init code in proc.S, which doesn't care about the bits that are conditionally set, and so we just #define PTE_MAYBE_NG to 0x0 for any assembler file that includes these definitions. This is dodgy because this means that PROT_NORMAL and friends is generally available in asm code, but defined in a way that deviates from the definition that C code will observe, which might lead to hard to diagnose issues down the road. So instead, #define PTE_MAYBE_NG only in the place where the PIE constants are evaluated, and #undef it again right after. This allows us to drop the #define from pgtable-prot.h, and avoid the risk of deviating definitions between asm and C. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/pgtable-prot.h | 4 ---- arch/arm64/mm/proc.S | 13 +++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index eed814b00a38..282e0ba658f0 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -57,10 +57,6 @@ #define _PAGE_READONLY_EXEC (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN) #define _PAGE_EXECONLY (_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN) -#ifdef __ASSEMBLY__ -#define PTE_MAYBE_NG 0 -#endif - #ifndef __ASSEMBLY__ #include diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 2995a92940e0..cb80ed3a2e52 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -457,11 +457,24 @@ alternative_else_nop_endif ubfx x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4 cbz x1, .Lskip_indirection + /* + * The PROT_* macros describing the various memory types may resolve to + * C expressions if they include the PTE_MAYBE_* macros, and so they + * can only be used from C code. The PIE_E* constants below are also + * defined in terms of those macros, but will mask out those + * PTE_MAYBE_* constants, whether they are set or not. So #define them + * as 0x0 here so we can evaluate the PIE_E* constants in asm context. + */ + +#define PTE_MAYBE_NG 0 + mov_q x0, PIE_E0 msr REG_PIRE0_EL1, x0 mov_q x0, PIE_E1 msr REG_PIR_EL1, x0 +#undef PTE_MAYBE_NG + mov x0, TCR2_EL1x_PIE msr REG_TCR2_EL1, x0