1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * APEI Generic Hardware Error Source support
4 *
5 * Generic Hardware Error Source provides a way to report platform
6 * hardware errors (such as that from chipset). It works in so called
7 * "Firmware First" mode, that is, hardware errors are reported to
8 * firmware firstly, then reported to Linux by firmware. This way,
9 * some non-standard hardware error registers or non-standard hardware
10 * link can be checked by firmware to produce more hardware error
11 * information for Linux.
12 *
13 * For more information about Generic Hardware Error Source, please
14 * refer to ACPI Specification version 4.0, section 17.3.2.6
15 *
16 * Copyright 2010,2011 Intel Corp.
17 * Author: Huang Ying <ying.huang@intel.com>
18 */
19
20 #include <linux/arm_sdei.h>
21 #include <linux/kernel.h>
22 #include <linux/moduleparam.h>
23 #include <linux/init.h>
24 #include <linux/acpi.h>
25 #include <linux/io.h>
26 #include <linux/interrupt.h>
27 #include <linux/timer.h>
28 #include <linux/cper.h>
29 #include <linux/cleanup.h>
30 #include <linux/platform_device.h>
31 #include <linux/mutex.h>
32 #include <linux/ratelimit.h>
33 #include <linux/vmalloc.h>
34 #include <linux/irq_work.h>
35 #include <linux/llist.h>
36 #include <linux/genalloc.h>
37 #include <linux/kfifo.h>
38 #include <linux/pci.h>
39 #include <linux/pfn.h>
40 #include <linux/aer.h>
41 #include <linux/nmi.h>
42 #include <linux/sched/clock.h>
43 #include <linux/uuid.h>
44 #include <linux/ras.h>
45 #include <linux/task_work.h>
46
47 #include <acpi/actbl1.h>
48 #include <acpi/ghes.h>
49 #include <acpi/apei.h>
50 #include <asm/fixmap.h>
51 #include <asm/tlbflush.h>
52 #include <cxl/event.h>
53 #include <ras/ras_event.h>
54
55 #include "apei-internal.h"
56
57 #define GHES_PFX "GHES: "
58
59 #define GHES_ESTATUS_MAX_SIZE 65536
60 #define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536
61
62 #define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3
63
64 /* This is just an estimation for memory pool allocation */
65 #define GHES_ESTATUS_CACHE_AVG_SIZE 512
66
67 #define GHES_ESTATUS_CACHES_SIZE 4
68
69 #define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL
70 /* Prevent too many caches are allocated because of RCU */
71 #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2)
72
73 #define GHES_ESTATUS_CACHE_LEN(estatus_len) \
74 (sizeof(struct ghes_estatus_cache) + (estatus_len))
75 #define GHES_ESTATUS_FROM_CACHE(estatus_cache) \
76 ((struct acpi_hest_generic_status *) \
77 ((struct ghes_estatus_cache *)(estatus_cache) + 1))
78
79 #define GHES_ESTATUS_NODE_LEN(estatus_len) \
80 (sizeof(struct ghes_estatus_node) + (estatus_len))
81 #define GHES_ESTATUS_FROM_NODE(estatus_node) \
82 ((struct acpi_hest_generic_status *) \
83 ((struct ghes_estatus_node *)(estatus_node) + 1))
84
85 #define GHES_VENDOR_ENTRY_LEN(gdata_len) \
86 (sizeof(struct ghes_vendor_record_entry) + (gdata_len))
87 #define GHES_GDATA_FROM_VENDOR_ENTRY(vendor_entry) \
88 ((struct acpi_hest_generic_data *) \
89 ((struct ghes_vendor_record_entry *)(vendor_entry) + 1))
90
91 /*
92 * NMI-like notifications vary by architecture, before the compiler can prune
93 * unused static functions it needs a value for these enums.
94 */
95 #ifndef CONFIG_ARM_SDE_INTERFACE
96 #define FIX_APEI_GHES_SDEI_NORMAL __end_of_fixed_addresses
97 #define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses
98 #endif
99
100 static ATOMIC_NOTIFIER_HEAD(ghes_report_chain);
101
is_hest_type_generic_v2(struct ghes * ghes)102 static inline bool is_hest_type_generic_v2(struct ghes *ghes)
103 {
104 return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2;
105 }
106
107 /*
108 * A platform may describe one error source for the handling of synchronous
109 * errors (e.g. MCE or SEA), or for handling asynchronous errors (e.g. SCI
110 * or External Interrupt). On x86, the HEST notifications are always
111 * asynchronous, so only SEA on ARM is delivered as a synchronous
112 * notification.
113 */
is_hest_sync_notify(struct ghes * ghes)114 static inline bool is_hest_sync_notify(struct ghes *ghes)
115 {
116 u8 notify_type = ghes->generic->notify.type;
117
118 return notify_type == ACPI_HEST_NOTIFY_SEA;
119 }
120
121 /*
122 * This driver isn't really modular, however for the time being,
123 * continuing to use module_param is the easiest way to remain
124 * compatible with existing boot arg use cases.
125 */
126 bool ghes_disable;
127 module_param_named(disable, ghes_disable, bool, 0);
128
129 /*
130 * "ghes.edac_force_enable" forcibly enables ghes_edac and skips the platform
131 * check.
132 */
133 static bool ghes_edac_force_enable;
134 module_param_named(edac_force_enable, ghes_edac_force_enable, bool, 0);
135
136 /*
137 * All error sources notified with HED (Hardware Error Device) share a
138 * single notifier callback, so they need to be linked and checked one
139 * by one. This holds true for NMI too.
140 *
141 * RCU is used for these lists, so ghes_list_mutex is only used for
142 * list changing, not for traversing.
143 */
144 static LIST_HEAD(ghes_hed);
145 static DEFINE_MUTEX(ghes_list_mutex);
146
147 /*
148 * A list of GHES devices which are given to the corresponding EDAC driver
149 * ghes_edac for further use.
150 */
151 static LIST_HEAD(ghes_devs);
152 static DEFINE_MUTEX(ghes_devs_mutex);
153
154 /*
155 * Because the memory area used to transfer hardware error information
156 * from BIOS to Linux can be determined only in NMI, IRQ or timer
157 * handler, but general ioremap can not be used in atomic context, so
158 * the fixmap is used instead.
159 *
160 * This spinlock is used to prevent the fixmap entry from being used
161 * simultaneously.
162 */
163 static DEFINE_SPINLOCK(ghes_notify_lock_irq);
164
165 struct ghes_vendor_record_entry {
166 struct work_struct work;
167 int error_severity;
168 char vendor_record[];
169 };
170
171 static struct gen_pool *ghes_estatus_pool;
172
173 static struct ghes_estatus_cache __rcu *ghes_estatus_caches[GHES_ESTATUS_CACHES_SIZE];
174 static atomic_t ghes_estatus_cache_alloced;
175
ghes_map(u64 pfn,enum fixed_addresses fixmap_idx)176 static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx)
177 {
178 phys_addr_t paddr;
179 pgprot_t prot;
180
181 paddr = PFN_PHYS(pfn);
182 prot = arch_apei_get_mem_attribute(paddr);
183 __set_fixmap(fixmap_idx, paddr, prot);
184
185 return (void __iomem *) __fix_to_virt(fixmap_idx);
186 }
187
ghes_unmap(void __iomem * vaddr,enum fixed_addresses fixmap_idx)188 static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
189 {
190 int _idx = virt_to_fix((unsigned long)vaddr);
191
192 WARN_ON_ONCE(fixmap_idx != _idx);
193 clear_fixmap(fixmap_idx);
194 }
195
ghes_estatus_pool_init(unsigned int num_ghes)196 int ghes_estatus_pool_init(unsigned int num_ghes)
197 {
198 unsigned long addr, len;
199 int rc;
200
201 ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
202 if (!ghes_estatus_pool)
203 return -ENOMEM;
204
205 len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX;
206 len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE);
207
208 addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
209 if (!addr)
210 goto err_pool_alloc;
211
212 rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
213 if (rc)
214 goto err_pool_add;
215
216 return 0;
217
218 err_pool_add:
219 vfree((void *)addr);
220
221 err_pool_alloc:
222 gen_pool_destroy(ghes_estatus_pool);
223
224 return -ENOMEM;
225 }
226
227 /**
228 * ghes_estatus_pool_region_free - free previously allocated memory
229 * from the ghes_estatus_pool.
230 * @addr: address of memory to free.
231 * @size: size of memory to free.
232 *
233 * Returns none.
234 */
ghes_estatus_pool_region_free(unsigned long addr,u32 size)235 void ghes_estatus_pool_region_free(unsigned long addr, u32 size)
236 {
237 gen_pool_free(ghes_estatus_pool, addr, size);
238 }
239 EXPORT_SYMBOL_GPL(ghes_estatus_pool_region_free);
240
map_gen_v2(struct ghes * ghes)241 static int map_gen_v2(struct ghes *ghes)
242 {
243 return apei_map_generic_address(&ghes->generic_v2->read_ack_register);
244 }
245
unmap_gen_v2(struct ghes * ghes)246 static void unmap_gen_v2(struct ghes *ghes)
247 {
248 apei_unmap_generic_address(&ghes->generic_v2->read_ack_register);
249 }
250
ghes_ack_error(struct acpi_hest_generic_v2 * gv2)251 static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2)
252 {
253 int rc;
254 u64 val = 0;
255
256 rc = apei_read(&val, &gv2->read_ack_register);
257 if (rc)
258 return;
259
260 val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset;
261 val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset;
262
263 apei_write(val, &gv2->read_ack_register);
264 }
265
ghes_new(struct acpi_hest_generic * generic)266 static struct ghes *ghes_new(struct acpi_hest_generic *generic)
267 {
268 struct ghes *ghes;
269 unsigned int error_block_length;
270 int rc;
271
272 ghes = kzalloc(sizeof(*ghes), GFP_KERNEL);
273 if (!ghes)
274 return ERR_PTR(-ENOMEM);
275
276 ghes->generic = generic;
277 if (is_hest_type_generic_v2(ghes)) {
278 rc = map_gen_v2(ghes);
279 if (rc)
280 goto err_free;
281 }
282
283 rc = apei_map_generic_address(&generic->error_status_address);
284 if (rc)
285 goto err_unmap_read_ack_addr;
286 error_block_length = generic->error_block_length;
287 if (error_block_length > GHES_ESTATUS_MAX_SIZE) {
288 pr_warn(FW_WARN GHES_PFX
289 "Error status block length is too long: %u for "
290 "generic hardware error source: %d.\n",
291 error_block_length, generic->header.source_id);
292 error_block_length = GHES_ESTATUS_MAX_SIZE;
293 }
294 ghes->estatus = kmalloc(error_block_length, GFP_KERNEL);
295 if (!ghes->estatus) {
296 rc = -ENOMEM;
297 goto err_unmap_status_addr;
298 }
299
300 return ghes;
301
302 err_unmap_status_addr:
303 apei_unmap_generic_address(&generic->error_status_address);
304 err_unmap_read_ack_addr:
305 if (is_hest_type_generic_v2(ghes))
306 unmap_gen_v2(ghes);
307 err_free:
308 kfree(ghes);
309 return ERR_PTR(rc);
310 }
311
ghes_fini(struct ghes * ghes)312 static void ghes_fini(struct ghes *ghes)
313 {
314 kfree(ghes->estatus);
315 apei_unmap_generic_address(&ghes->generic->error_status_address);
316 if (is_hest_type_generic_v2(ghes))
317 unmap_gen_v2(ghes);
318 }
319
ghes_severity(int severity)320 static inline int ghes_severity(int severity)
321 {
322 switch (severity) {
323 case CPER_SEV_INFORMATIONAL:
324 return GHES_SEV_NO;
325 case CPER_SEV_CORRECTED:
326 return GHES_SEV_CORRECTED;
327 case CPER_SEV_RECOVERABLE:
328 return GHES_SEV_RECOVERABLE;
329 case CPER_SEV_FATAL:
330 return GHES_SEV_PANIC;
331 default:
332 /* Unknown, go panic */
333 return GHES_SEV_PANIC;
334 }
335 }
336
ghes_copy_tofrom_phys(void * buffer,u64 paddr,u32 len,int from_phys,enum fixed_addresses fixmap_idx)337 static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len,
338 int from_phys,
339 enum fixed_addresses fixmap_idx)
340 {
341 void __iomem *vaddr;
342 u64 offset;
343 u32 trunk;
344
345 while (len > 0) {
346 offset = paddr - (paddr & PAGE_MASK);
347 vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx);
348 trunk = PAGE_SIZE - offset;
349 trunk = min(trunk, len);
350 if (from_phys)
351 memcpy_fromio(buffer, vaddr + offset, trunk);
352 else
353 memcpy_toio(vaddr + offset, buffer, trunk);
354 len -= trunk;
355 paddr += trunk;
356 buffer += trunk;
357 ghes_unmap(vaddr, fixmap_idx);
358 }
359 }
360
361 /* Check the top-level record header has an appropriate size. */
__ghes_check_estatus(struct ghes * ghes,struct acpi_hest_generic_status * estatus)362 static int __ghes_check_estatus(struct ghes *ghes,
363 struct acpi_hest_generic_status *estatus)
364 {
365 u32 len = cper_estatus_len(estatus);
366
367 if (len < sizeof(*estatus)) {
368 pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status block!\n");
369 return -EIO;
370 }
371
372 if (len > ghes->generic->error_block_length) {
373 pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status block length!\n");
374 return -EIO;
375 }
376
377 if (cper_estatus_check_header(estatus)) {
378 pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid CPER header!\n");
379 return -EIO;
380 }
381
382 return 0;
383 }
384
385 /* Read the CPER block, returning its address, and header in estatus. */
__ghes_peek_estatus(struct ghes * ghes,struct acpi_hest_generic_status * estatus,u64 * buf_paddr,enum fixed_addresses fixmap_idx)386 static int __ghes_peek_estatus(struct ghes *ghes,
387 struct acpi_hest_generic_status *estatus,
388 u64 *buf_paddr, enum fixed_addresses fixmap_idx)
389 {
390 struct acpi_hest_generic *g = ghes->generic;
391 int rc;
392
393 rc = apei_read(buf_paddr, &g->error_status_address);
394 if (rc) {
395 *buf_paddr = 0;
396 pr_warn_ratelimited(FW_WARN GHES_PFX
397 "Failed to read error status block address for hardware error source: %d.\n",
398 g->header.source_id);
399 return -EIO;
400 }
401 if (!*buf_paddr)
402 return -ENOENT;
403
404 ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1,
405 fixmap_idx);
406 if (!estatus->block_status) {
407 *buf_paddr = 0;
408 return -ENOENT;
409 }
410
411 return 0;
412 }
413
__ghes_read_estatus(struct acpi_hest_generic_status * estatus,u64 buf_paddr,enum fixed_addresses fixmap_idx,size_t buf_len)414 static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus,
415 u64 buf_paddr, enum fixed_addresses fixmap_idx,
416 size_t buf_len)
417 {
418 ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx);
419 if (cper_estatus_check(estatus)) {
420 pr_warn_ratelimited(FW_WARN GHES_PFX
421 "Failed to read error status block!\n");
422 return -EIO;
423 }
424
425 return 0;
426 }
427
ghes_read_estatus(struct ghes * ghes,struct acpi_hest_generic_status * estatus,u64 * buf_paddr,enum fixed_addresses fixmap_idx)428 static int ghes_read_estatus(struct ghes *ghes,
429 struct acpi_hest_generic_status *estatus,
430 u64 *buf_paddr, enum fixed_addresses fixmap_idx)
431 {
432 int rc;
433
434 rc = __ghes_peek_estatus(ghes, estatus, buf_paddr, fixmap_idx);
435 if (rc)
436 return rc;
437
438 rc = __ghes_check_estatus(ghes, estatus);
439 if (rc)
440 return rc;
441
442 return __ghes_read_estatus(estatus, *buf_paddr, fixmap_idx,
443 cper_estatus_len(estatus));
444 }
445
ghes_clear_estatus(struct ghes * ghes,struct acpi_hest_generic_status * estatus,u64 buf_paddr,enum fixed_addresses fixmap_idx)446 static void ghes_clear_estatus(struct ghes *ghes,
447 struct acpi_hest_generic_status *estatus,
448 u64 buf_paddr, enum fixed_addresses fixmap_idx)
449 {
450 estatus->block_status = 0;
451
452 if (!buf_paddr)
453 return;
454
455 ghes_copy_tofrom_phys(estatus, buf_paddr,
456 sizeof(estatus->block_status), 0,
457 fixmap_idx);
458
459 /*
460 * GHESv2 type HEST entries introduce support for error acknowledgment,
461 * so only acknowledge the error if this support is present.
462 */
463 if (is_hest_type_generic_v2(ghes))
464 ghes_ack_error(ghes->generic_v2);
465 }
466
467 /**
468 * struct ghes_task_work - for synchronous RAS event
469 *
470 * @twork: callback_head for task work
471 * @pfn: page frame number of corrupted page
472 * @flags: work control flags
473 *
474 * Structure to pass task work to be handled before
475 * returning to user-space via task_work_add().
476 */
477 struct ghes_task_work {
478 struct callback_head twork;
479 u64 pfn;
480 int flags;
481 };
482
memory_failure_cb(struct callback_head * twork)483 static void memory_failure_cb(struct callback_head *twork)
484 {
485 struct ghes_task_work *twcb = container_of(twork, struct ghes_task_work, twork);
486 int ret;
487
488 ret = memory_failure(twcb->pfn, twcb->flags);
489 gen_pool_free(ghes_estatus_pool, (unsigned long)twcb, sizeof(*twcb));
490
491 if (!ret || ret == -EHWPOISON || ret == -EOPNOTSUPP)
492 return;
493
494 pr_err("%#llx: Sending SIGBUS to %s:%d due to hardware memory corruption\n",
495 twcb->pfn, current->comm, task_pid_nr(current));
496 force_sig(SIGBUS);
497 }
498
ghes_do_memory_failure(u64 physical_addr,int flags)499 static bool ghes_do_memory_failure(u64 physical_addr, int flags)
500 {
501 struct ghes_task_work *twcb;
502 unsigned long pfn;
503
504 if (!IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE))
505 return false;
506
507 pfn = PHYS_PFN(physical_addr);
508 if (!pfn_valid(pfn) && !arch_is_platform_page(physical_addr)) {
509 pr_warn_ratelimited(FW_WARN GHES_PFX
510 "Invalid address in generic error data: %#llx\n",
511 physical_addr);
512 return false;
513 }
514
515 if (flags == MF_ACTION_REQUIRED && current->mm) {
516 twcb = (void *)gen_pool_alloc(ghes_estatus_pool, sizeof(*twcb));
517 if (!twcb)
518 return false;
519
520 twcb->pfn = pfn;
521 twcb->flags = flags;
522 init_task_work(&twcb->twork, memory_failure_cb);
523 task_work_add(current, &twcb->twork, TWA_RESUME);
524 return true;
525 }
526
527 memory_failure_queue(pfn, flags);
528 return true;
529 }
530
ghes_handle_memory_failure(struct acpi_hest_generic_data * gdata,int sev,bool sync)531 static bool ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata,
532 int sev, bool sync)
533 {
534 int flags = -1;
535 int sec_sev = ghes_severity(gdata->error_severity);
536 struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
537
538 if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
539 return false;
540
541 /* iff following two events can be handled properly by now */
542 if (sec_sev == GHES_SEV_CORRECTED &&
543 (gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED))
544 flags = MF_SOFT_OFFLINE;
545 if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE)
546 flags = sync ? MF_ACTION_REQUIRED : 0;
547
548 if (flags != -1)
549 return ghes_do_memory_failure(mem_err->physical_addr, flags);
550
551 return false;
552 }
553
ghes_handle_arm_hw_error(struct acpi_hest_generic_data * gdata,int sev,bool sync)554 static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,
555 int sev, bool sync)
556 {
557 struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata);
558 int flags = sync ? MF_ACTION_REQUIRED : 0;
559 bool queued = false;
560 int sec_sev, i;
561 char *p;
562
563 log_arm_hw_error(err);
564
565 sec_sev = ghes_severity(gdata->error_severity);
566 if (sev != GHES_SEV_RECOVERABLE || sec_sev != GHES_SEV_RECOVERABLE)
567 return false;
568
569 p = (char *)(err + 1);
570 for (i = 0; i < err->err_info_num; i++) {
571 struct cper_arm_err_info *err_info = (struct cper_arm_err_info *)p;
572 bool is_cache = (err_info->type == CPER_ARM_CACHE_ERROR);
573 bool has_pa = (err_info->validation_bits & CPER_ARM_INFO_VALID_PHYSICAL_ADDR);
574 const char *error_type = "unknown error";
575
576 /*
577 * The field (err_info->error_info & BIT(26)) is fixed to set to
578 * 1 in some old firmware of HiSilicon Kunpeng920. We assume that
579 * firmware won't mix corrected errors in an uncorrected section,
580 * and don't filter out 'corrected' error here.
581 */
582 if (is_cache && has_pa) {
583 queued = ghes_do_memory_failure(err_info->physical_fault_addr, flags);
584 p += err_info->length;
585 continue;
586 }
587
588 if (err_info->type < ARRAY_SIZE(cper_proc_error_type_strs))
589 error_type = cper_proc_error_type_strs[err_info->type];
590
591 pr_warn_ratelimited(FW_WARN GHES_PFX
592 "Unhandled processor error type: %s\n",
593 error_type);
594 p += err_info->length;
595 }
596
597 return queued;
598 }
599
600 /*
601 * PCIe AER errors need to be sent to the AER driver for reporting and
602 * recovery. The GHES severities map to the following AER severities and
603 * require the following handling:
604 *
605 * GHES_SEV_CORRECTABLE -> AER_CORRECTABLE
606 * These need to be reported by the AER driver but no recovery is
607 * necessary.
608 * GHES_SEV_RECOVERABLE -> AER_NONFATAL
609 * GHES_SEV_RECOVERABLE && CPER_SEC_RESET -> AER_FATAL
610 * These both need to be reported and recovered from by the AER driver.
611 * GHES_SEV_PANIC does not make it to this handling since the kernel must
612 * panic.
613 */
ghes_handle_aer(struct acpi_hest_generic_data * gdata)614 static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
615 {
616 #ifdef CONFIG_ACPI_APEI_PCIEAER
617 struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata);
618
619 if (pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID &&
620 pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) {
621 unsigned int devfn;
622 int aer_severity;
623 u8 *aer_info;
624
625 devfn = PCI_DEVFN(pcie_err->device_id.device,
626 pcie_err->device_id.function);
627 aer_severity = cper_severity_to_aer(gdata->error_severity);
628
629 /*
630 * If firmware reset the component to contain
631 * the error, we must reinitialize it before
632 * use, so treat it as a fatal AER error.
633 */
634 if (gdata->flags & CPER_SEC_RESET)
635 aer_severity = AER_FATAL;
636
637 aer_info = (void *)gen_pool_alloc(ghes_estatus_pool,
638 sizeof(struct aer_capability_regs));
639 if (!aer_info)
640 return;
641 memcpy(aer_info, pcie_err->aer_info, sizeof(struct aer_capability_regs));
642
643 aer_recover_queue(pcie_err->device_id.segment,
644 pcie_err->device_id.bus,
645 devfn, aer_severity,
646 (struct aer_capability_regs *)
647 aer_info);
648 }
649 #endif
650 }
651
652 static BLOCKING_NOTIFIER_HEAD(vendor_record_notify_list);
653
ghes_register_vendor_record_notifier(struct notifier_block * nb)654 int ghes_register_vendor_record_notifier(struct notifier_block *nb)
655 {
656 return blocking_notifier_chain_register(&vendor_record_notify_list, nb);
657 }
658 EXPORT_SYMBOL_GPL(ghes_register_vendor_record_notifier);
659
ghes_unregister_vendor_record_notifier(struct notifier_block * nb)660 void ghes_unregister_vendor_record_notifier(struct notifier_block *nb)
661 {
662 blocking_notifier_chain_unregister(&vendor_record_notify_list, nb);
663 }
664 EXPORT_SYMBOL_GPL(ghes_unregister_vendor_record_notifier);
665
ghes_vendor_record_work_func(struct work_struct * work)666 static void ghes_vendor_record_work_func(struct work_struct *work)
667 {
668 struct ghes_vendor_record_entry *entry;
669 struct acpi_hest_generic_data *gdata;
670 u32 len;
671
672 entry = container_of(work, struct ghes_vendor_record_entry, work);
673 gdata = GHES_GDATA_FROM_VENDOR_ENTRY(entry);
674
675 blocking_notifier_call_chain(&vendor_record_notify_list,
676 entry->error_severity, gdata);
677
678 len = GHES_VENDOR_ENTRY_LEN(acpi_hest_get_record_size(gdata));
679 gen_pool_free(ghes_estatus_pool, (unsigned long)entry, len);
680 }
681
ghes_defer_non_standard_event(struct acpi_hest_generic_data * gdata,int sev)682 static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata,
683 int sev)
684 {
685 struct acpi_hest_generic_data *copied_gdata;
686 struct ghes_vendor_record_entry *entry;
687 u32 len;
688
689 len = GHES_VENDOR_ENTRY_LEN(acpi_hest_get_record_size(gdata));
690 entry = (void *)gen_pool_alloc(ghes_estatus_pool, len);
691 if (!entry)
692 return;
693
694 copied_gdata = GHES_GDATA_FROM_VENDOR_ENTRY(entry);
695 memcpy(copied_gdata, gdata, acpi_hest_get_record_size(gdata));
696 entry->error_severity = sev;
697
698 INIT_WORK(&entry->work, ghes_vendor_record_work_func);
699 schedule_work(&entry->work);
700 }
701
702 /* Room for 8 entries */
703 #define CXL_CPER_PROT_ERR_FIFO_DEPTH 8
704 static DEFINE_KFIFO(cxl_cper_prot_err_fifo, struct cxl_cper_prot_err_work_data,
705 CXL_CPER_PROT_ERR_FIFO_DEPTH);
706
707 /* Synchronize schedule_work() with cxl_cper_prot_err_work changes */
708 static DEFINE_SPINLOCK(cxl_cper_prot_err_work_lock);
709 struct work_struct *cxl_cper_prot_err_work;
710
cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err * prot_err,int severity)711 static void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err,
712 int severity)
713 {
714 #ifdef CONFIG_ACPI_APEI_PCIEAER
715 struct cxl_cper_prot_err_work_data wd;
716 u8 *dvsec_start, *cap_start;
717
718 if (!(prot_err->valid_bits & PROT_ERR_VALID_AGENT_ADDRESS)) {
719 pr_err_ratelimited("CXL CPER invalid agent type\n");
720 return;
721 }
722
723 if (!(prot_err->valid_bits & PROT_ERR_VALID_ERROR_LOG)) {
724 pr_err_ratelimited("CXL CPER invalid protocol error log\n");
725 return;
726 }
727
728 if (prot_err->err_len != sizeof(struct cxl_ras_capability_regs)) {
729 pr_err_ratelimited("CXL CPER invalid RAS Cap size (%u)\n",
730 prot_err->err_len);
731 return;
732 }
733
734 if (!(prot_err->valid_bits & PROT_ERR_VALID_SERIAL_NUMBER))
735 pr_warn(FW_WARN "CXL CPER no device serial number\n");
736
737 guard(spinlock_irqsave)(&cxl_cper_prot_err_work_lock);
738
739 if (!cxl_cper_prot_err_work)
740 return;
741
742 switch (prot_err->agent_type) {
743 case RCD:
744 case DEVICE:
745 case LD:
746 case FMLD:
747 case RP:
748 case DSP:
749 case USP:
750 memcpy(&wd.prot_err, prot_err, sizeof(wd.prot_err));
751
752 dvsec_start = (u8 *)(prot_err + 1);
753 cap_start = dvsec_start + prot_err->dvsec_len;
754
755 memcpy(&wd.ras_cap, cap_start, sizeof(wd.ras_cap));
756 wd.severity = cper_severity_to_aer(severity);
757 break;
758 default:
759 pr_err_ratelimited("CXL CPER invalid agent type: %d\n",
760 prot_err->agent_type);
761 return;
762 }
763
764 if (!kfifo_put(&cxl_cper_prot_err_fifo, wd)) {
765 pr_err_ratelimited("CXL CPER kfifo overflow\n");
766 return;
767 }
768
769 schedule_work(cxl_cper_prot_err_work);
770 #endif
771 }
772
cxl_cper_register_prot_err_work(struct work_struct * work)773 int cxl_cper_register_prot_err_work(struct work_struct *work)
774 {
775 if (cxl_cper_prot_err_work)
776 return -EINVAL;
777
778 guard(spinlock)(&cxl_cper_prot_err_work_lock);
779 cxl_cper_prot_err_work = work;
780 return 0;
781 }
782 EXPORT_SYMBOL_NS_GPL(cxl_cper_register_prot_err_work, "CXL");
783
cxl_cper_unregister_prot_err_work(struct work_struct * work)784 int cxl_cper_unregister_prot_err_work(struct work_struct *work)
785 {
786 if (cxl_cper_prot_err_work != work)
787 return -EINVAL;
788
789 guard(spinlock)(&cxl_cper_prot_err_work_lock);
790 cxl_cper_prot_err_work = NULL;
791 return 0;
792 }
793 EXPORT_SYMBOL_NS_GPL(cxl_cper_unregister_prot_err_work, "CXL");
794
cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data * wd)795 int cxl_cper_prot_err_kfifo_get(struct cxl_cper_prot_err_work_data *wd)
796 {
797 return kfifo_get(&cxl_cper_prot_err_fifo, wd);
798 }
799 EXPORT_SYMBOL_NS_GPL(cxl_cper_prot_err_kfifo_get, "CXL");
800
801 /* Room for 8 entries for each of the 4 event log queues */
802 #define CXL_CPER_FIFO_DEPTH 32
803 DEFINE_KFIFO(cxl_cper_fifo, struct cxl_cper_work_data, CXL_CPER_FIFO_DEPTH);
804
805 /* Synchronize schedule_work() with cxl_cper_work changes */
806 static DEFINE_SPINLOCK(cxl_cper_work_lock);
807 struct work_struct *cxl_cper_work;
808
cxl_cper_post_event(enum cxl_event_type event_type,struct cxl_cper_event_rec * rec)809 static void cxl_cper_post_event(enum cxl_event_type event_type,
810 struct cxl_cper_event_rec *rec)
811 {
812 struct cxl_cper_work_data wd;
813
814 if (rec->hdr.length <= sizeof(rec->hdr) ||
815 rec->hdr.length > sizeof(*rec)) {
816 pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n",
817 rec->hdr.length);
818 return;
819 }
820
821 if (!(rec->hdr.validation_bits & CPER_CXL_COMP_EVENT_LOG_VALID)) {
822 pr_err(FW_WARN "CXL CPER invalid event\n");
823 return;
824 }
825
826 guard(spinlock_irqsave)(&cxl_cper_work_lock);
827
828 if (!cxl_cper_work)
829 return;
830
831 wd.event_type = event_type;
832 memcpy(&wd.rec, rec, sizeof(wd.rec));
833
834 if (!kfifo_put(&cxl_cper_fifo, wd)) {
835 pr_err_ratelimited("CXL CPER kfifo overflow\n");
836 return;
837 }
838
839 schedule_work(cxl_cper_work);
840 }
841
cxl_cper_register_work(struct work_struct * work)842 int cxl_cper_register_work(struct work_struct *work)
843 {
844 if (cxl_cper_work)
845 return -EINVAL;
846
847 guard(spinlock)(&cxl_cper_work_lock);
848 cxl_cper_work = work;
849 return 0;
850 }
851 EXPORT_SYMBOL_NS_GPL(cxl_cper_register_work, "CXL");
852
cxl_cper_unregister_work(struct work_struct * work)853 int cxl_cper_unregister_work(struct work_struct *work)
854 {
855 if (cxl_cper_work != work)
856 return -EINVAL;
857
858 guard(spinlock)(&cxl_cper_work_lock);
859 cxl_cper_work = NULL;
860 return 0;
861 }
862 EXPORT_SYMBOL_NS_GPL(cxl_cper_unregister_work, "CXL");
863
cxl_cper_kfifo_get(struct cxl_cper_work_data * wd)864 int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd)
865 {
866 return kfifo_get(&cxl_cper_fifo, wd);
867 }
868 EXPORT_SYMBOL_NS_GPL(cxl_cper_kfifo_get, "CXL");
869
ghes_do_proc(struct ghes * ghes,const struct acpi_hest_generic_status * estatus)870 static void ghes_do_proc(struct ghes *ghes,
871 const struct acpi_hest_generic_status *estatus)
872 {
873 int sev, sec_sev;
874 struct acpi_hest_generic_data *gdata;
875 guid_t *sec_type;
876 const guid_t *fru_id = &guid_null;
877 char *fru_text = "";
878 bool queued = false;
879 bool sync = is_hest_sync_notify(ghes);
880
881 sev = ghes_severity(estatus->error_severity);
882 apei_estatus_for_each_section(estatus, gdata) {
883 sec_type = (guid_t *)gdata->section_type;
884 sec_sev = ghes_severity(gdata->error_severity);
885 if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
886 fru_id = (guid_t *)gdata->fru_id;
887
888 if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
889 fru_text = gdata->fru_text;
890
891 if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
892 struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
893
894 atomic_notifier_call_chain(&ghes_report_chain, sev, mem_err);
895
896 arch_apei_report_mem_error(sev, mem_err);
897 queued = ghes_handle_memory_failure(gdata, sev, sync);
898 }
899 else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
900 ghes_handle_aer(gdata);
901 }
902 else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
903 queued = ghes_handle_arm_hw_error(gdata, sev, sync);
904 } else if (guid_equal(sec_type, &CPER_SEC_CXL_PROT_ERR)) {
905 struct cxl_cper_sec_prot_err *prot_err = acpi_hest_get_payload(gdata);
906
907 cxl_cper_post_prot_err(prot_err, gdata->error_severity);
908 } else if (guid_equal(sec_type, &CPER_SEC_CXL_GEN_MEDIA_GUID)) {
909 struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
910
911 cxl_cper_post_event(CXL_CPER_EVENT_GEN_MEDIA, rec);
912 } else if (guid_equal(sec_type, &CPER_SEC_CXL_DRAM_GUID)) {
913 struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
914
915 cxl_cper_post_event(CXL_CPER_EVENT_DRAM, rec);
916 } else if (guid_equal(sec_type, &CPER_SEC_CXL_MEM_MODULE_GUID)) {
917 struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
918
919 cxl_cper_post_event(CXL_CPER_EVENT_MEM_MODULE, rec);
920 } else {
921 void *err = acpi_hest_get_payload(gdata);
922
923 ghes_defer_non_standard_event(gdata, sev);
924 log_non_standard_event(sec_type, fru_id, fru_text,
925 sec_sev, err,
926 gdata->error_data_length);
927 }
928 }
929
930 /*
931 * If no memory failure work is queued for abnormal synchronous
932 * errors, do a force kill.
933 */
934 if (sync && !queued) {
935 dev_err(ghes->dev,
936 HW_ERR GHES_PFX "%s:%d: synchronous unrecoverable error (SIGBUS)\n",
937 current->comm, task_pid_nr(current));
938 force_sig(SIGBUS);
939 }
940 }
941
__ghes_print_estatus(const char * pfx,const struct acpi_hest_generic * generic,const struct acpi_hest_generic_status * estatus)942 static void __ghes_print_estatus(const char *pfx,
943 const struct acpi_hest_generic *generic,
944 const struct acpi_hest_generic_status *estatus)
945 {
946 static atomic_t seqno;
947 unsigned int curr_seqno;
948 char pfx_seq[64];
949
950 if (pfx == NULL) {
951 if (ghes_severity(estatus->error_severity) <=
952 GHES_SEV_CORRECTED)
953 pfx = KERN_WARNING;
954 else
955 pfx = KERN_ERR;
956 }
957 curr_seqno = atomic_inc_return(&seqno);
958 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
959 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
960 pfx_seq, generic->header.source_id);
961 cper_estatus_print(pfx_seq, estatus);
962 }
963
ghes_print_estatus(const char * pfx,const struct acpi_hest_generic * generic,const struct acpi_hest_generic_status * estatus)964 static int ghes_print_estatus(const char *pfx,
965 const struct acpi_hest_generic *generic,
966 const struct acpi_hest_generic_status *estatus)
967 {
968 /* Not more than 2 messages every 5 seconds */
969 static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2);
970 static DEFINE_RATELIMIT_STATE(ratelimit_uncorrected, 5*HZ, 2);
971 struct ratelimit_state *ratelimit;
972
973 if (ghes_severity(estatus->error_severity) <= GHES_SEV_CORRECTED)
974 ratelimit = &ratelimit_corrected;
975 else
976 ratelimit = &ratelimit_uncorrected;
977 if (__ratelimit(ratelimit)) {
978 __ghes_print_estatus(pfx, generic, estatus);
979 return 1;
980 }
981 return 0;
982 }
983
984 /*
985 * GHES error status reporting throttle, to report more kinds of
986 * errors, instead of just most frequently occurred errors.
987 */
ghes_estatus_cached(struct acpi_hest_generic_status * estatus)988 static int ghes_estatus_cached(struct acpi_hest_generic_status *estatus)
989 {
990 u32 len;
991 int i, cached = 0;
992 unsigned long long now;
993 struct ghes_estatus_cache *cache;
994 struct acpi_hest_generic_status *cache_estatus;
995
996 len = cper_estatus_len(estatus);
997 rcu_read_lock();
998 for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) {
999 cache = rcu_dereference(ghes_estatus_caches[i]);
1000 if (cache == NULL)
1001 continue;
1002 if (len != cache->estatus_len)
1003 continue;
1004 cache_estatus = GHES_ESTATUS_FROM_CACHE(cache);
1005 if (memcmp(estatus, cache_estatus, len))
1006 continue;
1007 atomic_inc(&cache->count);
1008 now = sched_clock();
1009 if (now - cache->time_in < GHES_ESTATUS_IN_CACHE_MAX_NSEC)
1010 cached = 1;
1011 break;
1012 }
1013 rcu_read_unlock();
1014 return cached;
1015 }
1016
ghes_estatus_cache_alloc(struct acpi_hest_generic * generic,struct acpi_hest_generic_status * estatus)1017 static struct ghes_estatus_cache *ghes_estatus_cache_alloc(
1018 struct acpi_hest_generic *generic,
1019 struct acpi_hest_generic_status *estatus)
1020 {
1021 int alloced;
1022 u32 len, cache_len;
1023 struct ghes_estatus_cache *cache;
1024 struct acpi_hest_generic_status *cache_estatus;
1025
1026 alloced = atomic_add_return(1, &ghes_estatus_cache_alloced);
1027 if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) {
1028 atomic_dec(&ghes_estatus_cache_alloced);
1029 return NULL;
1030 }
1031 len = cper_estatus_len(estatus);
1032 cache_len = GHES_ESTATUS_CACHE_LEN(len);
1033 cache = (void *)gen_pool_alloc(ghes_estatus_pool, cache_len);
1034 if (!cache) {
1035 atomic_dec(&ghes_estatus_cache_alloced);
1036 return NULL;
1037 }
1038 cache_estatus = GHES_ESTATUS_FROM_CACHE(cache);
1039 memcpy(cache_estatus, estatus, len);
1040 cache->estatus_len = len;
1041 atomic_set(&cache->count, 0);
1042 cache->generic = generic;
1043 cache->time_in = sched_clock();
1044 return cache;
1045 }
1046
ghes_estatus_cache_rcu_free(struct rcu_head * head)1047 static void ghes_estatus_cache_rcu_free(struct rcu_head *head)
1048 {
1049 struct ghes_estatus_cache *cache;
1050 u32 len;
1051
1052 cache = container_of(head, struct ghes_estatus_cache, rcu);
1053 len = cper_estatus_len(GHES_ESTATUS_FROM_CACHE(cache));
1054 len = GHES_ESTATUS_CACHE_LEN(len);
1055 gen_pool_free(ghes_estatus_pool, (unsigned long)cache, len);
1056 atomic_dec(&ghes_estatus_cache_alloced);
1057 }
1058
1059 static void
ghes_estatus_cache_add(struct acpi_hest_generic * generic,struct acpi_hest_generic_status * estatus)1060 ghes_estatus_cache_add(struct acpi_hest_generic *generic,
1061 struct acpi_hest_generic_status *estatus)
1062 {
1063 unsigned long long now, duration, period, max_period = 0;
1064 struct ghes_estatus_cache *cache, *new_cache;
1065 struct ghes_estatus_cache __rcu *victim;
1066 int i, slot = -1, count;
1067
1068 new_cache = ghes_estatus_cache_alloc(generic, estatus);
1069 if (!new_cache)
1070 return;
1071
1072 rcu_read_lock();
1073 now = sched_clock();
1074 for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) {
1075 cache = rcu_dereference(ghes_estatus_caches[i]);
1076 if (cache == NULL) {
1077 slot = i;
1078 break;
1079 }
1080 duration = now - cache->time_in;
1081 if (duration >= GHES_ESTATUS_IN_CACHE_MAX_NSEC) {
1082 slot = i;
1083 break;
1084 }
1085 count = atomic_read(&cache->count);
1086 period = duration;
1087 do_div(period, (count + 1));
1088 if (period > max_period) {
1089 max_period = period;
1090 slot = i;
1091 }
1092 }
1093 rcu_read_unlock();
1094
1095 if (slot != -1) {
1096 /*
1097 * Use release semantics to ensure that ghes_estatus_cached()
1098 * running on another CPU will see the updated cache fields if
1099 * it can see the new value of the pointer.
1100 */
1101 victim = xchg_release(&ghes_estatus_caches[slot],
1102 RCU_INITIALIZER(new_cache));
1103
1104 /*
1105 * At this point, victim may point to a cached item different
1106 * from the one based on which we selected the slot. Instead of
1107 * going to the loop again to pick another slot, let's just
1108 * drop the other item anyway: this may cause a false cache
1109 * miss later on, but that won't cause any problems.
1110 */
1111 if (victim)
1112 call_rcu(&unrcu_pointer(victim)->rcu,
1113 ghes_estatus_cache_rcu_free);
1114 }
1115 }
1116
__ghes_panic(struct ghes * ghes,struct acpi_hest_generic_status * estatus,u64 buf_paddr,enum fixed_addresses fixmap_idx)1117 static void __ghes_panic(struct ghes *ghes,
1118 struct acpi_hest_generic_status *estatus,
1119 u64 buf_paddr, enum fixed_addresses fixmap_idx)
1120 {
1121 const char *msg = GHES_PFX "Fatal hardware error";
1122
1123 __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus);
1124
1125 add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
1126
1127 ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
1128
1129 if (!panic_timeout)
1130 pr_emerg("%s but panic disabled\n", msg);
1131
1132 panic(msg);
1133 }
1134
ghes_proc(struct ghes * ghes)1135 static int ghes_proc(struct ghes *ghes)
1136 {
1137 struct acpi_hest_generic_status *estatus = ghes->estatus;
1138 u64 buf_paddr;
1139 int rc;
1140
1141 rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ);
1142 if (rc)
1143 goto out;
1144
1145 if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC)
1146 __ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
1147
1148 if (!ghes_estatus_cached(estatus)) {
1149 if (ghes_print_estatus(NULL, ghes->generic, estatus))
1150 ghes_estatus_cache_add(ghes->generic, estatus);
1151 }
1152 ghes_do_proc(ghes, estatus);
1153
1154 out:
1155 ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
1156
1157 return rc;
1158 }
1159
ghes_add_timer(struct ghes * ghes)1160 static void ghes_add_timer(struct ghes *ghes)
1161 {
1162 struct acpi_hest_generic *g = ghes->generic;
1163 unsigned long expire;
1164
1165 if (!g->notify.poll_interval) {
1166 pr_warn(FW_WARN GHES_PFX "Poll interval is 0 for generic hardware error source: %d, disabled.\n",
1167 g->header.source_id);
1168 return;
1169 }
1170 expire = jiffies + msecs_to_jiffies(g->notify.poll_interval);
1171 ghes->timer.expires = round_jiffies_relative(expire);
1172 add_timer(&ghes->timer);
1173 }
1174
ghes_poll_func(struct timer_list * t)1175 static void ghes_poll_func(struct timer_list *t)
1176 {
1177 struct ghes *ghes = timer_container_of(ghes, t, timer);
1178 unsigned long flags;
1179
1180 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
1181 ghes_proc(ghes);
1182 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
1183 if (!(ghes->flags & GHES_EXITING))
1184 ghes_add_timer(ghes);
1185 }
1186
ghes_irq_func(int irq,void * data)1187 static irqreturn_t ghes_irq_func(int irq, void *data)
1188 {
1189 struct ghes *ghes = data;
1190 unsigned long flags;
1191 int rc;
1192
1193 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
1194 rc = ghes_proc(ghes);
1195 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
1196 if (rc)
1197 return IRQ_NONE;
1198
1199 return IRQ_HANDLED;
1200 }
1201
ghes_notify_hed(struct notifier_block * this,unsigned long event,void * data)1202 static int ghes_notify_hed(struct notifier_block *this, unsigned long event,
1203 void *data)
1204 {
1205 struct ghes *ghes;
1206 unsigned long flags;
1207 int ret = NOTIFY_DONE;
1208
1209 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
1210 list_for_each_entry_rcu(ghes, &ghes_hed, list) {
1211 if (!ghes_proc(ghes))
1212 ret = NOTIFY_OK;
1213 }
1214 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
1215
1216 return ret;
1217 }
1218
1219 static struct notifier_block ghes_notifier_hed = {
1220 .notifier_call = ghes_notify_hed,
1221 };
1222
1223 /*
1224 * Handlers for CPER records may not be NMI safe. For example,
1225 * memory_failure_queue() takes spinlocks and calls schedule_work_on().
1226 * In any NMI-like handler, memory from ghes_estatus_pool is used to save
1227 * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes
1228 * ghes_proc_in_irq() to run in IRQ context where each estatus in
1229 * ghes_estatus_llist is processed.
1230 *
1231 * Memory from the ghes_estatus_pool is also used with the ghes_estatus_cache
1232 * to suppress frequent messages.
1233 */
1234 static struct llist_head ghes_estatus_llist;
1235 static struct irq_work ghes_proc_irq_work;
1236
ghes_proc_in_irq(struct irq_work * irq_work)1237 static void ghes_proc_in_irq(struct irq_work *irq_work)
1238 {
1239 struct llist_node *llnode, *next;
1240 struct ghes_estatus_node *estatus_node;
1241 struct acpi_hest_generic *generic;
1242 struct acpi_hest_generic_status *estatus;
1243 u32 len, node_len;
1244
1245 llnode = llist_del_all(&ghes_estatus_llist);
1246 /*
1247 * Because the time order of estatus in list is reversed,
1248 * revert it back to proper order.
1249 */
1250 llnode = llist_reverse_order(llnode);
1251 while (llnode) {
1252 next = llnode->next;
1253 estatus_node = llist_entry(llnode, struct ghes_estatus_node,
1254 llnode);
1255 estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
1256 len = cper_estatus_len(estatus);
1257 node_len = GHES_ESTATUS_NODE_LEN(len);
1258
1259 ghes_do_proc(estatus_node->ghes, estatus);
1260
1261 if (!ghes_estatus_cached(estatus)) {
1262 generic = estatus_node->generic;
1263 if (ghes_print_estatus(NULL, generic, estatus))
1264 ghes_estatus_cache_add(generic, estatus);
1265 }
1266 gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node,
1267 node_len);
1268
1269 llnode = next;
1270 }
1271 }
1272
ghes_print_queued_estatus(void)1273 static void ghes_print_queued_estatus(void)
1274 {
1275 struct llist_node *llnode;
1276 struct ghes_estatus_node *estatus_node;
1277 struct acpi_hest_generic *generic;
1278 struct acpi_hest_generic_status *estatus;
1279
1280 llnode = llist_del_all(&ghes_estatus_llist);
1281 /*
1282 * Because the time order of estatus in list is reversed,
1283 * revert it back to proper order.
1284 */
1285 llnode = llist_reverse_order(llnode);
1286 while (llnode) {
1287 estatus_node = llist_entry(llnode, struct ghes_estatus_node,
1288 llnode);
1289 estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
1290 generic = estatus_node->generic;
1291 ghes_print_estatus(NULL, generic, estatus);
1292 llnode = llnode->next;
1293 }
1294 }
1295
ghes_in_nmi_queue_one_entry(struct ghes * ghes,enum fixed_addresses fixmap_idx)1296 static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
1297 enum fixed_addresses fixmap_idx)
1298 {
1299 struct acpi_hest_generic_status *estatus, tmp_header;
1300 struct ghes_estatus_node *estatus_node;
1301 u32 len, node_len;
1302 u64 buf_paddr;
1303 int sev, rc;
1304
1305 if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG))
1306 return -EOPNOTSUPP;
1307
1308 rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx);
1309 if (rc) {
1310 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
1311 return rc;
1312 }
1313
1314 rc = __ghes_check_estatus(ghes, &tmp_header);
1315 if (rc) {
1316 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
1317 return rc;
1318 }
1319
1320 len = cper_estatus_len(&tmp_header);
1321 node_len = GHES_ESTATUS_NODE_LEN(len);
1322 estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len);
1323 if (!estatus_node)
1324 return -ENOMEM;
1325
1326 estatus_node->ghes = ghes;
1327 estatus_node->generic = ghes->generic;
1328 estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
1329
1330 if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) {
1331 ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
1332 rc = -ENOENT;
1333 goto no_work;
1334 }
1335
1336 sev = ghes_severity(estatus->error_severity);
1337 if (sev >= GHES_SEV_PANIC) {
1338 ghes_print_queued_estatus();
1339 __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx);
1340 }
1341
1342 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
1343
1344 /* This error has been reported before, don't process it again. */
1345 if (ghes_estatus_cached(estatus))
1346 goto no_work;
1347
1348 llist_add(&estatus_node->llnode, &ghes_estatus_llist);
1349
1350 return rc;
1351
1352 no_work:
1353 gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node,
1354 node_len);
1355
1356 return rc;
1357 }
1358
ghes_in_nmi_spool_from_list(struct list_head * rcu_list,enum fixed_addresses fixmap_idx)1359 static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
1360 enum fixed_addresses fixmap_idx)
1361 {
1362 int ret = -ENOENT;
1363 struct ghes *ghes;
1364
1365 rcu_read_lock();
1366 list_for_each_entry_rcu(ghes, rcu_list, list) {
1367 if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
1368 ret = 0;
1369 }
1370 rcu_read_unlock();
1371
1372 if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
1373 irq_work_queue(&ghes_proc_irq_work);
1374
1375 return ret;
1376 }
1377
1378 #ifdef CONFIG_ACPI_APEI_SEA
1379 static LIST_HEAD(ghes_sea);
1380
1381 /*
1382 * Return 0 only if one of the SEA error sources successfully reported an error
1383 * record sent from the firmware.
1384 */
ghes_notify_sea(void)1385 int ghes_notify_sea(void)
1386 {
1387 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea);
1388 int rv;
1389
1390 raw_spin_lock(&ghes_notify_lock_sea);
1391 rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA);
1392 raw_spin_unlock(&ghes_notify_lock_sea);
1393
1394 return rv;
1395 }
1396
ghes_sea_add(struct ghes * ghes)1397 static void ghes_sea_add(struct ghes *ghes)
1398 {
1399 mutex_lock(&ghes_list_mutex);
1400 list_add_rcu(&ghes->list, &ghes_sea);
1401 mutex_unlock(&ghes_list_mutex);
1402 }
1403
ghes_sea_remove(struct ghes * ghes)1404 static void ghes_sea_remove(struct ghes *ghes)
1405 {
1406 mutex_lock(&ghes_list_mutex);
1407 list_del_rcu(&ghes->list);
1408 mutex_unlock(&ghes_list_mutex);
1409 synchronize_rcu();
1410 }
1411 #else /* CONFIG_ACPI_APEI_SEA */
ghes_sea_add(struct ghes * ghes)1412 static inline void ghes_sea_add(struct ghes *ghes) { }
ghes_sea_remove(struct ghes * ghes)1413 static inline void ghes_sea_remove(struct ghes *ghes) { }
1414 #endif /* CONFIG_ACPI_APEI_SEA */
1415
1416 #ifdef CONFIG_HAVE_ACPI_APEI_NMI
1417 /*
1418 * NMI may be triggered on any CPU, so ghes_in_nmi is used for
1419 * having only one concurrent reader.
1420 */
1421 static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
1422
1423 static LIST_HEAD(ghes_nmi);
1424
ghes_notify_nmi(unsigned int cmd,struct pt_regs * regs)1425 static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
1426 {
1427 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
1428 int ret = NMI_DONE;
1429
1430 if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
1431 return ret;
1432
1433 raw_spin_lock(&ghes_notify_lock_nmi);
1434 if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI))
1435 ret = NMI_HANDLED;
1436 raw_spin_unlock(&ghes_notify_lock_nmi);
1437
1438 atomic_dec(&ghes_in_nmi);
1439 return ret;
1440 }
1441
ghes_nmi_add(struct ghes * ghes)1442 static void ghes_nmi_add(struct ghes *ghes)
1443 {
1444 mutex_lock(&ghes_list_mutex);
1445 if (list_empty(&ghes_nmi))
1446 register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes");
1447 list_add_rcu(&ghes->list, &ghes_nmi);
1448 mutex_unlock(&ghes_list_mutex);
1449 }
1450
ghes_nmi_remove(struct ghes * ghes)1451 static void ghes_nmi_remove(struct ghes *ghes)
1452 {
1453 mutex_lock(&ghes_list_mutex);
1454 list_del_rcu(&ghes->list);
1455 if (list_empty(&ghes_nmi))
1456 unregister_nmi_handler(NMI_LOCAL, "ghes");
1457 mutex_unlock(&ghes_list_mutex);
1458 /*
1459 * To synchronize with NMI handler, ghes can only be
1460 * freed after NMI handler finishes.
1461 */
1462 synchronize_rcu();
1463 }
1464 #else /* CONFIG_HAVE_ACPI_APEI_NMI */
ghes_nmi_add(struct ghes * ghes)1465 static inline void ghes_nmi_add(struct ghes *ghes) { }
ghes_nmi_remove(struct ghes * ghes)1466 static inline void ghes_nmi_remove(struct ghes *ghes) { }
1467 #endif /* CONFIG_HAVE_ACPI_APEI_NMI */
1468
ghes_nmi_init_cxt(void)1469 static void ghes_nmi_init_cxt(void)
1470 {
1471 init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq);
1472 }
1473
__ghes_sdei_callback(struct ghes * ghes,enum fixed_addresses fixmap_idx)1474 static int __ghes_sdei_callback(struct ghes *ghes,
1475 enum fixed_addresses fixmap_idx)
1476 {
1477 if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) {
1478 irq_work_queue(&ghes_proc_irq_work);
1479
1480 return 0;
1481 }
1482
1483 return -ENOENT;
1484 }
1485
ghes_sdei_normal_callback(u32 event_num,struct pt_regs * regs,void * arg)1486 static int ghes_sdei_normal_callback(u32 event_num, struct pt_regs *regs,
1487 void *arg)
1488 {
1489 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal);
1490 struct ghes *ghes = arg;
1491 int err;
1492
1493 raw_spin_lock(&ghes_notify_lock_sdei_normal);
1494 err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_NORMAL);
1495 raw_spin_unlock(&ghes_notify_lock_sdei_normal);
1496
1497 return err;
1498 }
1499
ghes_sdei_critical_callback(u32 event_num,struct pt_regs * regs,void * arg)1500 static int ghes_sdei_critical_callback(u32 event_num, struct pt_regs *regs,
1501 void *arg)
1502 {
1503 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical);
1504 struct ghes *ghes = arg;
1505 int err;
1506
1507 raw_spin_lock(&ghes_notify_lock_sdei_critical);
1508 err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_CRITICAL);
1509 raw_spin_unlock(&ghes_notify_lock_sdei_critical);
1510
1511 return err;
1512 }
1513
apei_sdei_register_ghes(struct ghes * ghes)1514 static int apei_sdei_register_ghes(struct ghes *ghes)
1515 {
1516 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
1517 return -EOPNOTSUPP;
1518
1519 return sdei_register_ghes(ghes, ghes_sdei_normal_callback,
1520 ghes_sdei_critical_callback);
1521 }
1522
apei_sdei_unregister_ghes(struct ghes * ghes)1523 static int apei_sdei_unregister_ghes(struct ghes *ghes)
1524 {
1525 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
1526 return -EOPNOTSUPP;
1527
1528 return sdei_unregister_ghes(ghes);
1529 }
1530
ghes_probe(struct platform_device * ghes_dev)1531 static int ghes_probe(struct platform_device *ghes_dev)
1532 {
1533 struct acpi_hest_generic *generic;
1534 struct ghes *ghes = NULL;
1535 unsigned long flags;
1536
1537 int rc = -EINVAL;
1538
1539 generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data;
1540 if (!generic->enabled)
1541 return -ENODEV;
1542
1543 switch (generic->notify.type) {
1544 case ACPI_HEST_NOTIFY_POLLED:
1545 case ACPI_HEST_NOTIFY_EXTERNAL:
1546 case ACPI_HEST_NOTIFY_SCI:
1547 case ACPI_HEST_NOTIFY_GSIV:
1548 case ACPI_HEST_NOTIFY_GPIO:
1549 break;
1550
1551 case ACPI_HEST_NOTIFY_SEA:
1552 if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) {
1553 pr_warn(GHES_PFX "Generic hardware error source: %d notified via SEA is not supported\n",
1554 generic->header.source_id);
1555 rc = -ENOTSUPP;
1556 goto err;
1557 }
1558 break;
1559 case ACPI_HEST_NOTIFY_NMI:
1560 if (!IS_ENABLED(CONFIG_HAVE_ACPI_APEI_NMI)) {
1561 pr_warn(GHES_PFX "Generic hardware error source: %d notified via NMI interrupt is not supported!\n",
1562 generic->header.source_id);
1563 goto err;
1564 }
1565 break;
1566 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1567 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) {
1568 pr_warn(GHES_PFX "Generic hardware error source: %d notified via SDE Interface is not supported!\n",
1569 generic->header.source_id);
1570 goto err;
1571 }
1572 break;
1573 case ACPI_HEST_NOTIFY_LOCAL:
1574 pr_warn(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n",
1575 generic->header.source_id);
1576 goto err;
1577 default:
1578 pr_warn(FW_WARN GHES_PFX "Unknown notification type: %u for generic hardware error source: %d\n",
1579 generic->notify.type, generic->header.source_id);
1580 goto err;
1581 }
1582
1583 rc = -EIO;
1584 if (generic->error_block_length <
1585 sizeof(struct acpi_hest_generic_status)) {
1586 pr_warn(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n",
1587 generic->error_block_length, generic->header.source_id);
1588 goto err;
1589 }
1590 ghes = ghes_new(generic);
1591 if (IS_ERR(ghes)) {
1592 rc = PTR_ERR(ghes);
1593 ghes = NULL;
1594 goto err;
1595 }
1596
1597 switch (generic->notify.type) {
1598 case ACPI_HEST_NOTIFY_POLLED:
1599 timer_setup(&ghes->timer, ghes_poll_func, 0);
1600 ghes_add_timer(ghes);
1601 break;
1602 case ACPI_HEST_NOTIFY_EXTERNAL:
1603 /* External interrupt vector is GSI */
1604 rc = acpi_gsi_to_irq(generic->notify.vector, &ghes->irq);
1605 if (rc) {
1606 pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n",
1607 generic->header.source_id);
1608 goto err;
1609 }
1610 rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED,
1611 "GHES IRQ", ghes);
1612 if (rc) {
1613 pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n",
1614 generic->header.source_id);
1615 goto err;
1616 }
1617 break;
1618
1619 case ACPI_HEST_NOTIFY_SCI:
1620 case ACPI_HEST_NOTIFY_GSIV:
1621 case ACPI_HEST_NOTIFY_GPIO:
1622 mutex_lock(&ghes_list_mutex);
1623 if (list_empty(&ghes_hed))
1624 register_acpi_hed_notifier(&ghes_notifier_hed);
1625 list_add_rcu(&ghes->list, &ghes_hed);
1626 mutex_unlock(&ghes_list_mutex);
1627 break;
1628
1629 case ACPI_HEST_NOTIFY_SEA:
1630 ghes_sea_add(ghes);
1631 break;
1632 case ACPI_HEST_NOTIFY_NMI:
1633 ghes_nmi_add(ghes);
1634 break;
1635 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1636 rc = apei_sdei_register_ghes(ghes);
1637 if (rc)
1638 goto err;
1639 break;
1640 default:
1641 BUG();
1642 }
1643
1644 platform_set_drvdata(ghes_dev, ghes);
1645
1646 ghes->dev = &ghes_dev->dev;
1647
1648 mutex_lock(&ghes_devs_mutex);
1649 list_add_tail(&ghes->elist, &ghes_devs);
1650 mutex_unlock(&ghes_devs_mutex);
1651
1652 /* Handle any pending errors right away */
1653 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
1654 ghes_proc(ghes);
1655 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
1656
1657 return 0;
1658
1659 err:
1660 if (ghes) {
1661 ghes_fini(ghes);
1662 kfree(ghes);
1663 }
1664 return rc;
1665 }
1666
ghes_remove(struct platform_device * ghes_dev)1667 static void ghes_remove(struct platform_device *ghes_dev)
1668 {
1669 int rc;
1670 struct ghes *ghes;
1671 struct acpi_hest_generic *generic;
1672
1673 ghes = platform_get_drvdata(ghes_dev);
1674 generic = ghes->generic;
1675
1676 ghes->flags |= GHES_EXITING;
1677 switch (generic->notify.type) {
1678 case ACPI_HEST_NOTIFY_POLLED:
1679 timer_shutdown_sync(&ghes->timer);
1680 break;
1681 case ACPI_HEST_NOTIFY_EXTERNAL:
1682 free_irq(ghes->irq, ghes);
1683 break;
1684
1685 case ACPI_HEST_NOTIFY_SCI:
1686 case ACPI_HEST_NOTIFY_GSIV:
1687 case ACPI_HEST_NOTIFY_GPIO:
1688 mutex_lock(&ghes_list_mutex);
1689 list_del_rcu(&ghes->list);
1690 if (list_empty(&ghes_hed))
1691 unregister_acpi_hed_notifier(&ghes_notifier_hed);
1692 mutex_unlock(&ghes_list_mutex);
1693 synchronize_rcu();
1694 break;
1695
1696 case ACPI_HEST_NOTIFY_SEA:
1697 ghes_sea_remove(ghes);
1698 break;
1699 case ACPI_HEST_NOTIFY_NMI:
1700 ghes_nmi_remove(ghes);
1701 break;
1702 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1703 rc = apei_sdei_unregister_ghes(ghes);
1704 if (rc) {
1705 /*
1706 * Returning early results in a resource leak, but we're
1707 * only here if stopping the hardware failed.
1708 */
1709 dev_err(&ghes_dev->dev, "Failed to unregister ghes (%pe)\n",
1710 ERR_PTR(rc));
1711 return;
1712 }
1713 break;
1714 default:
1715 BUG();
1716 break;
1717 }
1718
1719 ghes_fini(ghes);
1720
1721 mutex_lock(&ghes_devs_mutex);
1722 list_del(&ghes->elist);
1723 mutex_unlock(&ghes_devs_mutex);
1724
1725 kfree(ghes);
1726 }
1727
1728 static struct platform_driver ghes_platform_driver = {
1729 .driver = {
1730 .name = "GHES",
1731 },
1732 .probe = ghes_probe,
1733 .remove = ghes_remove,
1734 };
1735
acpi_ghes_init(void)1736 void __init acpi_ghes_init(void)
1737 {
1738 int rc;
1739
1740 acpi_sdei_init();
1741
1742 if (acpi_disabled)
1743 return;
1744
1745 switch (hest_disable) {
1746 case HEST_NOT_FOUND:
1747 return;
1748 case HEST_DISABLED:
1749 pr_info(GHES_PFX "HEST is not enabled!\n");
1750 return;
1751 default:
1752 break;
1753 }
1754
1755 if (ghes_disable) {
1756 pr_info(GHES_PFX "GHES is not enabled!\n");
1757 return;
1758 }
1759
1760 ghes_nmi_init_cxt();
1761
1762 rc = platform_driver_register(&ghes_platform_driver);
1763 if (rc)
1764 return;
1765
1766 rc = apei_osc_setup();
1767 if (rc == 0 && osc_sb_apei_support_acked)
1768 pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit and WHEA _OSC.\n");
1769 else if (rc == 0 && !osc_sb_apei_support_acked)
1770 pr_info(GHES_PFX "APEI firmware first mode is enabled by WHEA _OSC.\n");
1771 else if (rc && osc_sb_apei_support_acked)
1772 pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit.\n");
1773 else
1774 pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
1775 }
1776
1777 /*
1778 * Known x86 systems that prefer GHES error reporting:
1779 */
1780 static struct acpi_platform_list plat_list[] = {
1781 {"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions},
1782 { } /* End */
1783 };
1784
ghes_get_devices(void)1785 struct list_head *ghes_get_devices(void)
1786 {
1787 int idx = -1;
1788
1789 if (IS_ENABLED(CONFIG_X86)) {
1790 idx = acpi_match_platform_list(plat_list);
1791 if (idx < 0) {
1792 if (!ghes_edac_force_enable)
1793 return NULL;
1794
1795 pr_warn_once("Force-loading ghes_edac on an unsupported platform. You're on your own!\n");
1796 }
1797 } else if (list_empty(&ghes_devs)) {
1798 return NULL;
1799 }
1800
1801 return &ghes_devs;
1802 }
1803 EXPORT_SYMBOL_GPL(ghes_get_devices);
1804
ghes_register_report_chain(struct notifier_block * nb)1805 void ghes_register_report_chain(struct notifier_block *nb)
1806 {
1807 atomic_notifier_chain_register(&ghes_report_chain, nb);
1808 }
1809 EXPORT_SYMBOL_GPL(ghes_register_report_chain);
1810
ghes_unregister_report_chain(struct notifier_block * nb)1811 void ghes_unregister_report_chain(struct notifier_block *nb)
1812 {
1813 atomic_notifier_chain_unregister(&ghes_report_chain, nb);
1814 }
1815 EXPORT_SYMBOL_GPL(ghes_unregister_report_chain);
1816