Re: [RFC PATCH 15/18] target/riscv: Use boolean logic in pmp_hart_has_privs

Alistair <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
On Sat, 2026-08-15 at 13:37 -0700, Richard Henderson wrote:
> While addition with bool variables isn't wrong, as they promote
> to int, it's odd.  Use normal boolean operators instead.
> 
> Signed-off-by: Richard Henderson <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  target/riscv/tcg/pmp.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/target/riscv/tcg/pmp.c b/target/riscv/tcg/pmp.c
> index 5ea0e5b6c3..fc035c95cf 100644
> --- a/target/riscv/tcg/pmp.c
> +++ b/target/riscv/tcg/pmp.c
> @@ -413,16 +413,8 @@ bool pmp_hart_has_privs(CPURISCVState *env,
> hwaddr addr,
>          s = pmp_is_in_range(env, i, addr);
>          e = pmp_is_in_range(env, i, addr + pmp_size - 1);
>  
> -        /* partially inside */
> -        if ((s + e) == 1) {
> -            qemu_log_mask(LOG_GUEST_ERROR,
> -                          "pmp violation - access is partially
> inside\n");
> -            *allowed_privs = 0;
> -            return false;
> -        }
> -
>          /* fully inside */
> -        if (s + e == 2) {
> +        if (s && e) {
>              /*
>               * If the PMP entry is not off and the address is in
> range,
>               * do the priv check
> @@ -517,6 +509,14 @@ bool pmp_hart_has_privs(CPURISCVState *env,
> hwaddr addr,
>               */
>              return (privs & *allowed_privs) == privs;
>          }
> +
> +        /* partially inside */
> +        if (s || e) {
> +            qemu_log_mask(LOG_GUEST_ERROR,
> +                          "pmp violation - access is partially
> inside\n");
> +            *allowed_privs = 0;
> +            return false;
> +        }
>      }
>  
>      /* No rule matched */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.