Skip to content

Commit 23b7bad

Browse files
geomatsiavpatel
authored andcommitted
lib: sbi: check incoming dbtr shmem address
Current Debug Trigger SBI extension proposal suggests to activate shmem area and obtain its physical address from S-mode software in the following way: : If both `shmem_phys_lo` and `shmem_phys_hi` parameters are not : all-ones bitwise then `shmem_phys_lo` specifies the lower XLEN : bits and `shmem_phys_hi` specifies the upper XLEN bits of the : shared memory physical base address. The `shmem_phys_lo` MUST : be `(XLEN / 8)` byte aligned and the size of shared memory is : assumed to be `trig_max * (XLEN / 2)` bytes. For more details see the current version of the proposal: - https://lists.riscv.org/g/tech-debug/message/1302 On the other hand, 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. Similarly, on RV64, the M-mode can only access memory addressed by 64 bits. This commit checks shmem address in function sbi_dbtr_setup_shmem to make sure that shmem_phys_hi part of the valid address is zero. Besides, the macro DBTR_SHMEM_MAKE_PHYS is updated to take into account only low XLEN part. Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com> Reviewed-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
1 parent 0e45b63 commit 23b7bad

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

lib/sbi/sbi_dbtr.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ static unsigned long hart_state_ptr_offset;
4747
_idx < _max; \
4848
_idx++, _entry = ((_etype *)_base + _idx))
4949

50-
#if __riscv_xlen == 64
5150
#define DBTR_SHMEM_MAKE_PHYS(_p_hi, _p_lo) (_p_lo)
52-
#elif __riscv_xlen == 32
53-
#define DBTR_SHMEM_MAKE_PHYS(_p_hi, _p_lo) (((u64)(_p_hi) << 32) | (_p_lo))
54-
#else
55-
#error "Undefined XLEN"
56-
#endif
5751

5852
/* must call with hs != NULL */
5953
static inline bool sbi_dbtr_shmem_disabled(
@@ -277,6 +271,20 @@ int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
277271
if (shmem_phys_lo & SBI_DBTR_SHMEM_ALIGN_MASK)
278272
return SBI_ERR_INVALID_PARAM;
279273

274+
/*
275+
* On RV32, the M-mode can only access the first 4GB of
276+
* the physical address space because M-mode does not have
277+
* MMU to access full 34-bit physical address space.
278+
* So fail if the upper 32 bits of the physical address
279+
* is non-zero on RV32.
280+
*
281+
* On RV64, kernel sets upper 64bit address part to zero.
282+
* So fail if the upper 64bit of the physical address
283+
* is non-zero on RV64.
284+
*/
285+
if (shmem_phys_hi)
286+
return SBI_EINVALID_ADDR;
287+
280288
if (dom && !sbi_domain_check_addr(dom,
281289
DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi, shmem_phys_lo), smode,
282290
SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))

0 commit comments

Comments
 (0)