[PATCH v2 0/1] target/riscv: do not write SXL < UXL [GL4821]

Daniel Henrique Barboza posted 1 patch 3 days, 15 hours ago
Only 0 patches received!
target/riscv/tcg/csr.c               | 39 ++++++++++++------
tests/tcg/riscv64/system/meson.build |  7 ++++
tests/tcg/riscv64/test-uxl-sxl.S     | 59 ++++++++++++++++++++++++++++
3 files changed, 92 insertions(+), 13 deletions(-)
create mode 100644 tests/tcg/riscv64/test-uxl-sxl.S
[PATCH v2 0/1] target/riscv: do not write SXL < UXL [GL4821]
Posted by Daniel Henrique Barboza 3 days, 15 hours ago
Based-on: 20261110232614.83050-1-christianslima@proton.me
("target/riscv: change mstatus bits for read-only if S ou U unsupported")

Hi,

In this v2 there are 2 Sashiko-suggested changes:

- added a "Fixes" tag;

- simplified the 'min_val' calculation when writing SXL.  Sashiko said:

  "- [MEDIUM] In target/riscv/tcg/csr.c (write_mstatus), SXL can be set less
  than UXL if RVU is absent. The min_val for SXL is only derived from UXL
  if RVU is present; otherwise, it defaults to 0. This allows a guest to
  write SXL < UXL, violating the intended fix and the hardware contract.
  The check should ensure min_val is derived from UXL regardless of RVU."

This won't happen in practice since we're basing this patch on a commit
that will forbid UXL writes unless we have RVU, i.e. if there's no RVU
we can assume UXL will be zero.  But, by this same logic, this ternary
is unneeded:

   uint32_t min_val = mask & MSTATUS64_UXL
                      ? get_field(val, MSTATUS64_UXL) : 0;

And we should just use 'get_field(...)' directly instead.  So we're
ended up doing what Sashiko suggested but for other reason.

No other changes made.

Changes in v2:
- added "Fixes" tag;
- removed the ternary when assigning 'min_val' during SXL logic;
- v1 link: https://lore.kernel.org/qemu-devel/20261112163242.509864-1-daniel.barboza@oss.qualcomm.com/


Daniel Henrique Barboza (1):
  target/riscv: do not write SXL < UXL [GL4821]

 target/riscv/tcg/csr.c               | 39 ++++++++++++------
 tests/tcg/riscv64/system/meson.build |  7 ++++
 tests/tcg/riscv64/test-uxl-sxl.S     | 59 ++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 13 deletions(-)
 create mode 100644 tests/tcg/riscv64/test-uxl-sxl.S

-- 
2.43.0
Re: [PATCH v2 0/1] target/riscv: do not write SXL < UXL [GL4821]
Posted by Alistair Francis 3 days, 3 hours ago
On Thu, 2026-11-19 at 09:41 -0300, Daniel Henrique Barboza wrote:
> Based-on: 20261110232614.83050-1-christianslima@proton.me
> ("target/riscv: change mstatus bits for read-only if S ou U
> unsupported")
> 
> Hi,
> 
> In this v2 there are 2 Sashiko-suggested changes:
> 
> - added a "Fixes" tag;
> 
> - simplified the 'min_val' calculation when writing SXL.  Sashiko
> said:
> 
>   "- [MEDIUM] In target/riscv/tcg/csr.c (write_mstatus), SXL can be
> set less
>   than UXL if RVU is absent. The min_val for SXL is only derived from
> UXL
>   if RVU is present; otherwise, it defaults to 0. This allows a guest
> to
>   write SXL < UXL, violating the intended fix and the hardware
> contract.
>   The check should ensure min_val is derived from UXL regardless of
> RVU."
> 
> This won't happen in practice since we're basing this patch on a
> commit
> that will forbid UXL writes unless we have RVU, i.e. if there's no
> RVU
> we can assume UXL will be zero.  But, by this same logic, this
> ternary
> is unneeded:
> 
>    uint32_t min_val = mask & MSTATUS64_UXL
>                       ? get_field(val, MSTATUS64_UXL) : 0;
> 
> And we should just use 'get_field(...)' directly instead.  So we're
> ended up doing what Sashiko suggested but for other reason.
> 
> No other changes made.
> 
> Changes in v2:
> - added "Fixes" tag;
> - removed the ternary when assigning 'min_val' during SXL logic;
> - v1 link:
> https://lore.kernel.org/qemu-devel/20261112163242.509864-1-daniel.barboza@oss.qualcomm.com/
> 
> 
> Daniel Henrique Barboza (1):
>   target/riscv: do not write SXL < UXL [GL4821]

Why is there a GL in the commit message?

Alistair

> 
>  target/riscv/tcg/csr.c               | 39 ++++++++++++------
>  tests/tcg/riscv64/system/meson.build |  7 ++++
>  tests/tcg/riscv64/test-uxl-sxl.S     | 59
> ++++++++++++++++++++++++++++
>  3 files changed, 92 insertions(+), 13 deletions(-)
>  create mode 100644 tests/tcg/riscv64/test-uxl-sxl.S