From patchwork Tue Jun 25 14:57: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: 13711330 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 64692C3064D for ; Tue, 25 Jun 2024 15:02:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D22736B009E; Tue, 25 Jun 2024 11:01:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD1286B009F; Tue, 25 Jun 2024 11:01:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4B306B00A0; Tue, 25 Jun 2024 11:01:59 -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 92B516B009E for ; Tue, 25 Jun 2024 11:01:59 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E86CD1401E3 for ; Tue, 25 Jun 2024 15:01:58 +0000 (UTC) X-FDA: 82269725916.03.B39B7F5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id D220A40127 for ; Tue, 25 Jun 2024 15:01:39 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LCKBRIM7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719327688; a=rsa-sha256; cv=none; b=tRVXHw1P+1tBXJt/K6K9dYawa0FC8qf/bThtYHYmF+E8JCWgl9F+x4Q2hf4WP1lYeHiGqL 7PqjcFzNEUentqJmmrFHrenv6WcaEuHGVGdXm++Sk1XN9PnM81OsxsNecrlfbGQEplH8zK wxCzOdH2qVAL9tbj+19CAij4OySKZaU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LCKBRIM7; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of broonie@kernel.org designates 139.178.84.217 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=1719327688; 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=p394kNOGuUM4kB3+kce/KU992lWtCnOBaZy/f6a4gQE=; b=oqtPcysfu3r6Ktz52WtXI0ZTwDBgt3NjkXDxrpqXLDX6WSC4fFiCBobnHeA1Uzd/X3TIZd 0W55h9hEKHuGQiwDdLknsjlQYlAP2LPT1ejn7T/Py3/f9XRmKDomq3GIrQGCdqTQlwiZDu x32vbx5dWD0GEsHuOqfbNBnEY/u1Pf0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 52A246149C; Tue, 25 Jun 2024 15:01:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75909C32786; Tue, 25 Jun 2024 15:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327698; bh=SpxTDPkJgZRI3y2Hq1n9QzpjFWZ3Gxi3l59ZtBf4jLI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LCKBRIM7P1X1xpvsS4XEya+CU9QncvalN8/HgV0jOcZrtdPH96iZ79e/FfldlYcyQ KG4D/US9JjKXYl6B32tA/WiIsea5bmSRxlZ8rD+s9jRPHVCl2dfCCaNrSUGkPvyfTj f1I5FPA1gSm4owfH/cYTM//+93y5ac9PdpqIsqUC5aI5zL3mgYULmUS10eqDN02DIq s/+fZZEtRgCN8Yu91NoAulTdaszPk2cIrUC+Vub4cZGRGySZQD7qaEf30fZXBDXLWg apjmyGRWF49cRMCO2zvSf9I8skh6/KYYKTNe/c1B4e8lNgRIB89TjkLsb8q6EKyBRI v632mqX63KxEw== From: Mark Brown Date: Tue, 25 Jun 2024 15:57:36 +0100 Subject: [PATCH v9 08/39] arm64/gcs: Provide put_user_gcs() MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-8-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=1103; i=broonie@kernel.org; h=from:subject:message-id; bh=SpxTDPkJgZRI3y2Hq1n9QzpjFWZ3Gxi3l59ZtBf4jLI=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmett4CKl1cP0GjqsEsHZQn+ZUgv8UOnY1gwbJGEPy 0nF1gWuJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZnrbeAAKCRAk1otyXVSH0GTvB/ 4rzP26uQ2jw9FuRsJAqw1gE2ydgI2bc/iKdMxs34w3uUiteyu1KQntu5r5O6S/pDWsDvBv9DBJSjbX C3BsRvj08B3YrbhlpjJ8tIwJrzT0vK8lfVijApbbnDEGHfkQ+ktEFeGlNYYxlpcM0Dua+4CplUqp5v URfmO1+u9hbBub4a7rjyBrKim/HyioooMWWoj15ZNBrNVzgiZwuDPsq+EFXJ4OTwDXDflKXC4mpytk yRKGcwTpLlL/Y5xmDIsOW81n+j6uhypg+JIlOx/pXvC2LYHCcqFjuGdcEZetVcrga5Km8RdHiVztO4 fEt0Wr4EPbNTgi0mUCzBzWL4XUs9a/ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D220A40127 X-Stat-Signature: jh7a3imi6n3pgnzunkodypt5b86u19ma X-Rspam-User: X-HE-Tag: 1719327699-366725 X-HE-Meta: U2FsdGVkX18HcshWTMJHurgZhr8WyKuMKjXc7JVgDOeYER71EzqrhyAsab+MJ0ETJGMiHZct60IUhC9Wjw6e+U43mERiysz87Z2Cibf0Ynp1JMdLvzzD0yEMu8ZbSahAXekmwV+4R+OLDbiD5FLzVdxtK/td9h9tuSCDYoiNHBdL5LSDHCnPciiK8s3RELtIiNI4gGf6st3vlvLr/7J1q/CRIeJMscnqC4bvu/su+T7RdO1gDhplM2Hi0m/beD+Q5O2PsgYxAPD6RTFlEZcd44/e9XdU1pAP8f1fWWPbevaPwz4alQoeVmN1dM0tW4h4spmbBFp8zXWLrsHcH91uY8y1bx3k1rCSJT7cpLEWbCxQOVEX8yblddaWHXR0h/Knu8yzeRWQAIU0T+aJ7MlX0568PZBMhnu/yj4V9mpahHAhkSx4hY/yo0G3fZYMyMCtR0oniGiU37TN6rL3f5osv0Q+pt07uBMoavwtpUy7obuggquz0NSMOXFf2H+uy0knpeVNaeKVoeUI3FoONstCy6lJh6BfNCBCOrqjMKUo//T6O/akUVzmj2lXECXnzWzNHIlD879UDSCFEdefEpW3/2fxaoB8fKtAq3gqYKW7z4eZ2ggPHLScEeITRdQ5OcjIMlnTwqHWmsGVZQAtNgxvTYl+vEFt8Pc8feKtORPjmghqzKCTJvt/IbfM+ui6rFkvqfmmP3nq+2xK4716xSx7do4bfKCQYW3JxyzRdS1m+W8HgcBFfW3xNHvxHq7dV8fROsObOsrOP6C8egilmL/p1wsYvY21g0XWIQF4Vu9Hmpx/ypfTUdsfDNzLHzuYNQIsB5LLwWrsF0eHW0qjOxLmlYUSiG1wy9qzIOBj7yM0pI+E8CBU6srKdsoxrliTmSqtNHNpw5MfeTSu2tfrym6a/B+l+I9VRQppHy1w8uDfQiBXVsV7t479Qa9exjP4MmcDSnxuZFcz5IgpQBHkXG+ wW3fKaEM DeLulP1U8Py7jFvYGzJdjZPHq1bSTQznVxLnQv7e4dZYq55FhCEVi6zVx+vXvoPGTfofvfojvvAezkgaJXtQMsUA8oD5ObslK22hO4gKpQKfeo0ThW3FBPoePPpimigglxW+7YkXZtuXuIGCIx/5mCR1HIGBEkzhjWOA3M2wAkb5HT4q3ZenNNEymIemSF8EyJIpkgzMJCWXzwP0vNe9a/scw/CQ3g2VzkdwGvDsEVD6BtRWZ0K/j27+4A4OaM/yma9Io84jFpBGCUExpueT6pQzcFOHTIneBnAp/LQ5dm+njmkwtGGOdM1NLXucu6IL7fEYNVcPLPTkQUdnkNe54wnJDe8W4Ap2WOpxrV4KT4EOF+DntnTc7bC1jgvpydivOvAZSnLyhwiZqtbiE4PTQyXO+N8QiNkHUYbPU46s+MWlI9EY= 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: In order for EL1 to write to an EL0 GCS it must use the GCSSTTR instruction rather than a normal STTR. Provide a put_user_gcs() which does this. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/uaccess.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 22e10e79f56a..e118c3d772c8 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -445,6 +445,24 @@ static inline int gcssttr(unsigned long __user *addr, unsigned long val) return err; } +static inline void put_user_gcs(unsigned long val, unsigned long __user *addr, + int *err) +{ + int ret; + + if (!access_ok((char __user *)addr, sizeof(u64))) { + *err = -EFAULT; + return; + } + + uaccess_ttbr0_enable(); + ret = gcssttr(addr, val); + if (ret != 0) + *err = ret; + uaccess_ttbr0_disable(); +} + + #endif /* CONFIG_ARM64_GCS */ #endif /* __ASM_UACCESS_H */