From: Xiang W <wxjstz@126.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 6/7] lib: utils: Copy over restricted root domain memregions to FDT domains
Date: Sun, 11 Apr 2021 18:07:25 +0800 [thread overview]
Message-ID: <f9c13d6cd7294ec9abd7e443b1c216cb89a1d648.camel@126.com> (raw)
In-Reply-To: <20210410071808.759856-7-anup.patel@wdc.com>
? 2021-04-10?? 12:48 +0530?Anup Patel???
> We should copy over all restricted memregions from the root domain
> to the domains populated from FDT. These restricted root memregions
> are typically firmware memregion and M-mode only mmio memregions.
>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
looks good to me.
Reviewed-by: Xiang W <wxjstz@126.com>
Regards,
Xiang W
> ---
> lib/utils/fdt/fdt_domain.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c
> index 09615e5..95c195d 100644
> --- a/lib/utils/fdt/fdt_domain.c
> +++ b/lib/utils/fdt/fdt_domain.c
> @@ -222,7 +222,7 @@ static u32 fdt_domains_count;
> static struct sbi_domain fdt_domains[FDT_DOMAIN_MAX_COUNT];
> static struct sbi_hartmask fdt_masks[FDT_DOMAIN_MAX_COUNT];
> static struct sbi_domain_memregion
> - fdt_regions[FDT_DOMAIN_MAX_COUNT][FDT_DOMAIN_REGION_MAX_COUNT +
> 2];
> + fdt_regions[FDT_DOMAIN_MAX_COUNT][FDT_DOMAIN_REGION_MAX_COUNT +
> 1];
>
> static int __fdt_parse_region(void *fdt, int domain_offset,
> int region_offset, u32 region_access,
> @@ -276,7 +276,7 @@ static int __fdt_parse_domain(void *fdt, int
> domain_offset, void *opaque)
> struct sbi_hartmask *mask;
> struct sbi_hartmask assign_mask;
> int *cold_domain_offset = opaque;
> - struct sbi_domain_memregion *regions;
> + struct sbi_domain_memregion *reg, *regions;
> int i, err, len, cpus_offset, cpu_offset, doffset;
>
> /* Sanity check on maximum domains we can handle */
> @@ -314,13 +314,31 @@ static int __fdt_parse_domain(void *fdt, int
> domain_offset, void *opaque)
> /* Setup memregions from DT */
> val32 = 0;
> sbi_memset(regions, 0,
> - sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
> 2));
> + sizeof(*regions) * (FDT_DOMAIN_REGION_MAX_COUNT +
> 1));
> dom->regions = regions;
> err = fdt_iterate_each_memregion(fdt, domain_offset, &val32,
> __fdt_parse_region);
> if (err)
> return err;
> - sbi_domain_memregion_initfw(®ions[val32]);
> +
> + /*
> + * Copy over root domain memregions which don't allow
> + * read, write and execute from lower privilege modes.
> + *
> + * These root domain memregions without read, write,
> + * and execute permissions include:
> + * 1) firmware region protecting the firmware memory
> + * 2) mmio regions protecting M-mode only mmio devices
> + */
> + sbi_domain_for_each_memregion(&root, reg) {
> + if ((reg->flags & SBI_DOMAIN_MEMREGION_READABLE) ||
> + (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE) ||
> + (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE))
> + continue;
> + if (FDT_DOMAIN_REGION_MAX_COUNT <= val32)
> + return SBI_EINVAL;
> + sbi_memcpy(®ions[val32++], reg, sizeof(*reg));
> + }
>
> /* Read "boot-hart" DT property */
> val32 = -1U;
> --
> 2.25.1
>
>
next prev parent reply other threads:[~2021-04-11 10:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-10 7:18 [PATCH 0/7] Protect M-mode only MMIO devices Anup Patel
2021-04-10 7:18 ` [PATCH 1/7] lib: sbi: Domains can be registered only before finalizing domains Anup Patel
2021-04-11 7:49 ` Xiang W
2021-04-11 21:19 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 2/7] lib: sbi: Add sbi_domain_memregion_init() API Anup Patel
2021-04-11 7:50 ` Xiang W
2021-04-11 21:22 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 3/7] lib: sbi: Add sbi_domain_root_add_memregion() API Anup Patel
2021-04-11 8:43 ` Xiang W
2021-04-11 21:27 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 4/7] lib: utils/sys: Add CLINT memregion in the root domain Anup Patel
2021-04-11 9:05 ` Xiang W
2021-04-12 5:23 ` Anup Patel
2021-04-12 5:42 ` Xiang W
2021-04-12 6:24 ` Anup Patel
2021-04-10 7:18 ` [PATCH 5/7] lib: sbi: Make the root domain instance global variable Anup Patel
2021-04-11 10:07 ` Xiang W
2021-04-11 21:29 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 6/7] lib: utils: Copy over restricted root domain memregions to FDT domains Anup Patel
2021-04-11 10:07 ` Xiang W [this message]
2021-04-11 21:30 ` Alistair Francis
2021-04-10 7:18 ` [PATCH 7/7] lib: sbi: Make sbi_domain_memregion_initfw() a local function Anup Patel
2021-04-11 10:07 ` Xiang W
2021-04-11 21:32 ` Alistair Francis
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=f9c13d6cd7294ec9abd7e443b1c216cb89a1d648.camel@126.com \
--to=wxjstz@126.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox