From patchwork Wed Nov 22 09:42:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13464402 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 BBAC4C61D9C for ; Wed, 22 Nov 2023 09:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 552956B059A; Wed, 22 Nov 2023 04:43:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 501896B059B; Wed, 22 Nov 2023 04:43:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A3FA6B059C; Wed, 22 Nov 2023 04:43:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 28B3E6B059A for ; Wed, 22 Nov 2023 04:43:57 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0787214012B for ; Wed, 22 Nov 2023 09:43:57 +0000 (UTC) X-FDA: 81485103714.15.7063AD0 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf10.hostedemail.com (Postfix) with ESMTP id 0D4E9C001C for ; Wed, 22 Nov 2023 09:43:54 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jo0eqnhF; spf=pass (imf10.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1700646235; 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=oHZQJerEJ1fGH3Iz56dN3F6DX5L5AytuCbA413DTvB0=; b=KzQG0KkcyH2b9wy9yCO8HLETreYNYOZBuTLAd9To94xU5T9T24/4Lq/gOLiddvx4zdAb3V XbyYyTKPe8Ije4t8uUJDcJNB7lbj7Vffd9A5PH2Z4u0lb9a652xC0aAnYqzfAAcy848VRE JPvveIGgZkQjwfIOUtOR+NmvV5n2QgY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Jo0eqnhF; spf=pass (imf10.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1700646235; a=rsa-sha256; cv=none; b=lEnKoAcwbCujinnPq9LFMS3rWCCWE5NqXkr0Y/UiWZ+u8XMwXFK88V63R49t+soltTIWFa iuzYMwjnAHObg4AxuC3wcwhhOz2lW5mrN/J9rWHIesQ3EzZDZAAwNGHjHovGavvyLiu1nX QNlGouHbedVwjHx1GzfiuVomyEfuGTQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 67E5DB81190; Wed, 22 Nov 2023 09:43:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CF86C433CC; Wed, 22 Nov 2023 09:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700646233; bh=Kj5ys8EZzcB9lauTa/2n/TuM+KU70CYN6cCdyA5umEU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jo0eqnhFka9a7dffiKyy/h01WlRwGEogNuM4GOLoxUdOw9GTlY8Y8IsRwkGQAzVps ZejwMBmDzIrkQh7K7q2pQDPrZXsbBtCixxWp/qAS7BsVPKK22IOAiUXVCd05mRyTBF 4sHtlCXV5S5ajmQ08Ha0/qmbnTXoNEuvYf8Rpl3kx5lqfIJwozNKfyvlN0ixlabSCs z0tRYzkYowakVqbhA+GWa06AGpTmKfBv+oJbb2Y21eWQZergE/uRiRxQ0pVmATJcWM 102wKL6RaMwQ1C6yALuvXYKN5CI7cvjxWoE2cPJirA2ZviLOEi3nlbI0j8VIjMydt6 JEaT3JTOFHOeg== From: Mark Brown Date: Wed, 22 Nov 2023 09:42:18 +0000 Subject: [PATCH v7 08/39] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20231122-arm64-gcs-v7-8-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=2577; i=broonie@kernel.org; h=from:subject:message-id; bh=Kj5ys8EZzcB9lauTa/2n/TuM+KU70CYN6cCdyA5umEU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlXcz8bXL6mSlClcxo2LLkqYujwDOa49MNEAxac 4wcHFzLkiKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZV3M/AAKCRAk1otyXVSH 0GQIB/9o9cqptsu1ZwBDibIQWSTMXx2jyDsfuRCayo0AmyyLwhAIo2lXL771m3LtQpEJubjNSO3 PVjPlRoT2ipPWpt735Fg5NkUgjzEcT6xeT/oG5/YpHULuKMwSq9zvHV+woRV+lYiOZItIrNcgu+ GvMa1MuPADfJzXfw7QgtoClkc+6OfPC5vTsygXo0CEhRXV9O2659pBW0fQZPRmIa42fXbtTlpNK j3l29HNk16rpf+JFot2wdynC8PLWnTH38WB0LF2d+f+czqx+mOQs2STMWDPRpTF43MOm3QEIIJi SJNNHgxgi99OxRRLxuunS9Cf4qkX9bBRfInK56jnN8VLQHMW X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 0D4E9C001C X-Rspam-User: X-Stat-Signature: kwwme8wp9z9k8zs678kd4a5nohm1b7qc X-Rspamd-Server: rspam01 X-HE-Tag: 1700646234-236846 X-HE-Meta: U2FsdGVkX19iFjY++x8tgZ92MmKF6E0yZeNy0j/wqZT3HmmBqeTbdwRzf4mTHkoo2B8ZFJFH7fpbPHiEdfiB8XvnEXXK5icQaCTT8xPWUaRWVV2lD3O2ZzwZPXK/BxzBoj/LOHpqFOYpEqote7bbNo9BIjmr4htLONKOtfwvTlB8aVKBaohQVMCDJhrdmx/RbxSMcucX4TaQORZzrm/z5D4Uy3nEMPEFIM82LGOXgO5DZlx22Qsjfk5PRGIBA6HEEMxqBdboKNff4kNEdpzxdXNu/uag8unLN1U2STB4LSHNZIPylWhcwwXXi9dKztMKtyphv1IufGo+9/ef24sG1fNoncXVUht5YjyWLPnzI7OhwjPAJkNUJieo5Jea5HySNAyw2uD/4GbRLq8MY6DV05WKDNcjx0At8p12bPR3TZFb6ZtQYRknmDrWMwD6SWtaO8zL4mmhDUE/+awu5Va2zUTkHYt0kgF6iFkiLY5uNbz3Ien32s8dSDIVinao+Xm9CU/d2yJ3s83BrDo1DvAP1O508UZ2wD4Bql2H3V34s6V/8922/JjSTXDS5/tzh993OW6IQnXlCMRwDRbBa3Fg7rHYMtAjKGQMm6wVQAlKfF/WuwohGj8uqhqq4nHDKLqE7emmn7hO5HsPxzQoN/HjejU1U+YiPuSpzyi+TA40qJLz5aHkxCv+lTV86UOZytQkmKx1fVyaOTNIg/hpSr8Z0PXA5MH3ZPLcO7xg8RvYpsdBq9uMva4+WrlZK8OnJ1OBmmFp8GVivXEbk8jFVY+Do0EqmWGfAq0DsR3FREG4E+iD3Mfn0bOgZNbvxWUkqZHdbi7TIAAswyJVtrGTb8MpvG+fBiI4UIrLoRDrnG21xeaT8MpIyjopoWIcdQ9x9JOMTnulCP2e/wSCScUOZvkpboaA02pKIrxOUX+p3d/ipjRs4imgUFFgmBsKMzFY19AS9T8Nifd02lMSC8brOQg bNh+W4Su 4L8XJkfbPG+9cfyIsemUV1/dxtZET6Lu5TYa7AFejpqLmX2bzF+7vFP2bEvg2+mIAjnhTc2snGtoO1wFooF2Q2w/8zgoRuCRVRgNwoST7MoI7nJJR7n1H4eeBNgX9qE2kggfm+F9ShqM7EDU7V6mA22uQtMbO0u7okS2Lync0+1P3QT0rCOPfZkuMVPyPYCfeCHh1rUdCuTI5EiZVDUmeF9SOTOmqgbKevmNtCzFA8xNY2F89jCU1lhhbDxNN0DE8xiCkgpbTwmCOTjlJPognZCsH3dNN2iUCn2oSk7gAIgkjhxnHUh9U0AnmStUgL2cd1/NX 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. Signed-off-by: Mark Brown --- 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 14be5000c5a0..22e10e79f56a 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -425,4 +425,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 */