From patchwork Thu Aug 1 12:06:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13750386 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 A1250C52D54 for ; Thu, 1 Aug 2024 12:58:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34D766B0093; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AF4E6B00A2; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1295A6B00A3; Thu, 1 Aug 2024 08:58:11 -0400 (EDT) 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 E48386B0093 for ; Thu, 1 Aug 2024 08:58:10 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9E7B41C408D for ; Thu, 1 Aug 2024 12:58:10 +0000 (UTC) X-FDA: 82403679540.25.9579FBD Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id DABDD4000B for ; Thu, 1 Aug 2024 12:58:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FJCzDaYT; spf=pass (imf17.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=1722517031; 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=J+17pLu3G7dDibf78evDF4ipjQkmkdK/v8qlZFUwd4k=; b=FtwmbdqBDDXXd9W3AHUcdHDbJPVC59yzpk7kVijeZBiXZ7nPToG4GcGBouKF7fTFvteUmo 5JAup+ADAirleB2ECK6SmaLIIMliBLq/KabojTY8fpwYRPubwBWyLbj8MybggqOgjYu99E i3Sut6VIRsl/glikxq7nl1+cuYMUkKY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722517031; a=rsa-sha256; cv=none; b=gmunhm1BgO/175pcUaOR+l80674ElO+AiXGR+Q2/RNjY93Aij8M3dfndpKf2xZtV/m9tRN fqUojxNho7vdrUWV8t7CFZZ50RpvgyuSr2+FWLhonMdUgDbYHT5XADRahCf2Aj421+uBb5 e3yKXhfAt8vAgxUTgOxmkDd6hkxS5G8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FJCzDaYT; spf=pass (imf17.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 0E21462898; Thu, 1 Aug 2024 12:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BEEFC4AF0A; Thu, 1 Aug 2024 12:58:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722517087; bh=pr/SL5aXRHkEgbL61YT0WXgEv0CY13vhmdtve/jq07s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FJCzDaYTgHGPGRDGs3q91BDDMkyJYNXJ9l28iaaR4G/ZjvUUEUMEofxFR4EGbzrWK i7Ek/16URKLtwBc1hlMafY9YbSCGkquoX8rmFRCQ08rDxXFcDaR//nlZGW2QUEks1O HkFrj/gtGwWhWmpKSFsMS0n7QJdSe39Rzd6bhdG/8xKdSyOrts5Y/UKs3pOmNFqsRQ p48zboodXYB+6JXyVyxXF88GjyncMrpns+MDgNcJmtbK+ow9aQcBXNU2qrpqfqMQjT JjbdUytErk0J5QKWnXBEHc+ocova9NSO9/K7+/G0NOjVKONSV7LnqmxJbitAFz3DtP l2/FJGAFfHG+A== From: Mark Brown Date: Thu, 01 Aug 2024 13:06:34 +0100 Subject: [PATCH v10 07/40] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20240801-arm64-gcs-v10-7-699e2bd2190b@kernel.org> References: <20240801-arm64-gcs-v10-0-699e2bd2190b@kernel.org> In-Reply-To: <20240801-arm64-gcs-v10-0-699e2bd2190b@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.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2643; i=broonie@kernel.org; h=from:subject:message-id; bh=pr/SL5aXRHkEgbL61YT0WXgEv0CY13vhmdtve/jq07s=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBmq4YL5wsbsXpFLEnxHz0MZq4t/+nYJjX+FBLrDs1/ N1KvKSeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZquGCwAKCRAk1otyXVSH0ORxB/ 9s11x3nh7dQHtvX3MMe4dfLF77kaKt9nnh2hUEcXu6pG5/rLpFfae/LeU0oemP87Wwg8VI3Rc8GZA1 XFkfxYlXExPjnMj0q6PPaQ0GnI2ZFQ6xacPuGxoci7j79eZ6kxTRtRqol84eilLhP7ZofZtyUUnUaE CgzAkdr1bWGZLN++CxGV4YpKBICjj9LkdFKvT1HKMy8kwZklzUdGFEmbtBdk7rCi+m9P+PL0+g0prg uoVSgcUxvlnAu+/F8PQHPb/kvMXP1g0Ks4yKPB/nx0om9RFyY1BdkBB3EAo908dARyobtvzN6MaU5w Rl0zghQtR3bcLuKNMEY3/pLk1ooTRF X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Stat-Signature: es759nnqmhhzbigdmo9yzxn443owu63y X-Rspamd-Queue-Id: DABDD4000B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722517088-503311 X-HE-Meta: U2FsdGVkX19i/CE7n+A5Vnik3zpuaWgwmwbBdtYfu7kAF0uLwFPLKW+LxIdmYKkhkU8ug8qniAXC2DNoIjt1myYgs/eTcQLD93oZ/auo4Sv0VqT3HVlTySUiR3xP8Fl1q6ZBaUb2YDTEGHFzLuhZmcIow+yw+J8JEvZO2ruqWlEtww36z5wB/F4jlQ44Q/QHExy06DrI4XY8Bz2buSffUm2N172o/+ta8ZAFUbrTJkC7EehjYJI17+ujiiGq4rv7KHgelQb3olKrDJFg+aI4q2ceVpK7n5ZiLZxIBaB+vUxZZ5BeqDelcxAxya7PLixj3IACXaKyG2itkZcd9wRne7abkZDoFexAjqHRS+HpHXQYEiwH64OVDcPPkeCjNKLD1Adq7CGMLB5KQ3Jyf7QYdX02j3Uzb5YbxZn0A5Mv6fyuBzojcrBn/ytjRwet7BFohzCA6b1Gx42CHw2lBxLL2XXlXF+S9iw7eN5wKLPIVIOgGaIfd6/M7sVReHpz2JCMy3mLFih+GN1i2Nl0dwlAlXid0LwCEDMQhsUDa8RpccEQHwxiN7T/R20fDFa6KUeY0g5afGAT3zsDpwzv+3sjvCzvdg11VMaNxrET42Ik103i52Si8j9tIECR/j0zboNDWnm+VJt0VYPKAJaygdJBJHZlO2C9r2pWTGUplBiiDOwMClvOR73T35ubtKf5eRA2jzJJ3ZrJkxE43oD52meceGjUCelxZHNJ8Y2btswswyfjoKx5VzOxUheuxp0E6x/cTaN+CCDtsb9gAoirGmAtMx7bsE4tdA1HdecZoCttHNdN5pgV5XOwwizO8Zzx7ci4Ja+y+zpdPcteI1oxGhJi8qlUd53aeT3KG6An5A3pc55QEcwPi8EgD0ypBirJBNssyO4FZEM5FpFEH0gfdX7JpF4ron0qQCEuoOK0cQh+MFABl9UI7gQ0MhzXdlb6HUEMa/Zdc2QXsE8GKPivjF9 rpxLsRAN SrDNjwxlYZtNx3eWExEcCIs9KygNsHoqKXwqBX1cqdZkmVEQKUn7TehUX2UIgmt9QUw9Jh7VuGv/jTPNCJVDlBoriaI0FtRyqfti3A4Qm/8LSDEq7lek9Tx9z2mxYE9Rt13gt3cySmpO8WdoOX9yLFeei5fSa7mREXk4fGyS+dBm62/dEG8tN18WJBf06Pr0CxUFqevA6mD3iPXvZ6dwkZIziqTpb3duDAwVYkJMpipb5hh28UKnm78jFSSyA0b15ELvKUQkPhv/hOHER3TwqcnxlKXrEtBsKLCWuYjElCOTnFKmn54BbfS2PiXAEx5UMieg7MbV3D1Z7PpCMTCqZgkS4vxN9wFVoKuWOd+qIuWC0cFfL9jmKsY72+TY3SzqeMgfP 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: Define C callable functions for GCS instructions used by the kernel. In order to avoid ambitious toolchain requirements for GCS support these are manually encoded, this means we have fixed register numbers which will be a bit limiting for the compiler but none of these should be used in sufficiently fast paths for this to be a problem. Note that GCSSTTR is used to store to EL0. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown Acked-by: Catalin Marinas --- arch/arm64/include/asm/gcs.h | 51 ++++++++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/uaccess.h | 22 +++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/arch/arm64/include/asm/gcs.h b/arch/arm64/include/asm/gcs.h new file mode 100644 index 000000000000..7c5e95218db6 --- /dev/null +++ b/arch/arm64/include/asm/gcs.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 ARM Ltd. + */ +#ifndef __ASM_GCS_H +#define __ASM_GCS_H + +#include +#include + +static inline void gcsb_dsync(void) +{ + asm volatile(".inst 0xd503227f" : : : "memory"); +} + +static inline void gcsstr(u64 *addr, u64 val) +{ + register u64 *_addr __asm__ ("x0") = addr; + register long _val __asm__ ("x1") = val; + + /* GCSSTTR x1, x0 */ + asm volatile( + ".inst 0xd91f1c01\n" + : + : "rZ" (_val), "r" (_addr) + : "memory"); +} + +static inline void gcsss1(u64 Xt) +{ + asm volatile ( + "sys #3, C7, C7, #2, %0\n" + : + : "rZ" (Xt) + : "memory"); +} + +static inline u64 gcsss2(void) +{ + u64 Xt; + + asm volatile( + "SYSL %0, #3, C7, C7, #3\n" + : "=r" (Xt) + : + : "memory"); + + return Xt; +} + +#endif diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 28f665e0975a..6aba10e38d1c 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -502,4 +502,26 @@ static inline size_t probe_subpage_writeable(const char __user *uaddr, #endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */ +#ifdef CONFIG_ARM64_GCS + +static inline int gcssttr(unsigned long __user *addr, unsigned long val) +{ + register unsigned long __user *_addr __asm__ ("x0") = addr; + register unsigned long _val __asm__ ("x1") = val; + int err = 0; + + /* GCSSTTR x1, x0 */ + asm volatile( + "1: .inst 0xd91f1c01\n" + "2: \n" + _ASM_EXTABLE_UACCESS_ERR(1b, 2b, %w0) + : "+r" (err) + : "rZ" (_val), "r" (_addr) + : "memory"); + + return err; +} + +#endif /* CONFIG_ARM64_GCS */ + #endif /* __ASM_UACCESS_H */