From patchwork Tue Jun 25 14:57:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13711327 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 D4833C3064D for ; Tue, 25 Jun 2024 15:01:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66A836B0098; Tue, 25 Jun 2024 11:01:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61A636B0099; Tue, 25 Jun 2024 11:01:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BAF46B009A; Tue, 25 Jun 2024 11:01:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2903C6B0098 for ; Tue, 25 Jun 2024 11:01:35 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 93D05801BF for ; Tue, 25 Jun 2024 15:01:34 +0000 (UTC) X-FDA: 82269724908.04.191C11E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 4E21F40047 for ; Tue, 25 Jun 2024 15:01:32 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LB1z0uLC; spf=pass (imf01.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=1719327678; 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=UyxaLF6c8bbKp4k3CezmG/s8YRNENr77in7SNyRbvfg=; b=SHqhvslQ3bZInbZZ3FMOV/JRSCI9/oh0+zYgLn5Hi5bjW4s+6G0PrknZ4iUg94RCMQaftd +/o/Lof/cf2TdCDCdpy7gU7sU8Qt5HMxnuQCh+aY4R0IXPLIFM+AatiJkRLMSqzWSwtPZU HIQAMR/6su5mRDb1YUbD0W8yjQmrjtQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719327678; a=rsa-sha256; cv=none; b=Q73DbKPGODkdOcm8e6atDE+jvZJHAKFHTg0DJ7BZNYweFygyStcmwp1DoxcyDiSQ+pqi/G FXJg2JBKk3XczDpoPRWrQyL0Z7fOcrD+styqrLRu+7YKmwEQRzczZu6MMYVeXObR9Orzi2 NBCS+sR06ntH6en1JsaTX306ENJEEC4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LB1z0uLC; spf=pass (imf01.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 56ED36146C; Tue, 25 Jun 2024 15:01:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86A8EC32782; Tue, 25 Jun 2024 15:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719327691; bh=FZl6osZQv9tUt2U/ynTpAvRjKv0nX8jhIzHo4KZI7Xc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LB1z0uLCfALEQBxZq3EKZVaHBNY3stJUGGS33HnAF+qvGORdfESqvZIYxkj7bv+HS L54U6Iv2tOs7j44tOE4h84EJHGTDTjVlcLQ66TCpZjGdtamPPWx+W+Bk/1zpl79jTs jEkOH3pcuJ9K8R5CN7nTj8KGgEESCqUdR3u1CW3/JZ+hI+fOukZ6IgdLE8QPpSaRSl Mk3jTJZCntx0mFGHWhgYC7NFHGichd3Kt/0PHDAD4/TAgKu2FgqexAejVK5n7sGLxs 3Wwr+VUqSM/UeLdYhiOS9WB70a43AdK2D82QFbm3y+bMh8yXGTcW6K9Wkz8IKHsBlm UnY7K7gsZV2sw== From: Mark Brown Date: Tue, 25 Jun 2024 15:57:35 +0100 Subject: [PATCH v9 07/39] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Message-Id: <20240625-arm64-gcs-v9-7-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=2643; i=broonie@kernel.org; h=from:subject:message-id; bh=FZl6osZQv9tUt2U/ynTpAvRjKv0nX8jhIzHo4KZI7Xc=; b=owGbwMvMwMWocq27KDak/QLjabUkhrSq2+XPXm/0bpVzD/k8YQlf0IX13+pntU0rfHD/iHhl8g2+ bCazTkZjFgZGLgZZMUWWtc8yVqWHS2yd/2j+K5hBrEwgUxi4OAVgIh/bOBjaedu9c59WSqjki3yWWS WkUBj+trxszfmbhX3ln+cJShS8Cf0lqbfX6VfE3P7yG7qM5zdnnxDcNe9lvfSEMtXr+wyKs4KnPrjO 03bX9I920aOcdusdTDx8LEfvPJc1S5Bz4Jy27qW2XSfTifyd9orsthH/duhkuLbstLrrWjLxtWfwzk 6TSn9Fq1bVzi+rtRec4WJ5YrXh/5FvbypfOEwRnKmmf5YhbIl8RkBTI0+Vo70zt8D2Rc9+x0nrhWux r9w2U1Q0s4QjMOj/WnnbwBuuEyavaqiPEJ/ixn6mNC70/Lm+SL2s3r87+cOPFieUOHbynL2RzijscI z1zj19gUM/3++5eqSDT/FKbYIsAA== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Rspamd-Queue-Id: 4E21F40047 X-Stat-Signature: kg3fr73zxuk4g5aftwi8exs3ny73omtp X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1719327692-654444 X-HE-Meta: U2FsdGVkX19+lO2njLk3F1erQRLF20fQMneb7yXieMUC1KbLR/XrEAgYdqMWlqGer/dmCIC9Ge3S4OPkyq/uECGiZ4o1epdtZHE+9+urgKfzHCIoVvwyJMJ1jIMcbnVu2j4L91ZIS/OKcLtnNzHSRpwI+rumIjQ0oNzjflgKdEYqdjTVFMktwEXUiJiJqFBzQOOygiFKpJ9UAl/zYC2K8JXc5xEZBZZJ2WrgHi2hBth0U0/XE3244zw6kk1nVEFgp2SXZbGt2/BTSva1jbnkoKAhF8zLD0QBje2uAUlDAgH05ktY1M+zfWZAUYcB0LdDgngyCawp0/k58v7MMG/ir3PlN7+w8wq4nTJugNdUdYXNDYXfDfPlUR5DuhH4ajZcUvJiqNDbHScYbrT9xGGUi+39Ng/XuG+pFlsfUz+Uf0ytEUi4ItGggwlZeyfOvryV9PWc5QdJxYAP9Y1M5VgYdYtOSKLrC/H03MSgJoQattkxWBGUJPUCbf3R4OGMJa/dUdRRa3A6Up1SpUTBBpfl2ZuRR3IqsZGvbKap32e6M4kJUVtAyPHrGvvwXDi/c1SkJG38eyuDFkn5oUk3a8rlilOO+u54nZ7MmMMygS7jiY4GSY2br+RDtDO6RHUjAIybKfQCgqRbwe5j2v4clzdd8xLCQufrD+1zsgqQGv2T89eFBNKRDT6VTD1wZwDyCG+cWbghp6FS0LfiJsjbUz1hCJerQewhsPZ0mjDCJ7zD+oa6Rma0pbDmvKyVQHgU+hhE26M9/08HYgJdUepByTSZqZiTQAf7sYl0FJiHxEd9Ptr/ezt5srDEAbzK6CdC2z6NaXV7sn0jJqmBAOU5iTzdkrrTbPkQVogpobPI4qt/ZmEwSVS5e1uU83PCzrxM5HXmSnQkCG3Dk6Eel5dTXCi8TeMsphn7E/RsuJ+uZjVwkMgkRsWl9s8sI/9Hw547dCL3u6GDEBvz5tTIyjBBg0t 11EQ6MlT qnZu8rZ7beBGSfboAWYTPThdlTW2VuuyYYuDK2P+QU1657I7CjBgEThN30hTbJcSzsr5cUin5HuuQHS2u4uxzCgkvbl5eqt/Xt6xuCggzavXGnRpM8sdaO6DUWCJtmkrYZrv0WbGxvJlpHM373xHc299Rh9gtdH0TkUW3JW6Yw2CV64kWFVGQDn1srngij28LboKgYUvdtN0rt1WkfurKOdAG5PDREZmxBqX7w0a6ClJ5RpX7UTa9/Q5/7b9cYkPP1hldgPD96rNSfjakJe9ryu7BLttxzqgBTJy/n9rSRqTDvqPVA9NV9b0Ztrl6vryu+LwkVlvE+wWxtf5lge+JA4l/9eSZforBODzAR89oTfl9FJkP+Omz2FqG96Ul1PMct0QE 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 --- 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 */