All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: Joel Stanley <joel@jms.id.au>
Cc: opensbi@lists.infradead.org
Subject: Re: [PATCH 2/4] lib: sbi: Move PMP encoding into a new file
Date: Thu, 23 Apr 2026 10:59:34 +1000	[thread overview]
Message-ID: <aelrWTQA5dRlC_aM@lima-default> (raw)
In-Reply-To: <CACPK8Xc_q-N7kNtixS75z8=cX3ryHY6Kw-+S-8NjZhd+q4173Q@mail.gmail.com>

On Wed, Apr 01, 2026 at 11:20:53PM +1030, Joel Stanley wrote:
> On Tue, 10 Mar 2026 at 11:19, Nicholas Piggin <npiggin@gmail.com> wrote:
> >
> > The Tenstorrent RISC-V IOMMU PMP MMRs use the same encoding as PMP CSRs.
> > In preparation to support it, move the non hart-specific PMP operations
> > into their own file where they will also be used to build the IOMMU
> > PMPs.
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> 
> > --- a/lib/sbi/riscv_asm.c
> > +++ b/lib/sbi/riscv_asm.c
> 
> > +int is_pmp_entry_mapped(unsigned int entry)
> > +{
> > +       pmp_t pmp;
> 
> > +       if (hart_pmp_read(entry, &pmp))
> > +               return pmp_enabled(&pmp);
> 
> The diff is a bit all over the place so I may have confused myself.
> The patch keeps is_pmp_entry_mapped but changes the body from
> 
>     if (pmp_get(entry, &prot, &addr, &log2len) != 0)
>         return false;
> 
> to
> 
>     if (hart_pmp_read(entry, &pmp))
>         return pmp_enabled(&pmp);
> 
> but hart_pmp_read returns SBI_OK (0) on success. So we should keep the !=0?

Yes, you're right.

> 
> > +int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
> > +           unsigned long *log2len)
> > +{
> > +       pmp_t pmp;
> > +       int rc;
> >
> > -       /* return details */
> > -       *prot_out    = prot;
> 
> It looks like prot_out is no longer written to after your patch. This
> hunk never made it into the new pmp_decode:
> 
>        /* decode PMP config */
>        cfgmask = (0xffUL << pmpcfg_shift);
>        pmpcfg  = csr_read_num(pmpcfg_csr) & cfgmask;
>        prot    = pmpcfg >> pmpcfg_shift;

Good catch.

> > --- /dev/null
> > +++ b/lib/sbi/sbi_pmp.c
> > @@ -0,0 +1,91 @@
> 
> > +int pmp_create(pmp_t *pmp, unsigned long prot, unsigned long addr,
> > +           unsigned long log2len)
> > +{
> > +       unsigned long addrmask, pmpaddr;
> > +
> > +       /* check parameters */
> > +       if (log2len > __riscv_xlen || log2len < PMP_SHIFT)
> > +               return SBI_EINVAL;
> 
> Here we check that log2len <=__riscv_xlen, but in pmp_decode below we
> set log2len =  __riscv_xlen + 3. Is that just how it works, or should
> pmp_decode be able to decode what pmp_create does?

That + 3 looks wrong, I'll have to dig a bit more into it. I think I
need to simplify and/or split the patch up so it's a bit more feasbile
to review (and hopefully less buggy).

Thanks,
Nick

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  reply	other threads:[~2026-04-23  0:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10  0:49 [PATCH 1/4] platform: generic: Tenstorrent Atlantis support Nicholas Piggin
2026-03-10  0:49 ` [PATCH 2/4] lib: sbi: Move PMP encoding into a new file Nicholas Piggin
2026-04-01 12:50   ` Joel Stanley
2026-04-23  0:59     ` Nicholas Piggin [this message]
2026-03-10  0:49 ` [PATCH 3/4] lib: sbi: Add hart_ prefix to PMP functions Nicholas Piggin
2026-04-01 12:50   ` Joel Stanley
2026-03-10  0:49 ` [PATCH 4/4] platform: generic: tenstorrent: Add RISC-V IOMMU support Nicholas Piggin
2026-04-01 12:51   ` Joel Stanley
2026-04-23  1:01     ` Nicholas Piggin

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=aelrWTQA5dRlC_aM@lima-default \
    --to=npiggin@gmail.com \
    --cc=joel@jms.id.au \
    --cc=opensbi@lists.infradead.org \
    /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.