blob: ddecf25b5dd40766a75f74c39890dc52c4ece944 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Borislav Petkov09afc792019-04-20 22:06:43 +02002/*
3 * Copyright (c) 2017-2019 Borislav Petkov, SUSE Labs.
4 */
Borislav Petkov011d8262017-03-27 11:33:02 +02005#include <linux/mm.h>
6#include <linux/gfp.h>
Valdis Klētnieks0a54b802019-08-07 18:59:29 -04007#include <linux/ras.h>
Borislav Petkov011d8262017-03-27 11:33:02 +02008#include <linux/kernel.h>
Cong Wang0ade0b62019-04-16 14:33:51 -07009#include <linux/workqueue.h>
Borislav Petkov011d8262017-03-27 11:33:02 +020010
11#include <asm/mce.h>
12
13#include "debugfs.h"
14
15/*
16 * RAS Correctable Errors Collector
17 *
18 * This is a simple gadget which collects correctable errors and counts their
19 * occurrence per physical page address.
20 *
21 * We've opted for possibly the simplest data structure to collect those - an
22 * array of the size of a memory page. It stores 512 u64's with the following
23 * structure:
24 *
25 * [63 ... PFN ... 12 | 11 ... generation ... 10 | 9 ... count ... 0]
26 *
27 * The generation in the two highest order bits is two bits which are set to 11b
28 * on every insertion. During the course of each entry's existence, the
29 * generation field gets decremented during spring cleaning to 10b, then 01b and
30 * then 00b.
31 *
32 * This way we're employing the natural numeric ordering to make sure that newly
33 * inserted/touched elements have higher 12-bit counts (which we've manufactured)
34 * and thus iterating over the array initially won't kick out those elements
35 * which were inserted last.
36 *
37 * Spring cleaning is what we do when we reach a certain number CLEAN_ELEMS of
38 * elements entered into the array, during which, we're decaying all elements.
39 * If, after decay, an element gets inserted again, its generation is set to 11b
40 * to make sure it has higher numerical count than other, older elements and
41 * thus emulate an an LRU-like behavior when deleting elements to free up space
42 * in the page.
43 *
Borislav Petkovb8b5ca62019-04-20 21:30:11 +020044 * When an element reaches it's max count of action_threshold, we try to poison
45 * it by assuming that errors triggered action_threshold times in a single page
46 * are excessive and that page shouldn't be used anymore. action_threshold is
Borislav Petkov011d8262017-03-27 11:33:02 +020047 * initialized to COUNT_MASK which is the maximum.
48 *
49 * That error event entry causes cec_add_elem() to return !0 value and thus
50 * signal to its callers to log the error.
51 *
52 * To the question why we've chosen a page and moving elements around with
53 * memmove(), it is because it is a very simple structure to handle and max data
54 * movement is 4K which on highly optimized modern CPUs is almost unnoticeable.
55 * We wanted to avoid the pointer traversal of more complex structures like a
56 * linked list or some sort of a balancing search tree.
57 *
58 * Deleting an element takes O(n) but since it is only a single page, it should
59 * be fast enough and it shouldn't happen all too often depending on error
60 * patterns.
61 */
62
63#undef pr_fmt
64#define pr_fmt(fmt) "RAS: " fmt
65
66/*
67 * We use DECAY_BITS bits of PAGE_SHIFT bits for counting decay, i.e., how long
68 * elements have stayed in the array without having been accessed again.
69 */
70#define DECAY_BITS 2
71#define DECAY_MASK ((1ULL << DECAY_BITS) - 1)
72#define MAX_ELEMS (PAGE_SIZE / sizeof(u64))
73
74/*
75 * Threshold amount of inserted elements after which we start spring
76 * cleaning.
77 */
78#define CLEAN_ELEMS (MAX_ELEMS >> DECAY_BITS)
79
80/* Bits which count the number of errors happened in this 4K page. */
81#define COUNT_BITS (PAGE_SHIFT - DECAY_BITS)
82#define COUNT_MASK ((1ULL << COUNT_BITS) - 1)
83#define FULL_COUNT_MASK (PAGE_SIZE - 1)
84
85/*
86 * u64: [ 63 ... 12 | DECAY_BITS | COUNT_BITS ]
87 */
88
89#define PFN(e) ((e) >> PAGE_SHIFT)
90#define DECAY(e) (((e) >> COUNT_BITS) & DECAY_MASK)
91#define COUNT(e) ((unsigned int)(e) & COUNT_MASK)
92#define FULL_COUNT(e) ((e) & (PAGE_SIZE - 1))
93
94static struct ce_array {
95 u64 *array; /* container page */
96 unsigned int n; /* number of elements in the array */
97
98 unsigned int decay_count; /*
99 * number of element insertions/increments
100 * since the last spring cleaning.
101 */
102
103 u64 pfns_poisoned; /*
104 * number of PFNs which got poisoned.
105 */
106
107 u64 ces_entered; /*
108 * The number of correctable errors
109 * entered into the collector.
110 */
111
112 u64 decays_done; /*
113 * Times we did spring cleaning.
114 */
115
116 union {
117 struct {
118 __u32 disabled : 1, /* cmdline disabled */
119 __resv : 31;
120 };
121 __u32 flags;
122 };
123} ce_arr;
124
125static DEFINE_MUTEX(ce_mutex);
126static u64 dfs_pfn;
127
128/* Amount of errors after which we offline */
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200129static u64 action_threshold = COUNT_MASK;
Borislav Petkov011d8262017-03-27 11:33:02 +0200130
Cong Wang0ade0b62019-04-16 14:33:51 -0700131/* Each element "decays" each decay_interval which is 24hrs by default. */
132#define CEC_DECAY_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */
133#define CEC_DECAY_MIN_INTERVAL 1 * 60 * 60 /* 1h */
134#define CEC_DECAY_MAX_INTERVAL 30 * 24 * 60 * 60 /* one month */
135static struct delayed_work cec_work;
136static u64 decay_interval = CEC_DECAY_DEFAULT_INTERVAL;
Borislav Petkov011d8262017-03-27 11:33:02 +0200137
138/*
139 * Decrement decay value. We're using DECAY_BITS bits to denote decay of an
140 * element in the array. On insertion and any access, it gets reset to max.
141 */
142static void do_spring_cleaning(struct ce_array *ca)
143{
144 int i;
145
146 for (i = 0; i < ca->n; i++) {
147 u8 decay = DECAY(ca->array[i]);
148
149 if (!decay)
150 continue;
151
152 decay--;
153
154 ca->array[i] &= ~(DECAY_MASK << COUNT_BITS);
155 ca->array[i] |= (decay << COUNT_BITS);
156 }
157 ca->decay_count = 0;
158 ca->decays_done++;
159}
160
161/*
162 * @interval in seconds
163 */
Cong Wang0ade0b62019-04-16 14:33:51 -0700164static void cec_mod_work(unsigned long interval)
Borislav Petkov011d8262017-03-27 11:33:02 +0200165{
166 unsigned long iv;
167
Cong Wang0ade0b62019-04-16 14:33:51 -0700168 iv = interval * HZ;
169 mod_delayed_work(system_wq, &cec_work, round_jiffies(iv));
Borislav Petkov011d8262017-03-27 11:33:02 +0200170}
171
Cong Wang0ade0b62019-04-16 14:33:51 -0700172static void cec_work_fn(struct work_struct *work)
Borislav Petkov011d8262017-03-27 11:33:02 +0200173{
Cong Wang0ade0b62019-04-16 14:33:51 -0700174 mutex_lock(&ce_mutex);
Kees Cook254db5b2017-10-21 08:37:11 -0700175 do_spring_cleaning(&ce_arr);
Cong Wang0ade0b62019-04-16 14:33:51 -0700176 mutex_unlock(&ce_mutex);
Borislav Petkov011d8262017-03-27 11:33:02 +0200177
Cong Wang0ade0b62019-04-16 14:33:51 -0700178 cec_mod_work(decay_interval);
Borislav Petkov011d8262017-03-27 11:33:02 +0200179}
180
181/*
182 * @to: index of the smallest element which is >= then @pfn.
183 *
184 * Return the index of the pfn if found, otherwise negative value.
185 */
186static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
187{
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200188 int min = 0, max = ca->n - 1;
Borislav Petkov011d8262017-03-27 11:33:02 +0200189 u64 this_pfn;
Borislav Petkov011d8262017-03-27 11:33:02 +0200190
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200191 while (min <= max) {
192 int i = (min + max) >> 1;
Borislav Petkov011d8262017-03-27 11:33:02 +0200193
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200194 this_pfn = PFN(ca->array[i]);
Borislav Petkov011d8262017-03-27 11:33:02 +0200195
196 if (this_pfn < pfn)
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200197 min = i + 1;
Borislav Petkov011d8262017-03-27 11:33:02 +0200198 else if (this_pfn > pfn)
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200199 max = i - 1;
200 else if (this_pfn == pfn) {
201 if (to)
202 *to = i;
203
204 return i;
Borislav Petkov011d8262017-03-27 11:33:02 +0200205 }
206 }
207
Borislav Petkovf3c74b32019-04-20 13:27:51 +0200208 /*
209 * When the loop terminates without finding @pfn, min has the index of
210 * the element slot where the new @pfn should be inserted. The loop
211 * terminates when min > max, which means the min index points to the
212 * bigger element while the max index to the smaller element, in-between
213 * which the new @pfn belongs to.
214 *
215 * For more details, see exercise 1, Section 6.2.1 in TAOCP, vol. 3.
216 */
Borislav Petkov011d8262017-03-27 11:33:02 +0200217 if (to)
218 *to = min;
219
Borislav Petkov011d8262017-03-27 11:33:02 +0200220 return -ENOKEY;
221}
222
223static int find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
224{
225 WARN_ON(!to);
226
227 if (!ca->n) {
228 *to = 0;
229 return -ENOKEY;
230 }
231 return __find_elem(ca, pfn, to);
232}
233
234static void del_elem(struct ce_array *ca, int idx)
235{
236 /* Save us a function call when deleting the last element. */
237 if (ca->n - (idx + 1))
238 memmove((void *)&ca->array[idx],
239 (void *)&ca->array[idx + 1],
240 (ca->n - (idx + 1)) * sizeof(u64));
241
242 ca->n--;
243}
244
245static u64 del_lru_elem_unlocked(struct ce_array *ca)
246{
247 unsigned int min = FULL_COUNT_MASK;
248 int i, min_idx = 0;
249
250 for (i = 0; i < ca->n; i++) {
251 unsigned int this = FULL_COUNT(ca->array[i]);
252
253 if (min > this) {
254 min = this;
255 min_idx = i;
256 }
257 }
258
259 del_elem(ca, min_idx);
260
261 return PFN(ca->array[min_idx]);
262}
263
264/*
265 * We return the 0th pfn in the error case under the assumption that it cannot
266 * be poisoned and excessive CEs in there are a serious deal anyway.
267 */
268static u64 __maybe_unused del_lru_elem(void)
269{
270 struct ce_array *ca = &ce_arr;
271 u64 pfn;
272
273 if (!ca->n)
274 return 0;
275
276 mutex_lock(&ce_mutex);
277 pfn = del_lru_elem_unlocked(ca);
278 mutex_unlock(&ce_mutex);
279
280 return pfn;
281}
282
Borislav Petkov9632a322019-04-21 21:41:45 +0200283static bool sanity_check(struct ce_array *ca)
284{
285 bool ret = false;
286 u64 prev = 0;
287 int i;
288
289 for (i = 0; i < ca->n; i++) {
290 u64 this = PFN(ca->array[i]);
291
292 if (WARN(prev > this, "prev: 0x%016llx <-> this: 0x%016llx\n", prev, this))
293 ret = true;
294
295 prev = this;
296 }
297
298 if (!ret)
299 return ret;
300
301 pr_info("Sanity check dump:\n{ n: %d\n", ca->n);
302 for (i = 0; i < ca->n; i++) {
303 u64 this = PFN(ca->array[i]);
304
305 pr_info(" %03d: [%016llx|%03llx]\n", i, this, FULL_COUNT(ca->array[i]));
306 }
307 pr_info("}\n");
308
309 return ret;
310}
Borislav Petkov011d8262017-03-27 11:33:02 +0200311
Tony Luck9554bfe2020-02-14 14:27:15 -0800312static int cec_add_elem(u64 pfn)
Borislav Petkov011d8262017-03-27 11:33:02 +0200313{
314 struct ce_array *ca = &ce_arr;
Borislav Petkov9632a322019-04-21 21:41:45 +0200315 unsigned int to = 0;
Borislav Petkov011d8262017-03-27 11:33:02 +0200316 int count, ret = 0;
317
318 /*
319 * We can be called very early on the identify_cpu() path where we are
320 * not initialized yet. We ignore the error for simplicity.
321 */
322 if (!ce_arr.array || ce_arr.disabled)
323 return -ENODEV;
324
Borislav Petkov011d8262017-03-27 11:33:02 +0200325 mutex_lock(&ce_mutex);
326
WANG Chao09cbd212019-04-18 03:41:14 +0000327 ca->ces_entered++;
328
Borislav Petkovde0e0622019-04-20 14:06:37 +0200329 /* Array full, free the LRU slot. */
Borislav Petkov011d8262017-03-27 11:33:02 +0200330 if (ca->n == MAX_ELEMS)
331 WARN_ON(!del_lru_elem_unlocked(ca));
332
333 ret = find_elem(ca, pfn, &to);
334 if (ret < 0) {
335 /*
336 * Shift range [to-end] to make room for one more element.
337 */
338 memmove((void *)&ca->array[to + 1],
339 (void *)&ca->array[to],
340 (ca->n - to) * sizeof(u64));
341
Borislav Petkovde0e0622019-04-20 14:06:37 +0200342 ca->array[to] = pfn << PAGE_SHIFT;
Borislav Petkov011d8262017-03-27 11:33:02 +0200343 ca->n++;
Borislav Petkov011d8262017-03-27 11:33:02 +0200344 }
345
Borislav Petkovde0e0622019-04-20 14:06:37 +0200346 /* Add/refresh element generation and increment count */
347 ca->array[to] |= DECAY_MASK << COUNT_BITS;
348 ca->array[to]++;
349
350 /* Check action threshold and soft-offline, if reached. */
Borislav Petkov011d8262017-03-27 11:33:02 +0200351 count = COUNT(ca->array[to]);
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200352 if (count >= action_threshold) {
Borislav Petkov011d8262017-03-27 11:33:02 +0200353 u64 pfn = ca->array[to] >> PAGE_SHIFT;
354
355 if (!pfn_valid(pfn)) {
356 pr_warn("CEC: Invalid pfn: 0x%llx\n", pfn);
357 } else {
358 /* We have reached max count for this page, soft-offline it. */
359 pr_err("Soft-offlining pfn: 0x%llx\n", pfn);
Eric W. Biederman83b57532017-07-09 18:14:01 -0500360 memory_failure_queue(pfn, MF_SOFT_OFFLINE);
Borislav Petkov011d8262017-03-27 11:33:02 +0200361 ca->pfns_poisoned++;
362 }
363
364 del_elem(ca, to);
365
366 /*
Borislav Petkovde0e0622019-04-20 14:06:37 +0200367 * Return a >0 value to callers, to denote that we've reached
368 * the offlining threshold.
Borislav Petkov011d8262017-03-27 11:33:02 +0200369 */
370 ret = 1;
371
372 goto unlock;
373 }
374
Borislav Petkov011d8262017-03-27 11:33:02 +0200375 ca->decay_count++;
376
377 if (ca->decay_count >= CLEAN_ELEMS)
378 do_spring_cleaning(ca);
379
Borislav Petkov9632a322019-04-21 21:41:45 +0200380 WARN_ON_ONCE(sanity_check(ca));
381
Borislav Petkov011d8262017-03-27 11:33:02 +0200382unlock:
383 mutex_unlock(&ce_mutex);
384
385 return ret;
386}
387
388static int u64_get(void *data, u64 *val)
389{
390 *val = *(u64 *)data;
391
392 return 0;
393}
394
395static int pfn_set(void *data, u64 val)
396{
397 *(u64 *)data = val;
398
Borislav Petkov6d8e2942019-04-20 12:53:05 +0200399 cec_add_elem(val);
400
401 return 0;
Borislav Petkov011d8262017-03-27 11:33:02 +0200402}
403
404DEFINE_DEBUGFS_ATTRIBUTE(pfn_ops, u64_get, pfn_set, "0x%llx\n");
405
406static int decay_interval_set(void *data, u64 val)
407{
Cong Wang0ade0b62019-04-16 14:33:51 -0700408 if (val < CEC_DECAY_MIN_INTERVAL)
Borislav Petkov011d8262017-03-27 11:33:02 +0200409 return -EINVAL;
410
Cong Wang0ade0b62019-04-16 14:33:51 -0700411 if (val > CEC_DECAY_MAX_INTERVAL)
Borislav Petkov011d8262017-03-27 11:33:02 +0200412 return -EINVAL;
413
Borislav Petkov5cc6b16e2019-04-20 21:33:08 +0200414 *(u64 *)data = val;
Cong Wang0ade0b62019-04-16 14:33:51 -0700415 decay_interval = val;
Borislav Petkov011d8262017-03-27 11:33:02 +0200416
Cong Wang0ade0b62019-04-16 14:33:51 -0700417 cec_mod_work(decay_interval);
Borislav Petkov5cc6b16e2019-04-20 21:33:08 +0200418
Borislav Petkov011d8262017-03-27 11:33:02 +0200419 return 0;
420}
421DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n");
422
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200423static int action_threshold_set(void *data, u64 val)
Borislav Petkov011d8262017-03-27 11:33:02 +0200424{
425 *(u64 *)data = val;
426
427 if (val > COUNT_MASK)
428 val = COUNT_MASK;
429
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200430 action_threshold = val;
Borislav Petkov011d8262017-03-27 11:33:02 +0200431
432 return 0;
433}
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200434DEFINE_DEBUGFS_ATTRIBUTE(action_threshold_ops, u64_get, action_threshold_set, "%lld\n");
Borislav Petkov011d8262017-03-27 11:33:02 +0200435
Borislav Petkovf57518c2019-04-20 23:01:03 +0200436static const char * const bins[] = { "00", "01", "10", "11" };
437
Qinglang Miao4bd442e2020-09-19 09:22:52 +0800438static int array_show(struct seq_file *m, void *v)
Borislav Petkov011d8262017-03-27 11:33:02 +0200439{
440 struct ce_array *ca = &ce_arr;
Borislav Petkov011d8262017-03-27 11:33:02 +0200441 int i;
442
443 mutex_lock(&ce_mutex);
444
445 seq_printf(m, "{ n: %d\n", ca->n);
446 for (i = 0; i < ca->n; i++) {
447 u64 this = PFN(ca->array[i]);
448
Borislav Petkovf57518c2019-04-20 23:01:03 +0200449 seq_printf(m, " %3d: [%016llx|%s|%03llx]\n",
450 i, this, bins[DECAY(ca->array[i])], COUNT(ca->array[i]));
Borislav Petkov011d8262017-03-27 11:33:02 +0200451 }
452
453 seq_printf(m, "}\n");
454
455 seq_printf(m, "Stats:\nCEs: %llu\nofflined pages: %llu\n",
456 ca->ces_entered, ca->pfns_poisoned);
457
458 seq_printf(m, "Flags: 0x%x\n", ca->flags);
459
Cong Wang0ade0b62019-04-16 14:33:51 -0700460 seq_printf(m, "Decay interval: %lld seconds\n", decay_interval);
Borislav Petkov011d8262017-03-27 11:33:02 +0200461 seq_printf(m, "Decays: %lld\n", ca->decays_done);
462
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200463 seq_printf(m, "Action threshold: %lld\n", action_threshold);
Borislav Petkov011d8262017-03-27 11:33:02 +0200464
465 mutex_unlock(&ce_mutex);
466
467 return 0;
468}
469
Qinglang Miao4bd442e2020-09-19 09:22:52 +0800470DEFINE_SHOW_ATTRIBUTE(array);
Borislav Petkov011d8262017-03-27 11:33:02 +0200471
472static int __init create_debugfs_nodes(void)
473{
474 struct dentry *d, *pfn, *decay, *count, *array;
475
476 d = debugfs_create_dir("cec", ras_debugfs_dir);
477 if (!d) {
478 pr_warn("Error creating cec debugfs node!\n");
479 return -1;
480 }
481
Borislav Petkov011d8262017-03-27 11:33:02 +0200482 decay = debugfs_create_file("decay_interval", S_IRUSR | S_IWUSR, d,
Cong Wang0ade0b62019-04-16 14:33:51 -0700483 &decay_interval, &decay_interval_ops);
Borislav Petkov011d8262017-03-27 11:33:02 +0200484 if (!decay) {
485 pr_warn("Error creating decay_interval debugfs node!\n");
486 goto err;
487 }
488
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200489 count = debugfs_create_file("action_threshold", S_IRUSR | S_IWUSR, d,
490 &action_threshold, &action_threshold_ops);
Christophe JAILLET32288da2017-06-26 14:35:32 +0200491 if (!count) {
Borislav Petkovb8b5ca62019-04-20 21:30:11 +0200492 pr_warn("Error creating action_threshold debugfs node!\n");
Borislav Petkov011d8262017-03-27 11:33:02 +0200493 goto err;
494 }
495
Tony Luck60fd42d2019-05-06 13:13:22 +0200496 if (!IS_ENABLED(CONFIG_RAS_CEC_DEBUG))
497 return 0;
498
499 pfn = debugfs_create_file("pfn", S_IRUSR | S_IWUSR, d, &dfs_pfn, &pfn_ops);
500 if (!pfn) {
501 pr_warn("Error creating pfn debugfs node!\n");
502 goto err;
503 }
504
Qinglang Miao4bd442e2020-09-19 09:22:52 +0800505 array = debugfs_create_file("array", S_IRUSR, d, NULL, &array_fops);
Tony Luck60fd42d2019-05-06 13:13:22 +0200506 if (!array) {
507 pr_warn("Error creating array debugfs node!\n");
508 goto err;
509 }
Borislav Petkov011d8262017-03-27 11:33:02 +0200510
511 return 0;
512
513err:
514 debugfs_remove_recursive(d);
515
516 return 1;
517}
518
Tony Luck9554bfe2020-02-14 14:27:15 -0800519static int cec_notifier(struct notifier_block *nb, unsigned long val,
520 void *data)
521{
522 struct mce *m = (struct mce *)data;
523
524 if (!m)
525 return NOTIFY_DONE;
526
527 /* We eat only correctable DRAM errors with usable addresses. */
528 if (mce_is_memory_error(m) &&
529 mce_is_correctable(m) &&
Tony Luck23ba7102020-02-14 14:27:17 -0800530 mce_usable_address(m)) {
531 if (!cec_add_elem(m->addr >> PAGE_SHIFT)) {
532 m->kflags |= MCE_HANDLED_CEC;
533 return NOTIFY_OK;
534 }
535 }
Tony Luck9554bfe2020-02-14 14:27:15 -0800536
537 return NOTIFY_DONE;
538}
539
540static struct notifier_block cec_nb = {
541 .notifier_call = cec_notifier,
542 .priority = MCE_PRIO_CEC,
543};
544
Luca Stefani85e60842020-08-05 11:57:08 +0200545static int __init cec_init(void)
Borislav Petkov011d8262017-03-27 11:33:02 +0200546{
547 if (ce_arr.disabled)
Luca Stefani85e60842020-08-05 11:57:08 +0200548 return -ENODEV;
Borislav Petkov011d8262017-03-27 11:33:02 +0200549
550 ce_arr.array = (void *)get_zeroed_page(GFP_KERNEL);
551 if (!ce_arr.array) {
552 pr_err("Error allocating CE array page!\n");
Luca Stefani85e60842020-08-05 11:57:08 +0200553 return -ENOMEM;
Borislav Petkov011d8262017-03-27 11:33:02 +0200554 }
555
Borislav Petkovd0e375e2019-04-20 21:39:24 +0200556 if (create_debugfs_nodes()) {
557 free_page((unsigned long)ce_arr.array);
Luca Stefani85e60842020-08-05 11:57:08 +0200558 return -ENOMEM;
Borislav Petkovd0e375e2019-04-20 21:39:24 +0200559 }
Borislav Petkov011d8262017-03-27 11:33:02 +0200560
Cong Wang0ade0b62019-04-16 14:33:51 -0700561 INIT_DELAYED_WORK(&cec_work, cec_work_fn);
562 schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
Borislav Petkov011d8262017-03-27 11:33:02 +0200563
Tony Luck9554bfe2020-02-14 14:27:15 -0800564 mce_register_decode_chain(&cec_nb);
565
Borislav Petkov011d8262017-03-27 11:33:02 +0200566 pr_info("Correctable Errors collector initialized.\n");
Luca Stefani85e60842020-08-05 11:57:08 +0200567 return 0;
Borislav Petkov011d8262017-03-27 11:33:02 +0200568}
Tony Luck9554bfe2020-02-14 14:27:15 -0800569late_initcall(cec_init);
Borislav Petkov011d8262017-03-27 11:33:02 +0200570
571int __init parse_cec_param(char *str)
572{
573 if (!str)
574 return 0;
575
576 if (*str == '=')
577 str++;
578
Nicolas Iooss69a33002017-10-02 11:28:35 +0200579 if (!strcmp(str, "cec_disable"))
Borislav Petkov011d8262017-03-27 11:33:02 +0200580 ce_arr.disabled = 1;
581 else
582 return 0;
583
584 return 1;
585}