diff options
| author | Andy Lutomirski <luto@amacapital.net> | 2015-01-31 07:53:53 -0500 |
|---|---|---|
| committer | Andy Lutomirski <luto@amacapital.net> | 2015-02-01 07:02:53 -0500 |
| commit | b926e6f61a26036ee9eabe6761483954d481ad25 (patch) | |
| tree | 0ed87a7d7acc4e8f6e1e443f032b2444fd8eaa1e | |
| parent | 772a9aca12567badb5b9caf2af249a5991f47ea8 (diff) | |
x86, traps: Fix ist_enter from userspace
context_tracking_user_exit() has no effect if in_interrupt() returns true,
so ist_enter() didn't work. Fix it by calling exception_enter(), and thus
context_tracking_user_exit(), before incrementing the preempt count.
This also adds an assertion that will catch the problem reliably if
CONFIG_PROVE_RCU=y to help prevent the bug from being reintroduced.
Link: http://lkml.kernel.org/r/261ebee6aee55a4724746d0d7024697013c40a08.1422709102.git.luto@amacapital.net
Fixes: 959274753857 x86, traps: Track entry into and exit from IST context
Reported-and-tested-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
| -rw-r--r-- | arch/x86/kernel/traps.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 7176f84f95a4..c74f2f5652da 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c | |||
| @@ -110,15 +110,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs) | |||
| 110 | 110 | ||
| 111 | enum ctx_state ist_enter(struct pt_regs *regs) | 111 | enum ctx_state ist_enter(struct pt_regs *regs) |
| 112 | { | 112 | { |
| 113 | /* | 113 | enum ctx_state prev_state; |
| 114 | * We are atomic because we're on the IST stack (or we're on x86_32, | ||
| 115 | * in which case we still shouldn't schedule. | ||
| 116 | */ | ||
| 117 | preempt_count_add(HARDIRQ_OFFSET); | ||
| 118 | 114 | ||
| 119 | if (user_mode_vm(regs)) { | 115 | if (user_mode_vm(regs)) { |
| 120 | /* Other than that, we're just an exception. */ | 116 | /* Other than that, we're just an exception. */ |
| 121 | return exception_enter(); | 117 | prev_state = exception_enter(); |
| 122 | } else { | 118 | } else { |
| 123 | /* | 119 | /* |
| 124 | * We might have interrupted pretty much anything. In | 120 | * We might have interrupted pretty much anything. In |
| @@ -127,12 +123,27 @@ enum ctx_state ist_enter(struct pt_regs *regs) | |||
| 127 | * but we need to notify RCU. | 123 | * but we need to notify RCU. |
| 128 | */ | 124 | */ |
| 129 | rcu_nmi_enter(); | 125 | rcu_nmi_enter(); |
| 130 | return IN_KERNEL; /* the value is irrelevant. */ | 126 | prev_state = IN_KERNEL; /* the value is irrelevant. */ |
| 131 | } | 127 | } |
| 128 | |||
| 129 | /* | ||
| 130 | * We are atomic because we're on the IST stack (or we're on x86_32, | ||
| 131 | * in which case we still shouldn't schedule). | ||
| 132 | * | ||
| 133 | * This must be after exception_enter(), because exception_enter() | ||
| 134 | * won't do anything if in_interrupt() returns true. | ||
| 135 | */ | ||
| 136 | preempt_count_add(HARDIRQ_OFFSET); | ||
| 137 | |||
| 138 | /* This code is a bit fragile. Test it. */ | ||
| 139 | rcu_lockdep_assert(rcu_is_watching(), "ist_enter didn't work"); | ||
| 140 | |||
| 141 | return prev_state; | ||
| 132 | } | 142 | } |
| 133 | 143 | ||
| 134 | void ist_exit(struct pt_regs *regs, enum ctx_state prev_state) | 144 | void ist_exit(struct pt_regs *regs, enum ctx_state prev_state) |
| 135 | { | 145 | { |
| 146 | /* Must be before exception_exit. */ | ||
| 136 | preempt_count_sub(HARDIRQ_OFFSET); | 147 | preempt_count_sub(HARDIRQ_OFFSET); |
| 137 | 148 | ||
| 138 | if (user_mode_vm(regs)) | 149 | if (user_mode_vm(regs)) |
