Skip to content

Commit

Permalink
arm: use BASEPRI_MAX instead of BASEPRI to mask interrupts
Browse files Browse the repository at this point in the history
When locking interrupt in a critical session, it is
safer to do MSR BASEPRI_MAX instead of BASEPRI. The
rationale is that when writing to BASEPRI_MAX, the
writing is conditional, and is only applied if the
change is to a higher priority level. This commit
replaces BASEPRI with BASEPRI_MAX in operations that
aim to lock some specific interrupts:
- irq_lock()
- masking out PendSV
So, for example, it is not possible to actually
unmask any interrupts by doing an irq_lock operation.
The commit does not introduce behavioral changes.
However, it makes irq_lock() more robust against
future changes to the IRQ locking mechanism.

Signed-off-by: Ioannis Glaropoulos <[email protected]>
  • Loading branch information
ioannisg authored and cfriedt committed Jul 29, 2021
1 parent 7156183 commit 03c4bcd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion arch/arm/core/aarch32/swap_helper.S
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ out_fp_endif:
cpsid i
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
movs.n r0, #_EXC_IRQ_DEFAULT_PRIO
msr BASEPRI, r0
msr BASEPRI_MAX, r0
isb /* Make the effect of disabling interrupts be realized immediately */
#elif defined(CONFIG_ARMV7_R)
/*
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/core/aarch32/userspace.S
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ SECTION_FUNC(TEXT,z_arm_userspace_enter)

/* Lock PendSV while reprogramming PSP and PSPLIM */
mov r0, #_EXC_PENDSV_PRIO_MASK
msr BASEPRI, r0
msr BASEPRI_MAX, r0
isb

/* Set PSPLIM to guard the thread's user stack. */
Expand Down Expand Up @@ -456,7 +456,7 @@ dispatch_syscall:

/* Lock PendSV while reprogramming PSP and PSPLIM */
mov r3, #_EXC_PENDSV_PRIO_MASK
msr BASEPRI, r3
msr BASEPRI_MAX, r3
isb

/* Set PSPLIM to guard the thread's user stack. */
Expand Down
2 changes: 1 addition & 1 deletion include/arch/arm/aarch32/asm_inline_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static ALWAYS_INLINE unsigned int arch_irq_lock(void)
__asm__ volatile(
"mov %1, %2;"
"mrs %0, BASEPRI;"
"msr BASEPRI, %1;"
"msr BASEPRI_MAX, %1;"
"isb;"
: "=r"(key), "=r"(tmp)
: "i"(_EXC_IRQ_DEFAULT_PRIO)
Expand Down

0 comments on commit 03c4bcd

Please sign in to comment.