From patchwork Wed Feb 14 12:29:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13556422 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 47777C48BC1 for ; Wed, 14 Feb 2024 12:32:30 +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=yY+jS3bFfP8VNDJiNrQgoLcYcqqXWBMRVGs8ovaGcQo=; b=YdRiJGkpI267OhxEVIvR2nQ0ny 7rYismJzjKOqIxTlzllMkOb18GbPEQwg2kqgzwY+ptKpdYNn7+Hb85Pm1ZdlHPkM97s87km+HtIuZ RFZRQyHHEudUAnc673djnNrFMQD2e1Yl+31cAhqUWLLlWyK4zBsvfE9KuWXiz3f+pHPNqDEmlZwNJ AYrIu+pZwb+7whR7hs/Uz4oLbL40KiKYhNINqJ+nrDwzde48BWAtNEAhZwhteJFaoCNqCHQr0JIBV cpk58JEflB3uOR1jFVN9nezAmMLY1MSb4t+HEl4L/HaptajQBpKJxCtWEdbOp5vmxKzNRugYG8QNr 4qKxPhwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEQv-0000000CpST-2beY; Wed, 14 Feb 2024 12:32:13 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEPX-0000000CotU-3di8 for linux-arm-kernel@bombadil.infradead.org; Wed, 14 Feb 2024 12:30:48 +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=UmoIXXu47giuVJ5/WB15T78TLfAAHMBF5RoN/vaIbRU=; b=lT/+dbJV2hBQytmcWkCuBSC7sd ZsA60tjC94Q8aG3kX4RYtpAEHadeVx0UZY4ewLO5sBNufPMVPDbDHw1te8gBKpFGRvG4d8BsS1D0W nj0KMsWLJRoLJnLABLgjUNHjdNaJKQ4dJSvyTRQ5E4oZ2p8Viqh+AWARYIYyUDEj9Nl+Z86koIsSK YEs6IbG5iwZavdSSyvCpvjN9sBl8875V37zBu7Rcdsy4ODOsF07XbM/Kt3buSOveHv3LLV6aSES6X 8pqgFTuuGWns2gOAGFqAI8EwqNAJ65mRmevwh7W7G6gSvqqIyODLkMW4EI8BRaKhAnRa6qsWPesoM rsGjW2Gg==; Received: from mail-yw1-f201.google.com ([209.85.128.201]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1raEPS-0000000GE5y-2LAq for linux-arm-kernel@lists.infradead.org; Wed, 14 Feb 2024 12:30:46 +0000 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-607ac7dbd61so5960067b3.3 for ; Wed, 14 Feb 2024 04:30:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707913840; x=1708518640; 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=UmoIXXu47giuVJ5/WB15T78TLfAAHMBF5RoN/vaIbRU=; b=cvXZI5Tm8hloNeHdCHP43G+IX7g0J8Pr3orPsKweymuROeJk9bkVkdlcNWv3hs7044 tamjGWreWYNQhiZeoz05/aPQH+yTJuLWXJRRQu93e91dYDmF3A8cS1I/xHH9rZgnHwJl QvdIgWEn11Ms9JYyresdsfL+2L5GXQUrXwRiyYvXQcT/1JuKmep1ENBFTvucbBGJ/Kw3 iGbiiZ1fQZyYuFeWs+mw25wV8B85pogC1nemMwfNzSaxa7XttRrGQkyAqJANF67LDkru pPc2FyN6qU0cKBTlHZZJjE0i8SaqTIbGssplqklmIeW+biDYNkFAuU/vjnX7yNTWzCk8 oSDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707913840; x=1708518640; 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=UmoIXXu47giuVJ5/WB15T78TLfAAHMBF5RoN/vaIbRU=; b=WcNW6YtvSkR2CuwiyfjkN2e9IBxS5k4Hl8K+bX87vILIFwARl4TPTSSGPGYj+VDTxc t2ekcZ9rdank/TgTXlKPRl4EEW8bYGvpUJE2QzIiDwBoCa+KpFENOKs79N17VcA6pSnn ycRMU70wWRJ31wbuT2uUVv8TcZ0ykyXYhnMIKytTf4O62vqwnFU4oM+AqXXsm2joVJcV pcBak2OC0fmoGrpwT7VEOpVa/x8GgsdG2ORwET5/JbMGOZZk6xdFw28J9GqFMji05ZB0 otbAc2lwxxoh9IvC2eYeLKZmC9B6ExkvjQm/HOJ7jp+LTRktS01LJ6c9wlz6K1utUkyj WLSA== X-Gm-Message-State: AOJu0YzAtcG8DY38llIx9KOaB31lcjBbKyt3IOQxa8ymQIw/3Eq3A0Ti iVmOGxAR2Y6v1CAI/0iJDwtjsT4tNZTB2XD4O/33b1KL0UXp0xNM6JS4THupQBdOdiZSF9k4hkA +kSxSKlfWjw/EI1p8hCifFLs7nJ3RbYdmd1K7p554ywVlH/D19i5FaB5W48RVWtG3Q6GDsKUtzx wuh1gVuoEg18GnqW9qHMFfW8RLHkdRU3sytygkYhtQ X-Google-Smtp-Source: AGHT+IGdBb6dQYvzbp1+SKDT77XsP93KDTljffX9vj7hWypgEQW6cMiWl4W28ll5CeJCQ2rR7lGryyV5 X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a81:4f05:0:b0:607:b9f1:e821 with SMTP id d5-20020a814f05000000b00607b9f1e821mr30281ywb.5.1707913840128; Wed, 14 Feb 2024 04:30:40 -0800 (PST) Date: Wed, 14 Feb 2024 13:29:13 +0100 In-Reply-To: <20240214122845.2033971-45-ardb+git@google.com> Mime-Version: 1.0 References: <20240214122845.2033971-45-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=nInT/OYTmfVDNGSlyD0iMsc5q3tEV1+nqq5c+zMgpP8=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXMJmnXzWEG7Hdn//Odddj+89z6C6aVL7bsy1b67em9s ExxV2Z1RykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjINDdGhqcXlJhWFbN092pu 0n3lqGRlnhfYGDBJ3+hF+w2f9D0V7xn+2dRILnm/csakGEP7isnuLv7HZj+UufvgncW2yQFxr2z eswMA X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214122845.2033971-72-ardb+git@google.com> Subject: [PATCH v8 27/43] 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-20240214_123042_797134_B6417926 X-CRM114-Status: GOOD ( 15.90 ) 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