From patchwork Mon Jul 31 13:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13334674 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 5864AC001DF for ; Mon, 31 Jul 2023 13:52:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E73AB28004B; Mon, 31 Jul 2023 09:52:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4AAF280023; Mon, 31 Jul 2023 09:52:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D39E128004B; Mon, 31 Jul 2023 09:52:01 -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 C3511280023 for ; Mon, 31 Jul 2023 09:52:01 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 98DBA1A0AE5 for ; Mon, 31 Jul 2023 13:52:01 +0000 (UTC) X-FDA: 81072045642.13.2BB5701 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id B022D40025 for ; Mon, 31 Jul 2023 13:51:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="mSSSKzu/"; spf=pass (imf11.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=1690811519; 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=RiRra371vnC/K7aW/lS3yxDUYWSr5hTseY8nLXePyV0=; b=KhBg3Bc+fQeREcsJ6/rN8+M62rQsibv+s8DnXB7kWPRlIjs7N/NhxTmaptC8cwKrNiOgJA /1NUjmFW+nYR6S/R/PTsOT1UCQoBIH1vV/F7moIQsKaPKzCZl+ChNcoZQ+4PvzVcr3QVHZ WMwnODXux3outxXfuQt4HVn+v7LUU8A= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="mSSSKzu/"; spf=pass (imf11.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=1690811519; a=rsa-sha256; cv=none; b=vHECqM7MTCpf2KihnlmoeGfEidlxjunGLCDw+glIQS+AM2RKVHoIO8OOXXxYr40knSMgej 9UQl4t7MLLRlZYqTZApNC3iLoYJKzIpIZM6MqEV0Mjg47EqIonEpCuluam4QX5uJom4/DX mPQQZ8Vc/tuA72+Sp3YMAwugw0rFIrI= 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 D2B2361138; Mon, 31 Jul 2023 13:51:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91AA8C433C8; Mon, 31 Jul 2023 13:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690811518; bh=viG5anxcCcnETy6WTEqLj0O+gpdZleg7ylSYSUDSWcI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mSSSKzu/+QPBBakkr45wlX9iKeJxSV3cpcmQLgAc4ESbF/iG02+RnaTU3bQ5T4R1R Kw6LX+osxC9ep54R3iYjYNgQ+6DT6w7VDzmxi98o2AEGXQOppTzll2hpPv3eBxu/B2 rwMAkkj7K0zr+kT0apzE2k+Tue7Fgxe5UejX54nFqsn7yoFZPLCZJCkxh1wT6qRBxg wdoK63KoGSo5kBnLWsJAnOBxxKxS7UmF+wY79mBh/GPrFVaCENDT4L5MC8AbRw+wNf MQMBzeYPtbwAUNwOXLFT1KOQnCTxZve755M5cURARwYJUkYgPsMg/IE/rbeDS9hkit 7twM1r/XoxEag== From: Mark Brown Date: Mon, 31 Jul 2023 14:43:20 +0100 Subject: [PATCH v3 11/36] arm64/mm: Map pages for guarded control stack MIME-Version: 1.0 Message-Id: <20230731-arm64-gcs-v3-11-cddf9f980d98@kernel.org> References: <20230731-arm64-gcs-v3-0-cddf9f980d98@kernel.org> In-Reply-To: <20230731-arm64-gcs-v3-0-cddf9f980d98@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-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=1225; i=broonie@kernel.org; h=from:subject:message-id; bh=viG5anxcCcnETy6WTEqLj0O+gpdZleg7ylSYSUDSWcI=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkx7wcNNzB4eHbwePmvMbzyb2eKoUsPKpySJhqxMYO VO/4ZKaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZMe8HAAKCRAk1otyXVSH0E3bB/ 9kkSCSHClFMS8SVmSHhi/kdEidEpwq32cAUbFcwXkdeJjv/CrJsT5T8aku4YfmN1sY57bMYWiOFJCR rFY9qUYZhNPKyVK111nZII+nZtmV4F3UkxDrfeEkNH6xkOECetiv67QQOmgxwuMd6Mql/p94935ORh jgjiwaG54dImasHCJz8MxPQKdfrNGJHycnUS11u+lW7Vy0+tdh6Q90ATBtt0mrn8zi11TrpPzLB6lQ zhmwTiknW/gyPJFn9WIj1tzw3E3areua+5W8q1LF2N58SVUiovl4RgsSDgWKBCRuV7TMOgnVg8piHU Q4ZHM9VIPmML5AZAJsLnLlvAfvCar1 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: B022D40025 X-Rspam-User: X-Stat-Signature: w6d8ac8uha6kmzaz87ysxz74u1rcje5p X-Rspamd-Server: rspam01 X-HE-Tag: 1690811519-241126 X-HE-Meta: U2FsdGVkX1/ojnf51zktPR4KD5iO+CJwy5JdEoNy2WzvdAw4oB14KdAui06+cVe/30bD0GgmIDXMjnYRS5NQmb1aYKmN2jI2skVoPg7Awisa7htiWw6TAr65XzhOBNf1NYinQfgqeg9Nem7EkjI5nS9AIBkOsPSa6PT0t6dKKAVa0Gu9KDLZ7uIgtEaU2DZHYYdxHYsdQZJlKLlKGh8WPBN6WLeNz4OqD90s+i6QLaOMkBbi96WZIdE2Q2XeooXSFXma0wFOYkCmORw9ItOLUL49LnM76dpneQvq2cJCbfhL/XbWIY8Uf+WdRTitGfVJZUV3Z2vhFc7I1nCOEOED7pR3nHqOKw+5gb0dcayya06HPANc/fyL2CBTrNZDGlzUjF3DMBUKEEf5iHKmU0TewGNJ/w7LvQlyvRyyzXcVk7XMrh+Duak1pjS6GRaxpduitO+rcL5kn3+RELIJ4P3hTHydWWqNZwGsSSC1CCKMxzQ6nK3TRmXakGsVr9jZ+DZ5XMq2jx8oxGgLFPIgUGOJ8l7E/yzRWMSrws/EBPA8lnipbKBziCFkFe2ULRCEWSprR4WgQb2NR4uoENTpElo5bdPmUSm/3PPMuabARWqL4HuaZ4Ye1Q6lXGlN70urDVBwid2Jx1Nsd4+6q0Xw1hoP7SAoufrOH4y6EvMj7h2qpxt0aMVLTBdCE7S/rYsQ1fOYlP71zHd+vt8KBznwmnGjQDmPTduRdnqz7TqwR2dEohJiydcN8JWEMfFwRH9VFmXQPA4Kyslmsj8VI8kqd47LIPA9baaK99IVoEBO7+HizjRUBJX6h2w7DDs8GW+jfFqjBMWBS/a63y2IY6o870dCBh1lxnAybDECNqvEX3QjR/jpOVBhGsBNCiLgHkYs60M+0uSWG2ZF7MyzyvAIk/v8e05KH7lMnwTfmoN07QYr0A0I6GNBGwb8rxqKOHp/QFo81oFGK3qL4y06iDgWS17 S27+CR1z RMQ7Lxysz9LUw+R0oxgXCQOmH009DSAax9itV2y1soy/YmuiAgyME/L8jSpmQL4rPIrXn02rocsUxvvLPVNqANCYrrgCnqptBXUCjQawpMNzDdba+P74eirKI6fxI18TjwCfYPMh+/JamBW+fe53TCbIYFGtHrecSE+laOql1fJIoec3IyKJYk4J5+zc0shRnio550FmWJhTZbyy5iDWzi6roKVkIu3KL4XmCYFWZ0SbyFRdIgy/IQWon6deaR32B5QeZrdLSRnJX999yRO+mHJN7nBB6ULXzEyD6RCY2XAOhdi2Iq2avy8LbEmRjuN2me8dognuL4gJidLQ0i8fk8qnK/Zkh5G1h6g/jAL3803TKKm0vyMofmPDa3zWsQII5GL5ZNRO3x7mOJqz/043uTm+VQrpNm7oqMl2X9ylGlq0oKH4= 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: 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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index 8f5b7ce857ed..e2ca770920ed 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -79,8 +79,23 @@ 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. + * + * TODO: Just make protection_map[] bigger? Nothing seems + * ideal here. + */ + 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;