From: Samuel Ortiz <sameo@rivosinc.com>
To: Stefan O'Rear <sorear@fastmail.com>
Cc: "Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
linux-riscv@lists.infradead.org, linux@rivosinc.com,
"Conor Dooley" <conor.dooley@microchip.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Heiko Stuebner" <heiko.stuebner@vrull.eu>,
"Anup Patel" <apatel@ventanamicro.com>,
linux-kernel@vger.kernel.org,
"Hongren (Zenithal) Zheng" <i@zenithal.me>,
"Guo Ren" <guoren@kernel.org>,
"Atish Patra" <atishp@rivosinc.com>,
"Björn Töpel" <bjorn@rivosinc.com>,
"Evan Green" <evan@rivosinc.com>
Subject: Re: [PATCH 2/3] RISC-V: hwprobe: Expose Zbc and the scalar crypto extensions
Date: Mon, 10 Jul 2023 09:59:40 +0200 [thread overview]
Message-ID: <ZKu6bCMPX0WKetVp@vermeer> (raw)
In-Reply-To: <b208a2cb-bf68-4f4f-9c99-6a2e5853d26e@app.fastmail.com>
On Wed, Jun 28, 2023 at 09:25:02AM -0400, Stefan O'Rear wrote:
> On Wed, Jun 28, 2023, at 6:04 AM, Samuel Ortiz wrote:
> > On Tue, Jun 27, 2023 at 08:34:20PM -0400, Stefan O'Rear wrote:
> >> On Tue, Jun 27, 2023, at 10:37 AM, Samuel Ortiz wrote:
> >> > Zbc was missing from a previous Bit-Manipulation extension hwprobe
> >> > patch.
> >> >
> >> > Add all scalar crypto extensions bits, and define a macro for setting
> >> > the hwprobe key/pair in a more readable way.
> >> >
> >> > Signed-off-by: Samuel Ortiz <sameo@rivosinc.com>
> >> > ---
> >> > Documentation/riscv/hwprobe.rst | 33 ++++++++++++++++++++++++
> >> > arch/riscv/include/uapi/asm/hwprobe.h | 11 ++++++++
> >> > arch/riscv/kernel/sys_riscv.c | 36 ++++++++++++++++-----------
> >> > 3 files changed, 66 insertions(+), 14 deletions(-)
> >> >
> >> > diff --git a/Documentation/riscv/hwprobe.rst b/Documentation/riscv/hwprobe.rst
> >> > index 19165ebd82ba..3177550106e0 100644
> >> > --- a/Documentation/riscv/hwprobe.rst
> >> > +++ b/Documentation/riscv/hwprobe.rst
> >> > @@ -72,11 +72,44 @@ The following keys are defined:
> >> > extensions.
> >> >
> >> > * :c:macro:`RISCV_HWPROBE_EXT_ZBB`: The Zbb extension is supported,
> >> > as defined
> >> > + in version 1.0 of the Bit-Manipulation ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZBC`: The Zbc extension is supported,
> >> > as defined
> >> > in version 1.0 of the Bit-Manipulation ISA extensions.
> >> >
> >> > * :c:macro:`RISCV_HWPROBE_EXT_ZBS`: The Zbs extension is supported,
> >> > as defined
> >> > in version 1.0 of the Bit-Manipulation ISA extensions.
> >> >
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZBKB`: The Zbkb extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZBKC`: The Zbkc extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZBKX`: The Zbkx extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKND`: The Zknd extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKNE`: The Zkne extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKNH`: The Zknh extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKR`: The Zkr extension is supported,
> >> > as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKSED`: The Zksed extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKSH`: The Zksh extension is
> >> > supported, as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > + * :c:macro:`RISCV_HWPROBE_EXT_ZKT`: The Zkt extension is supported,
> >> > as defined
> >> > + in version 1.0 of the Scalar Cryptography ISA extensions.
> >> > +
> >> > * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains
> >> > performance
> >> > information about the selected set of processors.
> >> >
> >> > diff --git a/arch/riscv/include/uapi/asm/hwprobe.h
> >> > b/arch/riscv/include/uapi/asm/hwprobe.h
> >> > index 006bfb48343d..8357052061b3 100644
> >> > --- a/arch/riscv/include/uapi/asm/hwprobe.h
> >> > +++ b/arch/riscv/include/uapi/asm/hwprobe.h
> >> > @@ -29,6 +29,17 @@ struct riscv_hwprobe {
> >> > #define RISCV_HWPROBE_EXT_ZBA (1 << 3)
> >> > #define RISCV_HWPROBE_EXT_ZBB (1 << 4)
> >> > #define RISCV_HWPROBE_EXT_ZBS (1 << 5)
> >> > +#define RISCV_HWPROBE_EXT_ZBC (1 << 6)
> >> > +#define RISCV_HWPROBE_EXT_ZBKB (1 << 7)
> >> > +#define RISCV_HWPROBE_EXT_ZBKC (1 << 8)
> >> > +#define RISCV_HWPROBE_EXT_ZBKX (1 << 9)
> >> > +#define RISCV_HWPROBE_EXT_ZKND (1 << 10)
> >> > +#define RISCV_HWPROBE_EXT_ZKNE (1 << 11)
> >> > +#define RISCV_HWPROBE_EXT_ZKNH (1 << 12)
> >> > +#define RISCV_HWPROBE_EXT_ZKR (1 << 13)
> >> > +#define RISCV_HWPROBE_EXT_ZKSED (1 << 14)
> >> > +#define RISCV_HWPROBE_EXT_ZKSH (1 << 15)
> >> > +#define RISCV_HWPROBE_EXT_ZKT (1 << 16)
> >> > #define RISCV_HWPROBE_KEY_CPUPERF_0 5
> >> > #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
> >> > #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
> >> > diff --git a/arch/riscv/kernel/sys_riscv.c
> >> > b/arch/riscv/kernel/sys_riscv.c
> >> > index 26ef5526bfb4..df15926196b6 100644
> >> > --- a/arch/riscv/kernel/sys_riscv.c
> >> > +++ b/arch/riscv/kernel/sys_riscv.c
> >> > @@ -145,20 +145,28 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe
> >> > *pair,
> >> > for_each_cpu(cpu, cpus) {
> >> > struct riscv_isainfo *isainfo = &hart_isa[cpu];
> >> >
> >> > - if (riscv_isa_extension_available(isainfo->isa, ZBA))
> >> > - pair->value |= RISCV_HWPROBE_EXT_ZBA;
> >> > - else
> >> > - missing |= RISCV_HWPROBE_EXT_ZBA;
> >> > -
> >> > - if (riscv_isa_extension_available(isainfo->isa, ZBB))
> >> > - pair->value |= RISCV_HWPROBE_EXT_ZBB;
> >> > - else
> >> > - missing |= RISCV_HWPROBE_EXT_ZBB;
> >> > -
> >> > - if (riscv_isa_extension_available(isainfo->isa, ZBS))
> >> > - pair->value |= RISCV_HWPROBE_EXT_ZBS;
> >> > - else
> >> > - missing |= RISCV_HWPROBE_EXT_ZBS;
> >> > +#define SET_HWPROBE_EXT_PAIR(ext) \
> >> > + do { \
> >> > + if (riscv_isa_extension_available(isainfo->isa, ext)) \
> >> > + pair->value |= RISCV_HWPROBE_EXT_## ext; \
> >> > + else \
> >> > + missing |= RISCV_HWPROBE_EXT_## ext; \
> >> > + } while (false) \
> >> > +
> >> > + SET_HWPROBE_EXT_PAIR(ZBA);
> >> > + SET_HWPROBE_EXT_PAIR(ZBB);
> >> > + SET_HWPROBE_EXT_PAIR(ZBC);
> >> > + SET_HWPROBE_EXT_PAIR(ZBS);
> >> > + SET_HWPROBE_EXT_PAIR(ZBKB);
> >> > + SET_HWPROBE_EXT_PAIR(ZBKC);
> >> > + SET_HWPROBE_EXT_PAIR(ZBKX);
> >> > + SET_HWPROBE_EXT_PAIR(ZKND);
> >> > + SET_HWPROBE_EXT_PAIR(ZKNE);
> >> > + SET_HWPROBE_EXT_PAIR(ZKNH);
> >> > + SET_HWPROBE_EXT_PAIR(ZKR);
> >>
> >> Does the presence of a HWPROBE_EXT bit imply that userspace software can
> >> actually directly use the described feature? If so, we should probably
> >> not set ZKR unless mseccfg.USEED=1.
> >
> > mseccfg is MRW, so only accessible from M-mode only afaiu. So I don't
> > think we would be able to check that from Linux in S-mode.
>
> Check directly, no, but your patch already makes the assumption that
> mseccfg.SSEED=1 if zkr is present in the device tree. Which is fine as long
> as that contract is documented somewhere (presumably, the device tree
> binding; some of the language in the RVA22U64 profile spec implies USEED=0,
> but linux does not require profiles and they don't exist for rv32).
>
> If we want U-mode behavior to be discoverable and/or predictable, we have
> three good options:
Thanks for the suggestions.
> Simplest: Document that we expect USEED=0 or USEED=1. Set zkr appropriately
> in hwprobe.
>
> Most flexible: Work with the SBI people to add a SBI_EXT_FWFEATURE for USEED,
> as well as defining the value on kernel entry. Expose this via hwprobe and
> a new prctl.
I'd like to go down that route, but this depends on [1] to get
accepted/merged first.
Would it make sense to go with only documenting the USEED expectation
for now and then move to the more flexible FWFEATURE SBI approach?
Cheers,
Samuel.
[1] https://lists.riscv.org/g/tech-prs/message/540
next prev parent reply other threads:[~2023-07-10 7:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 14:37 [PATCH 0/3] RISC-V: archrandom support Samuel Ortiz
2023-06-27 14:37 ` [PATCH 1/3] RISC-V: add Bitmanip/Scalar Crypto parsing from DT Samuel Ortiz
2023-06-27 18:14 ` Evan Green
2023-06-27 18:44 ` Hongren (Zenithal) Zheng
2023-06-27 18:48 ` Conor Dooley
2023-06-27 19:03 ` Hongren (Zenithal) Zheng
2023-06-27 19:18 ` Conor Dooley
2023-06-28 9:59 ` Samuel Ortiz
2023-06-28 10:01 ` Samuel Ortiz
2023-06-28 11:10 ` Conor Dooley
2023-06-28 12:30 ` Samuel Ortiz
2023-06-28 16:49 ` Conor Dooley
2023-06-28 17:18 ` Evan Green
2023-06-28 17:24 ` Conor Dooley
2023-07-03 17:39 ` Conor Dooley
[not found] ` <97a7d701-3b48-252e-6d78-ef3d0e7f8f03@web.de>
2023-06-28 12:29 ` Samuel Ortiz
2023-06-27 14:37 ` [PATCH 2/3] RISC-V: hwprobe: Expose Zbc and the scalar crypto extensions Samuel Ortiz
2023-06-27 18:13 ` Evan Green
2023-06-28 0:34 ` Stefan O'Rear
2023-06-28 10:04 ` Samuel Ortiz
2023-06-28 13:25 ` Stefan O'Rear
2023-07-10 7:59 ` Samuel Ortiz [this message]
2023-07-12 5:54 ` Stefan O'Rear
2023-06-27 14:37 ` [PATCH 3/3] RISC-V: Implement archrandom when Zkr is available Samuel Ortiz
2023-06-27 19:09 ` Conor Dooley
2023-06-28 12:28 ` Samuel Ortiz
2023-06-28 1:00 ` Stefan O'Rear
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZKu6bCMPX0WKetVp@vermeer \
--to=sameo@rivosinc.com \
--cc=ajones@ventanamicro.com \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=atishp@rivosinc.com \
--cc=bjorn@rivosinc.com \
--cc=conor.dooley@microchip.com \
--cc=evan@rivosinc.com \
--cc=guoren@kernel.org \
--cc=heiko.stuebner@vrull.eu \
--cc=i@zenithal.me \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux@rivosinc.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=sorear@fastmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox