diff options
author | Himanshu Chauhan <hchauhan@ventanamicro.com> | 2023-01-09 08:20:36 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2023-01-09 15:34:12 +0300 |
commit | aace1e145dbd987e6bd5a8b4583faafde7d33c43 (patch) | |
tree | 0433b5bbe13bf5fc79665d5a882b91363b5a337e | |
parent | 9e0ba090763a7d31d63ba67421b09647f2f2adc4 (diff) | |
download | opensbi-aace1e145dbd987e6bd5a8b4583faafde7d33c43.tar.xz |
lib: sbi: Use finer permission semantics for address validation
Use the fine grained permisssion semantics for address validation
of a given region.
Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Tested-by: Anup Patel <anup@brainfault.org>
-rw-r--r-- | lib/sbi/sbi_domain.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 19e2029..97eec25 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -107,24 +107,34 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, { bool rmmio, mmio = false; struct sbi_domain_memregion *reg; - unsigned long rstart, rend, rflags, rwx = 0; + unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0; if (!dom) return false; + /* + * Use M_{R/W/X} bits because the SU-bits are at the + * same relative offsets. If the mode is not M, the SU + * bits will fall at same offsets after the shift. + */ if (access_flags & SBI_DOMAIN_READ) - rwx |= SBI_DOMAIN_MEMREGION_READABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_READABLE; + if (access_flags & SBI_DOMAIN_WRITE) - rwx |= SBI_DOMAIN_MEMREGION_WRITEABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE; + if (access_flags & SBI_DOMAIN_EXECUTE) - rwx |= SBI_DOMAIN_MEMREGION_EXECUTABLE; + rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE; + if (access_flags & SBI_DOMAIN_MMIO) mmio = true; sbi_domain_for_each_memregion(dom, reg) { rflags = reg->flags; - if (mode == PRV_M && !(rflags & SBI_DOMAIN_MEMREGION_MMODE)) - continue; + rrwx = (mode == PRV_M ? + (rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) : + (rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK) + >> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT); rstart = reg->base; rend = (reg->order < __riscv_xlen) ? @@ -133,7 +143,7 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom, rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? true : false; if (mmio != rmmio) return false; - return ((rflags & rwx) == rwx) ? true : false; + return ((rrwx & rwx) == rwx) ? true : false; } } |