From patchwork Wed Nov 22 09:42:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464405 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 5A4F5C61D9C for ; Wed, 22 Nov 2023 09:44:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA1D86B05A0; Wed, 22 Nov 2023 04:44:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E524E6B05A1; Wed, 22 Nov 2023 04:44:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF22E6B05A2; Wed, 22 Nov 2023 04:44:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BBAFD6B05A0 for ; Wed, 22 Nov 2023 04:44:18 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 925F6A04B0 for ; Wed, 22 Nov 2023 09:44:18 +0000 (UTC) X-FDA: 81485104596.30.86044DB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id AF9F94000B for ; Wed, 22 Nov 2023 09:44:16 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=h210R7jL; spf=pass (imf12.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=1700646256; 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=NSorrFaz1NAT3W8+gjPP65V3WERq3K/Abd+JMiBMrFQ=; b=GL/IXoab6GmmgMfkRg/1c7vFznGdi5HwDo9XaJiW3QuAVowVmMiT3U5hvriuqUPgKueEPx wLiqmsj3GYFjEHfmKY7rudfw0aFWeO5mv8j6PaKfiE3SyzReqv7y38HEX10bOh1HzsUj5f sJD32tSUEcAdHN0QPFP8nOpWhSRlbrw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700646256; a=rsa-sha256; cv=none; b=m6y/UVVWtjd93z4p3whXFEEqx9mjL5wwvARlgLP5ltDq4IpyVCgAvWTDtsv+YtZoflW3nU pC6GbjWrE1g/0q30QQu3E2chx9A3QfqAnIPh/Z+BRJ4EL57tJrNERqqVbd29Bm+ZxSLTs9 Zsg6Pt57/Js21PVsqSnW+QzQiw8X0h4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=h210R7jL; spf=pass (imf12.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D3BF261B74; Wed, 22 Nov 2023 09:44:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F7A2C433CA; Wed, 22 Nov 2023 09:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646255; bh=gCkTJXN9hgWCfubwLDLAmQpOXrRFEWNkqe7LcsfqPUI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=h210R7jLnqkzHFNW2i+bNC/uW8728czTflygATeqPHl26mTG4iNTO/3gkMXGYPXFf PH8vpoZOA7k8ZL9aFvlCjOOCziT6vy26FbZL1HE665xm4hvAUJvhE2zp6t9hzCfeqo t3IJNIHcA7tQBbVdWXAS2/RmKl+4V3XS5f8pVjvm5p17xaH9rKDG8KJPCnyHe4rKv0 HxFWNWYXflOIzbRkGZ3oNzHRXJweodM+ntU8HkYYfwHN9YnMhlU/AiZ+ctbxSLTi3K 3WwpCNuPtS29zMJyc0EWpf9s7RymWtpI9ltp4+horOAkwOTgBysp6m7F9DquRI7H+/ 0znHAiLzjXVdg== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:21 +0000 Subject: [PATCH v7 11/39] arm64/mm: Allocate PIE slots for EL0 guarded control stack MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-11-201c483bd775@kernel.org> References: <20231122-arm64-gcs-v7-0-201c483bd775@kernel.org> In-Reply-To: <20231122-arm64-gcs-v7-0-201c483bd775@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-0438c X-Developer-Signature: v=1; a=openpgp-sha256; l=2936; i=broonie@kernel.org; h=from:subject:message-id; bh=gCkTJXN9hgWCfubwLDLAmQpOXrRFEWNkqe7LcsfqPUI=; b=owGbwMvMwMWocq27KDak/QLjabUkhtTYM/8lHrpkfRDKsNrcv+HM4ftX0yZd2fNToL57XXlv5 UOvmIi3nYzGLAyMXAyyYoosa59lrEoPl9g6/9H8VzCDWJlApjBwcQrARDYpsP937Bf6G8WaH8wS YTJz+hT7PkttgeLI1xVXNCfMl/p82eTBruI2duXO/qP+f9YFX1rxK9B2h3NLW5GFu63oJoVFOc7 nV3j7lmhOOmrZMmGVgMOGJ4cce5+8qrfkvBvQJLSi70Sdr71Os2Jxf7PPrIgIzU8e9Wx3HhrOE3 ysuznx3ozqD5f5a+2631l8OJr1ce1l7+Soja23YtudX1UYLvRvdFzOZWPi92LpBmcVmZ5psxr/6 r3u15w538Em9ti7wptlYtEt+X7dAtEnsv4v5Hn4b9vTpHNKzlr3+ULlnBjm/GI4y7naUo9PZJX0 9sqNSfN2StnU8k4oPOfcdSVw4iMT1+awP0b8OSEmRlssAQ== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: 5mnjp94s6cyghhnfosp8oqyzhn7briaj X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: AF9F94000B X-Rspam-User: X-HE-Tag: 1700646256-340321 X-HE-Meta: U2FsdGVkX19QCq4QhjGKqE9DQB04bmngwQfqGgGIx6NP5PDxNWWSOst5/E0hVOUFlBUyb7GfcAmUHtN0GvjmMwb+o5+2r+/s3zEnU3vWyQeXlqHUyUhmc77dAVtgwcOYd7QLEgwMMbToiI4oky7UuXV616blHj+X1sFFMMaKTpFV70+PPr++cLb5oC8rwMAlzfCiag+GAF99VCWFHuHNh9mj7O3e1XX/xC8mnCZzODBEdKWDPUwW5r50j0JDFp5WRT/uOpI/RWbWloQoRe6fn8kUzrWTrHV5sG7Muqhmu/ILc4sKJxFPxSAKORndBpf1lLBDgAX7kL9XfR6AQk7kt/Ae/sbgDDAOEnsdi8f0VcTQWffjFWJ76YYSpXmI+6wJY2KJsrGcimnM/hLKwCE4wMAx0s6hOH3dJKgdx7NRSBsKymy1j/GRrhiSndxLfQYecLwU/d1WvfIeLJSXxlBTesvBy/dKNJAxmBAq2GlWKsF81qm3OjHjkQvUTm205y2ZBmdmK7UJr3cc2Rk8lGYlt0ddX+nfyP/HrXqhOewOTsegLSPlZq5wPN805iFtLohwUXeRcUh+p920IunRgekYlhyPpb3DVMpekcWE68E89iCQGk231IAhzh4Z5mzeukuwS2KEwjBaxXf26A7c44VxW5JCBKHstYXYIT2d5nJRNekAv8qqhBanxkkb+9630oAvG7EmAUyhYmGRaJ68fDgJtJfukDLcQjhK8se+4DOkGkOl3KbdjVi9OUN6l3eXGmMBtu74nFiAtr1W0jVgU6UXloEMsMz76MUREE+2OoutoXnbWOXcqNi+ITnBl8nKdhSzIRYo8rMvLu98pjJwAJ6PSZLQa0ccgwIBKr9+8ownCHeszEqKJbwPlqY4t4ObCSzUenXYK3/q2tZZzlAyhWv97iTmNC78m/Pt3LYpD3VYXZypZ13M/fPkAdmzzkB8WuSiY/BXpjh9Sc35VBFz8Lj ywYzeDtD suLhJ3Xs4VQ8T6+1ZMAKA/iS4jRZOhQ+fH7HsTWGqTHXjmHEBGZieUx0954wDB6ivbndL8Hyws82wfrWx1L1ITa1oAnnIrTtcSAX+ZKKJIbfiyd9INVfuEutKskxfpenilF0p+wfpgeRRgBPg56++eBirxlh3xGMUuWVWXlPO1s7wV6VnCnuz5kmrCFcRsssrXMlBOraRHJSZHMUbvyAuzw2vkVrSJc91BnMEIa2jBHujGR1tHd8MCVGDLg/9yrnwpqIa7gjUn8ShiIB4ypaPeg4zMQ+9Whc6QSDJNc/8jUUMhydpDDPzvw5jTJ0ZXO0Jphkc 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 e9624f6326dd..297a645e8a0f 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -127,15 +127,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) | \ @@ -143,6 +151,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) | \