Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 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 | * |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 16 | * Copyright 2010,2011 Intel Corp. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 17 | * Author: Huang Ying <ying.huang@intel.com> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 18 | */ |
| 19 | |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 20 | #include <linux/arm_sdei.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Paul Gortmaker | 020bf06 | 2016-02-15 00:27:50 -0500 | [diff] [blame] | 22 | #include <linux/moduleparam.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/acpi.h> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/interrupt.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 27 | #include <linux/timer.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 28 | #include <linux/cper.h> |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/mutex.h> |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 31 | #include <linux/ratelimit.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 32 | #include <linux/vmalloc.h> |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 33 | #include <linux/irq_work.h> |
| 34 | #include <linux/llist.h> |
| 35 | #include <linux/genalloc.h> |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 36 | #include <linux/pci.h> |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 37 | #include <linux/pfn.h> |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 38 | #include <linux/aer.h> |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 39 | #include <linux/nmi.h> |
Ingo Molnar | e601757 | 2017-02-01 16:36:40 +0100 | [diff] [blame] | 40 | #include <linux/sched/clock.h> |
Tyler Baicar | 297b64c | 2017-06-21 12:17:12 -0600 | [diff] [blame] | 41 | #include <linux/uuid.h> |
| 42 | #include <linux/ras.h> |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 43 | |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 44 | #include <acpi/actbl1.h> |
Mauro Carvalho Chehab | 40e0641 | 2013-02-15 05:41:22 -0300 | [diff] [blame] | 45 | #include <acpi/ghes.h> |
Tomasz Nowicki | 9dae3d0 | 2014-07-22 11:20:11 +0200 | [diff] [blame] | 46 | #include <acpi/apei.h> |
James Morse | 4f89fa2 | 2017-11-06 18:44:24 +0000 | [diff] [blame] | 47 | #include <asm/fixmap.h> |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 48 | #include <asm/tlbflush.h> |
Tyler Baicar | 297b64c | 2017-06-21 12:17:12 -0600 | [diff] [blame] | 49 | #include <ras/ras_event.h> |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 50 | |
| 51 | #include "apei-internal.h" |
| 52 | |
| 53 | #define GHES_PFX "GHES: " |
| 54 | |
| 55 | #define GHES_ESTATUS_MAX_SIZE 65536 |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 56 | #define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 |
| 57 | |
| 58 | #define GHES_ESTATUS_POOL_MIN_ALLOC_ORDER 3 |
| 59 | |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 60 | /* This is just an estimation for memory pool allocation */ |
| 61 | #define GHES_ESTATUS_CACHE_AVG_SIZE 512 |
| 62 | |
| 63 | #define GHES_ESTATUS_CACHES_SIZE 4 |
| 64 | |
Len Brown | 70cb6e1 | 2011-08-02 18:00:21 -0400 | [diff] [blame] | 65 | #define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 66 | /* Prevent too many caches are allocated because of RCU */ |
| 67 | #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) |
| 68 | |
| 69 | #define GHES_ESTATUS_CACHE_LEN(estatus_len) \ |
| 70 | (sizeof(struct ghes_estatus_cache) + (estatus_len)) |
| 71 | #define GHES_ESTATUS_FROM_CACHE(estatus_cache) \ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 72 | ((struct acpi_hest_generic_status *) \ |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 73 | ((struct ghes_estatus_cache *)(estatus_cache) + 1)) |
| 74 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 75 | #define GHES_ESTATUS_NODE_LEN(estatus_len) \ |
| 76 | (sizeof(struct ghes_estatus_node) + (estatus_len)) |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 77 | #define GHES_ESTATUS_FROM_NODE(estatus_node) \ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 78 | ((struct acpi_hest_generic_status *) \ |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 79 | ((struct ghes_estatus_node *)(estatus_node) + 1)) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 80 | |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 81 | /* |
| 82 | * NMI-like notifications vary by architecture, before the compiler can prune |
| 83 | * unused static functions it needs a value for these enums. |
| 84 | */ |
| 85 | #ifndef CONFIG_ARM_SDE_INTERFACE |
| 86 | #define FIX_APEI_GHES_SDEI_NORMAL __end_of_fixed_addresses |
| 87 | #define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses |
| 88 | #endif |
| 89 | |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 90 | static inline bool is_hest_type_generic_v2(struct ghes *ghes) |
| 91 | { |
| 92 | return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; |
| 93 | } |
| 94 | |
Paul Gortmaker | 020bf06 | 2016-02-15 00:27:50 -0500 | [diff] [blame] | 95 | /* |
| 96 | * This driver isn't really modular, however for the time being, |
| 97 | * continuing to use module_param is the easiest way to remain |
| 98 | * compatible with existing boot arg use cases. |
| 99 | */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 100 | bool ghes_disable; |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 101 | module_param_named(disable, ghes_disable, bool, 0); |
| 102 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 103 | /* |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 104 | * All error sources notified with HED (Hardware Error Device) share a |
| 105 | * single notifier callback, so they need to be linked and checked one |
| 106 | * by one. This holds true for NMI too. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 107 | * |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 108 | * RCU is used for these lists, so ghes_list_mutex is only used for |
| 109 | * list changing, not for traversing. |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 110 | */ |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 111 | static LIST_HEAD(ghes_hed); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 112 | static DEFINE_MUTEX(ghes_list_mutex); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 113 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 114 | /* |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 115 | * Because the memory area used to transfer hardware error information |
| 116 | * from BIOS to Linux can be determined only in NMI, IRQ or timer |
| 117 | * handler, but general ioremap can not be used in atomic context, so |
James Morse | 4f89fa2 | 2017-11-06 18:44:24 +0000 | [diff] [blame] | 118 | * the fixmap is used instead. |
James Morse | 520e18a | 2017-11-06 18:44:25 +0000 | [diff] [blame] | 119 | * |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 120 | * This spinlock is used to prevent the fixmap entry from being used |
James Morse | 4f89fa2 | 2017-11-06 18:44:24 +0000 | [diff] [blame] | 121 | * simultaneously. |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 122 | */ |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 123 | static DEFINE_SPINLOCK(ghes_notify_lock_irq); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 124 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 125 | static struct gen_pool *ghes_estatus_pool; |
| 126 | static unsigned long ghes_estatus_pool_size_request; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 127 | |
Borislav Petkov | 8f7c31f | 2014-09-29 13:33:17 +0200 | [diff] [blame] | 128 | static struct ghes_estatus_cache *ghes_estatus_caches[GHES_ESTATUS_CACHES_SIZE]; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 129 | static atomic_t ghes_estatus_cache_alloced; |
| 130 | |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 131 | static int ghes_panic_timeout __read_mostly = 30; |
| 132 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 133 | static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 134 | { |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 135 | phys_addr_t paddr; |
| 136 | pgprot_t prot; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 137 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 138 | paddr = PFN_PHYS(pfn); |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 139 | prot = arch_apei_get_mem_attribute(paddr); |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 140 | __set_fixmap(fixmap_idx, paddr, prot); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 141 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 142 | return (void __iomem *) __fix_to_virt(fixmap_idx); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 143 | } |
| 144 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 145 | static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 146 | { |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 147 | int _idx = virt_to_fix((unsigned long)vaddr); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 148 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 149 | WARN_ON_ONCE(fixmap_idx != _idx); |
| 150 | clear_fixmap(fixmap_idx); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 151 | } |
| 152 | |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 153 | int ghes_estatus_pool_init(int num_ghes) |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 154 | { |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 155 | unsigned long addr, len; |
Liguang Zhang | 6abc762 | 2019-07-15 14:58:44 +0800 | [diff] [blame] | 156 | int rc; |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 157 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 158 | ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1); |
| 159 | if (!ghes_estatus_pool) |
| 160 | return -ENOMEM; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 161 | |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 162 | len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX; |
| 163 | len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 164 | |
James Morse | fb7be08 | 2019-01-29 18:48:41 +0000 | [diff] [blame] | 165 | ghes_estatus_pool_size_request = PAGE_ALIGN(len); |
James Morse | 0ac234b | 2019-01-29 18:48:39 +0000 | [diff] [blame] | 166 | addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); |
| 167 | if (!addr) |
Liguang Zhang | 6abc762 | 2019-07-15 14:58:44 +0800 | [diff] [blame] | 168 | goto err_pool_alloc; |
James Morse | 0ac234b | 2019-01-29 18:48:39 +0000 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * New allocation must be visible in all pgd before it can be found by |
| 172 | * an NMI allocating from the pool. |
| 173 | */ |
| 174 | vmalloc_sync_all(); |
| 175 | |
Liguang Zhang | 6abc762 | 2019-07-15 14:58:44 +0800 | [diff] [blame] | 176 | rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1); |
| 177 | if (rc) |
| 178 | goto err_pool_add; |
| 179 | |
| 180 | return 0; |
| 181 | |
| 182 | err_pool_add: |
| 183 | vfree((void *)addr); |
| 184 | |
| 185 | err_pool_alloc: |
| 186 | gen_pool_destroy(ghes_estatus_pool); |
| 187 | |
| 188 | return -ENOMEM; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 189 | } |
| 190 | |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 191 | static int map_gen_v2(struct ghes *ghes) |
| 192 | { |
| 193 | return apei_map_generic_address(&ghes->generic_v2->read_ack_register); |
| 194 | } |
| 195 | |
| 196 | static void unmap_gen_v2(struct ghes *ghes) |
| 197 | { |
| 198 | apei_unmap_generic_address(&ghes->generic_v2->read_ack_register); |
| 199 | } |
| 200 | |
James Morse | 06ddead | 2019-01-29 18:48:46 +0000 | [diff] [blame] | 201 | static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2) |
| 202 | { |
| 203 | int rc; |
| 204 | u64 val = 0; |
| 205 | |
| 206 | rc = apei_read(&val, &gv2->read_ack_register); |
| 207 | if (rc) |
| 208 | return; |
| 209 | |
| 210 | val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset; |
| 211 | val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset; |
| 212 | |
| 213 | apei_write(val, &gv2->read_ack_register); |
| 214 | } |
| 215 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 216 | static struct ghes *ghes_new(struct acpi_hest_generic *generic) |
| 217 | { |
| 218 | struct ghes *ghes; |
| 219 | unsigned int error_block_length; |
| 220 | int rc; |
| 221 | |
| 222 | ghes = kzalloc(sizeof(*ghes), GFP_KERNEL); |
| 223 | if (!ghes) |
| 224 | return ERR_PTR(-ENOMEM); |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 225 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 226 | ghes->generic = generic; |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 227 | if (is_hest_type_generic_v2(ghes)) { |
| 228 | rc = map_gen_v2(ghes); |
| 229 | if (rc) |
| 230 | goto err_free; |
| 231 | } |
| 232 | |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 233 | rc = apei_map_generic_address(&generic->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 234 | if (rc) |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 235 | goto err_unmap_read_ack_addr; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 236 | error_block_length = generic->error_block_length; |
| 237 | if (error_block_length > GHES_ESTATUS_MAX_SIZE) { |
Kefeng Wang | 933ca4e | 2019-10-18 11:18:25 +0800 | [diff] [blame] | 238 | pr_warn(FW_WARN GHES_PFX |
| 239 | "Error status block length is too long: %u for " |
| 240 | "generic hardware error source: %d.\n", |
| 241 | error_block_length, generic->header.source_id); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 242 | error_block_length = GHES_ESTATUS_MAX_SIZE; |
| 243 | } |
| 244 | ghes->estatus = kmalloc(error_block_length, GFP_KERNEL); |
| 245 | if (!ghes->estatus) { |
| 246 | rc = -ENOMEM; |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 247 | goto err_unmap_status_addr; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | return ghes; |
| 251 | |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 252 | err_unmap_status_addr: |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 253 | apei_unmap_generic_address(&generic->error_status_address); |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 254 | err_unmap_read_ack_addr: |
| 255 | if (is_hest_type_generic_v2(ghes)) |
| 256 | unmap_gen_v2(ghes); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 257 | err_free: |
| 258 | kfree(ghes); |
| 259 | return ERR_PTR(rc); |
| 260 | } |
| 261 | |
| 262 | static void ghes_fini(struct ghes *ghes) |
| 263 | { |
| 264 | kfree(ghes->estatus); |
Huang Ying | 34ddeb0 | 2012-06-12 11:20:19 +0800 | [diff] [blame] | 265 | apei_unmap_generic_address(&ghes->generic->error_status_address); |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 266 | if (is_hest_type_generic_v2(ghes)) |
| 267 | unmap_gen_v2(ghes); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 268 | } |
| 269 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 270 | static inline int ghes_severity(int severity) |
| 271 | { |
| 272 | switch (severity) { |
Huang Ying | ad4ecef | 2010-08-02 15:48:23 +0800 | [diff] [blame] | 273 | case CPER_SEV_INFORMATIONAL: |
| 274 | return GHES_SEV_NO; |
| 275 | case CPER_SEV_CORRECTED: |
| 276 | return GHES_SEV_CORRECTED; |
| 277 | case CPER_SEV_RECOVERABLE: |
| 278 | return GHES_SEV_RECOVERABLE; |
| 279 | case CPER_SEV_FATAL: |
| 280 | return GHES_SEV_PANIC; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 281 | default: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 282 | /* Unknown, go panic */ |
Huang Ying | ad4ecef | 2010-08-02 15:48:23 +0800 | [diff] [blame] | 283 | return GHES_SEV_PANIC; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 287 | static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 288 | int from_phys, |
| 289 | enum fixed_addresses fixmap_idx) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 290 | { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 291 | void __iomem *vaddr; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 292 | u64 offset; |
| 293 | u32 trunk; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 294 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 295 | while (len > 0) { |
| 296 | offset = paddr - (paddr & PAGE_MASK); |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 297 | vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 298 | trunk = PAGE_SIZE - offset; |
| 299 | trunk = min(trunk, len); |
| 300 | if (from_phys) |
| 301 | memcpy_fromio(buffer, vaddr + offset, trunk); |
| 302 | else |
| 303 | memcpy_toio(vaddr + offset, buffer, trunk); |
| 304 | len -= trunk; |
| 305 | paddr += trunk; |
| 306 | buffer += trunk; |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 307 | ghes_unmap(vaddr, fixmap_idx); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 308 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 309 | } |
| 310 | |
James Morse | f2a681b | 2019-01-29 18:48:54 +0000 | [diff] [blame] | 311 | /* Check the top-level record header has an appropriate size. */ |
| 312 | static int __ghes_check_estatus(struct ghes *ghes, |
| 313 | struct acpi_hest_generic_status *estatus) |
| 314 | { |
| 315 | u32 len = cper_estatus_len(estatus); |
| 316 | |
| 317 | if (len < sizeof(*estatus)) { |
| 318 | pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status block!\n"); |
| 319 | return -EIO; |
| 320 | } |
| 321 | |
| 322 | if (len > ghes->generic->error_block_length) { |
| 323 | pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status block length!\n"); |
| 324 | return -EIO; |
| 325 | } |
| 326 | |
| 327 | if (cper_estatus_check_header(estatus)) { |
| 328 | pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid CPER header!\n"); |
| 329 | return -EIO; |
| 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
James Morse | e00a6e3 | 2019-01-29 18:48:55 +0000 | [diff] [blame] | 335 | /* Read the CPER block, returning its address, and header in estatus. */ |
| 336 | static int __ghes_peek_estatus(struct ghes *ghes, |
| 337 | struct acpi_hest_generic_status *estatus, |
| 338 | u64 *buf_paddr, enum fixed_addresses fixmap_idx) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 339 | { |
| 340 | struct acpi_hest_generic *g = ghes->generic; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 341 | int rc; |
| 342 | |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 343 | rc = apei_read(buf_paddr, &g->error_status_address); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 344 | if (rc) { |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 345 | *buf_paddr = 0; |
James Morse | 93066e9 | 2019-01-29 18:48:38 +0000 | [diff] [blame] | 346 | pr_warn_ratelimited(FW_WARN GHES_PFX |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 347 | "Failed to read error status block address for hardware error source: %d.\n", |
| 348 | g->header.source_id); |
| 349 | return -EIO; |
| 350 | } |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 351 | if (!*buf_paddr) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 352 | return -ENOENT; |
| 353 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 354 | ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1, |
| 355 | fixmap_idx); |
| 356 | if (!estatus->block_status) { |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 357 | *buf_paddr = 0; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 358 | return -ENOENT; |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 359 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 360 | |
Liguang Zhang | 371b868 | 2019-06-25 13:15:28 +0800 | [diff] [blame] | 361 | return 0; |
James Morse | e00a6e3 | 2019-01-29 18:48:55 +0000 | [diff] [blame] | 362 | } |
James Morse | f2a681b | 2019-01-29 18:48:54 +0000 | [diff] [blame] | 363 | |
James Morse | e00a6e3 | 2019-01-29 18:48:55 +0000 | [diff] [blame] | 364 | static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, |
| 365 | u64 buf_paddr, enum fixed_addresses fixmap_idx, |
| 366 | size_t buf_len) |
| 367 | { |
| 368 | ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx); |
James Morse | f2a681b | 2019-01-29 18:48:54 +0000 | [diff] [blame] | 369 | if (cper_estatus_check(estatus)) { |
James Morse | 93066e9 | 2019-01-29 18:48:38 +0000 | [diff] [blame] | 370 | pr_warn_ratelimited(FW_WARN GHES_PFX |
| 371 | "Failed to read error status block!\n"); |
James Morse | f2a681b | 2019-01-29 18:48:54 +0000 | [diff] [blame] | 372 | return -EIO; |
| 373 | } |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 374 | |
James Morse | f2a681b | 2019-01-29 18:48:54 +0000 | [diff] [blame] | 375 | return 0; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 376 | } |
| 377 | |
James Morse | e00a6e3 | 2019-01-29 18:48:55 +0000 | [diff] [blame] | 378 | static int ghes_read_estatus(struct ghes *ghes, |
| 379 | struct acpi_hest_generic_status *estatus, |
| 380 | u64 *buf_paddr, enum fixed_addresses fixmap_idx) |
| 381 | { |
| 382 | int rc; |
| 383 | |
| 384 | rc = __ghes_peek_estatus(ghes, estatus, buf_paddr, fixmap_idx); |
| 385 | if (rc) |
| 386 | return rc; |
| 387 | |
| 388 | rc = __ghes_check_estatus(ghes, estatus); |
| 389 | if (rc) |
| 390 | return rc; |
| 391 | |
| 392 | return __ghes_read_estatus(estatus, *buf_paddr, fixmap_idx, |
| 393 | cper_estatus_len(estatus)); |
| 394 | } |
| 395 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 396 | static void ghes_clear_estatus(struct ghes *ghes, |
| 397 | struct acpi_hest_generic_status *estatus, |
| 398 | u64 buf_paddr, enum fixed_addresses fixmap_idx) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 399 | { |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 400 | estatus->block_status = 0; |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 401 | |
| 402 | if (!buf_paddr) |
| 403 | return; |
| 404 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 405 | ghes_copy_tofrom_phys(estatus, buf_paddr, |
| 406 | sizeof(estatus->block_status), 0, |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 407 | fixmap_idx); |
James Morse | 06ddead | 2019-01-29 18:48:46 +0000 | [diff] [blame] | 408 | |
| 409 | /* |
| 410 | * GHESv2 type HEST entries introduce support for error acknowledgment, |
| 411 | * so only acknowledge the error if this support is present. |
| 412 | */ |
| 413 | if (is_hest_type_generic_v2(ghes)) |
| 414 | ghes_ack_error(ghes->generic_v2); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 415 | } |
| 416 | |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 417 | static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 418 | { |
| 419 | #ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE |
| 420 | unsigned long pfn; |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 421 | int flags = -1; |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 422 | int sec_sev = ghes_severity(gdata->error_severity); |
Tyler Baicar | bbcc2e7 | 2017-06-21 12:17:05 -0600 | [diff] [blame] | 423 | struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 424 | |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 425 | if (!(mem_err->validation_bits & CPER_MEM_VALID_PA)) |
| 426 | return; |
| 427 | |
| 428 | pfn = mem_err->physical_addr >> PAGE_SHIFT; |
| 429 | if (!pfn_valid(pfn)) { |
| 430 | pr_warn_ratelimited(FW_WARN GHES_PFX |
| 431 | "Invalid address in generic error data: %#llx\n", |
| 432 | mem_err->physical_addr); |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | /* iff following two events can be handled properly by now */ |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 437 | if (sec_sev == GHES_SEV_CORRECTED && |
Chen, Gong | ca104ed | 2013-11-25 02:15:01 -0500 | [diff] [blame] | 438 | (gdata->flags & CPER_SEC_ERROR_THRESHOLD_EXCEEDED)) |
| 439 | flags = MF_SOFT_OFFLINE; |
| 440 | if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE) |
| 441 | flags = 0; |
| 442 | |
| 443 | if (flags != -1) |
Eric W. Biederman | 83b5753 | 2017-07-09 18:14:01 -0500 | [diff] [blame] | 444 | memory_failure_queue(pfn, flags); |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 445 | #endif |
| 446 | } |
| 447 | |
Tyler Baicar | 9852ce9 | 2017-11-28 16:48:09 -0500 | [diff] [blame] | 448 | /* |
| 449 | * PCIe AER errors need to be sent to the AER driver for reporting and |
| 450 | * recovery. The GHES severities map to the following AER severities and |
| 451 | * require the following handling: |
| 452 | * |
| 453 | * GHES_SEV_CORRECTABLE -> AER_CORRECTABLE |
| 454 | * These need to be reported by the AER driver but no recovery is |
| 455 | * necessary. |
| 456 | * GHES_SEV_RECOVERABLE -> AER_NONFATAL |
| 457 | * GHES_SEV_RECOVERABLE && CPER_SEC_RESET -> AER_FATAL |
| 458 | * These both need to be reported and recovered from by the AER driver. |
| 459 | * GHES_SEV_PANIC does not make it to this handling since the kernel must |
| 460 | * panic. |
| 461 | */ |
| 462 | static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) |
Tyler Baicar | 3c5b977f | 2017-11-28 16:48:08 -0500 | [diff] [blame] | 463 | { |
| 464 | #ifdef CONFIG_ACPI_APEI_PCIEAER |
| 465 | struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata); |
| 466 | |
Tyler Baicar | 9852ce9 | 2017-11-28 16:48:09 -0500 | [diff] [blame] | 467 | if (pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID && |
Tyler Baicar | 3c5b977f | 2017-11-28 16:48:08 -0500 | [diff] [blame] | 468 | pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) { |
| 469 | unsigned int devfn; |
| 470 | int aer_severity; |
| 471 | |
| 472 | devfn = PCI_DEVFN(pcie_err->device_id.device, |
| 473 | pcie_err->device_id.function); |
| 474 | aer_severity = cper_severity_to_aer(gdata->error_severity); |
| 475 | |
| 476 | /* |
| 477 | * If firmware reset the component to contain |
| 478 | * the error, we must reinitialize it before |
| 479 | * use, so treat it as a fatal AER error. |
| 480 | */ |
| 481 | if (gdata->flags & CPER_SEC_RESET) |
| 482 | aer_severity = AER_FATAL; |
| 483 | |
| 484 | aer_recover_queue(pcie_err->device_id.segment, |
| 485 | pcie_err->device_id.bus, |
| 486 | devfn, aer_severity, |
| 487 | (struct aer_capability_regs *) |
| 488 | pcie_err->aer_info); |
| 489 | } |
| 490 | #endif |
| 491 | } |
| 492 | |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 493 | static void ghes_do_proc(struct ghes *ghes, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 494 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 495 | { |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 496 | int sev, sec_sev; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 497 | struct acpi_hest_generic_data *gdata; |
Andy Shevchenko | 5b53696 | 2017-06-05 19:40:43 +0300 | [diff] [blame] | 498 | guid_t *sec_type; |
Andy Shevchenko | bb100b6 | 2019-07-17 13:55:43 +0300 | [diff] [blame] | 499 | const guid_t *fru_id = &guid_null; |
Tyler Baicar | 297b64c | 2017-06-21 12:17:12 -0600 | [diff] [blame] | 500 | char *fru_text = ""; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 501 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 502 | sev = ghes_severity(estatus->error_severity); |
| 503 | apei_estatus_for_each_section(estatus, gdata) { |
Andy Shevchenko | 5b53696 | 2017-06-05 19:40:43 +0300 | [diff] [blame] | 504 | sec_type = (guid_t *)gdata->section_type; |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 505 | sec_sev = ghes_severity(gdata->error_severity); |
Tyler Baicar | 297b64c | 2017-06-21 12:17:12 -0600 | [diff] [blame] | 506 | if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID) |
| 507 | fru_id = (guid_t *)gdata->fru_id; |
| 508 | |
| 509 | if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT) |
| 510 | fru_text = gdata->fru_text; |
| 511 | |
Andy Shevchenko | 5b53696 | 2017-06-05 19:40:43 +0300 | [diff] [blame] | 512 | if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) { |
Tyler Baicar | bbcc2e7 | 2017-06-21 12:17:05 -0600 | [diff] [blame] | 513 | struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); |
| 514 | |
Alexandru Gagniuc | 305d0e0 | 2018-04-30 16:33:50 -0500 | [diff] [blame] | 515 | ghes_edac_report_mem_error(sev, mem_err); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 516 | |
Tomasz Nowicki | 9dae3d0 | 2014-07-22 11:20:11 +0200 | [diff] [blame] | 517 | arch_apei_report_mem_error(sev, mem_err); |
Naveen N. Rao | cf870c7 | 2013-07-10 14:57:01 +0530 | [diff] [blame] | 518 | ghes_handle_memory_failure(gdata, sev); |
Huang Ying | ba61ca4 | 2011-07-13 13:14:28 +0800 | [diff] [blame] | 519 | } |
Andy Shevchenko | 5b53696 | 2017-06-05 19:40:43 +0300 | [diff] [blame] | 520 | else if (guid_equal(sec_type, &CPER_SEC_PCIE)) { |
Tyler Baicar | 9852ce9 | 2017-11-28 16:48:09 -0500 | [diff] [blame] | 521 | ghes_handle_aer(gdata); |
Huang Ying | a654e5e | 2011-12-08 11:25:41 +0800 | [diff] [blame] | 522 | } |
Tyler Baicar | e9279e8 | 2017-06-21 12:17:13 -0600 | [diff] [blame] | 523 | else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) { |
| 524 | struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); |
| 525 | |
| 526 | log_arm_hw_error(err); |
| 527 | } else { |
Tyler Baicar | 297b64c | 2017-06-21 12:17:12 -0600 | [diff] [blame] | 528 | void *err = acpi_hest_get_payload(gdata); |
| 529 | |
| 530 | log_non_standard_event(sec_type, fru_id, fru_text, |
| 531 | sec_sev, err, |
| 532 | gdata->error_data_length); |
| 533 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 534 | } |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 535 | } |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 536 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 537 | static void __ghes_print_estatus(const char *pfx, |
| 538 | const struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 539 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 540 | { |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 541 | static atomic_t seqno; |
| 542 | unsigned int curr_seqno; |
| 543 | char pfx_seq[64]; |
| 544 | |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 545 | if (pfx == NULL) { |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 546 | if (ghes_severity(estatus->error_severity) <= |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 547 | GHES_SEV_CORRECTED) |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 548 | pfx = KERN_WARNING; |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 549 | else |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 550 | pfx = KERN_ERR; |
Huang Ying | 32c361f | 2010-12-07 10:22:31 +0800 | [diff] [blame] | 551 | } |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 552 | curr_seqno = atomic_inc_return(&seqno); |
| 553 | snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno); |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 554 | printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n", |
Huang Ying | 5ba82ab | 2011-12-08 11:25:44 +0800 | [diff] [blame] | 555 | pfx_seq, generic->header.source_id); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 556 | cper_estatus_print(pfx_seq, estatus); |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 557 | } |
| 558 | |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 559 | static int ghes_print_estatus(const char *pfx, |
| 560 | const struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 561 | const struct acpi_hest_generic_status *estatus) |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 562 | { |
| 563 | /* Not more than 2 messages every 5 seconds */ |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 564 | static DEFINE_RATELIMIT_STATE(ratelimit_corrected, 5*HZ, 2); |
| 565 | static DEFINE_RATELIMIT_STATE(ratelimit_uncorrected, 5*HZ, 2); |
| 566 | struct ratelimit_state *ratelimit; |
Huang Ying | 5588340 | 2011-07-13 13:14:15 +0800 | [diff] [blame] | 567 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 568 | if (ghes_severity(estatus->error_severity) <= GHES_SEV_CORRECTED) |
| 569 | ratelimit = &ratelimit_corrected; |
| 570 | else |
| 571 | ratelimit = &ratelimit_uncorrected; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 572 | if (__ratelimit(ratelimit)) { |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 573 | __ghes_print_estatus(pfx, generic, estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 574 | return 1; |
| 575 | } |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * GHES error status reporting throttle, to report more kinds of |
| 581 | * errors, instead of just most frequently occurred errors. |
| 582 | */ |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 583 | static int ghes_estatus_cached(struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 584 | { |
| 585 | u32 len; |
| 586 | int i, cached = 0; |
| 587 | unsigned long long now; |
| 588 | struct ghes_estatus_cache *cache; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 589 | struct acpi_hest_generic_status *cache_estatus; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 590 | |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 591 | len = cper_estatus_len(estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 592 | rcu_read_lock(); |
| 593 | for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) { |
| 594 | cache = rcu_dereference(ghes_estatus_caches[i]); |
| 595 | if (cache == NULL) |
| 596 | continue; |
| 597 | if (len != cache->estatus_len) |
| 598 | continue; |
| 599 | cache_estatus = GHES_ESTATUS_FROM_CACHE(cache); |
| 600 | if (memcmp(estatus, cache_estatus, len)) |
| 601 | continue; |
| 602 | atomic_inc(&cache->count); |
| 603 | now = sched_clock(); |
| 604 | if (now - cache->time_in < GHES_ESTATUS_IN_CACHE_MAX_NSEC) |
| 605 | cached = 1; |
| 606 | break; |
| 607 | } |
| 608 | rcu_read_unlock(); |
| 609 | return cached; |
| 610 | } |
| 611 | |
| 612 | static struct ghes_estatus_cache *ghes_estatus_cache_alloc( |
| 613 | struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 614 | struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 615 | { |
| 616 | int alloced; |
| 617 | u32 len, cache_len; |
| 618 | struct ghes_estatus_cache *cache; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 619 | struct acpi_hest_generic_status *cache_estatus; |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 620 | |
| 621 | alloced = atomic_add_return(1, &ghes_estatus_cache_alloced); |
| 622 | if (alloced > GHES_ESTATUS_CACHE_ALLOCED_MAX) { |
| 623 | atomic_dec(&ghes_estatus_cache_alloced); |
| 624 | return NULL; |
| 625 | } |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 626 | len = cper_estatus_len(estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 627 | cache_len = GHES_ESTATUS_CACHE_LEN(len); |
| 628 | cache = (void *)gen_pool_alloc(ghes_estatus_pool, cache_len); |
| 629 | if (!cache) { |
| 630 | atomic_dec(&ghes_estatus_cache_alloced); |
| 631 | return NULL; |
| 632 | } |
| 633 | cache_estatus = GHES_ESTATUS_FROM_CACHE(cache); |
| 634 | memcpy(cache_estatus, estatus, len); |
| 635 | cache->estatus_len = len; |
| 636 | atomic_set(&cache->count, 0); |
| 637 | cache->generic = generic; |
| 638 | cache->time_in = sched_clock(); |
| 639 | return cache; |
| 640 | } |
| 641 | |
| 642 | static void ghes_estatus_cache_free(struct ghes_estatus_cache *cache) |
| 643 | { |
| 644 | u32 len; |
| 645 | |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 646 | len = cper_estatus_len(GHES_ESTATUS_FROM_CACHE(cache)); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 647 | len = GHES_ESTATUS_CACHE_LEN(len); |
| 648 | gen_pool_free(ghes_estatus_pool, (unsigned long)cache, len); |
| 649 | atomic_dec(&ghes_estatus_cache_alloced); |
| 650 | } |
| 651 | |
| 652 | static void ghes_estatus_cache_rcu_free(struct rcu_head *head) |
| 653 | { |
| 654 | struct ghes_estatus_cache *cache; |
| 655 | |
| 656 | cache = container_of(head, struct ghes_estatus_cache, rcu); |
| 657 | ghes_estatus_cache_free(cache); |
| 658 | } |
| 659 | |
| 660 | static void ghes_estatus_cache_add( |
| 661 | struct acpi_hest_generic *generic, |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 662 | struct acpi_hest_generic_status *estatus) |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 663 | { |
| 664 | int i, slot = -1, count; |
| 665 | unsigned long long now, duration, period, max_period = 0; |
| 666 | struct ghes_estatus_cache *cache, *slot_cache = NULL, *new_cache; |
| 667 | |
| 668 | new_cache = ghes_estatus_cache_alloc(generic, estatus); |
| 669 | if (new_cache == NULL) |
| 670 | return; |
| 671 | rcu_read_lock(); |
| 672 | now = sched_clock(); |
| 673 | for (i = 0; i < GHES_ESTATUS_CACHES_SIZE; i++) { |
| 674 | cache = rcu_dereference(ghes_estatus_caches[i]); |
| 675 | if (cache == NULL) { |
| 676 | slot = i; |
| 677 | slot_cache = NULL; |
| 678 | break; |
| 679 | } |
| 680 | duration = now - cache->time_in; |
| 681 | if (duration >= GHES_ESTATUS_IN_CACHE_MAX_NSEC) { |
| 682 | slot = i; |
| 683 | slot_cache = cache; |
| 684 | break; |
| 685 | } |
| 686 | count = atomic_read(&cache->count); |
Len Brown | 70cb6e1 | 2011-08-02 18:00:21 -0400 | [diff] [blame] | 687 | period = duration; |
| 688 | do_div(period, (count + 1)); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 689 | if (period > max_period) { |
| 690 | max_period = period; |
| 691 | slot = i; |
| 692 | slot_cache = cache; |
| 693 | } |
| 694 | } |
| 695 | /* new_cache must be put into array after its contents are written */ |
| 696 | smp_wmb(); |
| 697 | if (slot != -1 && cmpxchg(ghes_estatus_caches + slot, |
| 698 | slot_cache, new_cache) == slot_cache) { |
| 699 | if (slot_cache) |
| 700 | call_rcu(&slot_cache->rcu, ghes_estatus_cache_rcu_free); |
| 701 | } else |
| 702 | ghes_estatus_cache_free(new_cache); |
| 703 | rcu_read_unlock(); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 704 | } |
| 705 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 706 | static void __ghes_panic(struct ghes *ghes, |
| 707 | struct acpi_hest_generic_status *estatus, |
| 708 | u64 buf_paddr, enum fixed_addresses fixmap_idx) |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 709 | { |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 710 | __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus); |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 711 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 712 | ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); |
Lenny Szubowicz | 98cff8b | 2018-12-19 11:50:52 -0500 | [diff] [blame] | 713 | |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 714 | /* reboot to log the error! */ |
| 715 | if (!panic_timeout) |
| 716 | panic_timeout = ghes_panic_timeout; |
| 717 | panic("Fatal hardware error!"); |
| 718 | } |
| 719 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 720 | static int ghes_proc(struct ghes *ghes) |
| 721 | { |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 722 | struct acpi_hest_generic_status *estatus = ghes->estatus; |
James Morse | eeb2555 | 2019-01-29 18:48:42 +0000 | [diff] [blame] | 723 | u64 buf_paddr; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 724 | int rc; |
| 725 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 726 | rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 727 | if (rc) |
| 728 | goto out; |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 729 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 730 | if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC) |
| 731 | __ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); |
Jonathan (Zhixiong) Zhang | 2fb5853 | 2017-06-21 12:17:10 -0600 | [diff] [blame] | 732 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 733 | if (!ghes_estatus_cached(estatus)) { |
| 734 | if (ghes_print_estatus(NULL, ghes->generic, estatus)) |
| 735 | ghes_estatus_cache_add(ghes->generic, estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 736 | } |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 737 | ghes_do_proc(ghes, estatus); |
Tyler Baicar | 42aa560 | 2017-06-21 12:17:04 -0600 | [diff] [blame] | 738 | |
Tyler Baicar | aaf2c2f | 2017-08-28 10:53:41 -0600 | [diff] [blame] | 739 | out: |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 740 | ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); |
Tyler Baicar | aaf2c2f | 2017-08-28 10:53:41 -0600 | [diff] [blame] | 741 | |
Punit Agrawal | 806487a | 2016-10-18 17:07:19 +0100 | [diff] [blame] | 742 | return rc; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 743 | } |
| 744 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 745 | static void ghes_add_timer(struct ghes *ghes) |
| 746 | { |
| 747 | struct acpi_hest_generic *g = ghes->generic; |
| 748 | unsigned long expire; |
| 749 | |
| 750 | if (!g->notify.poll_interval) { |
Kefeng Wang | 933ca4e | 2019-10-18 11:18:25 +0800 | [diff] [blame] | 751 | pr_warn(FW_WARN GHES_PFX "Poll interval is 0 for generic hardware error source: %d, disabled.\n", |
| 752 | g->header.source_id); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 753 | return; |
| 754 | } |
| 755 | expire = jiffies + msecs_to_jiffies(g->notify.poll_interval); |
| 756 | ghes->timer.expires = round_jiffies_relative(expire); |
| 757 | add_timer(&ghes->timer); |
| 758 | } |
| 759 | |
Kees Cook | d527200 | 2017-10-12 16:19:27 -0700 | [diff] [blame] | 760 | static void ghes_poll_func(struct timer_list *t) |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 761 | { |
Kees Cook | d527200 | 2017-10-12 16:19:27 -0700 | [diff] [blame] | 762 | struct ghes *ghes = from_timer(ghes, t, timer); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 763 | unsigned long flags; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 764 | |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 765 | spin_lock_irqsave(&ghes_notify_lock_irq, flags); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 766 | ghes_proc(ghes); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 767 | spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 768 | if (!(ghes->flags & GHES_EXITING)) |
| 769 | ghes_add_timer(ghes); |
| 770 | } |
| 771 | |
| 772 | static irqreturn_t ghes_irq_func(int irq, void *data) |
| 773 | { |
| 774 | struct ghes *ghes = data; |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 775 | unsigned long flags; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 776 | int rc; |
| 777 | |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 778 | spin_lock_irqsave(&ghes_notify_lock_irq, flags); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 779 | rc = ghes_proc(ghes); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 780 | spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 781 | if (rc) |
| 782 | return IRQ_NONE; |
| 783 | |
| 784 | return IRQ_HANDLED; |
| 785 | } |
| 786 | |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 787 | static int ghes_notify_hed(struct notifier_block *this, unsigned long event, |
| 788 | void *data) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 789 | { |
| 790 | struct ghes *ghes; |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 791 | unsigned long flags; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 792 | int ret = NOTIFY_DONE; |
| 793 | |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 794 | spin_lock_irqsave(&ghes_notify_lock_irq, flags); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 795 | rcu_read_lock(); |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 796 | list_for_each_entry_rcu(ghes, &ghes_hed, list) { |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 797 | if (!ghes_proc(ghes)) |
| 798 | ret = NOTIFY_OK; |
| 799 | } |
| 800 | rcu_read_unlock(); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 801 | spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 802 | |
| 803 | return ret; |
| 804 | } |
| 805 | |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 806 | static struct notifier_block ghes_notifier_hed = { |
| 807 | .notifier_call = ghes_notify_hed, |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 808 | }; |
| 809 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 810 | /* |
James Morse | 9c9d080 | 2019-01-29 18:48:47 +0000 | [diff] [blame] | 811 | * Handlers for CPER records may not be NMI safe. For example, |
| 812 | * memory_failure_queue() takes spinlocks and calls schedule_work_on(). |
| 813 | * In any NMI-like handler, memory from ghes_estatus_pool is used to save |
| 814 | * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes |
| 815 | * ghes_proc_in_irq() to run in IRQ context where each estatus in |
| 816 | * ghes_estatus_llist is processed. |
| 817 | * |
| 818 | * Memory from the ghes_estatus_pool is also used with the ghes_estatus_cache |
| 819 | * to suppress frequent messages. |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 820 | */ |
| 821 | static struct llist_head ghes_estatus_llist; |
| 822 | static struct irq_work ghes_proc_irq_work; |
| 823 | |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 824 | static void ghes_proc_in_irq(struct irq_work *irq_work) |
| 825 | { |
| 826 | struct llist_node *llnode, *next; |
| 827 | struct ghes_estatus_node *estatus_node; |
| 828 | struct acpi_hest_generic *generic; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 829 | struct acpi_hest_generic_status *estatus; |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 830 | u32 len, node_len; |
| 831 | |
| 832 | llnode = llist_del_all(&ghes_estatus_llist); |
| 833 | /* |
| 834 | * Because the time order of estatus in list is reversed, |
| 835 | * revert it back to proper order. |
| 836 | */ |
Chen, Gong | 8d21d4c | 2014-07-28 02:50:59 -0400 | [diff] [blame] | 837 | llnode = llist_reverse_order(llnode); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 838 | while (llnode) { |
| 839 | next = llnode->next; |
| 840 | estatus_node = llist_entry(llnode, struct ghes_estatus_node, |
| 841 | llnode); |
| 842 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
Chen, Gong | 88f074f | 2013-10-18 14:28:59 -0700 | [diff] [blame] | 843 | len = cper_estatus_len(estatus); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 844 | node_len = GHES_ESTATUS_NODE_LEN(len); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 845 | ghes_do_proc(estatus_node->ghes, estatus); |
Huang Ying | 152cef4 | 2011-07-13 13:14:26 +0800 | [diff] [blame] | 846 | if (!ghes_estatus_cached(estatus)) { |
| 847 | generic = estatus_node->generic; |
| 848 | if (ghes_print_estatus(NULL, generic, estatus)) |
| 849 | ghes_estatus_cache_add(generic, estatus); |
| 850 | } |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 851 | gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, |
| 852 | node_len); |
| 853 | llnode = next; |
| 854 | } |
| 855 | } |
| 856 | |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 857 | static void ghes_print_queued_estatus(void) |
| 858 | { |
| 859 | struct llist_node *llnode; |
| 860 | struct ghes_estatus_node *estatus_node; |
| 861 | struct acpi_hest_generic *generic; |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 862 | struct acpi_hest_generic_status *estatus; |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 863 | |
| 864 | llnode = llist_del_all(&ghes_estatus_llist); |
| 865 | /* |
| 866 | * Because the time order of estatus in list is reversed, |
| 867 | * revert it back to proper order. |
| 868 | */ |
Chen, Gong | 8d21d4c | 2014-07-28 02:50:59 -0400 | [diff] [blame] | 869 | llnode = llist_reverse_order(llnode); |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 870 | while (llnode) { |
| 871 | estatus_node = llist_entry(llnode, struct ghes_estatus_node, |
| 872 | llnode); |
| 873 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
Huang Ying | 46d12f0 | 2011-12-08 11:25:45 +0800 | [diff] [blame] | 874 | generic = estatus_node->generic; |
| 875 | ghes_print_estatus(NULL, generic, estatus); |
| 876 | llnode = llnode->next; |
| 877 | } |
| 878 | } |
| 879 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 880 | static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, |
| 881 | enum fixed_addresses fixmap_idx) |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 882 | { |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 883 | struct acpi_hest_generic_status *estatus, tmp_header; |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 884 | struct ghes_estatus_node *estatus_node; |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 885 | u32 len, node_len; |
| 886 | u64 buf_paddr; |
| 887 | int sev, rc; |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 888 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 889 | if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG)) |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 890 | return -EOPNOTSUPP; |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 891 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 892 | rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx); |
| 893 | if (rc) { |
| 894 | ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); |
| 895 | return rc; |
| 896 | } |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 897 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 898 | rc = __ghes_check_estatus(ghes, &tmp_header); |
| 899 | if (rc) { |
| 900 | ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); |
| 901 | return rc; |
| 902 | } |
| 903 | |
| 904 | len = cper_estatus_len(&tmp_header); |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 905 | node_len = GHES_ESTATUS_NODE_LEN(len); |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 906 | estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); |
| 907 | if (!estatus_node) |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 908 | return -ENOMEM; |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 909 | |
| 910 | estatus_node->ghes = ghes; |
| 911 | estatus_node->generic = ghes->generic; |
| 912 | estatus = GHES_ESTATUS_FROM_NODE(estatus_node); |
Borislav Petkov | 1156849 | 2015-03-18 09:41:35 +0100 | [diff] [blame] | 913 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 914 | if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) { |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 915 | ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 916 | rc = -ENOENT; |
| 917 | goto no_work; |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 918 | } |
| 919 | |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 920 | sev = ghes_severity(estatus->error_severity); |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 921 | if (sev >= GHES_SEV_PANIC) { |
| 922 | ghes_print_queued_estatus(); |
James Morse | f2a7e05 | 2019-01-29 18:48:53 +0000 | [diff] [blame] | 923 | __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx); |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 924 | } |
| 925 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 926 | ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 927 | |
James Morse | d9f608d | 2019-01-29 18:48:56 +0000 | [diff] [blame] | 928 | /* This error has been reported before, don't process it again. */ |
| 929 | if (ghes_estatus_cached(estatus)) |
| 930 | goto no_work; |
| 931 | |
| 932 | llist_add(&estatus_node->llnode, &ghes_estatus_llist); |
| 933 | |
| 934 | return rc; |
| 935 | |
| 936 | no_work: |
| 937 | gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, |
| 938 | node_len); |
| 939 | |
| 940 | return rc; |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 941 | } |
| 942 | |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 943 | static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list, |
| 944 | enum fixed_addresses fixmap_idx) |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 945 | { |
| 946 | int ret = -ENOENT; |
Borislav Petkov | 6169ddf | 2015-03-18 09:55:21 +0100 | [diff] [blame] | 947 | struct ghes *ghes; |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 948 | |
| 949 | rcu_read_lock(); |
| 950 | list_for_each_entry_rcu(ghes, rcu_list, list) { |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 951 | if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 952 | ret = 0; |
| 953 | } |
| 954 | rcu_read_unlock(); |
| 955 | |
| 956 | if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret) |
| 957 | irq_work_queue(&ghes_proc_irq_work); |
| 958 | |
| 959 | return ret; |
| 960 | } |
James Morse | 9c9d080 | 2019-01-29 18:48:47 +0000 | [diff] [blame] | 961 | |
| 962 | #ifdef CONFIG_ACPI_APEI_SEA |
| 963 | static LIST_HEAD(ghes_sea); |
| 964 | |
| 965 | /* |
| 966 | * Return 0 only if one of the SEA error sources successfully reported an error |
| 967 | * record sent from the firmware. |
| 968 | */ |
| 969 | int ghes_notify_sea(void) |
| 970 | { |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 971 | static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea); |
| 972 | int rv; |
| 973 | |
| 974 | raw_spin_lock(&ghes_notify_lock_sea); |
James Morse | b972d2e | 2019-01-29 18:48:57 +0000 | [diff] [blame] | 975 | rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 976 | raw_spin_unlock(&ghes_notify_lock_sea); |
| 977 | |
| 978 | return rv; |
James Morse | 9c9d080 | 2019-01-29 18:48:47 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static void ghes_sea_add(struct ghes *ghes) |
| 982 | { |
| 983 | mutex_lock(&ghes_list_mutex); |
| 984 | list_add_rcu(&ghes->list, &ghes_sea); |
| 985 | mutex_unlock(&ghes_list_mutex); |
| 986 | } |
| 987 | |
| 988 | static void ghes_sea_remove(struct ghes *ghes) |
| 989 | { |
| 990 | mutex_lock(&ghes_list_mutex); |
| 991 | list_del_rcu(&ghes->list); |
| 992 | mutex_unlock(&ghes_list_mutex); |
| 993 | synchronize_rcu(); |
| 994 | } |
| 995 | #else /* CONFIG_ACPI_APEI_SEA */ |
| 996 | static inline void ghes_sea_add(struct ghes *ghes) { } |
| 997 | static inline void ghes_sea_remove(struct ghes *ghes) { } |
| 998 | #endif /* CONFIG_ACPI_APEI_SEA */ |
| 999 | |
| 1000 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 1001 | /* |
| 1002 | * NMI may be triggered on any CPU, so ghes_in_nmi is used for |
| 1003 | * having only one concurrent reader. |
| 1004 | */ |
| 1005 | static atomic_t ghes_in_nmi = ATOMIC_INIT(0); |
| 1006 | |
| 1007 | static LIST_HEAD(ghes_nmi); |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 1008 | |
| 1009 | static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) |
| 1010 | { |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1011 | static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi); |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 1012 | int ret = NMI_DONE; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1013 | |
Jiri Kosina | 6fe9e7c | 2015-03-27 10:05:00 +0100 | [diff] [blame] | 1014 | if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) |
| 1015 | return ret; |
| 1016 | |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1017 | raw_spin_lock(&ghes_notify_lock_nmi); |
James Morse | b484079 | 2019-01-29 18:48:52 +0000 | [diff] [blame] | 1018 | if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI)) |
James Morse | ee2eb3d | 2019-01-29 18:48:45 +0000 | [diff] [blame] | 1019 | ret = NMI_HANDLED; |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1020 | raw_spin_unlock(&ghes_notify_lock_nmi); |
Borislav Petkov | 6169ddf | 2015-03-18 09:55:21 +0100 | [diff] [blame] | 1021 | |
Jiri Kosina | 6fe9e7c | 2015-03-27 10:05:00 +0100 | [diff] [blame] | 1022 | atomic_dec(&ghes_in_nmi); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1023 | return ret; |
| 1024 | } |
| 1025 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1026 | static void ghes_nmi_add(struct ghes *ghes) |
| 1027 | { |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1028 | mutex_lock(&ghes_list_mutex); |
| 1029 | if (list_empty(&ghes_nmi)) |
| 1030 | register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes"); |
| 1031 | list_add_rcu(&ghes->list, &ghes_nmi); |
| 1032 | mutex_unlock(&ghes_list_mutex); |
| 1033 | } |
| 1034 | |
| 1035 | static void ghes_nmi_remove(struct ghes *ghes) |
| 1036 | { |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1037 | mutex_lock(&ghes_list_mutex); |
| 1038 | list_del_rcu(&ghes->list); |
| 1039 | if (list_empty(&ghes_nmi)) |
| 1040 | unregister_nmi_handler(NMI_LOCAL, "ghes"); |
| 1041 | mutex_unlock(&ghes_list_mutex); |
| 1042 | /* |
| 1043 | * To synchronize with NMI handler, ghes can only be |
| 1044 | * freed after NMI handler finishes. |
| 1045 | */ |
| 1046 | synchronize_rcu(); |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1047 | } |
James Morse | 255097c | 2019-01-29 18:48:48 +0000 | [diff] [blame] | 1048 | #else /* CONFIG_HAVE_ACPI_APEI_NMI */ |
| 1049 | static inline void ghes_nmi_add(struct ghes *ghes) { } |
| 1050 | static inline void ghes_nmi_remove(struct ghes *ghes) { } |
| 1051 | #endif /* CONFIG_HAVE_ACPI_APEI_NMI */ |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1052 | |
| 1053 | static void ghes_nmi_init_cxt(void) |
| 1054 | { |
| 1055 | init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq); |
| 1056 | } |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1057 | |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 1058 | static int __ghes_sdei_callback(struct ghes *ghes, |
| 1059 | enum fixed_addresses fixmap_idx) |
| 1060 | { |
| 1061 | if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) { |
| 1062 | irq_work_queue(&ghes_proc_irq_work); |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
| 1067 | return -ENOENT; |
| 1068 | } |
| 1069 | |
| 1070 | static int ghes_sdei_normal_callback(u32 event_num, struct pt_regs *regs, |
| 1071 | void *arg) |
| 1072 | { |
| 1073 | static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal); |
| 1074 | struct ghes *ghes = arg; |
| 1075 | int err; |
| 1076 | |
| 1077 | raw_spin_lock(&ghes_notify_lock_sdei_normal); |
| 1078 | err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_NORMAL); |
| 1079 | raw_spin_unlock(&ghes_notify_lock_sdei_normal); |
| 1080 | |
| 1081 | return err; |
| 1082 | } |
| 1083 | |
| 1084 | static int ghes_sdei_critical_callback(u32 event_num, struct pt_regs *regs, |
| 1085 | void *arg) |
| 1086 | { |
| 1087 | static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical); |
| 1088 | struct ghes *ghes = arg; |
| 1089 | int err; |
| 1090 | |
| 1091 | raw_spin_lock(&ghes_notify_lock_sdei_critical); |
| 1092 | err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_CRITICAL); |
| 1093 | raw_spin_unlock(&ghes_notify_lock_sdei_critical); |
| 1094 | |
| 1095 | return err; |
| 1096 | } |
| 1097 | |
| 1098 | static int apei_sdei_register_ghes(struct ghes *ghes) |
| 1099 | { |
| 1100 | if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) |
| 1101 | return -EOPNOTSUPP; |
| 1102 | |
| 1103 | return sdei_register_ghes(ghes, ghes_sdei_normal_callback, |
| 1104 | ghes_sdei_critical_callback); |
| 1105 | } |
| 1106 | |
| 1107 | static int apei_sdei_unregister_ghes(struct ghes *ghes) |
| 1108 | { |
| 1109 | if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) |
| 1110 | return -EOPNOTSUPP; |
| 1111 | |
| 1112 | return sdei_unregister_ghes(ghes); |
| 1113 | } |
| 1114 | |
Bill Pemberton | da095fd3 | 2012-11-19 13:22:46 -0500 | [diff] [blame] | 1115 | static int ghes_probe(struct platform_device *ghes_dev) |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1116 | { |
| 1117 | struct acpi_hest_generic *generic; |
| 1118 | struct ghes *ghes = NULL; |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1119 | unsigned long flags; |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1120 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1121 | int rc = -EINVAL; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1122 | |
Jin Dongming | 1dd6b20 | 2010-09-29 19:53:53 +0800 | [diff] [blame] | 1123 | generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1124 | if (!generic->enabled) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1125 | return -ENODEV; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1126 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1127 | switch (generic->notify.type) { |
| 1128 | case ACPI_HEST_NOTIFY_POLLED: |
| 1129 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 1130 | case ACPI_HEST_NOTIFY_SCI: |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1131 | case ACPI_HEST_NOTIFY_GSIV: |
| 1132 | case ACPI_HEST_NOTIFY_GPIO: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1133 | break; |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1134 | |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 1135 | case ACPI_HEST_NOTIFY_SEA: |
| 1136 | if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) { |
| 1137 | pr_warn(GHES_PFX "Generic hardware error source: %d notified via SEA is not supported\n", |
| 1138 | generic->header.source_id); |
| 1139 | rc = -ENOTSUPP; |
| 1140 | goto err; |
| 1141 | } |
| 1142 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1143 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1144 | if (!IS_ENABLED(CONFIG_HAVE_ACPI_APEI_NMI)) { |
| 1145 | pr_warn(GHES_PFX "Generic hardware error source: %d notified via NMI interrupt is not supported!\n", |
| 1146 | generic->header.source_id); |
| 1147 | goto err; |
| 1148 | } |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1149 | break; |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 1150 | case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: |
| 1151 | if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) { |
| 1152 | pr_warn(GHES_PFX "Generic hardware error source: %d notified via SDE Interface is not supported!\n", |
| 1153 | generic->header.source_id); |
| 1154 | goto err; |
| 1155 | } |
| 1156 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1157 | case ACPI_HEST_NOTIFY_LOCAL: |
Kefeng Wang | 933ca4e | 2019-10-18 11:18:25 +0800 | [diff] [blame] | 1158 | pr_warn(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n", |
| 1159 | generic->header.source_id); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1160 | goto err; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1161 | default: |
Kefeng Wang | 933ca4e | 2019-10-18 11:18:25 +0800 | [diff] [blame] | 1162 | pr_warn(FW_WARN GHES_PFX "Unknown notification type: %u for generic hardware error source: %d\n", |
| 1163 | generic->notify.type, generic->header.source_id); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1164 | goto err; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1165 | } |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1166 | |
| 1167 | rc = -EIO; |
| 1168 | if (generic->error_block_length < |
Lv Zheng | 0a00fd5 | 2014-06-03 16:32:53 +0800 | [diff] [blame] | 1169 | sizeof(struct acpi_hest_generic_status)) { |
Kefeng Wang | 933ca4e | 2019-10-18 11:18:25 +0800 | [diff] [blame] | 1170 | pr_warn(FW_BUG GHES_PFX "Invalid error block length: %u for generic hardware error source: %d\n", |
| 1171 | generic->error_block_length, generic->header.source_id); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1172 | goto err; |
| 1173 | } |
| 1174 | ghes = ghes_new(generic); |
| 1175 | if (IS_ERR(ghes)) { |
| 1176 | rc = PTR_ERR(ghes); |
| 1177 | ghes = NULL; |
| 1178 | goto err; |
| 1179 | } |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1180 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1181 | switch (generic->notify.type) { |
| 1182 | case ACPI_HEST_NOTIFY_POLLED: |
Bhaskar Upadhaya | cea79e7 | 2020-01-08 09:17:38 -0800 | [diff] [blame] | 1183 | timer_setup(&ghes->timer, ghes_poll_func, 0); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1184 | ghes_add_timer(ghes); |
| 1185 | break; |
| 1186 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 1187 | /* External interrupt vector is GSI */ |
Wei Yongjun | a98d4f6 | 2013-06-03 02:08:39 +0000 | [diff] [blame] | 1188 | rc = acpi_gsi_to_irq(generic->notify.vector, &ghes->irq); |
| 1189 | if (rc) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1190 | pr_err(GHES_PFX "Failed to map GSI to IRQ for generic hardware error source: %d\n", |
| 1191 | generic->header.source_id); |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 1192 | goto err; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1193 | } |
Loc Ho | bdb9458 | 2017-07-21 11:24:37 -0700 | [diff] [blame] | 1194 | rc = request_irq(ghes->irq, ghes_irq_func, IRQF_SHARED, |
| 1195 | "GHES IRQ", ghes); |
Wei Yongjun | a98d4f6 | 2013-06-03 02:08:39 +0000 | [diff] [blame] | 1196 | if (rc) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1197 | pr_err(GHES_PFX "Failed to register IRQ for generic hardware error source: %d\n", |
| 1198 | generic->header.source_id); |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 1199 | goto err; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1200 | } |
| 1201 | break; |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1202 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1203 | case ACPI_HEST_NOTIFY_SCI: |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1204 | case ACPI_HEST_NOTIFY_GSIV: |
| 1205 | case ACPI_HEST_NOTIFY_GPIO: |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1206 | mutex_lock(&ghes_list_mutex); |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1207 | if (list_empty(&ghes_hed)) |
| 1208 | register_acpi_hed_notifier(&ghes_notifier_hed); |
| 1209 | list_add_rcu(&ghes->list, &ghes_hed); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1210 | mutex_unlock(&ghes_list_mutex); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1211 | break; |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1212 | |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 1213 | case ACPI_HEST_NOTIFY_SEA: |
| 1214 | ghes_sea_add(ghes); |
| 1215 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1216 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1217 | ghes_nmi_add(ghes); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1218 | break; |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 1219 | case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: |
| 1220 | rc = apei_sdei_register_ghes(ghes); |
| 1221 | if (rc) |
| 1222 | goto err; |
| 1223 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1224 | default: |
| 1225 | BUG(); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1226 | } |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 1227 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1228 | platform_set_drvdata(ghes_dev, ghes); |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1229 | |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 1230 | ghes_edac_register(ghes, &ghes_dev->dev); |
| 1231 | |
Tyler Baicar | 77b246b | 2017-06-21 12:17:15 -0600 | [diff] [blame] | 1232 | /* Handle any pending errors right away */ |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1233 | spin_lock_irqsave(&ghes_notify_lock_irq, flags); |
Tyler Baicar | 77b246b | 2017-06-21 12:17:15 -0600 | [diff] [blame] | 1234 | ghes_proc(ghes); |
James Morse | 3b880cb | 2019-01-29 18:48:51 +0000 | [diff] [blame] | 1235 | spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); |
Tyler Baicar | 77b246b | 2017-06-21 12:17:15 -0600 | [diff] [blame] | 1236 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1237 | return 0; |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 1238 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1239 | err: |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1240 | if (ghes) { |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1241 | ghes_fini(ghes); |
| 1242 | kfree(ghes); |
| 1243 | } |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1244 | return rc; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Bill Pemberton | b59bc2f | 2012-11-21 23:13:09 +0100 | [diff] [blame] | 1247 | static int ghes_remove(struct platform_device *ghes_dev) |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1248 | { |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 1249 | int rc; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1250 | struct ghes *ghes; |
| 1251 | struct acpi_hest_generic *generic; |
| 1252 | |
| 1253 | ghes = platform_get_drvdata(ghes_dev); |
| 1254 | generic = ghes->generic; |
| 1255 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1256 | ghes->flags |= GHES_EXITING; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1257 | switch (generic->notify.type) { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1258 | case ACPI_HEST_NOTIFY_POLLED: |
| 1259 | del_timer_sync(&ghes->timer); |
| 1260 | break; |
| 1261 | case ACPI_HEST_NOTIFY_EXTERNAL: |
| 1262 | free_irq(ghes->irq, ghes); |
| 1263 | break; |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1264 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1265 | case ACPI_HEST_NOTIFY_SCI: |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1266 | case ACPI_HEST_NOTIFY_GSIV: |
| 1267 | case ACPI_HEST_NOTIFY_GPIO: |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1268 | mutex_lock(&ghes_list_mutex); |
| 1269 | list_del_rcu(&ghes->list); |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1270 | if (list_empty(&ghes_hed)) |
| 1271 | unregister_acpi_hed_notifier(&ghes_notifier_hed); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1272 | mutex_unlock(&ghes_list_mutex); |
James Morse | 7d64f82 | 2017-03-16 14:30:39 +0000 | [diff] [blame] | 1273 | synchronize_rcu(); |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1274 | break; |
Shiju Jose | 7bf130e | 2017-05-19 11:39:11 +0200 | [diff] [blame] | 1275 | |
Tyler Baicar | 7edda08 | 2017-06-21 12:17:09 -0600 | [diff] [blame] | 1276 | case ACPI_HEST_NOTIFY_SEA: |
| 1277 | ghes_sea_remove(ghes); |
| 1278 | break; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1279 | case ACPI_HEST_NOTIFY_NMI: |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1280 | ghes_nmi_remove(ghes); |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1281 | break; |
James Morse | f9f0539 | 2019-01-29 18:49:02 +0000 | [diff] [blame] | 1282 | case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: |
| 1283 | rc = apei_sdei_unregister_ghes(ghes); |
| 1284 | if (rc) |
| 1285 | return rc; |
| 1286 | break; |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1287 | default: |
| 1288 | BUG(); |
| 1289 | break; |
| 1290 | } |
| 1291 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1292 | ghes_fini(ghes); |
Mauro Carvalho Chehab | 2148054 | 2013-02-15 06:10:39 -0300 | [diff] [blame] | 1293 | |
| 1294 | ghes_edac_unregister(ghes); |
| 1295 | |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1296 | kfree(ghes); |
| 1297 | |
| 1298 | platform_set_drvdata(ghes_dev, NULL); |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | static struct platform_driver ghes_platform_driver = { |
| 1304 | .driver = { |
| 1305 | .name = "GHES", |
Huang Ying | 7ad6e94 | 2010-08-02 15:48:24 +0800 | [diff] [blame] | 1306 | }, |
| 1307 | .probe = ghes_probe, |
| 1308 | .remove = ghes_remove, |
| 1309 | }; |
| 1310 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1311 | static int __init ghes_init(void) |
| 1312 | { |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1313 | int rc; |
| 1314 | |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1315 | if (acpi_disabled) |
| 1316 | return -ENODEV; |
| 1317 | |
Punit Agrawal | e931d0d | 2017-08-29 14:20:20 +0100 | [diff] [blame] | 1318 | switch (hest_disable) { |
| 1319 | case HEST_NOT_FOUND: |
| 1320 | return -ENODEV; |
| 1321 | case HEST_DISABLED: |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1322 | pr_info(GHES_PFX "HEST is not enabled!\n"); |
| 1323 | return -EINVAL; |
Punit Agrawal | e931d0d | 2017-08-29 14:20:20 +0100 | [diff] [blame] | 1324 | default: |
| 1325 | break; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1326 | } |
| 1327 | |
Huang Ying | b6a9501 | 2011-07-13 13:14:19 +0800 | [diff] [blame] | 1328 | if (ghes_disable) { |
| 1329 | pr_info(GHES_PFX "GHES is not enabled!\n"); |
| 1330 | return -EINVAL; |
| 1331 | } |
| 1332 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 1333 | ghes_nmi_init_cxt(); |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1334 | |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1335 | rc = platform_driver_register(&ghes_platform_driver); |
| 1336 | if (rc) |
James Morse | e147133 | 2019-01-29 18:48:40 +0000 | [diff] [blame] | 1337 | goto err; |
Huang Ying | 67eb2e9 | 2011-07-13 13:14:25 +0800 | [diff] [blame] | 1338 | |
Huang Ying | 9fb0bfe | 2011-07-13 13:14:21 +0800 | [diff] [blame] | 1339 | rc = apei_osc_setup(); |
| 1340 | if (rc == 0 && osc_sb_apei_support_acked) |
| 1341 | pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit and WHEA _OSC.\n"); |
| 1342 | else if (rc == 0 && !osc_sb_apei_support_acked) |
| 1343 | pr_info(GHES_PFX "APEI firmware first mode is enabled by WHEA _OSC.\n"); |
| 1344 | else if (rc && osc_sb_apei_support_acked) |
| 1345 | pr_info(GHES_PFX "APEI firmware first mode is enabled by APEI bit.\n"); |
| 1346 | else |
| 1347 | pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); |
| 1348 | |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1349 | return 0; |
Huang Ying | 81e88fd | 2011-01-12 14:44:55 +0800 | [diff] [blame] | 1350 | err: |
| 1351 | return rc; |
Huang Ying | d334a49 | 2010-05-18 14:35:20 +0800 | [diff] [blame] | 1352 | } |
Paul Gortmaker | 020bf06 | 2016-02-15 00:27:50 -0500 | [diff] [blame] | 1353 | device_initcall(ghes_init); |