From patchwork Tue Jan 23 14:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527552 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 0480DC47258 for ; Tue, 23 Jan 2024 14:57:14 +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=dRS7jSCCOfsPa+XYLLsqWbSLwPIWACe19X7Nra0ANmk=; b=EvDRlpPqatwQNv6GXCZ2xoS1aL aj3IsCirS9VRNlG866HdiH8KkS4rXtsceVXCNVri9G+6WRvRbmsrv61b1bZm026u2FV7zoiZ15Wvg 5fer/B20OYayTA1UkpZ1ihZx74pFD867lHX31dHPnxBU1vDNfuL+fUV2Mk4/xwBCWT5uSv+x72k8W taUaq1f9V3ksCWth00e57y3CVHGKmBRXAZboUWeFeNJ+5HSnCWOV8Ia8BuOKl5d4wQvk7EPvgVva9 KcIp443Mo+lgRxK/0UgPUftCZA4/aMgTAEB1zKV9AW/D3XgdRc2gu7A3+UVmrnpKXFkj8J5xR5eia iCQs79Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSICb-00Guje-1L; Tue, 23 Jan 2024 14:56:37 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIBm-00GuJo-2Q for linux-arm-kernel@bombadil.infradead.org; Tue, 23 Jan 2024 14:55:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MHFTHO0gJ07B4N0Yy9EnU2+LDAtL9wfGuZAkfKiS0UQ=; b=j9iDkPZii8kOYilRCZRORFxkrr NHAeR8fiHqrlQdxyswc7PW3k188AtGQvKGL58hMLpBV2gNJcn57Mii79hwnh6s09cZQZzSQN243XO ANOkj6Lc1PRros8FB1kDCje9C12XrvNGjyS/quqouX+NPXFNEmL0aAIJiVt8Xv1aDDtcqHYv1Yfbw d8xwjnRTJGWzDBgOmOnxEyUdqayQyM64+HbZlzeAadchUeHm9NT39gxB3a7n6Di1+hvvwS4nZGgRR vRcW8xC+0co5ilFnRNbfeXI7YKxvDi59LGgC/ASF5ONk7iUYhPS7q1vS7u6sEjBJdFIA1swMwW5NI +EkegoUQ==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rSIBj-00000003vVZ-0Y5v for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:55:44 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5fface2c4afso36099727b3.0 for ; Tue, 23 Jan 2024 06:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021741; x=1706626541; 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=MHFTHO0gJ07B4N0Yy9EnU2+LDAtL9wfGuZAkfKiS0UQ=; b=PHKGDk64vHxIA/B7mpyyJN9DfqzT0DoBCu0xyZjNwBRvkZoB0W1hWFJ0FCIfo+oKUV mPA2aBzI8OvPGBvNUdi4O0EKT9dQAvxNZfoUBuqDWGa95/9h5bGdcUJDVT7/bvRpDCVw YqibioxTYzKTpbvPl6gUIx/fh/wFM0M781OC+NdcZ0LCJZOuFt0axvfXAeBtkEAyu+Ks zYx8QnRTPseRGFmhWrssDU93iPvRJtNwtDgjXLaYNBoEPWauLiiF2g9WUW9tkjH2TtdK hJ+zyswB5N4nEcoEvgQWrLn0+a9pHOhWUsk/MiV5UwV4ODl1bJwW999g8uLDWvOYNJpq Pm/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021741; x=1706626541; 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=MHFTHO0gJ07B4N0Yy9EnU2+LDAtL9wfGuZAkfKiS0UQ=; b=Bh/wuIwvgZy/6ifh4GfNRD0aRQeKjvJET6ztkZxL9yL+PvAexoXmx90toUCC7oXDmx 9wMQI+AVLbnt40YoyD9dcXB0Y1Xf7nnunI61K1UcLLYhJ8oWRkX7F0itJHRVXTw2ziFz huMX5dl6KUazzrKc8OgdIO91BhJXvs84DHNmzzyqcLEyGAYDrxhwjaquLXKgaB4r1USg wuXhuDi/6FRt5dz7i7eg2l2gjC3TkbFNZakzw8GWC1ePvh82aPai6gCt/WsKCmeaQfo/ uevuENXIyeUBU4Sgj/KMHisy59mTKyAgTMg+jewJnGmXF9rCPKnbE0WLFW1uLoifT2Sg MVMg== X-Gm-Message-State: AOJu0YzUIDzEOVgbxLkPM98+JmDxl6qlZaZD/TfPuBjZ8FiX9W4iXAlH bxL77IQr8sX5kGNaTkLGZyKIOoM8IqefyKdWamxEGcMWYtxZVEifs2dpQV/BlV8IXaw7tupSxct WcSGbxW7tqbRvieFcNkTwidavJRgjF4MZUBaParsI4iW+eTwzRD1a6dO32DsXNn/1uYwqE05XnV 2Btob42wCCFTqfWTxQ44lJ2qDPk8fsfdquTlBVRNx2 X-Google-Smtp-Source: AGHT+IGIfYafj6uMO+fAV5Evx4JGtjtChvVa+yK8yMiI5RFW4oXjnDAmCkAaDyahCnJDdxO1NSxZpVDn X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a05:6902:2288:b0:dbe:a220:68ee with SMTP id dn8-20020a056902228800b00dbea22068eemr328557ybb.0.1706021740830; Tue, 23 Jan 2024 06:55:40 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:33 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@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=+DIdhx9FTnpM/JUeo1/oVW1dtczn86Yl6zsEwdhDaz8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pfepm48kB/33q2j/sf+Wws6LtUuFvPUT4/7MbMuX2 7XJv2ZfRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjI9d0M/6u7Wn9oc3tlKKg/ 1/OYyXR2f+LcNXLbl2Y68KyK/MCW58TIcL9hbf0z3qDmKCkba6eA5xuCP+2+p2VnUP2m/iiLmUI rOwA= X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-86-ardb+git@google.com> Subject: [PATCH v7 34/50] arm64: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_145543_319305_912D82CD X-CRM114-Status: GOOD ( 16.03 ) 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 483dbfa39c4c..63ced9ccec21 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 d104ddab26a4..6e1b2bc41a9f 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -456,11 +456,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