From patchwork Sat Feb 3 12:25:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13544135 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 BCB5AC4828F for ; Sat, 3 Feb 2024 12:30:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4ACBC6B0092; Sat, 3 Feb 2024 07:30:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 435556B0093; Sat, 3 Feb 2024 07:30:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FD956B0095; Sat, 3 Feb 2024 07:30:56 -0500 (EST) 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 1B03F6B0092 for ; Sat, 3 Feb 2024 07:30:56 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E94CFA1D02 for ; Sat, 3 Feb 2024 12:30:55 +0000 (UTC) X-FDA: 81750426870.16.507B7CF Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id 5BEE88001A for ; Sat, 3 Feb 2024 12:30:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pF7nqRrZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1706963454; 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=LvWXep/scgLUJOQC4GSZwGhqKR9iIm4HZS7QLjp4RT8=; b=K6lQomgd9mWR86coJjHpCZ2g1HVtVFJCdlaYY4xMnfiE3OixTN6z/N5neZVb4bTzPM3sui lsTOT3437VKUUkltahpazW5Sl4J4m/ZntoHFDDM7BKVB3LIAztyt+sfBmV6FyrCnjU2Gng XkmP9eft9p8bbZQgHACeBw5NGZ90KXY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pF7nqRrZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706963454; a=rsa-sha256; cv=none; b=vac6DQA28ik3cT00fkslfBXK1yqrGGs5KpOue4iDpI013CsRV29wHcLdcF8g/OHZwrQH/Q 0anRkYb7lK9qkqBrFYefaluqhzVDQHmwC4UPw7ZAQf2kLY9rWp+ss7B15urJx506wWfBXY 0fQwIzLjbKpS2lWutvrhBpwImblRarg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 7AE11CE1F0C; Sat, 3 Feb 2024 12:30:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C475C43390; Sat, 3 Feb 2024 12:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706963448; bh=+xprcrSIR+r2HgpXmJPi2lCD7uV8JeEsPkL8Hbk9EMs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pF7nqRrZUhMqdiSGGPRZ4lQFV9LAa39nD4GPEx2pS4SHjfN3SyIUFZR2Ncyf50pbK gcUitWiq8R081mUDfpLYs8f83JqvKeJhtIYHomgIenfRIpeZGr7t37qfR5e7P242C0 yAjJTLv8+DHI2+tBewBy5RlcRObbJsIrkJboK8hy1jh+m5+qlZIdQ01Rx7JyO7FzxB UpP7vAxry8k/EdaVxXUk987ecA9dYoJUu0tj+eqXMr6gkgokd72MQj+oCkT4ExaRqf 2j3DD+Oti0+xH7uSt2T4aXnMyCPvtZRwVl+4ynyOwbpwYTQxarJNo6RxomoQcVoFC1 Cd//sQHU5hr8A== From: Mark Brown Date: Sat, 03 Feb 2024 12:25:36 +0000 Subject: [PATCH v8 10/38] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Message-Id: <20240203-arm64-gcs-v8-10-c9fec77673ef@kernel.org> References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> In-Reply-To: <20240203-arm64-gcs-v8-0-c9fec77673ef@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 , Thiago Jung Bauermann , 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-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2936; i=broonie@kernel.org; h=from:subject:message-id; bh=+xprcrSIR+r2HgpXmJPi2lCD7uV8JeEsPkL8Hbk9EMs=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjDY6r7GyBRKw7wUgsZ+3nfEbNbAsesepgDtEw2w f6AWxyWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb4w2AAKCRAk1otyXVSH0KszCA CFSKuiESPpOpCspjr7eC4F35RG5kiLJP0HvJZjycPYcFxtl9dvbsnp0qpk9kwV3sdW0jN2LHxK77XV +PCEGj/fKNBU75dICtXgs2uLlQW8DBTzCDw5TAQzsQIDZwbATaaXD6dwqA2jFnExw/StImkNDeij0B ZRWxF2yKfgGJ1MmZzmUJi94IQSLO3DGmVwXC4q3LN/vT/aVbx9GjC+2f5aNBkpaJgkSsZhpp3nT0Uy qr6/+LduI3OPyrsVtXMpp0GLZ8qhasqr5QNlNBn1LeEEPVIiUmbbNx2PEogj2m82LLNAD5aw0zqR/N Relyii0MDbUbCWfD6Vk60iGQtQM3Vi X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5BEE88001A X-Stat-Signature: 4gx3ax1eg1besbamfkkpsagwr983y9fi X-HE-Tag: 1706963452-841024 X-HE-Meta: U2FsdGVkX1+K4IsM02OQ/a1PuSLyCIcl8r11Zzn7YtxULdTsV7LIs9dEpF3l5YWdfMafS/3+jsRkybP1/WdC0C2QxSDkSWr6gZs0mgvsj4h3063NShRLirpZOt15mqSgRVs/Ni8xSeEuHkx85xqFDYUdAEJRZR9eNnanURZ444pztkYYrpQxHXYC6emADqObn3sNjVwYaSBTjY6TYud6GDQqKVB15nC1HUxXralTBwbE/Tzy/5WhQDMfR5XtphEcBgZ3I7Ak5U6+Mu5REIh3JrC8EEx1nNHGJkj89ZQzNJZ+8EtdCBnRjtjcww3PHqSvGBes2AuLOtwm+WcJeXKNpH6DBD3Gnj/FOobJpIhBAoNq0F9ukr79cYO4EvzylAsyTAYV2ZmWgLhLt5AupaRm/KN5/6ckntNd3+BUklrO66BwuNqkx1kJ76HKoihsnjE0WAfvS6G2xRm3Ro0aDfjMjMZ4nIh6VuV6q1s1mIeCgJIX5ru1fteFuWv9JdVBkA76zeoJNDcXfWz/29IJeoo4rrzkXXqJIegMBlo2oaGZtea0CqCSr11UhxOZgGj2UBfLjoEvsGtJA9hp4ySp99c7GAL4FKcdgI8YCeziyMiaUSk742F4FR8DyRW2v8TdfqA1a5snJG3iMqGcR2GiFeaQobK2sAeWRZ3excHLkRDIoWFQafLzISaRzyeLqcjQ2o/ASps/zVbUGgBLvQo/MvrIbGkRm7XAfQSt7jPusX5q/SzBllAy9PYUL0NLfa0O2dxv/2LSqXAEewI90j3ooJmX8QzoYGBwIAiNdbkhHOZRrihsF/GreDJMcwukvaoH0hfW7Nbt/17gdHG1w+0CNrr/x5L28g9EvvRjFgNEazP1yzGJq84/dd2dTcVsQOKYp2KEZfJu85mZqJT22cYPjOskDtuO784eo5Ablw5x3EmMOVkKr/ErpgEG4BGhNovqAqbR//FJ7egKLTMoe5HBimB dB8TVFpm xtb/N//v0dayNVEJMEjPdH3QOJtbOHdBrmwXet9nrVOsYg+RU29E4EDw5aIzQP980EZOgzoWgqK9ZfDYwKWu2rChAvc33Lzfks7vd/wOapQD3sj3yTcdgro8ZRt3OOuxVKz7BNr8P9VZC76SOdlbne+V28CZOCLgSti2Yi04b43RME+JWlgoXzNKGpG4Fh4Skpu/SqM4OMiqZ3DGVVC1B4riKz3SEDQMgRnhzl/HwOrz0xdn5Ol8E57vWwVmlFleihbXcajc0Ns0hkQBCOOTnoV9NcbxcMOlwM0OGdiQe6TpA72zsft5+ghqUe4UiuRbSo/NM 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. 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 483dbfa39c4c..14a33e0bece3 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -129,15 +129,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_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) | \ @@ -145,6 +153,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) | \