|
40 | 40 | #define CREATE_TRACE_POINTS
|
41 | 41 | #include <trace/events/nmi.h>
|
42 | 42 |
|
| 43 | +/* |
| 44 | + * An emergency handler can be set in any context including NMI |
| 45 | + */ |
43 | 46 | struct nmi_desc {
|
44 | 47 | raw_spinlock_t lock;
|
| 48 | + nmi_handler_t emerg_handler; |
45 | 49 | struct list_head head;
|
46 | 50 | };
|
47 | 51 |
|
@@ -132,9 +136,22 @@ static void nmi_check_duration(struct nmiaction *action, u64 duration)
|
132 | 136 | static int nmi_handle(unsigned int type, struct pt_regs *regs)
|
133 | 137 | {
|
134 | 138 | struct nmi_desc *desc = nmi_to_desc(type);
|
| 139 | + nmi_handler_t ehandler; |
135 | 140 | struct nmiaction *a;
|
136 | 141 | int handled=0;
|
137 | 142 |
|
| 143 | + /* |
| 144 | + * Call the emergency handler, if set |
| 145 | + * |
| 146 | + * In the case of crash_nmi_callback() emergency handler, it will |
| 147 | + * return in the case of the crashing CPU to enable it to complete |
| 148 | + * other necessary crashing actions ASAP. Other handlers in the |
| 149 | + * linked list won't need to be run. |
| 150 | + */ |
| 151 | + ehandler = desc->emerg_handler; |
| 152 | + if (ehandler) |
| 153 | + return ehandler(type, regs); |
| 154 | + |
138 | 155 | rcu_read_lock();
|
139 | 156 |
|
140 | 157 | /*
|
@@ -224,6 +241,31 @@ void unregister_nmi_handler(unsigned int type, const char *name)
|
224 | 241 | }
|
225 | 242 | EXPORT_SYMBOL_GPL(unregister_nmi_handler);
|
226 | 243 |
|
| 244 | +/** |
| 245 | + * set_emergency_nmi_handler - Set emergency handler |
| 246 | + * @type: NMI type |
| 247 | + * @handler: the emergency handler to be stored |
| 248 | + * |
| 249 | + * Set an emergency NMI handler which, if set, will preempt all the other |
| 250 | + * handlers in the linked list. If a NULL handler is passed in, it will clear |
| 251 | + * it. It is expected that concurrent calls to this function will not happen |
| 252 | + * or the system is screwed beyond repair. |
| 253 | + */ |
| 254 | +void set_emergency_nmi_handler(unsigned int type, nmi_handler_t handler) |
| 255 | +{ |
| 256 | + struct nmi_desc *desc = nmi_to_desc(type); |
| 257 | + |
| 258 | + if (WARN_ON_ONCE(desc->emerg_handler == handler)) |
| 259 | + return; |
| 260 | + desc->emerg_handler = handler; |
| 261 | + |
| 262 | + /* |
| 263 | + * Ensure the emergency handler is visible to other CPUs before |
| 264 | + * function return |
| 265 | + */ |
| 266 | + smp_wmb(); |
| 267 | +} |
| 268 | + |
227 | 269 | static void
|
228 | 270 | pci_serr_error(unsigned char reason, struct pt_regs *regs)
|
229 | 271 | {
|
|
0 commit comments