From patchwork Mon Aug 7 22:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13345133 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 91B8DC41513 for ; Mon, 7 Aug 2023 22:02:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28C906B007D; Mon, 7 Aug 2023 18:02:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 217118D0003; Mon, 7 Aug 2023 18:02:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08F9B8D0001; Mon, 7 Aug 2023 18:02:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E9F956B007D for ; Mon, 7 Aug 2023 18:02:42 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BE61740C0F for ; Mon, 7 Aug 2023 22:02:42 +0000 (UTC) X-FDA: 81098683764.27.35DA891 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id D9253100025 for ; Mon, 7 Aug 2023 22:02:40 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=B7+8io7J; spf=pass (imf05.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=1691445761; 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=XE0cp/pXkFJO5Epc20SRtvrQrMW2Zd7bcQADyaYtsBc=; b=SB9RPI8ybVO0hi/JqokYHbepa/ws1+wpvWXj1Wyx5ZBhsvGKtGsH9NzHt9hgcpXyi9d7Tb kaxbRqJTXO4cm/a+24gAmj2MEduvxbpjziwBERluyopkbYG8GFzypU5R7ZwRUMPjQ6hDN+ AUYgqTvKBrVDli1QFq8TPPVtXEZrdEg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691445761; a=rsa-sha256; cv=none; b=hzU1iwhy9nk3vHZoJ0CGxjHs5u7qNImnUcnBJqDQB37E6ZASI1k+LwNOIw/MBiPVGWFQuf Pyr41F3/qo7tW9iSphAzB0vSuwJXL1dhuO4BqEhsSWjiQqFwwt4OMiBBCzazD98SnHEBpq k74YuQJMh6L/rC0CR/utiRTZoT+5rE8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=B7+8io7J; spf=pass (imf05.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 (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FA48622A1; Mon, 7 Aug 2023 22:02:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B665AC433CB; Mon, 7 Aug 2023 22:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691445759; bh=aGB9MytFbopKILsUP0kPuxTbIpt9GJuR7uXvXLP6vLo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B7+8io7JEg/LIWoZNhiKlYaOzexSqBArV056/ScJvMpxGs2kYB4Okzkzol5kScHYE 55HMmJFzcyF8LtgXCBJKWR7eLCptLh/oMa3OwoCIW/lmiSswqdleH9vkIljQqqI1NG HLehvcCG393fnl1siFCS/s7UzNZzDQUk8j/IEVppVkDJ+oI6SfDcO/ioLRso4uqmWd 0nFYrpM45VWM6oql/4rbBGH9Bwejm80beYj84++Sz29XVXXPZ08K9bNizQdES4ri9s TnarJsT6SfHg4wd1fb/cH2kV7WdxLpv3PjSjRekkZcxhPwSttByrH0KzubjmRIB62N obTS3NSXeRxEw== From: Mark Brown Date: Mon, 07 Aug 2023 23:00:16 +0100 Subject: [PATCH v4 11/36] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20230807-arm64-gcs-v4-11-68cfa37f9069@kernel.org> References: <20230807-arm64-gcs-v4-0-68cfa37f9069@kernel.org> In-Reply-To: <20230807-arm64-gcs-v4-0-68cfa37f9069@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 , 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-034f2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1124; i=broonie@kernel.org; h=from:subject:message-id; bh=aGB9MytFbopKILsUP0kPuxTbIpt9GJuR7uXvXLP6vLo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBk0WmgYE5sTjIW0s7MSSUHBmNdoL8mADFajoHMlxxa sLCcTiKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZNFpoAAKCRAk1otyXVSH0CQmB/ 4hCrLHpUMmcfdaL24W2A5mDkcuuBM88bAHrKma9GqNW27peedUqdX7QojJVVcc8Pti+JDlRJQlF6eA QZEKYM3bKTE3mosdO+93NlHTPGn7gi26Pt1S42K8kRxwwm3mJo1gL/HQE1ao9d0KZg9o9LHWjR9UsG hAoZdZeodWYeIhnbOvuyIXIfGKTlRPnEOtzr//cVzV6vxPF3kggLcSNXBGXhBYJxComChKV/1oWfxG tHKcsX37YMulc8njZNNNcc7c79OcVYO4TFDHmUNkosm8ee1zIH4H+rIteZ0Pyhx3nAnQLUDe23kVjg n0K3NwP/ZpHSz6lX1gqzfW1nyN7hWy X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: D9253100025 X-Rspam-User: X-Stat-Signature: h7h5rn85467ny33dizcejs5t8r96aqe7 X-Rspamd-Server: rspam03 X-HE-Tag: 1691445760-602165 X-HE-Meta: U2FsdGVkX1+9koInywVmDFj3ufFf+e2uSI0XY3t+mtv18srrJT5MUhYA2KgQ3p2B2U8Q40DF7kxJFuSpfbIHwX1aOGpWaM8d+TXQFOQbYvvOzaNnTBl5RkwCnhosEupunacaMtboHKL+TDEwap4bbpHmPyntjw4H5bH/+4RXQnRR7bWmA/AOzwghMF4FtAa5p/QV0nKRxjF0ok1ZEVqFsWpNM1oqfHBwUfOfHPA2U30eLqEEwj0+tLQdrdIQfoSh9c81erhkicxxhwlP3i7u0qLYp5lv/+RJJ3DtU5ScgOlL1H991TyX9YPWhJ5GHXAuoUp1GFitbZ9gRFY7Y5IlwXAvs7TfH/7dyNn7jEsXEES5+pQvWM0cWVBvb6SfB6SMKlWxZxa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vack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Map pages flagged as being part of a GCS as such rather than using the full set of generic VM flags. This is done using a conditional rather than extending the size of protection_map since that would make for a very sparse array. Signed-off-by: Mark Brown --- arch/arm64/mm/mmap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 8f5b7ce857ed..8f40198cd44e 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -79,8 +79,18 @@ arch_initcall(adjust_protection_map); pgprot_t vm_get_page_prot(unsigned long vm_flags) { - pteval_t prot = pgprot_val(protection_map[vm_flags & + pteval_t prot; + + /* If this is a GCS then only interpret VM_WRITE. */ + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { + if (vm_flags & VM_WRITE) + prot = _PAGE_GCS; + else + prot = _PAGE_GCS_RO; + } else { + prot = pgprot_val(protection_map[vm_flags & (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]); + } if (vm_flags & VM_ARM64_BTI) prot |= PTE_GP;