From patchwork Mon Oct 9 12:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13413509 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 3F33CE95A91 for ; Mon, 9 Oct 2023 12:11:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B54ED8D0063; Mon, 9 Oct 2023 08:11:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B05BF8D0031; Mon, 9 Oct 2023 08:11:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F3C08D0063; Mon, 9 Oct 2023 08:11:36 -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 8C97D8D0031 for ; Mon, 9 Oct 2023 08:11:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 691E3B484B for ; Mon, 9 Oct 2023 12:11:36 +0000 (UTC) X-FDA: 81325808592.28.3C0680B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf05.hostedemail.com (Postfix) with ESMTP id 70C9F10001B for ; Mon, 9 Oct 2023 12:11:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ATlHVM6A; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 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=1696853494; 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=Aw9uk67+s5HTS/4C+7Hw36JUsrXswdGZ2FWphnKG6DE=; b=uB5aiXesojXTQAPNrDme+kueycbiCiPwHy/DMgx4lUpzlffZOXhDlXhhvTvOQhU6dRClGx kzmlcMyXx3kpRIjdROL1jp6Mcuf6polLrPCnq+Fr9IRJiwGsjRfMVhc81mBhmNEz72UMBv 2gO4RcS4K0LK48sHcgBfv7sjPwB7gcg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ATlHVM6A; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of broonie@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696853494; a=rsa-sha256; cv=none; b=n9x6+dfMj+M5rqGD9vEptHsX679GY/bCEypTnHbeRJoF8PjeSYoPB8AMKKpUptGxRGorFG yKsp1qHJDvN/Ko3OMK3LnQ9Mp9jQ6kBi8/vLOBEboFp6EMehiZHiIiTiPPoEKvIqtMBd7M JNLuBv+7Q5BriKH6KKiyyHR+KuexuwM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 20255B8106F; Mon, 9 Oct 2023 12:11:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5217BC43140; Mon, 9 Oct 2023 12:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696853492; bh=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ATlHVM6AZeAPwZROhTDwJAXvT1SullAlI71Vn91fpb40hH0HMjTlCj8nJbcQ3Ud3N vAhVspCDOeDsjgUAUBTNGwGZTHyokcbBzVVVErlZF4gaRCHvA8132tfS0cYpyz7zso 71qgrkpCNYoX1KdrSBTd0nrMqNW0UrLUB3WheJ1j3Kxtod1a3ousFlJ406c1t6piU1 g2ElyABWAZHRc+nRTRI776ggjev9EOJbu2ipxrPSF075+9nWfWD952VGnmTcu1crg0 Z7YMy8L5LgmZwKM9Yix342mpSS9lneIbrD2Co0e1PKXQCoXswDTriYD68tGfTJY1IF 3nsQDM/pqU+/g== From: Mark Brown Date: Mon, 09 Oct 2023 13:08:42 +0100 Subject: [PATCH v6 08/38] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20231009-arm64-gcs-v6-8-78e55deaa4dd@kernel.org> References: <20231009-arm64-gcs-v6-0-78e55deaa4dd@kernel.org> In-Reply-To: <20231009-arm64-gcs-v6-0-78e55deaa4dd@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 , 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=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlI+2X6KvSDevFmNU73sRXi3dVSic6kb7utwq77DtU O9AtxbeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZSPtlwAKCRAk1otyXVSH0PJzB/ 9bjtfdH/kreNste9Rhszz++5TtrXwaf+/u3cMsmbyDsfIECxfrMIwsOBr1iJ61TV0lhBla3gTWKzee B7mmzi+ozphCNHbM0MDRz0F62SQzuaeuxTGQWp7rTUbtm2aMqwK3vOlXDbfkp7E1yyMaHz3Z5xh6Tw h8d1vRGZv5sXyZyDBBI2aiEO6lThtTrLozvtuWQ1vgfWue+wjzrq1aMDgiN8IeAW1HmSGSYmliogM6 532osJm9A/FjGeWX/7VE6UK1Q45iesDwGfzySGm0oNzW9Uex8YR3/NTmPzJ2zulrHA/KnIamunKmUR uhxZ729qwQ62A064U8mJ4OD4jGhU9v X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 70C9F10001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: maiantjnua4qjqxi1iq79n4g6kwj49ri X-HE-Tag: 1696853494-633142 X-HE-Meta: U2FsdGVkX189qfFfTry2i0ajLfYsMvsGZgURNJZC8sliiZPs9hTtPvXdfTz9bZ/c5WNAWOf79Qi1QIIb8LW0ReRITdMqPjPmLWCvKCTOVKiKHXHmaeSIJLsDek+r0zXPrLInIFQUPDP4gxFLFGsWoCeXoY4I6fhTut+TNo8PlYioA+4yBPgP8h1KXcvV9GjljNwhTUEds7Uk2V/SkEyag0V8YQgl/lUVhxxrf1G03ZVdyoSbNdUUAguD2CkcDKJeWbP1SiTDLL384b1qwVpIag6DnvPpqxUxZJ3Ssiacfcg2IjMYPH5cZIMVMWkaFlQCIC+wDPYgQYxHuGp7New9D+ncVQYuCz4iDo+dt820zi2U4SyXAXk2gUBEvvjIW+TxZqjXoD/qeLs3VkNvFFDe7BFx7KuDLg64JXW6VKr0JS3THxA6UxptumhHH44is1UXdd/Q1t3B4ioUpdTwny1yvS0YOJTZtoXZzl6yj6kV5e+61qzkr6o8lUBZMvLqr1SK1c8VcpeoZzOGrh826PPFFKcfSeH8Oz3YXasZHRgx9Yyn98BDe7kJSlgc776QF/B6pYHK4qiXhcj6ls1jRt4NtJCU14GTVWaFvwejKEkHa68rStHjZnnpScQJDuSgTAs/R9DKrGinCmvwbD60OwYNgUwv/6Mmi8fUj2BiWjWfK59Ap95oISIYblPJdxZJWmeh1welmemdpUvgwsC59Oc94KricooRELjnnJILv7iSbcC6tRoHq7wjipKzqO5PTLZeTQer46yQKc4PENJ76PymMO3zAnW5pX6UaXJ0RI7KvBoVqWKxegoLHU9JRookuj29eqWn0glky2csTftOgM9nsnAJjeJDGncLhpLr4pUW+rPix0ZUILyRW8ok6MwIIo2mP7LAY184HwKWE5MBa5KIQGqHw5r3dq8vrpkOG4QiW0lM+elsNQx2RX83n2mj60H8VwdLqwZNHXij+0oBAxv U/iUn7Jw B0Nh2YGskv/1Hw3E34SiNPNoDrZYOmqgbJhr5bHpXlHk8ielp2W2cGS8kpDcGVP3qHhqzjLsb+Wp7r2Umgti4NJSJLx9xZJP/xX4qDBkdiv4Sjb0JU/cSnZdEL/4HzD2MMpq+CZz8t6JYcM/dnITgrNDEYh2l8874KxJ0EAszF6wjaGQZvEoBnW8ksngfB8D0S+RXr+HP3kXn61i7PqMEtgYAjQrQMvJ4iORa8V32jkhLiiwuqpy6ppyGZRPTEu33DS8KSECWGwdoKDn0gbNz17Worb17VbVDe46+zaTWv7WZV2K50tw9MpHPWIVbm5IX3zrlwnD1rJVr/X4= 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: 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 */