All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rémi Denis-Courmont" <remi@remlab.net>
To: Conor Dooley <conor@kernel.org>, Guo Ren <guoren@kernel.org>,
	linux-riscv@lists.infradead.org
Cc: palmer@dabbelt.com, heiko@sntech.de, charlie@rivosinc.com,
	Palmer Dabbelt <palmer@rivosinc.com>,
	Conor Dooley <conor.dooley@microchip.com>,
	linux-riscv@lists.infradead.org,
	Jisheng Zhang <jszhang@kernel.org>
Subject: Re: [PATCH v2] RISC-V: Don't trust V from the riscv,isa DT property on T-Head CPUs
Date: Thu, 13 Jul 2023 21:47:29 +0300	[thread overview]
Message-ID: <1855588.tdWV9SEqCh@basile.remlab.net> (raw)
In-Reply-To: <ZLAoIWX+qqWvucWz@xhacker>

Le torstaina 13. heinäkuuta 2023, 19.36.49 EEST Jisheng Zhang a écrit :
> On Wed, Jul 12, 2023 at 06:48:02PM +0100, Conor Dooley wrote:
> > From: Palmer Dabbelt <palmer@rivosinc.com>
> > 
> > The last merge window contained both V support and the deprecation of
> > the riscv,isa DT property, with the V implementation reading riscv,isa
> > to determine the presence of the V extension.  At the time that was the
> > only way to do it, but there's a lot of ambiguity around V in ISA
> > strings.  In particular, there is a lot of firmware in the wild that
> > uses "v" in the riscv,isa DT property to communicate support for the
> > 0.7.1 version of the Vector specification implemented by T-Head CPU
> > cores.
> 
> Add Guo
> 
> Hi Conor, Palmer,
> 
> FWICT, new T-HEAD's riscv cores such as C908 support standard RVV-1.0,
> this patch looks like a big hammer for T-HEAD. I do understand why
> this patch is provided, but can we mitigate the situation by carefully
> review the DTs?

There are many tricks to detect that RVV is present but noncomformant at run-
time. If the kernel can at least temporarily enable V to make the check, the 
example below works. Converting the user-space console program to a kernel 
function is left as an exercise to the reader:

----8<--------8<--------8<--------8<--------8<--------8<--------8<----
#include <stdio.h>

int main(void)
{
        long vtype;

        __asm__ (
                "vsetvli zero, zero, e8, m1, ta, ma\n"
                "csrr   %1, vtype\n" : "=r" (vtype) : "r" (0xC0));

        if (vtype < 0)
                puts("RVV 0.7.1");
        else
                puts("RVV 1.0+");

        return 0;
}
----8<--------8<--------8<--------8<--------8<--------8<--------8<----

The trick here is that the vector configuration is valid for RVV 1.0, but not 
for RVV 0.7.1 so the sign/illegal bit gets.

-- 
Rémi Denis-Courmont
http://www.remlab.net/




_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2023-07-13 18:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12 17:48 [PATCH v2] RISC-V: Don't trust V from the riscv,isa DT property on T-Head CPUs Conor Dooley
2023-07-13 16:36 ` Jisheng Zhang
2023-07-13 16:56   ` Palmer Dabbelt
2023-07-13 17:04     ` Conor Dooley
2023-07-13 17:12       ` Jisheng Zhang
2023-07-13 17:36         ` Conor Dooley
2023-07-13 18:20           ` Conor Dooley
2023-07-13 17:33   ` Guo Ren
2023-07-13 17:43     ` Palmer Dabbelt
2023-07-14  6:07       ` Guo Ren
2023-07-13 17:45     ` Conor Dooley
2023-07-14  6:14       ` Guo Ren
2023-07-14 11:10         ` Conor Dooley
2023-07-14 18:45           ` Conor Dooley
2023-07-15  6:11             ` Guo Ren
2023-07-15  6:07           ` Guo Ren
2023-07-13 18:47   ` Rémi Denis-Courmont [this message]
2023-07-13 18:50     ` Rémi Denis-Courmont
2023-07-14 19:21 ` Conor Dooley
2023-07-15  6:12   ` Guo Ren

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=1855588.tdWV9SEqCh@basile.remlab.net \
    --to=remi@remlab.net \
    --cc=charlie@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=conor@kernel.org \
    --cc=guoren@kernel.org \
    --cc=heiko@sntech.de \
    --cc=jszhang@kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=palmer@rivosinc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.