[PATCH v3 9/9] target/riscv: Use a smaller guess size for no-MMU PMP

Alistair Francis posted 9 patches 5 years, 7 months ago
Maintainers: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Sagar Karandikar <sagark@eecs.berkeley.edu>, Alistair Francis <Alistair.Francis@wdc.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>
There is a newer version of this series
[PATCH v3 9/9] target/riscv: Use a smaller guess size for no-MMU PMP
Posted by Alistair Francis 5 years, 7 months ago
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 target/riscv/pmp.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index 0e6b640fbd..607a991260 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -233,12 +233,16 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
         return true;
     }
 
-    /*
-     * if size is unknown (0), assume that all bytes
-     * from addr to the end of the page will be accessed.
-     */
     if (size == 0) {
-        pmp_size = -(addr | TARGET_PAGE_MASK);
+        if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
+            /*
+             * If size is unknown (0), assume that all bytes
+             * from addr to the end of the page will be accessed.
+             */
+            pmp_size = -(addr | TARGET_PAGE_MASK);
+        } else {
+            pmp_size = sizeof(target_ulong);
+        }
     } else {
         pmp_size = size;
     }
-- 
2.26.2


Re: [PATCH v3 9/9] target/riscv: Use a smaller guess size for no-MMU PMP
Posted by Bin Meng 5 years, 7 months ago
On Wed, May 20, 2020 at 5:40 AM Alistair Francis
<alistair.francis@wdc.com> wrote:
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  target/riscv/pmp.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> index 0e6b640fbd..607a991260 100644
> --- a/target/riscv/pmp.c
> +++ b/target/riscv/pmp.c
> @@ -233,12 +233,16 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
>          return true;
>      }
>
> -    /*
> -     * if size is unknown (0), assume that all bytes
> -     * from addr to the end of the page will be accessed.
> -     */
>      if (size == 0) {
> -        pmp_size = -(addr | TARGET_PAGE_MASK);
> +        if (!riscv_feature(env, RISCV_FEATURE_MMU)) {

My previous comments were not fully addressed. I think the logic should be:

if (riscv_feature(env, RISCV_FEATURE_MMU))

Otherwise it does not match your comment and the commit title.

> +            /*
> +             * If size is unknown (0), assume that all bytes
> +             * from addr to the end of the page will be accessed.
> +             */
> +            pmp_size = -(addr | TARGET_PAGE_MASK);
> +        } else {
> +            pmp_size = sizeof(target_ulong);
> +        }
>      } else {
>          pmp_size = size;
>      }

Regards,
Bin

Re: [PATCH v3 9/9] target/riscv: Use a smaller guess size for no-MMU PMP
Posted by Alistair Francis 5 years, 6 months ago
On Wed, May 20, 2020 at 6:52 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, May 20, 2020 at 5:40 AM Alistair Francis
> <alistair.francis@wdc.com> wrote:
> >
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >  target/riscv/pmp.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> > index 0e6b640fbd..607a991260 100644
> > --- a/target/riscv/pmp.c
> > +++ b/target/riscv/pmp.c
> > @@ -233,12 +233,16 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
> >          return true;
> >      }
> >
> > -    /*
> > -     * if size is unknown (0), assume that all bytes
> > -     * from addr to the end of the page will be accessed.
> > -     */
> >      if (size == 0) {
> > -        pmp_size = -(addr | TARGET_PAGE_MASK);
> > +        if (!riscv_feature(env, RISCV_FEATURE_MMU)) {
>
> My previous comments were not fully addressed. I think the logic should be:
>
> if (riscv_feature(env, RISCV_FEATURE_MMU))
>
> Otherwise it does not match your comment and the commit title.

Ah! You are right. This uncovered a bug with how we set the MMU as
well. I have fixed this and added a new patch.

Alistair

>
> > +            /*
> > +             * If size is unknown (0), assume that all bytes
> > +             * from addr to the end of the page will be accessed.
> > +             */
> > +            pmp_size = -(addr | TARGET_PAGE_MASK);
> > +        } else {
> > +            pmp_size = sizeof(target_ulong);
> > +        }
> >      } else {
> >          pmp_size = size;
> >      }
>
> Regards,
> Bin