From patchwork Tue Jun 25 14:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13711329 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 29197C3064D for ; Tue, 25 Jun 2024 15:01:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B24E16B009C; Tue, 25 Jun 2024 11:01:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD4406B009D; Tue, 25 Jun 2024 11:01:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 975516B009E; Tue, 25 Jun 2024 11:01:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7A4296B009C for ; Tue, 25 Jun 2024 11:01:55 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2CF9B801BF for ; Tue, 25 Jun 2024 15:01:55 +0000 (UTC) X-FDA: 82269725790.18.83D0C5D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 46BA51C001F for ; Tue, 25 Jun 2024 15:01:52 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ilJXrKEm; spf=pass (imf20.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719327706; 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=N5xlaKfE1qe1MkU2t/MFh1LCl5bc+UWmzF2cua6bJB4=; b=Sdmf+XNf5I0c/1F66PM0BlhWpJ/FVkPfMCzFa/ZVkzm7oUUmDnpEQldrjAyvaxmZJgakXJ CwL7+f0u7nTDcxRzUFJGQxyHWGcj97tD706Tyg85cTYNAKhE+uQs2FusQx0Tplg55w+L3g 66aMfCH/7gvMHxKNEiDl5in0dhUElvY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ilJXrKEm; spf=pass (imf20.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719327706; a=rsa-sha256; cv=none; b=V9w0bYRdY9O9gaT7crgdvbIG8eljBXn9EUSdo6vnxacvoSzT9Jqk8EQoXru8FdrdFGsaYr OEsGviUUjcgoiivIamQnfSZd0ECqwD4CPHBj9hDq2/r0o1n/ajPLb3z4IBoF/j+w+sHEsI dgdycBOojkIMMWD9KEsdynCY6EZyVyo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 318F961463; Tue, 25 Jun 2024 15:01:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C39AC32781; Tue, 25 Jun 2024 15:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327711; bh=WqKsS1qVwE6VKZ/8GkyAqMVM3MB00X49lYjibfc4BZQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ilJXrKEmoiep8bJXwU2ISOt1APx0j4HH52q1DZ7pmu5WhdjJ/gwYyljQqcWY3Vjg3 oXgriQ2ABM/n4QvbZVNHyWpA1l28qOgXngRQbejJl+SAjFIiK4POMXDzZ4CdLj+AZ5 tfwouCFft2E3QW54hM5YYqgtVHVEXfWXOq+8hAlcKDRBIiOCsxBUxERRufuNMJCaBc avKoDFeEtMVgkM9n89rShVeR31dChFcneUSoU8caUxnt20VEENuYHTXS53Zmlo1ItW VbCvVI0OkIz2PFeY4WxioBe14xv474Ptj6kuGOTvPrjmreGF3N6W/5NZvO+pPDz+5O EY4Ko0lF0s0/A== From: Mark Brown Date: Tue, 25 Jun 2024 15:57:38 +0100 Subject: [PATCH v9 10/39] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-10-0f634469b8f0@kernel.org> References: <20240625-arm64-gcs-v9-0-0f634469b8f0@kernel.org> In-Reply-To: <20240625-arm64-gcs-v9-0-0f634469b8f0@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 , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , Kees Cook Cc: "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , Thiago Jung Bauermann , Ross Burton , 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.14-dev-d4707 X-Developer-Signature: v=1; a=openpgp-sha256; l=3028; i=broonie@kernel.org; h=from:subject:message-id; bh=WqKsS1qVwE6VKZ/8GkyAqMVM3MB00X49lYjibfc4BZQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmett6+kzmyOKCgGmOpKaR0cYZSVyO/9vRJKYT504K +JJF8pmJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZnrbegAKCRAk1otyXVSH0LTlB/ 9valnIlrade2yvkfz/cq7OVs3qbTVZqiZu4l/buYvQpXRVuiOmXSzOsy72Yn1FZwf56B5iBpBMKom1 eJKNSskeZTfA7KqoX4PcpxkTwpE8HITZA4bgrVDb4CZSH+CAp1ktvwdcV93bLRbpruBdY2Sj50uocW PKeE7/Ui7c7xjlvSyFe/nzll9PwXqYCu++22FsAl0k/us/kmVqiQziqJ9ovcxfB70CSEckHHUSciGp /tEIJ8r6dNBoTfitEpdbcbOkIqijQGoOiq+gtbhuw3/GFLnYklH/3jquwVYxA2LbzQJHqTV05fyZ1l ilXi6zOwiYbwYEysmWGxPakaUJRNkv X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 46BA51C001F X-Stat-Signature: s9for63f8x4df6zfu1gc6xn9c5dxooqt X-HE-Tag: 1719327712-300063 X-HE-Meta: U2FsdGVkX1+VgrWbydnMxt5BrnWiaBj8YKH8q2NLvvYfPgPp5SQdAmq9Izjmh4xSWQUV1SWSxAG9kR5JApYmuq7y4gDJEdMd69av3peqJcovwwUUZgnKtXIJSaPd5lHqdQhsOMVwnuyKDU4ZBZ0G9ULZ592YaNVq1a1nWmSPHJu3V+P0DOYch7yMP2i7oE+lt5JvTd7rxXZBL8uxE1aHZ6AgM1OoRzTy45fjV5oAKheerusdCpEuXoIxPfF4po8ervthzzplmLBGKC/kzLP8KToquBkjPTNcUFJ7yq0lOd7AYn3Bj0swS7A5bgD1U0kZ5UIZSR2qR84qwwZIt8oWUcF0A3rzlyCbWaFM5Gm8fuUiZfIOKiUahSHPupW2xWZhJCAxameGNeI0TC5dvlC+vemcMaTN8aA1srkX3oxQsNGBWdmmymMC4JQvYbfjqB+yPtAOcYePa3jX8FJrwAqapbXY/tpmjfHix9W7Sk7SUmaYO9DrXZZX0dxMFnpsIWdpTRPidZjycg94prXB+06TZM6YjkOKCUJ24N7y6cyBFgZtc1DpeOwQr9M8xd+IVOAACDhdOY+Wt5ciP7NmLplHjuIdq2UszbAg32WT8HYm/I1m/+3MpZF5/TgwESQ01W1UjJzadDj7dTkLZTQf4wxMMP3IYg8PNRBUcPxFySTBNak+DhMr8UwRpHpnlxWsdMMi6bzDgrzWiibuOXAlEoV+zQZSMra+D08Qg6QCdjY7dPNEnh2HWm/de9uYzc2e2CiNtSInejb0bjt/HqB3sIk+kZpi+yBudde3sItM3FwTtnpcjpDcpL5hcJZE36qKA2GAMJP90MEZwpFu0+xFftq0NjcM7xucDb5PS7BcHpwQVuC6m46wxH7zAWBeoZfSHs7BEMuWLd5qxdB2OALreXtwemab4jNCNoz2GOHawbC3ouX8Ghe69ysBxt87GxBJXcLbY9X3UDtc1R8iN/6Xxql FMmf3VCi z+Q0wol7/HWsuCM5nRIQR2Jlu22q5qOsJHEsBjeeCjuUvCPzMAQ2rIhpL6duQAraXao+iU5eK1Tt29WvR8/tQzggHMd+JlNHsldhdJXYy6EqakLMhYDtzb8H2x68S6VJOBQESyTqf+8qhAYnjafdC9G3y8A7xIyVKEkEjjIUjdlJ0eb3GBccywnivCGB3TAgfRaHUEHFTgvPyHd4XRJezY4nVqaN/yfb6+2oWkQyyiPufyraKTFPwqlg+wRWIpnvl0HVDLT4sHdpdmjN6hrkS808f7zFizmXONAYbH7iOwwWONXK6jbUdA7dE9YtOLjacokReSRNs9jFeQpvOTIY6bNIc1iq2Jd8pK+mbgDFe31FS130tETG1zNtz9Rcq7UMBFAQP 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: List-Subscribe: List-Unsubscribe: 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. Reviewed-by: Thiago Jung Bauermann 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 b11cfb9fdd37..545d54c88520 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -144,15 +144,23 @@ static inline bool __pure lpa2_is_enabled(void) /* 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_NG | PTE_UXN | PTE_WRITE | PTE_USER) +#define _PAGE_GCS_RO (_PAGE_DEFAULT | PTE_NG | 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) | \ @@ -160,6 +168,8 @@ static inline bool __pure lpa2_is_enabled(void) 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) | \