[PATCH v2 5/5] Add two entries:

Himanshu Chauhan hchauhan at ventanamicro.com
Wed Jan 18 18:41:37 PST 2023


On Wed, Jan 18, 2023 at 08:17:26PM +0800, Xiang W wrote:
> 在 2023-01-18星期三的 17:07 +0530,Himanshu Chauhan写道:
> >   1. TEXT: fw_start to _fw_rw_offset with RX permissions
> >   2. DATA: _fw_rw_offset to fw_size with RW permissions
> > 
> > These permissions are still not enforced from M-mode but lay
> > the ground work for enforcing them for M-mode. SU-mode don't
> > have any access to these regions.
> > 
> > Sample output:
> >  Domain0 Region01  : 0x0000000080000000-0x000000008001ffff M: (R,X) S/U: ()
> >  Domain0 Region02  : 0x0000000080020000-0x000000008003ffff M: (R,W) S/U: ()
> > 
> > Signed-off-by: Himanshu Chauhan <hchauhan at ventanamicro.com>
> > ---
> >  lib/sbi/sbi_domain.c | 23 +++++++++++++++++++++--
> >  1 file changed, 21 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> > index f6addc4..3dceb6a 100644
> > --- a/lib/sbi/sbi_domain.c
> > +++ b/lib/sbi/sbi_domain.c
> > @@ -637,12 +637,31 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
> >         u32 i;
> >         const struct sbi_platform *plat = sbi_platform_ptr(scratch);
> >  
> > +       if ((scratch->fw_rw_offset & (scratch->fw_rw_offset - 1)) != 0) {
> 
> This expression is false at scratch-> fw_rw_offset = 0.
> 0 is not a power of 2.
> suggestion:
>     if ((scratch->fw_rw_offset & (scratch->fw_rw_offset - 1)) != 0 || scratch->fw_rw_offset == 0) {

fw_rw_offset is provided by the linker. It will fall after text, ro, and symbols and then it is
protected by LOG2CEIL. Unless everything is preceding fw_rw_offset is zero, fw_rw_offset can't
be zero. So I think this check is safe here.

Regards
Himanshu

> 
> Regards,
> Xiang W
> 
> > +               sbi_printf("%s: Firmware read-write offset not a power of 2 (0x%lx)\n",
> > +                          __func__, scratch->fw_rw_offset);
> > +               return SBI_EINVAL;
> > +       }
> > +
> > +       if ((scratch->fw_start & (scratch->fw_rw_offset - 1)) != 0) {
> > +               sbi_printf("%s: Firmware start and read-write offset not aligned\n",
> > +                          __func__);
> > +               return SBI_EINVAL;
> > +       }
> > +
> >         /* Root domain firmware memory region */
> > -       sbi_domain_memregion_init(scratch->fw_start, scratch->fw_size,
> > -                                 SBI_DOMAIN_MEMREGION_M_RWX,
> > +       sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset,
> > +                                 (SBI_DOMAIN_MEMREGION_M_READABLE |
> > +                                  SBI_DOMAIN_MEMREGION_M_EXECUTABLE),
> >                                   &root_fw_region);
> >         domain_memregion_initfw(&root_memregs[root_memregs_count++]);
> >  
> > +       sbi_domain_memregion_init((scratch->fw_start + scratch->fw_rw_offset),
> > +                                 (scratch->fw_size - scratch->fw_rw_offset),
> > +                                 (SBI_DOMAIN_MEMREGION_M_READABLE |
> > +                                  SBI_DOMAIN_MEMREGION_M_WRITABLE),
> > +                                 &root_memregs[root_memregs_count++]);
> > +
> >         /* Root domain allow everything memory region */
> >         sbi_domain_memregion_init(0, ~0UL,
> >                                   (SBI_DOMAIN_MEMREGION_READABLE |
> > -- 
> > 2.39.0
> > 
> > 
> 



More information about the opensbi mailing list