Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp48852lqp; Fri, 12 Apr 2024 10:07:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOrLoMFVidGapua+lWD7PTyjiipJx78Lmq6wuyi/dt9xJH/qRGgJH3vuyaxVetjVGdszPICWb+nJ5BadOKpghF3/7bzwUSRylfQEKGhg== X-Google-Smtp-Source: AGHT+IETtoudSMXrdQr+queC37j45T7/12+tmZ5slGSWJ5u4usqK59UDd9zNYPiiggoAoQBbvOVO X-Received: by 2002:a17:902:e809:b0:1e5:9da5:a799 with SMTP id u9-20020a170902e80900b001e59da5a799mr2383759plg.6.1712941651934; Fri, 12 Apr 2024 10:07:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712941651; cv=pass; d=google.com; s=arc-20160816; b=Nucsos+FVPAci7BRRbQi7Q3vNSXYIUWZ/smVgkVwNcrqs9+funY2DybBDETY5XjCAW N52Aum5EzfJL4FgNeAf29n/0N+dZZ60kn4G947feIbUK7395x6GjYu4bkW3pBzwpTfiP A99tLuAJOu7ohIgzRrQG8snNd4swR2TZnTIJv12Hf+Km3ba8F5jUpT4NGmw/G+FEzeA+ MrtpmF0NOLGCyYKksiXWLiNLzAxGiWX+bo2SXoniZvKhIKSh7XcIKaNYUmvdUlrTAUuB E6L0VXg685vffla7sOnblQSw7OJk3I0G0n5oxiKor+QO70I3YG8OEeCXa2wY5tk1zFFV JAog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=/Vu6rgY+yqOGOmOLw32t5d3GS611sOvqhECdZtjPZOA=; fh=IahNbPI3OJmYlvK8hBFIVVYyi9HbCTM/mVBQ4HTUhy4=; b=YXF2X67IIh26zBQspVECXnqxeCzZ7cF9thceBmiHYQR8EcX7Rn7lyWO23SeE8ROanh QRYSAaj6ElnH5GGgoW1yD9wlL8KrfB2J33Q035KcX4tJ6jAxsXhCqPAOlGtd3PdEDMDj zym28nqT2dJcNiwpN3soWral9DyaS1kPr/B5Qr/vx/bx7ttJKX7IL2HXQQ6eCVTmU44d FoihCfRJf7YJ+GHNf+vpNUmOCqbZDv+jDE6w4shLCgviefm+WcyeNFQerublJio5R6mG iyeemp23x4kCsQItzsmkorO/iq/KQxKGqTbFVCC0bD85H23sZD6VIMz1YhhM4isT/faV i0vA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WxJt3yaj; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-143112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143112-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n7-20020a170902f60700b001e2abe09daesi3667903plg.303.2024.04.12.10.07.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WxJt3yaj; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-143112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143112-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BCA57282475 for ; Fri, 12 Apr 2024 17:06:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CF1314D6FD; Fri, 12 Apr 2024 17:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="WxJt3yaj" Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 750DC14D2AC for ; Fri, 12 Apr 2024 17:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712941562; cv=none; b=CiEeKAZtZ+Ra0V6UvOeCZe8JaHXu20CWMSQCkL0Eee+4a83k4OrZXMGkmLgaFnSS3PqsviUS5dX44UjkSRsQD0tFc5QTdosvDvgUHRquyB/oyEEj2OBZYpfdgMagzK3UlK5vxNb+PZesesgpVW06EiUdnczsFrKkl2dYeVmEcNY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712941562; c=relaxed/simple; bh=j3u4Pfc/DXRoTLtIqFpIe/08sKRybrTTrcMzZ99pca4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mSP9EyoP0p44q5zknHPPaG3ldBJn4s56ZCrtebKxiO+Qf23gPX1ErAzPgQOE+THG+ehADM1h8aXHcYqVtBhNv+BA1OX5N9NRYZJ3ItoxdN8ekknKVgQlp8SjLJ9HEBJXqG+KJB3a010MtLgYnxc0lKjbAHk3ZURIirltgsGJARQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=WxJt3yaj; arc=none smtp.client-ip=209.85.208.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d9fe2b37acso13612591fa.2 for ; Fri, 12 Apr 2024 10:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712941558; x=1713546358; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/Vu6rgY+yqOGOmOLw32t5d3GS611sOvqhECdZtjPZOA=; b=WxJt3yajC3VWoWICwC0AiS1S8yKAce2dlQd3xqDY7gNy+H8lzoMqZgSJOXiDcwcBvz WlUH60ecRuw39M1oleeVGzYZ5DVCsGRNO0hKaL/6jzwLPJVKsQEXjv4myrhwK9WfDdfC ohR2g+E0grqq5yy19rGWdq6xPZ1n0p9CH0xMMX8mN1NyR10VZijRiovoC44xfLLDYz3z HqtnOg7vHVok7wKHrE0jGrjtAb9it1K95uKkMQFMR33cl8KJLVVevv+xGNDk1FJDq6ah rh3HWbE2lqyOCtynXaNIPLiG4WyRu0S21YPyD+gql44hqPMp/U6mcf/IGP1N31ankdUA YFlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712941558; x=1713546358; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/Vu6rgY+yqOGOmOLw32t5d3GS611sOvqhECdZtjPZOA=; b=AnGjTf6k7Lf8vvQrTf1TJgoFj6ov0KNcBxEESg8wrTwQR/vzBugHfYMSUypr16NTUz vfNQn5hlE9frCVx2StRusd8K347p6s0Sc6q7ORJUTIgSIuKCQKTKbCE7VgnygxeLa8Ts fhLnOBZrVMFI5S1giHhfGZeZbomavW4m+I4uYyY5XSETFV6yNSFwDYGOYm05eUZlufAx lHFRLY0vxyM7owoAkmDSYarbDh3w9wsYiQ59zLA/ede1bBz/yN7NDg0nAcznKaOXHNGx By4JPPxW6vZezkvZrM8PVW4nkBtwu7yoLzJ0yJl14pqn3NbhyNNqlI/holVdGYRyFGgm 6w6g== X-Forwarded-Encrypted: i=1; AJvYcCWw/ElopqAJvrQSLbyX8XzQs4bqzwIter9DXTgXcCWS2yDr4VeGsJv97jD8p9Y8CIU3hUNxMW3Ng0QtIRCMLZibsKwR8hWzCHty4x19 X-Gm-Message-State: AOJu0YwIQI+nPQQbWoU8YelB2uvs4abOWtdEkDhc6DTztxenbtctU0Wn JnesZ8LB8w96qnQBk4kCXhezgxMkel3nqoyPWa64PaxCVINERkom8EzU3cv5pmQEsZsxPVrRHYS h0g+VPExt+CyqcEOrlQWoi7g4mwnO+Xzgl+Aqjw== X-Received: by 2002:a2e:be04:0:b0:2d8:da4c:5909 with SMTP id z4-20020a2ebe04000000b002d8da4c5909mr2118700ljq.51.1712941557792; Fri, 12 Apr 2024 10:05:57 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411-dev-charlie-support_thead_vector_6_9-v1-0-4af9815ec746@rivosinc.com> <20240411-dev-charlie-support_thead_vector_6_9-v1-16-4af9815ec746@rivosinc.com> In-Reply-To: <20240411-dev-charlie-support_thead_vector_6_9-v1-16-4af9815ec746@rivosinc.com> From: Evan Green Date: Fri, 12 Apr 2024 10:05:21 -0700 Message-ID: Subject: Re: [PATCH 16/19] riscv: hwprobe: Add vendor extension probing To: Charlie Jenkins Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Conor Dooley , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Jonathan Corbet , Shuah Khan , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 11, 2024 at 9:12=E2=80=AFPM Charlie Jenkins wrote: > > Add a new hwprobe key "RISCV_HWPROBE_KEY_VENDOR_EXT_0" which allows > userspace to probe for the new RISCV_ISA_VENDOR_EXT_XTHEADVECTOR vendor > extension. > > Signed-off-by: Charlie Jenkins > --- > arch/riscv/include/asm/hwprobe.h | 4 +-- > arch/riscv/include/uapi/asm/hwprobe.h | 10 +++++- > arch/riscv/kernel/sys_hwprobe.c | 59 +++++++++++++++++++++++++++++= ++++-- > 3 files changed, 68 insertions(+), 5 deletions(-) > > diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hw= probe.h > index 630507dff5ea..e68496b4f8de 100644 > --- a/arch/riscv/include/asm/hwprobe.h > +++ b/arch/riscv/include/asm/hwprobe.h > @@ -1,6 +1,6 @@ > /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ > /* > - * Copyright 2023 Rivos, Inc > + * Copyright 2023-2024 Rivos, Inc > */ > > #ifndef _ASM_HWPROBE_H > @@ -8,7 +8,7 @@ > > #include > > -#define RISCV_HWPROBE_MAX_KEY 6 > +#define RISCV_HWPROBE_MAX_KEY 7 > > static inline bool riscv_hwprobe_key_is_valid(__s64 key) > { > diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/u= api/asm/hwprobe.h > index 9f2a8e3ff204..6614d3adfc75 100644 > --- a/arch/riscv/include/uapi/asm/hwprobe.h > +++ b/arch/riscv/include/uapi/asm/hwprobe.h > @@ -1,6 +1,6 @@ > /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ > /* > - * Copyright 2023 Rivos, Inc > + * Copyright 2023-2024 Rivos, Inc > */ > > #ifndef _UAPI_ASM_HWPROBE_H > @@ -67,6 +67,14 @@ struct riscv_hwprobe { > #define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0) > #define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) > #define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6 > +/* > + * It is not possible for one CPU to have multiple vendor ids, so each v= endor > + * has its own vendor extension "namespace". The keys for each vendor st= arts > + * at zero. > + */ > +#define RISCV_HWPROBE_KEY_VENDOR_EXT_0 7 > + /* T-Head */ > +#define RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR (1 << 0) > /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ > > /* Flags */ > diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwpr= obe.c > index e0a42c851511..365ce7380443 100644 > --- a/arch/riscv/kernel/sys_hwprobe.c > +++ b/arch/riscv/kernel/sys_hwprobe.c > @@ -69,7 +69,8 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair= , > if (riscv_isa_extension_available(NULL, c)) > pair->value |=3D RISCV_HWPROBE_IMA_C; > > - if (has_vector() && !riscv_has_vendor_extension_unlikely(RISCV_IS= A_VENDOR_EXT_XTHEADVECTOR)) > + if (has_vector() && > + !__riscv_isa_vendor_extension_available(NULL, RISCV_ISA_VENDO= R_EXT_XTHEADVECTOR)) > pair->value |=3D RISCV_HWPROBE_IMA_V; > > /* > @@ -112,7 +113,8 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pa= ir, > EXT_KEY(ZACAS); > EXT_KEY(ZICOND); > > - if (has_vector() && !riscv_has_vendor_extension_unlikely(= RISCV_ISA_VENDOR_EXT_XTHEADVECTOR)) { > + if (has_vector() && > + !riscv_has_vendor_extension_unlikely(RISCV_ISA_VENDOR= _EXT_XTHEADVECTOR)) { > EXT_KEY(ZVBB); > EXT_KEY(ZVBC); > EXT_KEY(ZVKB); > @@ -139,6 +141,55 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *p= air, > pair->value &=3D ~missing; > } > > +static void hwprobe_isa_vendor_ext0(struct riscv_hwprobe *pair, > + const struct cpumask *cpus) > +{ > + int cpu; > + u64 missing =3D 0; > + > + pair->value =3D 0; > + > + struct riscv_hwprobe mvendorid =3D { > + .key =3D RISCV_HWPROBE_KEY_MVENDORID, > + .value =3D 0 > + }; > + > + hwprobe_arch_id(&mvendorid, cpus); > + > + /* Set value to zero if CPUs in the set do not have the same vend= or. */ > + if (mvendorid.value =3D=3D -1ULL) > + return; > + > + /* > + * Loop through and record vendor extensions that 1) anyone has, = and > + * 2) anyone doesn't have. > + */ > + for_each_cpu(cpu, cpus) { > + struct riscv_isainfo *isavendorinfo =3D &hart_isa_vendor[= cpu]; > + > +#define VENDOR_EXT_KEY(ext) = \ > + do { = \ > + if (__riscv_isa_vendor_extension_available(isavendorinfo-= >isa, \ > + RISCV_ISA_VENDOR= _EXT_##ext)) \ > + pair->value |=3D RISCV_HWPROBE_VENDOR_EXT_##ext; = \ > + else = \ > + missing |=3D RISCV_HWPROBE_VENDOR_EXT_##ext; = \ > + } while (false) > + > + /* > + * Only use VENDOR_EXT_KEY() for extensions which can be exposed = to userspace, > + * regardless of the kernel's configuration, as no other checks, = besides > + * presence in the hart_vendor_isa bitmap, are made. > + */ > + VENDOR_EXT_KEY(XTHEADVECTOR); > + > +#undef VENDOR_EXT_KEY Hey Charlie, Thanks for writing this up! At the very least I think the THEAD-specific stuff should probably end up in its own file, otherwise it'll get chaotic with vendors clamoring to add stuff right here. What do you think about this approach: * We leave RISCV_HWPROBE_MAX_KEY as the max key for the "generic world", eg 6-ish * We define that any key above 0x8000000000000000 is in the vendor space, so the meaning of the keys depends first on the mvendorid value. * In the kernel code, each new vendor adds on to a global struct, which might look something like: struct hwprobe_vendor_space vendor_space[] =3D { { .mvendorid =3D VENDOR_THEAD, .max_hwprobe_key =3D THEAD_MAX_HWPROBE_KEY, // currently 1 or 0x8000000000000001 with what you've got. .hwprobe_fn =3D thead_hwprobe }, ... }; * A hwprobe_thead.c implements thead_hwprobe(), and is called whenever the generic hwprobe encounters a key >=3D0x8000000000000000. * Generic code for setting up the VDSO can then still call the vendor-specific hwprobe_fn() repeatedly with an "all CPUs" mask from the base to max_hwprobe_key and set up the cached tables in userspace. * Since the VDSO data has limited space we may have to cap the number of vendor keys we cache to be lower than max_hwprobe_key. Since the data itself is not exposed to usermode we can raise this cap later if needed. -Evan > + } > + > + /* Now turn off reporting features if any CPU is missing it. */ > + pair->value &=3D ~missing; > +} > + > static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long e= xt) > { > struct riscv_hwprobe pair; > @@ -216,6 +267,10 @@ static void hwprobe_one_pair(struct riscv_hwprobe *p= air, > pair->value =3D riscv_cboz_block_size; > break; > > + case RISCV_HWPROBE_KEY_VENDOR_EXT_0: > + hwprobe_isa_vendor_ext0(pair, cpus); > + break; > + > /* > * For forward compatibility, unknown keys don't fail the whole > * call, but get their element key set to -1 and value set to 0 > > -- > 2.44.0 >