Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions arch/riscv/core/pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,13 @@ static void write_pmp_entries(unsigned int start, unsigned int end,
ARRAY_SIZE(thread->arch.u_mode_pmpaddr_regs)

/*
* This is used to seed thread PMP copies with global m-mode cfg entries
* sharing the same cfg register. Locked entries aren't modifiable but
* Stores the initial values of the pmpcfg CSRs, covering all global
* m-mode PMP entries. This array is sized to hold all pmpcfg registers
* necessary for CONFIG_PMP_SLOTS. It is used to seed the per-thread
* PMP configuration copies. Locked entries aren't modifiable but
* we could have non-locked entries here too.
*/
static unsigned long global_pmp_cfg[1];
static unsigned long global_pmp_cfg[CONFIG_PMP_SLOTS / PMPCFG_STRIDE];
static unsigned long global_pmp_last_addr;

/* End of global PMP entry range */
Expand Down Expand Up @@ -432,12 +434,12 @@ void z_riscv_pmp_init(void)
/* Make sure secondary CPUs produced the same values */
if (global_pmp_end_index != 0) {
__ASSERT(global_pmp_end_index == index, "");
__ASSERT(global_pmp_cfg[0] == pmp_cfg[0], "");
__ASSERT(memcmp(pmp_cfg, global_pmp_cfg, sizeof(global_pmp_cfg)) == 0, "");
__ASSERT(global_pmp_last_addr == pmp_addr[index - 1], "");
}
#endif

global_pmp_cfg[0] = pmp_cfg[0];
memcpy(global_pmp_cfg, pmp_cfg, sizeof(pmp_cfg));
global_pmp_last_addr = pmp_addr[index - 1];
global_pmp_end_index = index;

Expand All @@ -457,9 +459,9 @@ static inline unsigned int z_riscv_pmp_thread_init(unsigned long *pmp_addr,
ARG_UNUSED(index_limit);

/*
* Retrieve pmpcfg0 partial content from global entries.
* Retrieve the pmpcfg register with partial content from global entries.
*/
pmp_cfg[0] = global_pmp_cfg[0];
memcpy(pmp_cfg, global_pmp_cfg, sizeof(global_pmp_cfg));

/*
* Retrieve the pmpaddr value matching the last global PMP slot.
Expand Down Expand Up @@ -520,7 +522,7 @@ void z_riscv_pmp_stackguard_enable(struct k_thread *thread)

/* Write our m-mode MPP entries */
write_pmp_entries(global_pmp_end_index, thread->arch.m_mode_pmp_end_index,
false /* no need to clear to the end */,
true,
PMP_M_MODE(thread));

if (PMP_DEBUG_DUMP) {
Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/arch/riscv/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct _thread_arch {
#endif
#ifdef CONFIG_PMP_STACK_GUARD
unsigned int m_mode_pmp_end_index;
unsigned long m_mode_pmpaddr_regs[PMP_M_MODE_SLOTS];
unsigned long m_mode_pmpcfg_regs[PMP_M_MODE_SLOTS / sizeof(unsigned long)];
unsigned long m_mode_pmpaddr_regs[CONFIG_PMP_SLOTS];
unsigned long m_mode_pmpcfg_regs[CONFIG_PMP_SLOTS / sizeof(unsigned long)];
#endif
};

Expand Down