[PATCH v6 2/7] lib: sbi_domain: add sbi_domain_get_oldpmp_flags

Anup Patel anup at brainfault.org
Thu Dec 18 06:36:48 PST 2025


On Thu, Dec 18, 2025 at 4:14 PM Bo Gan <ganboing at gmail.com> wrote:
>
> Factor out logic in `sbi_hart_oldpmp_configure` into function
> `sbi_domain_get_oldpmp_flags`, analogous to `sbi_domain_get_smepmp_flags`.
> Platform specific hart-protection implementation can now leverage it.
>
> Signed-off-by: Bo Gan <ganboing at gmail.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup

> ---
>  include/sbi/sbi_domain.h |  7 +++++++
>  lib/sbi/sbi_domain.c     | 22 ++++++++++++++++++++++
>  lib/sbi/sbi_hart_pmp.c   | 17 +----------------
>  3 files changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
> index 1196d609..3360e090 100644
> --- a/include/sbi/sbi_domain.h
> +++ b/include/sbi/sbi_domain.h
> @@ -253,6 +253,13 @@ void sbi_domain_memregion_init(unsigned long addr,
>                                 unsigned long flags,
>                                 struct sbi_domain_memregion *reg);
>
> +/**
> + * Return the oldpmp pmpcfg LRWX encoding for the flags in @reg.
> + *
> + * @param reg pointer to memory region; its flags field encodes permissions.
> + */
> +unsigned int sbi_domain_get_oldpmp_flags(struct sbi_domain_memregion *reg);
> +
>  /**
>   * Return the Smepmp pmpcfg LRWX encoding for the flags in @reg.
>   *
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index 96d10c76..74cc1e3f 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -121,6 +121,28 @@ void sbi_domain_memregion_init(unsigned long addr,
>         }
>  }
>
> +unsigned int sbi_domain_get_oldpmp_flags(struct sbi_domain_memregion *reg)
> +{
> +
> +       unsigned int pmp_flags = 0;
> +
> +       /*
> +        * If permissions are to be enforced for all modes on
> +        * this region, the lock bit should be set.
> +        */
> +       if (reg->flags & SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS)
> +               pmp_flags |= PMP_L;
> +
> +       if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE)
> +               pmp_flags |= PMP_R;
> +       if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE)
> +               pmp_flags |= PMP_W;
> +       if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
> +               pmp_flags |= PMP_X;
> +
> +       return pmp_flags;
> +}
> +
>  unsigned int sbi_domain_get_smepmp_flags(struct sbi_domain_memregion *reg)
>  {
>         unsigned int pmp_flags = 0;
> diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
> index 7f970ca3..be459129 100644
> --- a/lib/sbi/sbi_hart_pmp.c
> +++ b/lib/sbi/sbi_hart_pmp.c
> @@ -272,22 +272,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
>                 if (!is_valid_pmp_idx(pmp_count, pmp_idx))
>                         return SBI_EFAIL;
>
> -               pmp_flags = 0;
> -
> -               /*
> -                * If permissions are to be enforced for all modes on
> -                * this region, the lock bit should be set.
> -                */
> -               if (reg->flags & SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS)
> -                       pmp_flags |= PMP_L;
> -
> -               if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE)
> -                       pmp_flags |= PMP_R;
> -               if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE)
> -                       pmp_flags |= PMP_W;
> -               if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
> -                       pmp_flags |= PMP_X;
> -
> +               pmp_flags = sbi_domain_get_oldpmp_flags(reg);
>                 pmp_addr = reg->base >> PMP_SHIFT;
>                 if (pmp_log2gran <= reg->order && pmp_addr < pmp_addr_max) {
>                         sbi_platform_pmp_set(sbi_platform_ptr(scratch),
> --
> 2.34.1
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list