From patchwork Mon Oct 9 12:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413512 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57066E95A8E for ; Mon, 9 Oct 2023 12:11:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E89026B010B; Mon, 9 Oct 2023 08:11:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E39B16B010C; Mon, 9 Oct 2023 08:11:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDA306B010F; Mon, 9 Oct 2023 08:11:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BA3BC6B010B for ; Mon, 9 Oct 2023 08:11:56 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7F5CB12012C for ; Mon, 9 Oct 2023 12:11:56 +0000 (UTC) X-FDA: 81325809432.06.D0AA300 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf12.hostedemail.com (Postfix) with ESMTP id 841034000A for ; Mon, 9 Oct 2023 12:11:54 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Edg0MkiX; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696853514; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cAuWkRf6b/jGEAz7q4RZSQYiNZF0bp03IMJiZYXPxKI=; b=MLSH9nZkzOZ9Mpls0LjA/GAEahtQooCleqRSeMx1sONAY+aNY2I0n8PHRXX0jyeh12qiE5 1mcSndf694W41SvU9Og0fi6Yz+9Aa60Z3tQp4mvLRWal0DJ9Fxu6BcB+XpzwKB61CZttfR wy9ft9kNBV5Lbtpcaf8TL00RLPKsJE8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Edg0MkiX; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696853514; a=rsa-sha256; cv=none; b=MY7m8GRCi44n8O8fo44iqh0gL23IucuAmPaHn6rjyXaqWoBqjc4aL+nGtNgOeShC60fsRR Lv6L9XJaZQNo11XfbBpYo7xuIDgkW3QtM3GFXmzRi0wUCRDBNxV1xWC6QR/795e5fXaShY 7IqwvxN2EHz7cs5dyDDJ3K94p2Pw87s= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 0D82BB80D95; Mon, 9 Oct 2023 12:11:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B865C433CC; Mon, 9 Oct 2023 12:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853512; bh=42MhIHJYoAESIQOg6Faf648pZFSDD4v6BdFtVSfz3SE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Edg0MkiXTgq0915C8p+R0ggtuWzow4Y1+CyDxlrdLxMNLcdP876Pfi+Z4iJaoh6Ii 2yar+LS0z1DWsttaTGOfOfQkpzOpdvnuOOaQS8fYdA3KJljRY9GhfphtTKAGquocrC 0tiN3n9LytAnZ8oHKWq9YNpf77rmGP1otZgx157zCHs/aDF9t2Kv5q48lDAki8lD9G wuQ+d8ZY6ju5sVJX+UnkNdLMtNw5IlNsqJFhkKrpEkuGaOXgwLHSEEQrcw/0c8iDtF WalKM+IELiCcWgONrK/a5o7fg5/czE0+2IXgjgjrpOLdG6cWRdwHsmBYJv2hdAzzmE x6DiVLPYyCH6w== From: Mark Brown Date: Mon, 09 Oct 2023 13:08:45 +0100 Subject: [PATCH v6 11/38] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-11-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> To: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Brown X-Mailer: b4 0.13-dev-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2918; i=broonie@kernel.org; h=from:subject:message-id; bh=42MhIHJYoAESIQOg6Faf648pZFSDD4v6BdFtVSfz3SE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2ZJRM/idFdS62wSkMToCjd7iU1NYZRbt5LlFz+ CFhJnEOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtmQAKCRAk1otyXVSH0IWBB/ 9ziSylzGcu5afgUxGvT7hjnE7Uc44cyH5zSZbtg0jtpfkjqQEuCg/+aUmduG9pHKiIS13aD+T0OsAM tv28vqEdVmh/ont4bU8MGEfTdaSBvxCUX6+Gk05UBUOF1vhGLRKuj7XKWWvOdD22A/05tM3jepQ0Au T4Flrh771B4GAFJ8jT5r+ARzgqeSIyDXjkFMMpAtR/z9UG+OFIYep/LUqxo8wAI8e5LzzwU79iKrgJ Uz9oEPRfu/G69F6okL5SmJn+heGcKjP2qmT8OB52h2HmvSaGqVOFpysYgnwztsTNa0P6LU+2JO2PI0 r3LrEVJzW+5tdSZupMleqt5dgTwb7V X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 841034000A X-Stat-Signature: m418tk6hg5o6nxkqnmikbraqwnyfbgpz X-Rspam-User: X-HE-Tag: 1696853514-634886 X-HE-Meta: U2FsdGVkX18gxvst/bsVUrsDlSETYNnlREqbrHsxDWe3mtfmvuyy3kSvSwZssb2AJFjOqHpXkWV26IIoBvRVgfwdPEK8VGUhWyjq7k5S6mgtmuadOoTedLGZjyJ5l36FojBBkr72vPExDDA965HTNvUdoIvVr5VI4POEEeXjT51M5akEEvPiHB1ZZUCjcyZQ1d+jWYAqyFQ63zUzWSvG4J4yUuBDFmvI+ctrttQFrkXpbAebn3QFZFnLWNsXFSp9iTESqfBTk+UTCqtyGqRjXMIwz0aAACV+6lEf/tkbco05njmoI1w6NkQxHwAstw3zYeCwS6SRzi2ybGkIf6s4MIXpoQmVpis/NcAW7WGZHO69VrDrNt0CTBL1qcywn8xeR0ulP4E9SLOt9Q2KBcGnM+j4/FZAYJs1QE+PXAxcwbqGAxcAixUCKgsI++Ie2vDWeSzpxNZa7vPp4h74xqPmateChvmx2e5//S+hJE39R8I3HJC5zvsfRVkhboADTY/ISnrCgay41shSB7zThjezG+GlqLh3QqtfeyqgK9W+wiK57SAcuaFbGS5eiHk+3wAu9Knb002ASstcQrRWl6ojOHmO465YVOm0pGGobhvSIBZQDQEjAqhCgTm/JanaOmgWDBNgRfVtm+jp6BXQeCGBQcJQAYkKz0BhF5URVdPdoNJ1ejQhP0sb1+sf4xk1GibdLEEClw4AeRs5taDwySt1dLin5d+HVkJS37appJH5kPtY2D/ZdwLGhK9WHnXp6LETqY4pVUOquDrj+w144Qo5Znq4J/H6cYB/xdU0JoY2BaGa8a0LCr/KeIXy1yyk2eDmSCyRW07RMnygZH+rB0mD1LoaLVJjL+AvrBT9vDiqYZ1W2GFcUKtzTq3JmVv2vfeJIE2qOmzOhC8W9zC4nWy1C2VcZKRtI8IEYwroMZsCtgnezD3GoiHaP8JEpU0g5gumA8BrHrDEiR9hKyd3ML8 AfwAEmcT iTh3/5zxF6kXt62iIycNYYHqrs27tPV/nloe8W6SNht7s+YqI/F7TD5uQbNpLtZ6UNXmxz5IMhE3LQu3My7Bi6GLZc3A7qzDv0uzRlrm2OFIQye7TlO2zMvETe8vdusuUL43neYLCC38U+xxlqn6ThuKnrnO16SMM343nvpfrFcsM4pe5LcYv/l9+mjlE36sLicI49ZMCAUNpnryaTjNA/LGEy7qh2VICrkTC/gh6vjc393sm9mWBwLa/BsjGjP9yFjK0OyZ5NvYpsBqaCLKZpdqn96hvaWSuRwxZv9NbVgbziclGmdkCT6MXnVyth6tmJP1g2mMUpOeCCPc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Pages used for guarded control stacks need to be described to the hardware using the Permission Indirection Extension, GCS is not supported without PIE. In order to support copy on write for guarded stacks we allocate two values, one for active GCSs and one for GCS pages marked as read only prior to copy. Since the actual effect is defined using PIE the specific bit pattern used does not matter to the hardware but we choose two values which differ only in PTE_WRITE in order to help share code with non-PIE cases. Signed-off-by: Mark Brown --- arch/arm64/include/asm/pgtable-prot.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index eed814b00a38..d71474d0d2f4 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -131,15 +131,23 @@ extern bool arm64_use_ng_mappings; /* 6: PTE_PXN | PTE_WRITE */ /* 7: PAGE_SHARED_EXEC PTE_PXN | PTE_WRITE | PTE_USER */ /* 8: PAGE_KERNEL_ROX PTE_UXN */ -/* 9: PTE_UXN | PTE_USER */ +/* 9: PAGE_GCS_RO PTE_UXN | PTE_USER */ /* a: PAGE_KERNEL_EXEC PTE_UXN | PTE_WRITE */ -/* b: PTE_UXN | PTE_WRITE | PTE_USER */ +/* b: PAGE_GCS PTE_UXN | PTE_WRITE | PTE_USER */ /* c: PAGE_KERNEL_RO PTE_UXN | PTE_PXN */ /* d: PAGE_READONLY PTE_UXN | PTE_PXN | PTE_USER */ /* e: PAGE_KERNEL PTE_UXN | PTE_PXN | PTE_WRITE */ /* f: PAGE_SHARED PTE_UXN | PTE_PXN | PTE_WRITE | PTE_USER */ +#define _PAGE_GCS (_PAGE_DEFAULT | PTE_UXN | PTE_WRITE | PTE_USER) +#define _PAGE_GCS_RO (_PAGE_DEFAULT | PTE_UXN | PTE_USER) + +#define PAGE_GCS __pgprot(_PAGE_GCS) +#define PAGE_GCS_RO __pgprot(_PAGE_GCS_RO) + #define PIE_E0 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_GCS) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX) | \ @@ -147,6 +155,8 @@ extern bool arm64_use_ng_mappings; PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW)) #define PIE_E1 ( \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_NONE_O) | \ + PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_NONE_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \