Skip to content

Commit 226038a

Browse files
committed
riscv: pmp: Rename PMP stackguard functions to kernelmode
Rename the `z_riscv_pmp_stackguard_*` functions to `z_riscv_pmp_kernelmode_*`. This change better reflects that these functions are used for general kernel mode PMP configuration, not strictly limited to stack guard purposes. Call sites in fatal.c, isr.S, and switch.S have been updated accordingly. Signed-off-by: Firas Sammoura <[email protected]>
1 parent 540278c commit 226038a

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

arch/riscv/core/fatal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void z_riscv_fault(struct arch_esf *esf)
229229
* Remove the thread's PMP setting to prevent triggering a stack
230230
* overflow error again due to the previous configuration.
231231
*/
232-
z_riscv_pmp_stackguard_disable();
232+
z_riscv_pmp_kernelmode_disable();
233233
#endif /* CONFIG_PMP_STACK_GUARD */
234234
reason = K_ERR_STACK_CHK_FAIL;
235235
}

arch/riscv/core/isr.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ no_fp: /* increment _current->arch.exception_depth */
376376
and t0, t0, t1
377377
bnez t0, 1f
378378
lr a0, ___cpu_t_current_OFFSET(s0)
379-
call z_riscv_pmp_stackguard_enable
379+
call z_riscv_pmp_kernelmode_enable
380380
1:
381381
#endif /* CONFIG_PMP_STACK_GUARD */
382382

@@ -524,7 +524,7 @@ is_user_syscall:
524524
* PMP for kernel mode stack guard.
525525
*/
526526
lr a0, ___cpu_t_current_OFFSET(s0)
527-
call z_riscv_pmp_stackguard_enable
527+
call z_riscv_pmp_kernelmode_enable
528528
#endif
529529

530530
/* It is safe to re-enable IRQs now */
@@ -599,7 +599,7 @@ is_interrupt:
599599
and t0, t0, t1
600600
bnez t0, 1f
601601
lr a0, ___cpu_t_current_OFFSET(s0)
602-
call z_riscv_pmp_stackguard_enable
602+
call z_riscv_pmp_kernelmode_enable
603603
j 2f
604604
#endif /* CONFIG_USERSPACE */
605605
1: /* Re-activate PMP for m-mode */

arch/riscv/core/pmp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void z_riscv_pmp_init(void)
455455
* This early, the kernel init code uses the IRQ stack and we want to
456456
* safeguard it as soon as possible. But we need a temporary default
457457
* "catch all" PMP entry for MPRV to work. Later on, this entry will
458-
* be set for each thread by z_riscv_pmp_stackguard_prepare().
458+
* be set for each thread by z_riscv_pmp_kernelmode_prepare().
459459
*/
460460
set_pmp_mprv_catchall(&index, pmp_addr, pmp_cfg, ARRAY_SIZE(pmp_addr));
461461

@@ -548,7 +548,7 @@ static inline unsigned int z_riscv_pmp_thread_init(unsigned long *pmp_addr,
548548
*
549549
* This is called once during new thread creation.
550550
*/
551-
void z_riscv_pmp_stackguard_prepare(struct k_thread *thread)
551+
void z_riscv_pmp_kernelmode_prepare(struct k_thread *thread)
552552
{
553553
unsigned int index = z_riscv_pmp_thread_init(PMP_M_MODE(thread));
554554
uintptr_t stack_bottom;
@@ -576,7 +576,7 @@ void z_riscv_pmp_stackguard_prepare(struct k_thread *thread)
576576
*
577577
* This is called on every context switch.
578578
*/
579-
void z_riscv_pmp_stackguard_enable(struct k_thread *thread)
579+
void z_riscv_pmp_kernelmode_enable(struct k_thread *thread)
580580
{
581581
LOG_DBG("pmp_stackguard_enable for thread %p", thread);
582582

@@ -605,7 +605,7 @@ void z_riscv_pmp_stackguard_enable(struct k_thread *thread)
605605
/**
606606
* @brief Remove PMP stackguard content to actual PMP registers
607607
*/
608-
void z_riscv_pmp_stackguard_disable(void)
608+
void z_riscv_pmp_kernelmode_disable(void)
609609
{
610610

611611
unsigned long pmp_addr[CONFIG_PMP_SLOTS];

arch/riscv/core/switch.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SECTION_FUNC(TEXT, z_riscv_switch)
6464
#if defined(CONFIG_PMP_STACK_GUARD)
6565
/* Stack guard has priority over user space for PMP usage. */
6666
mv s0, a0
67-
call z_riscv_pmp_stackguard_enable
67+
call z_riscv_pmp_kernelmode_enable
6868
mv a0, s0
6969
#elif defined(CONFIG_USERSPACE)
7070
/*

arch/riscv/core/thread.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
9999

100100
#if defined(CONFIG_PMP_STACK_GUARD)
101101
/* Setup PMP regions of PMP stack guard of thread. */
102-
z_riscv_pmp_stackguard_prepare(thread);
102+
z_riscv_pmp_kernelmode_prepare(thread);
103103
#endif /* CONFIG_PMP_STACK_GUARD */
104104

105105
#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
@@ -178,7 +178,7 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
178178

179179
#ifdef CONFIG_PMP_STACK_GUARD
180180
/* reconfigure as the kernel mode stack will be different */
181-
z_riscv_pmp_stackguard_prepare(_current);
181+
z_riscv_pmp_kernelmode_prepare(_current);
182182
#endif
183183

184184
/* Set up Physical Memory Protection */

arch/riscv/include/pmp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#define PMPCFG_STRIDE (__riscv_xlen / 8)
1111

1212
void z_riscv_pmp_init(void);
13-
void z_riscv_pmp_stackguard_prepare(struct k_thread *thread);
14-
void z_riscv_pmp_stackguard_enable(struct k_thread *thread);
15-
void z_riscv_pmp_stackguard_disable(void);
13+
void z_riscv_pmp_kernelmode_prepare(struct k_thread *thread);
14+
void z_riscv_pmp_kernelmode_enable(struct k_thread *thread);
15+
void z_riscv_pmp_kernelmode_disable(void);
1616
void z_riscv_pmp_usermode_init(struct k_thread *thread);
1717
void z_riscv_pmp_usermode_prepare(struct k_thread *thread);
1818
void z_riscv_pmp_usermode_enable(struct k_thread *thread);

0 commit comments

Comments
 (0)