From patchwork Sat Feb 3 12:25:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13544132 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 CCD3BC4828D for ; Sat, 3 Feb 2024 12:30:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60AF16B0085; Sat, 3 Feb 2024 07:30:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5944A6B0087; Sat, 3 Feb 2024 07:30:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 435056B0088; Sat, 3 Feb 2024 07:30:01 -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 2E7886B0085 for ; Sat, 3 Feb 2024 07:30:01 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E27FAA08C5 for ; Sat, 3 Feb 2024 12:30:00 +0000 (UTC) X-FDA: 81750424560.25.FD110B0 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf15.hostedemail.com (Postfix) with ESMTP id BF737A000C for ; Sat, 3 Feb 2024 12:29:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dTXtO9zo; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 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=1706963399; 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=dCDB88itTdxefasSuF7fJThrrxd6Ms5Z4eNc97V8+kHwsW41N9i6DPszTB7h27m72dZ+/f g1KRHFOy73MSLBNUZTONUiWBcok0YEvO11BUuQ9cFyR61fnJb7h50o9i+XzjyQLVblEBZt gF6RuFM56bafQgJaAuKgq/nenplpHXM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dTXtO9zo; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of broonie@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=broonie@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706963399; a=rsa-sha256; cv=none; b=WnbI4K81XOwhg6hOEt335ARFmzGrlO7DJFBx0msNRHp0Uer0trVN3gyH+Pydu9gm4WgPxk AnbgpicKs5o/S20iqx5yS/jM8FLlssbZaETgKKDjfMeeTMWNYLMBWk8YShMGssSY4xbB+T ZaW2rpi6QugtFJkUP70wPjFTsl0Kyp4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 233E1CE1F0F; Sat, 3 Feb 2024 12:29:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AA6CC43390; Sat, 3 Feb 2024 12:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706963387; bh=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dTXtO9zoQm9JKCKVlTQvs8wgeMjkGOAr950r85KgQGAT34nQSSQ2ln64WxHAiJSSm 6PEarPvcoqFTmKT5cj+HNeUFr7pQcIfGbe/klZhA+Gkoa1v65gL5yD+Mqw28o9xbW0 XEQWk+Cl9jbYrlf5kijxq1s1ROA0BB6StTf0KMmMKXIXwpAXOM4xDKVclfS0df/Po7 Rg/marbuHTjU5J+T7iEW5sdtvASHVxoDEH5nKmz85XW+1Sl01maEm6BdV2XzdcuK/R tONiZcB3QLD8rufqmcRFLGHZ2neKaX5nb/wRhPu8oq4ux9CAUl85rntpWtq1LMJ8Ql D7+aWaDk0Ov9g== From: Mark Brown Date: Sat, 03 Feb 2024 12:25:33 +0000 Subject: [PATCH v8 07/38] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20240203-arm64-gcs-v8-7-c9fec77673ef@kernel.org> References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> In-Reply-To: <20240203-arm64-gcs-v8-0-c9fec77673ef@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-a684c X-Developer-Signature: v=1; a=openpgp-sha256; l=2577; i=broonie@kernel.org; h=from:subject:message-id; bh=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlvjDWl0RFbpcffLYcZJBiVq99jNr+C4cCBZd5T7RM G4XEv1eJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZb4w1gAKCRAk1otyXVSH0NwrB/ 9qoPgQtako2eNJFYJjaadGibJhrC+O0rrQ1WjE8Q9ksJCD+xyk2iXaeED1LmGEM3ZQMaNLezHZnqCE YzpJZxzTffvJ8MbMj0ZW+j7kI8MOe0jm4w+PMPvPf+YCHQA6kzklMsd8HOMnmCxKe01+hbtiiPcqoc JTMZW6BCL8+fjQ4aICJpz1CafRa5IhasNRga1FPU8SCgl0E+ojogy3ewXC9Q7Wit+8L8ZW94hHa7U7 iVy9XiEFddFnqgZdhk3E6a5F07EjPMBMRMbI2jRxrz1G2a9/PDQ8C8bc23U49FNAxKrBjW3jJR6IZ7 NU+2krwITMBnkNo5cyh4uleB8jnJMb X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: BF737A000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: kysejfrtjzn4yxb1kfz47w9tbw4gpcg3 X-HE-Tag: 1706963395-415105 X-HE-Meta: U2FsdGVkX1/6zFHj65YZkYqOW3+WN57VuOgPvCHh11Wwmso2sDYDzM6HC/+zTR8RX+Ttfz4A24rAR/OmD4LoT4Q0s3H+/h8qZxhO3YvgjhR27MyULGLKEYmWMSCODjC4CdEdodQzJ6Hs8BByex1KB6IADu0QC3K3T20NBeUxRIavXpu3jYBjwsbAWH/WXTxbO0xOQ8siLYb5p3vce/b2BGod1NEeZRyxzUsjLA50PpS7DrHXxarIskdnfZllWhvFWIzJ8ws/FjtKidavwDl/UIRBnb906ZA/mwCq3adMamIsAmytO8ZL3KLKG+lu3amoRJbTR3upmW7KFr93i51gRQ6bY++AedAbpoz8upBq8Erz5G/u2+SLdqIpgiuF1bT30rs/6H01BEDKxJk38K273wInDEZ876dRKL7wEJiUQDmklxp1rxELuwIdZHPboMgESVBSAHNp18NF4CI5bEVEErryNSM60d9JYc2GoUrGWKgRNF4JHivZ0zKx+2YsoHkTi4yyW3P40o8yGQ8PNteaK3Lx+wWj0tndAZ6Hy85vtXxgyFfxXn0WjXC2k6zhl9IeWrWG3c7Lv3F2+BPkZIJheO/vrp2pjzs6kEb5j0AGHW6EMXb/fkYN0SnWjBhIXrZ+9eYsgb/QUqqrcx25nYDrpkzgwjjjQdA9T+mOu6gkAV9f2gJQuRJKh0fNHBn1Tt17R8sfAeHU30LuBSGSqH7LUvNU1QbSYWPpYtvyMrsrg3LE3TOZd0WPRvpku3Qg348JHr1WXDhXAcvKiN3WqrXyxJ5f9kSAK0ncGBs+g+hGB4bHdE7yRmsp5T6bLIoz2XUi916NDj4NjPKjQIo34AspMd4MGUt/wLlwKSC8tVElujSrw/ylOzAQ8HMlNz6rxU65zgxp2eTjUbp0UUXMOReBuV4HyCuHvWQtkxpqY2X/xggA1DekUkzcpjyJc4U+H1ZEx9UpzUyBpdjkb6oLrna ozoQ2/rZ ddtmMGxxbWC3l2ev6qHHkqHJMqIiErR+RlnpSaJIToFLl5enSiBWcNEx9Ysz5OFy/TIwoTjB1imKn8YeO8GXx1Z4/sdS/K9hQS6lA9pqLbybpGs+swt3XrfjHytJ8E6gzkuhSlJHX/W/8rP4T61BYbIJTmnaKEbXZzBgo60o2uOHdIuWR+fUFVF5ioNwnCLYyMTQKwwF5OrzN1HgzM3Yb9SrfAX1VjPRmp3qM8talXJLT2ayi4O2OC80HWWhJcbtH899lh3bDSHgtSkWnWmGE4AtILmAMG0sNl5093Sta5sdSLlnCgiKwJhiRMny4ZbYkQjzp 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 */