Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4462142rwb; Mon, 31 Jul 2023 07:16:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFqWDfsxiQbWjIxgS2mioyTmCUIn27+cbx8QPLFmgNrBeQOZ5k/RPIvlk10zLIBA01yFYGi X-Received: by 2002:a05:6512:23a5:b0:4fb:52f1:9ab4 with SMTP id c37-20020a05651223a500b004fb52f19ab4mr7420369lfv.50.1690812986487; Mon, 31 Jul 2023 07:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690812986; cv=none; d=google.com; s=arc-20160816; b=eiyOHJBd87sUxL3N0682G8OXF5lxW551a/iOP7suMcG76c526F1IcA5HDdW/65QBsv GaZ9ORzyAwEhXPQRuz2ZcSjwTlM5AYrjaDCJdLGclPdsr1rEFlkiKCH1SruQhAqhG8JY h90SC68uX9M2adS66wtXGr5awku3cTQIGNlM9NbpuIIVgKUcpOymTwY8cZ/xWEExur7+ QFMexZ8qgkrOrohCrCgbRh7YtmRN+5mtjGwRTzRZj/zkBI0killmtWBbG68QouIU1l6z Md86KotavdHIZNGkbpt0AjwCR8cuq0j+us0CyTQobJGBmvCDNjSTOXcZDq6LH2XaZFf7 oEzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Aw9uk67+s5HTS/4C+7Hw36JUsrXswdGZ2FWphnKG6DE=; fh=EdAFSmIgUzZTC6WCy4Jg1wBZ0/m6m2d/OjiRUJ3BsTI=; b=z3rWRQnPQtV3wjOqTrKj+M4+vK1yuLT3d67eSr56wfw/Mrm2Fz/HHHE6K1/lg1S/Jj MhHyypmEX+SuBZNiMgQjOZqTj6VFJIUtp+He/0MpQurmM6FJsKbdj5I1S20+rE2y1L2Q mLET34SdY4hUcpWKcYQst5ccTZjdr7zd3B43py1V1Utxd6CVvNVZDTqbNXR8ySjes4DQ oPcVAoalSYopHuSK+FoLt8tIdVFMlF3jCVyOv4wpoUwx0qC4RbzzYDA8X4xvrF32JYLk +gW/qyDouIVGnRTG5eXF8cGIBklAsy4gLdtotTQ/HaN5JEAwdNtraYKRU9PsXyMX63Hn 64IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tZ0mtVgG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020aa7d44d000000b00522594a6151si6442506edr.461.2023.07.31.07.15.59; Mon, 31 Jul 2023 07:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tZ0mtVgG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231451AbjGaNwN (ORCPT + 99 others); Mon, 31 Jul 2023 09:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232115AbjGaNvo (ORCPT ); Mon, 31 Jul 2023 09:51:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0F051986; Mon, 31 Jul 2023 06:51:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 42B6361138; Mon, 31 Jul 2023 13:51:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDF23C433C9; Mon, 31 Jul 2023 13:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690811487; bh=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tZ0mtVgGDNTbsC0me9RZvJkswmBEIQcoj/AN5nwmGFwL1Y8OVrdc2b0XShKGL4r9s puDP7rOxTZrPVPIfRMkV6t+XD/3ogD4QHdFEf/0+CGcRu3JeYKhRYCCQ9hhmweu/S6 j0w3nftlbmHhm8F7JB13RqCkpZMbhMSeMRBcDZdlF7jTQquihSs0pgIub+k7zXKFT/ saYc3fjnQDqqEInpE3ff1lC+8+A4OA1bBdwl6OH2rwb4nxOr4ih/JRuMhp+DT+sRnA Y5X8Gb7948++cW+lGGs1Kelkv7tzQtKSmpcpAKHkzfT8l4Vr7Hop9eHqszsHMHVXU5 B+5rwOZlXPb7w== From: Mark Brown Date: Mon, 31 Jul 2023 14:43:15 +0100 Subject: [PATCH v3 06/36] arm64/gcs: Add manual encodings of GCS instructions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230731-arm64-gcs-v3-6-cddf9f980d98@kernel.org> References: <20230731-arm64-gcs-v3-0-cddf9f980d98@kernel.org> In-Reply-To: <20230731-arm64-gcs-v3-0-cddf9f980d98@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 , 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-099c9 X-Developer-Signature: v=1; a=openpgp-sha256; l=2577; i=broonie@kernel.org; h=from:subject:message-id; bh=sadX6jRs7DdBAThhpdGK2D3phr2V3dLQCMXle4b8GlY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkx7wYrQknxcMFlI+zXyyFjVrqAyFbdP30d9e19GKh YDA9b4qJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZMe8GAAKCRAk1otyXVSH0LvYB/ 9nNuc0hiQ3DUndmYc0z2CG75eRkYkiKY1KKjiuK2A7oJzFhcasbQTA8d5ibJFwyccDP2QfoM8UJ7V7 vD6AivBvRHidGh3LAm7IgfoNE6g9cETUZZBe40ToD20JqWUQ/WAwL8VFDACP+BVZo6TWO1zakWM68H WGAyRdbnJ3ZidPiOG6EvZAIQtZcc3wre4PaJp7rTf0prFPBugkXDfFB1Le6GyqvuqxLUUFzTKckoKJ YqEV27W3dqNVQrCZR9K4HxBUXgvQ/Ldli4mpEOtc7p7MMR7sDhTe98w/vKoKuatsLmIOCvSDEB5mP0 fniuGIluMtAs+bPRvccs8MqjY/P9pG X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.30.2