History

arm64: entry.S: Do not preempt from IRQ before all cpufeatures are enabled

Preempting from IRQ-return means that the task has its PSTATE saved on the stack, which will get restored when the task is resumed and does the actual IRQ return. However, enabling some CPU features requires modifying the PSTATE. This means that, if a task was scheduled out during an IRQ-return before all CPU features are enabled, the task might restore a PSTATE that does not include the feature enablement changes once scheduled back in. * Task 1: PAN == 0 ---| |--------------- | |<- return from IRQ, PSTATE.PAN = 0 | <- IRQ | +--------+ <- preempt() +-- ^ | reschedule Task 1, PSTATE.PAN == 1 * Init: --------------------+------------------------ ^ | enable_cpu_features set PSTATE.PAN on all CPUs Worse than this, since PSTATE is untouched when task switching is done, a task missing the new bits in PSTATE might affect another task, if both do direct calls to schedule() (outside of IRQ/exception contexts). Fix this by preventing preemption on IRQ-return until features are enabled on all CPUs. This way the only PSTATE values that are saved on the stack are from synchronous exceptions. These are expected to be fatal this early, the exception is BRK for WARN_ON(), but as this uses do_debug_exception() which keeps IRQs masked, it shouldn't call schedule().

Julien Thierry committed 7 years ago

Commit 19c95f21 parent 8c551f93 files · +20 −1Browse files

Showing the changes to include (1 of 3 files). Show all

Unified · Split

include/linux/sched.h+1−0
@@ -223,6 +223,7 @@ extern long schedule_timeout_uninterruptible(long timeout); · 222 unmodified lines
223extern long schedule_timeout_idle(long timeout);223extern long schedule_timeout_idle(long timeout);
224asmlinkage void schedule(void);224asmlinkage void schedule(void);
225extern void schedule_preempt_disabled(void);225extern void schedule_preempt_disabled(void);
226asmlinkage void preempt_schedule_irq(void);
226 227
227extern int __must_check io_schedule_prepare(void);228extern int __must_check io_schedule_prepare(void);
228extern void io_schedule_finish(int token);229extern void io_schedule_finish(int token);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t