lib: sbi: sbi_mpxy_set_shmem adds parameter check
PATCH 1/1 lib: sbi: sbi_mpxy_set_shmem adds parameter check
Shared memory needs to be accessed in M-Mode, and the high address of physical memory should be 0
Signed-off-by Xiang W <[email protected]>
--- lib/sbi/sbi_mpxy.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
lib/sbi/sbi_mpxy.c +14 -0
@@ -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_PARAM ; + if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo), mpxy_shmem_size, PRV_S,
Signature · 1 line
2.47.2
Quoted 3 lines · Xiang W
Shared memory needs to be accessed in M-Mode, and the high address of physical memory should be 0
The patch subject and description needs to be improved but I will take care of it at the time of merging this patch.
Quoted 17 lines
Signed-off-by Xiang W <[email protected]>--- lib/sbi/sbi_mpxy.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)lib/sbi/sbi_mpxy.c +3
-0@@ -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
lib/sbi/sbi_mpxy.c int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo, · line 302
Quoted 10 lines
lib/sbi/sbi_mpxy.c +10
-0+* 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_PARAM ;
The error code should be SBI_ERR_INVALID_ADDRESS to align with the SBI spec. I will address this at the time of merging this patch.
Quoted 7 lines
lib/sbi/sbi_mpxy.c +1
-1+ if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo), mpxy_shmem_size, PRV_S, --2.47.2
Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi