Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp118129lqp; Fri, 12 Apr 2024 12:08:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWyZxqbUjaf5A6Tq2LwzjyPlZc8Dnz2pC8MBM6c2ueVD+lx0Qr1KYsLGU0vGrWKmZCk3av4l0aMcBxG9ppl3jevoiDvPYtiEwsC5hJNaQ== X-Google-Smtp-Source: AGHT+IEWJusQEC0Tdkgitx2jFnAGj6/HB9WeSlxrBV9D59hOIxyCcriRGjIzYibJjv9UUYZnapM9 X-Received: by 2002:a05:6512:21d1:b0:513:d5ec:afb with SMTP id d17-20020a05651221d100b00513d5ec0afbmr2054219lft.40.1712948917014; Fri, 12 Apr 2024 12:08:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712948916; cv=pass; d=google.com; s=arc-20160816; b=en2ChxVuLLi6yDGYGPJcTS152rORP5g/VkSc+D6pGci8QzTvU52dd68yd2lk1ePZ5I ua+m9yDybCOgIgU/aMgu07oLchopA5oIRtXwlbqqwH72P4XPbj6pbleu2NJpwOY7tew8 gNUSFs9KIAUyJgToHicfbwjMF/XlZjg9UzrHQI+ljjh3FkUKR0HVCKoCpEC7KvoU6vQC mJicrVyhYfLbN+km+LXteuHA5J1Bhf8J1p3MxRXGutv3HjgJZjk1kfE/tlG/DFsRiH8Z F/M2nAxVVY92ySrUDIDBZPeTo/vVRHFiqh4N08g7yGogFxvvSzKzxz9SEno2F1CtU5b4 Sx5w== 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=hh4bjYtVZmJ141zkkU7dHeg5BG8kICTOwvRezA5T/ZI=; fh=cu7zNAYg6KP8Buf9nDe2+3578p1b1VU25mSGUtHafcQ=; b=SudflW1EereeVxIkrydq+ukr+GJRKM2VwvgaQlBa9rvyr4tMg1A6UejULsczYHtb3d ggcgiJ9VB8FuuSR4J2yefXmyWMHsmfZQslShRojOQvKZ54btelrLPTSvdYGvfD8eQ9GG YsHv1ZqCx4txX0eu9BBsgmbOJoTlk5Oo4wziUx1WQdficOK3Gw9MAAz1Hhz2YzA+7rdq 14mvbJI6uTdPzDBuNxcWm88NhWJ9pL91SG8apeTNDQiInDobYwAcVM/qdcQZYHuEr+hR t7ZX77q9EF6vDPUbM+0vd84RPzci5KV+xt2pKPJnghTzWfGdUkkqfTIED1yJdKqVfYET 9i4w==; 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=b44b2ODl; 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-143239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143239-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q10-20020a1709066b0a00b00a5210b288f8si1925157ejr.919.2024.04.12.12.08.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 12:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=b44b2ODl; 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-143239-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143239-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8B5C81F236E9 for ; Fri, 12 Apr 2024 19:08:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADDAA14F9EA; Fri, 12 Apr 2024 19:08:27 +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="b44b2ODl" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 8AC8614EC7C for ; Fri, 12 Apr 2024 19:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712948906; cv=none; b=Ibj/N3hyhhRIgvdv875DR52dA7/xlx5MNDOu5IWURK0AaYKpcsZpgVVySCx9iwCxVtDga7RRvMPGsy7aC7RoxGo/sOvUrP0oqLfTI+jMzthOIVdgQuZUXUzcG9oWhyysZUrW9crwo7jKTKfpwNflqSSy5dGFapKAsuLScrVHx2I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712948906; c=relaxed/simple; bh=ZHY0B2jrDYHH28AXwuw2LEYbH6Qivb5lwAIUg7KPzaA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=cLqsb1c2dQEPm76oActs2z/Zo9JOzyzhZ1+ng2lE/X7tvD7PhBZO9m+8tMXcru7u9ZIYPvr6slfJ+5Upn+vjGnMvjxnLe6mJK1bNjP/1dggWiSmMKZfNOeik4mhjooRNL5ZLwp3s2mmIVEJ5h+iARXy7PeZNnEhd2EHqkaVl1ME= 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=b44b2ODl; arc=none smtp.client-ip=209.85.208.176 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-f176.google.com with SMTP id 38308e7fff4ca-2da01cb187cso21839911fa.0 for ; Fri, 12 Apr 2024 12:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712948903; x=1713553703; 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=hh4bjYtVZmJ141zkkU7dHeg5BG8kICTOwvRezA5T/ZI=; b=b44b2ODljVVGCcEQvrwG3GnRwAMD0EbzpDljsEX1LRlASTLQd8AooiMyRX+s/TlXKc +yw3ND8Unc3vzvdzU5Khyb8vWbmtdjExrhEsiGA2UKqJIHHxJuaz0rRjotC6EjD3+dzj eBg3cvbOqcjxJaedTOgyxr9p+4rcw1+zrmnqFQM8zMyhznRsxT8yulbEg3MN292kRp27 FUN/ve02+cKY3sGg8omI5j/ml9tXCdvnxEG/Ag4h2sCzntFLC88pM3Pgt7TDRV9NXUiD D/BFAc89R0YJfLU/fY3Rapo5TU90nYGmZ2dEe3WszVHSbsLZuXihoJRnx/LWt2VGF04F yiDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712948903; x=1713553703; 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=hh4bjYtVZmJ141zkkU7dHeg5BG8kICTOwvRezA5T/ZI=; b=PGfr1bFny2KKt4LoVj4Dhq/hka0chhdKlBIkBgazTOCVKCWmysrYSm2TZU9nN6K581 v129P82Gtb9mWVmUdUTmzoy5oMOzCZX4iUs4wXaSdg9O4kBOCtKu31J5gWDVaN3KMFeq TtIBCovMLaYKyWb9lEYvhcjTFj67SKT+Qw+4B1dRN5CE/budpVnQSXNZ2q1zMriWEakg X6mb4H66z3oOZJ7bF5qP5CFfSlUgUL73fxQPALNLMdhachsQMd1bAusvraR7vkF9DbR/ DP4zrhtI1mYnUNgDbLeGF/zCEqcyahwq9QSV022O0Ek0AShnyStpTVaVpXSbeUwn0yeC In5g== X-Forwarded-Encrypted: i=1; AJvYcCU7NevW2zX0G7jQJ9kqTdnedPSRHJfyjDafT0/0v9eB8jluTn2HDUqBzeUHt/TmeMbF/HlGNMYDyQzkRT/D+9trgfm3WhgMIqH0+Hy5 X-Gm-Message-State: AOJu0YxYL2hryae+ikal+kezKUzqH3jV7giKgbt17/1vCegDTKdkhDz/ i9oLRyTu4nxoIjSryCB7GLnFvFA+QKKOYamkJPABk7IgbYVJnLcMAZTSWm/2J6whdajeRr/mzDV sQDsazM4QNKbu4ogeknRxq80SplcAB/+szB5OBA== X-Received: by 2002:a2e:be1a:0:b0:2d8:95de:23ed with SMTP id z26-20020a2ebe1a000000b002d895de23edmr3111321ljq.17.1712948902720; Fri, 12 Apr 2024 12:08:22 -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: From: Evan Green Date: Fri, 12 Apr 2024 12:07:46 -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 Fri, Apr 12, 2024 at 11:17=E2=80=AFAM Charlie Jenkins wrote: > > On Fri, Apr 12, 2024 at 10:05:21AM -0700, Evan Green wrote: > > 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 vend= or > > > 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/as= m/hwprobe.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/inclu= de/uapi/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 ea= ch vendor > > > + * has its own vendor extension "namespace". The keys for each vendo= r starts > > > + * 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_= hwprobe.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(RISC= V_ISA_VENDOR_EXT_XTHEADVECTOR)) > > > + if (has_vector() && > > > + !__riscv_isa_vendor_extension_available(NULL, RISCV_ISA_V= ENDOR_EXT_XTHEADVECTOR)) > > > pair->value |=3D RISCV_HWPROBE_IMA_V; > > > > > > /* > > > @@ -112,7 +113,8 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe= *pair, > > > EXT_KEY(ZACAS); > > > EXT_KEY(ZICOND); > > > > > > - if (has_vector() && !riscv_has_vendor_extension_unlik= ely(RISCV_ISA_VENDOR_EXT_XTHEADVECTOR)) { > > > + if (has_vector() && > > > + !riscv_has_vendor_extension_unlikely(RISCV_ISA_VE= NDOR_EXT_XTHEADVECTOR)) { > > > EXT_KEY(ZVBB); > > > EXT_KEY(ZVBC); > > > EXT_KEY(ZVKB); > > > @@ -139,6 +141,55 @@ static void hwprobe_isa_ext0(struct riscv_hwprob= e *pair, > > > 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 = vendor. */ > > > + if (mvendorid.value =3D=3D -1ULL) > > > + return; > > > + > > > + /* > > > + * Loop through and record vendor extensions that 1) anyone h= as, and > > > + * 2) anyone doesn't have. > > > + */ > > > + for_each_cpu(cpu, cpus) { > > > + struct riscv_isainfo *isavendorinfo =3D &hart_isa_ven= dor[cpu]; > > > + > > > +#define VENDOR_EXT_KEY(ext) = \ > > > + do { = \ > > > + if (__riscv_isa_vendor_extension_available(isavendori= nfo->isa, \ > > > + RISCV_ISA_VE= NDOR_EXT_##ext)) \ > > > + pair->value |=3D RISCV_HWPROBE_VENDOR_EXT_##e= xt; \ > > > + else = \ > > > + missing |=3D RISCV_HWPROBE_VENDOR_EXT_##ext; = \ > > > + } while (false) > > > + > > > + /* > > > + * Only use VENDOR_EXT_KEY() for extensions which can be expo= sed to userspace, > > > + * regardless of the kernel's configuration, as no other chec= ks, 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. > > Great idea! > > > 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, // currentl= y > > 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. > > I know vendor extensions are kind of the "wild west" of riscv, but in > spite of that I want to design a consistent API. The issue I had with > having this "vendor space" for exposing vendor extensions was that this > is something that is inherently the same for all vendors. I see a vendor > space like this more applicable for something like > "RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE" where a vendor has a specific > value they would like to expose. I do agree that having a vendor space > is a good design choice, but I am not convinced that vendor extensions > are the proper use-case. > > By having RISCV_HWPROBE_KEY_VENDOR_EXT_0 we can expose the vendor > extensions in the same way that standard extensions are exposed, with a > bitmask representing each extension. If these are instead in the vendor > space, each vendor would probably be inclined to introduce a key like > RISCV_HWPROBE_KEY_THEAD_EXT_0 that returns a bitmask of all of the thead > vendor extensions. This duplicated effort is what I am trying to avoid. > The alternative would be that vendors have a separate key for each > vendor extension they would like to expose, but that is strictly less > efficient than the existing bitmask probing. > > Do you think that having the vendor space is appropriate for vendor > extensions given my concerns? I do see what you're going for. It's tidy for a bitmask to just let anyone allocate the next bit, but leaves you with the same problem when a vendor decides they want to expose an enum, or decides they want to expose a bazillion things. I think a generalized version of the approach you've written would be: simply let vendors allocate keys from the same global space we're already using. My worry was that it would turn into an expansive suburban sprawl of mostly dead bits, or in the case of vendor-specific keys, full of "if (mvendor_id() !=3D MINE) return 0;". My hope with the vendored keyspace is it would keep the sprawl from polluting the general array of (hopefully valuable) info with stuff that's likely to become less relevant as time passes. It also lowers the bar a bit to make it easier for vendors to expose bits, as they don't consume global space for everyone for all of time, just themselves. So yes, personally I'm still in the camp of siloing the vendor stuff off to its own area. -Evan