summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorXiang W <[email protected]>2025-03-19 20:37:07 +0800
committerAnup Patel <[email protected]>2025-04-15 10:19:13 +0530
commitce57cb572e3dec5ae0cf122e5f1e71f3d8e647ff (patch)
tree15ace0b4c16ae98237d2aa4d157898bade95cd8f /lib
parent0442f1318e116ac54c95ebcf88d504fc5633195a (diff)
lib: sbi: Add parameter check in sbi_mpxy_set_shmem()
Shared memory needs to be accessed in M-Mode so for now the high address of shared memory can't non-zero. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi/sbi_mpxy.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
index c5d9d1bb..c7f311ed 100644
--- a/lib/sbi/sbi_mpxy.c
+++ b/lib/sbi/sbi_mpxy.c
@@ -287,6 +287,20 @@ int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,
if (shmem_phys_lo & ~PAGE_MASK)
return SBI_ERR_INVALID_PARAM;
+ /*
+ * On RV32, the M-mode can only access the first 4GB of
+ * the physical address space because M-mode does not have
+ * MMU to access full 34-bit physical address space.
+ * So fail if the upper 32 bits of the physical address
+ * is non-zero on RV32.
+ *
+ * On RV64, kernel sets upper 64bit address part to zero.
+ * So fail if the upper 64bit of the physical address
+ * is non-zero on RV64.
+ */
+ if (shmem_phys_hi)
+ return SBI_ERR_INVALID_ADDRESS;
+
if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo),
mpxy_shmem_size, PRV_S,