hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/edac/ghes_edac.c
....@@ -1,12 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * GHES/EDAC Linux driver
34 *
4
- * This file may be distributed under the terms of the GNU General Public
5
- * License version 2.
6
- *
75 * Copyright (c) 2013 by Mauro Carvalho Chehab
86 *
9
- * Red Hat Inc. http://www.redhat.com
7
+ * Red Hat Inc. https://www.redhat.com
108 */
119
1210 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -17,19 +15,34 @@
1715 #include "edac_module.h"
1816 #include <ras/ras_event.h>
1917
20
-struct ghes_edac_pvt {
21
- struct list_head list;
22
- struct ghes *ghes;
18
+struct ghes_pvt {
2319 struct mem_ctl_info *mci;
2420
2521 /* Buffers for the error handling routine */
26
- char detail_location[240];
27
- char other_detail[160];
22
+ char other_detail[400];
2823 char msg[80];
2924 };
3025
31
-static atomic_t ghes_init = ATOMIC_INIT(0);
32
-static struct ghes_edac_pvt *ghes_pvt;
26
+static refcount_t ghes_refcount = REFCOUNT_INIT(0);
27
+
28
+/*
29
+ * Access to ghes_pvt must be protected by ghes_lock. The spinlock
30
+ * also provides the necessary (implicit) memory barrier for the SMP
31
+ * case to make the pointer visible on another CPU.
32
+ */
33
+static struct ghes_pvt *ghes_pvt;
34
+
35
+/*
36
+ * This driver's representation of the system hardware, as collected
37
+ * from DMI.
38
+ */
39
+struct ghes_hw_desc {
40
+ int num_dimms;
41
+ struct dimm_info *dimms;
42
+} ghes_hw;
43
+
44
+/* GHES registration mutex */
45
+static DEFINE_MUTEX(ghes_reg_mutex);
3346
3447 /*
3548 * Sync with other, potentially concurrent callers of
....@@ -41,6 +54,8 @@
4154 /* "ghes_edac.force_load=1" skips the platform check */
4255 static bool __read_mostly force_load;
4356 module_param(force_load, bool, 0);
57
+
58
+static bool system_scanned;
4459
4560 /* Memory Device - Type 17 of SMBIOS spec */
4661 struct memdev_dmi_entry {
....@@ -68,131 +83,170 @@
6883 u16 conf_mem_clk_speed;
6984 } __attribute__((__packed__));
7085
71
-struct ghes_edac_dimm_fill {
72
- struct mem_ctl_info *mci;
73
- unsigned count;
74
-};
75
-
76
-static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg)
86
+static struct dimm_info *find_dimm_by_handle(struct mem_ctl_info *mci, u16 handle)
7787 {
78
- int *num_dimm = arg;
88
+ struct dimm_info *dimm;
7989
80
- if (dh->type == DMI_ENTRY_MEM_DEVICE)
81
- (*num_dimm)++;
90
+ mci_for_each_dimm(mci, dimm) {
91
+ if (dimm->smbios_handle == handle)
92
+ return dimm;
93
+ }
94
+
95
+ return NULL;
8296 }
8397
84
-static void ghes_edac_dmidecode(const struct dmi_header *dh, void *arg)
98
+static void dimm_setup_label(struct dimm_info *dimm, u16 handle)
8599 {
86
- struct ghes_edac_dimm_fill *dimm_fill = arg;
87
- struct mem_ctl_info *mci = dimm_fill->mci;
100
+ const char *bank = NULL, *device = NULL;
88101
89
- if (dh->type == DMI_ENTRY_MEM_DEVICE) {
90
- struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh;
91
- struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
92
- mci->n_layers,
93
- dimm_fill->count, 0, 0);
94
- u16 rdr_mask = BIT(7) | BIT(13);
102
+ dmi_memdev_name(handle, &bank, &device);
95103
96
- if (entry->size == 0xffff) {
97
- pr_info("Can't get DIMM%i size\n",
98
- dimm_fill->count);
99
- dimm->nr_pages = MiB_TO_PAGES(32);/* Unknown */
100
- } else if (entry->size == 0x7fff) {
101
- dimm->nr_pages = MiB_TO_PAGES(entry->extended_size);
102
- } else {
103
- if (entry->size & BIT(15))
104
- dimm->nr_pages = MiB_TO_PAGES((entry->size & 0x7fff) << 10);
105
- else
106
- dimm->nr_pages = MiB_TO_PAGES(entry->size);
107
- }
104
+ /*
105
+ * Set to a NULL string when both bank and device are zero. In this case,
106
+ * the label assigned by default will be preserved.
107
+ */
108
+ snprintf(dimm->label, sizeof(dimm->label), "%s%s%s",
109
+ (bank && *bank) ? bank : "",
110
+ (bank && *bank && device && *device) ? " " : "",
111
+ (device && *device) ? device : "");
112
+}
108113
109
- switch (entry->memory_type) {
110
- case 0x12:
111
- if (entry->type_detail & BIT(13))
112
- dimm->mtype = MEM_RDDR;
113
- else
114
- dimm->mtype = MEM_DDR;
115
- break;
116
- case 0x13:
117
- if (entry->type_detail & BIT(13))
118
- dimm->mtype = MEM_RDDR2;
119
- else
120
- dimm->mtype = MEM_DDR2;
121
- break;
122
- case 0x14:
123
- dimm->mtype = MEM_FB_DDR2;
124
- break;
125
- case 0x18:
126
- if (entry->type_detail & BIT(12))
127
- dimm->mtype = MEM_NVDIMM;
128
- else if (entry->type_detail & BIT(13))
129
- dimm->mtype = MEM_RDDR3;
130
- else
131
- dimm->mtype = MEM_DDR3;
132
- break;
133
- case 0x1a:
134
- if (entry->type_detail & BIT(12))
135
- dimm->mtype = MEM_NVDIMM;
136
- else if (entry->type_detail & BIT(13))
137
- dimm->mtype = MEM_RDDR4;
138
- else
139
- dimm->mtype = MEM_DDR4;
140
- break;
141
- default:
142
- if (entry->type_detail & BIT(6))
143
- dimm->mtype = MEM_RMBS;
144
- else if ((entry->type_detail & rdr_mask) == rdr_mask)
145
- dimm->mtype = MEM_RDR;
146
- else if (entry->type_detail & BIT(7))
147
- dimm->mtype = MEM_SDR;
148
- else if (entry->type_detail & BIT(9))
149
- dimm->mtype = MEM_EDO;
150
- else
151
- dimm->mtype = MEM_UNKNOWN;
152
- }
114
+static void assign_dmi_dimm_info(struct dimm_info *dimm, struct memdev_dmi_entry *entry)
115
+{
116
+ u16 rdr_mask = BIT(7) | BIT(13);
153117
154
- /*
155
- * Actually, we can only detect if the memory has bits for
156
- * checksum or not
157
- */
158
- if (entry->total_width == entry->data_width)
159
- dimm->edac_mode = EDAC_NONE;
118
+ if (entry->size == 0xffff) {
119
+ pr_info("Can't get DIMM%i size\n", dimm->idx);
120
+ dimm->nr_pages = MiB_TO_PAGES(32);/* Unknown */
121
+ } else if (entry->size == 0x7fff) {
122
+ dimm->nr_pages = MiB_TO_PAGES(entry->extended_size);
123
+ } else {
124
+ if (entry->size & BIT(15))
125
+ dimm->nr_pages = MiB_TO_PAGES((entry->size & 0x7fff) << 10);
160126 else
161
- dimm->edac_mode = EDAC_SECDED;
127
+ dimm->nr_pages = MiB_TO_PAGES(entry->size);
128
+ }
162129
163
- dimm->dtype = DEV_UNKNOWN;
164
- dimm->grain = 128; /* Likely, worse case */
130
+ switch (entry->memory_type) {
131
+ case 0x12:
132
+ if (entry->type_detail & BIT(13))
133
+ dimm->mtype = MEM_RDDR;
134
+ else
135
+ dimm->mtype = MEM_DDR;
136
+ break;
137
+ case 0x13:
138
+ if (entry->type_detail & BIT(13))
139
+ dimm->mtype = MEM_RDDR2;
140
+ else
141
+ dimm->mtype = MEM_DDR2;
142
+ break;
143
+ case 0x14:
144
+ dimm->mtype = MEM_FB_DDR2;
145
+ break;
146
+ case 0x18:
147
+ if (entry->type_detail & BIT(12))
148
+ dimm->mtype = MEM_NVDIMM;
149
+ else if (entry->type_detail & BIT(13))
150
+ dimm->mtype = MEM_RDDR3;
151
+ else
152
+ dimm->mtype = MEM_DDR3;
153
+ break;
154
+ case 0x1a:
155
+ if (entry->type_detail & BIT(12))
156
+ dimm->mtype = MEM_NVDIMM;
157
+ else if (entry->type_detail & BIT(13))
158
+ dimm->mtype = MEM_RDDR4;
159
+ else
160
+ dimm->mtype = MEM_DDR4;
161
+ break;
162
+ default:
163
+ if (entry->type_detail & BIT(6))
164
+ dimm->mtype = MEM_RMBS;
165
+ else if ((entry->type_detail & rdr_mask) == rdr_mask)
166
+ dimm->mtype = MEM_RDR;
167
+ else if (entry->type_detail & BIT(7))
168
+ dimm->mtype = MEM_SDR;
169
+ else if (entry->type_detail & BIT(9))
170
+ dimm->mtype = MEM_EDO;
171
+ else
172
+ dimm->mtype = MEM_UNKNOWN;
173
+ }
165174
166
- /*
167
- * FIXME: It shouldn't be hard to also fill the DIMM labels
168
- */
175
+ /*
176
+ * Actually, we can only detect if the memory has bits for
177
+ * checksum or not
178
+ */
179
+ if (entry->total_width == entry->data_width)
180
+ dimm->edac_mode = EDAC_NONE;
181
+ else
182
+ dimm->edac_mode = EDAC_SECDED;
169183
170
- if (dimm->nr_pages) {
171
- edac_dbg(1, "DIMM%i: %s size = %d MB%s\n",
172
- dimm_fill->count, edac_mem_types[dimm->mtype],
173
- PAGES_TO_MiB(dimm->nr_pages),
174
- (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : "");
175
- edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n",
176
- entry->memory_type, entry->type_detail,
177
- entry->total_width, entry->data_width);
184
+ dimm->dtype = DEV_UNKNOWN;
185
+ dimm->grain = 128; /* Likely, worse case */
186
+
187
+ dimm_setup_label(dimm, entry->handle);
188
+
189
+ if (dimm->nr_pages) {
190
+ edac_dbg(1, "DIMM%i: %s size = %d MB%s\n",
191
+ dimm->idx, edac_mem_types[dimm->mtype],
192
+ PAGES_TO_MiB(dimm->nr_pages),
193
+ (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : "");
194
+ edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n",
195
+ entry->memory_type, entry->type_detail,
196
+ entry->total_width, entry->data_width);
197
+ }
198
+
199
+ dimm->smbios_handle = entry->handle;
200
+}
201
+
202
+static void enumerate_dimms(const struct dmi_header *dh, void *arg)
203
+{
204
+ struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh;
205
+ struct ghes_hw_desc *hw = (struct ghes_hw_desc *)arg;
206
+ struct dimm_info *d;
207
+
208
+ if (dh->type != DMI_ENTRY_MEM_DEVICE)
209
+ return;
210
+
211
+ /* Enlarge the array with additional 16 */
212
+ if (!hw->num_dimms || !(hw->num_dimms % 16)) {
213
+ struct dimm_info *new;
214
+
215
+ new = krealloc(hw->dimms, (hw->num_dimms + 16) * sizeof(struct dimm_info),
216
+ GFP_KERNEL);
217
+ if (!new) {
218
+ WARN_ON_ONCE(1);
219
+ return;
178220 }
179221
180
- dimm_fill->count++;
222
+ hw->dimms = new;
181223 }
224
+
225
+ d = &hw->dimms[hw->num_dimms];
226
+ d->idx = hw->num_dimms;
227
+
228
+ assign_dmi_dimm_info(d, entry);
229
+
230
+ hw->num_dimms++;
231
+}
232
+
233
+static void ghes_scan_system(void)
234
+{
235
+ if (system_scanned)
236
+ return;
237
+
238
+ dmi_walk(enumerate_dimms, &ghes_hw);
239
+
240
+ system_scanned = true;
182241 }
183242
184243 void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err)
185244 {
186
- enum hw_event_mc_err_type type;
187245 struct edac_raw_error_desc *e;
188246 struct mem_ctl_info *mci;
189
- struct ghes_edac_pvt *pvt = ghes_pvt;
247
+ struct ghes_pvt *pvt;
190248 unsigned long flags;
191249 char *p;
192
- u8 grain_bits;
193
-
194
- if (!pvt)
195
- return;
196250
197251 /*
198252 * We can do the locking below because GHES defers error processing
....@@ -204,6 +258,10 @@
204258
205259 spin_lock_irqsave(&ghes_lock, flags);
206260
261
+ pvt = ghes_pvt;
262
+ if (!pvt)
263
+ goto unlock;
264
+
207265 mci = pvt->mci;
208266 e = &mci->error_desc;
209267
....@@ -211,7 +269,6 @@
211269 memset(e, 0, sizeof (*e));
212270 e->error_count = 1;
213271 e->grain = 1;
214
- strcpy(e->label, "unknown label");
215272 e->msg = pvt->msg;
216273 e->other_detail = pvt->other_detail;
217274 e->top_layer = -1;
....@@ -222,17 +279,17 @@
222279
223280 switch (sev) {
224281 case GHES_SEV_CORRECTED:
225
- type = HW_EVENT_ERR_CORRECTED;
282
+ e->type = HW_EVENT_ERR_CORRECTED;
226283 break;
227284 case GHES_SEV_RECOVERABLE:
228
- type = HW_EVENT_ERR_UNCORRECTED;
285
+ e->type = HW_EVENT_ERR_UNCORRECTED;
229286 break;
230287 case GHES_SEV_PANIC:
231
- type = HW_EVENT_ERR_FATAL;
288
+ e->type = HW_EVENT_ERR_FATAL;
232289 break;
233290 default:
234291 case GHES_SEV_NO:
235
- type = HW_EVENT_ERR_INFO;
292
+ e->type = HW_EVENT_ERR_INFO;
236293 }
237294
238295 edac_dbg(1, "error validation_bits: 0x%08llx\n",
....@@ -300,8 +357,8 @@
300357
301358 /* Error address */
302359 if (mem_err->validation_bits & CPER_MEM_VALID_PA) {
303
- e->page_frame_number = mem_err->physical_addr >> PAGE_SHIFT;
304
- e->offset_in_page = mem_err->physical_addr & ~PAGE_MASK;
360
+ e->page_frame_number = PHYS_PFN(mem_err->physical_addr);
361
+ e->offset_in_page = offset_in_page(mem_err->physical_addr);
305362 }
306363
307364 /* Error grain */
....@@ -320,26 +377,52 @@
320377 p += sprintf(p, "rank:%d ", mem_err->rank);
321378 if (mem_err->validation_bits & CPER_MEM_VALID_BANK)
322379 p += sprintf(p, "bank:%d ", mem_err->bank);
323
- if (mem_err->validation_bits & CPER_MEM_VALID_ROW)
324
- p += sprintf(p, "row:%d ", mem_err->row);
380
+ if (mem_err->validation_bits & CPER_MEM_VALID_BANK_GROUP)
381
+ p += sprintf(p, "bank_group:%d ",
382
+ mem_err->bank >> CPER_MEM_BANK_GROUP_SHIFT);
383
+ if (mem_err->validation_bits & CPER_MEM_VALID_BANK_ADDRESS)
384
+ p += sprintf(p, "bank_address:%d ",
385
+ mem_err->bank & CPER_MEM_BANK_ADDRESS_MASK);
386
+ if (mem_err->validation_bits & (CPER_MEM_VALID_ROW | CPER_MEM_VALID_ROW_EXT)) {
387
+ u32 row = mem_err->row;
388
+
389
+ row |= cper_get_mem_extension(mem_err->validation_bits, mem_err->extended);
390
+ p += sprintf(p, "row:%d ", row);
391
+ }
325392 if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN)
326393 p += sprintf(p, "col:%d ", mem_err->column);
327394 if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION)
328395 p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos);
329396 if (mem_err->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) {
330397 const char *bank = NULL, *device = NULL;
398
+ struct dimm_info *dimm;
399
+
331400 dmi_memdev_name(mem_err->mem_dev_handle, &bank, &device);
332401 if (bank != NULL && device != NULL)
333402 p += sprintf(p, "DIMM location:%s %s ", bank, device);
334403 else
335404 p += sprintf(p, "DIMM DMI handle: 0x%.4x ",
336405 mem_err->mem_dev_handle);
406
+
407
+ dimm = find_dimm_by_handle(mci, mem_err->mem_dev_handle);
408
+ if (dimm) {
409
+ e->top_layer = dimm->idx;
410
+ strcpy(e->label, dimm->label);
411
+ }
337412 }
413
+ if (mem_err->validation_bits & CPER_MEM_VALID_CHIP_ID)
414
+ p += sprintf(p, "chipID: %d ",
415
+ mem_err->extended >> CPER_MEM_CHIP_ID_SHIFT);
338416 if (p > e->location)
339417 *(p - 1) = '\0';
340418
419
+ if (!*e->label)
420
+ strcpy(e->label, "unknown memory");
421
+
341422 /* All other fields are mapped on e->other_detail */
342423 p = pvt->other_detail;
424
+ p += snprintf(p, sizeof(pvt->other_detail),
425
+ "APEI location: %s ", e->location);
343426 if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) {
344427 u64 status = mem_err->error_status;
345428
....@@ -413,21 +496,9 @@
413496 if (p > pvt->other_detail)
414497 *(p - 1) = '\0';
415498
416
- /* Sanity-check driver-supplied grain value. */
417
- if (WARN_ON_ONCE(!e->grain))
418
- e->grain = 1;
499
+ edac_raw_mc_handle_error(e);
419500
420
- grain_bits = fls_long(e->grain - 1);
421
-
422
- /* Generate the trace event */
423
- snprintf(pvt->detail_location, sizeof(pvt->detail_location),
424
- "APEI location: %s %s", e->location, e->other_detail);
425
- trace_mc_event(type, e->msg, e->label, e->error_count,
426
- mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
427
- (e->page_frame_number << PAGE_SHIFT) | e->offset_in_page,
428
- grain_bits, e->syndrome, pvt->detail_location);
429
-
430
- edac_raw_mc_handle_error(type, mci, e);
501
+unlock:
431502 spin_unlock_irqrestore(&ghes_lock, flags);
432503 }
433504
....@@ -442,11 +513,12 @@
442513 int ghes_edac_register(struct ghes *ghes, struct device *dev)
443514 {
444515 bool fake = false;
445
- int rc, num_dimm = 0;
446516 struct mem_ctl_info *mci;
517
+ struct ghes_pvt *pvt;
447518 struct edac_mc_layer layers[1];
448
- struct ghes_edac_dimm_fill dimm_fill;
519
+ unsigned long flags;
449520 int idx = -1;
521
+ int rc = 0;
450522
451523 if (IS_ENABLED(CONFIG_X86)) {
452524 /* Check if safe to enable on this system */
....@@ -454,37 +526,40 @@
454526 if (!force_load && idx < 0)
455527 return -ENODEV;
456528 } else {
529
+ force_load = true;
457530 idx = 0;
458531 }
532
+
533
+ /* finish another registration/unregistration instance first */
534
+ mutex_lock(&ghes_reg_mutex);
459535
460536 /*
461537 * We have only one logical memory controller to which all DIMMs belong.
462538 */
463
- if (atomic_inc_return(&ghes_init) > 1)
464
- return 0;
539
+ if (refcount_inc_not_zero(&ghes_refcount))
540
+ goto unlock;
465541
466
- /* Get the number of DIMMs */
467
- dmi_walk(ghes_edac_count_dimms, &num_dimm);
542
+ ghes_scan_system();
468543
469544 /* Check if we've got a bogus BIOS */
470
- if (num_dimm == 0) {
545
+ if (!ghes_hw.num_dimms) {
471546 fake = true;
472
- num_dimm = 1;
547
+ ghes_hw.num_dimms = 1;
473548 }
474549
475550 layers[0].type = EDAC_MC_LAYER_ALL_MEM;
476
- layers[0].size = num_dimm;
551
+ layers[0].size = ghes_hw.num_dimms;
477552 layers[0].is_virt_csrow = true;
478553
479
- mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct ghes_edac_pvt));
554
+ mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct ghes_pvt));
480555 if (!mci) {
481556 pr_info("Can't allocate memory for EDAC data\n");
482
- return -ENOMEM;
557
+ rc = -ENOMEM;
558
+ goto unlock;
483559 }
484560
485
- ghes_pvt = mci->pvt_info;
486
- ghes_pvt->ghes = ghes;
487
- ghes_pvt->mci = mci;
561
+ pvt = mci->pvt_info;
562
+ pvt->mci = mci;
488563
489564 mci->pdev = dev;
490565 mci->mtype_cap = MEM_FLAG_EMPTY;
....@@ -504,16 +579,36 @@
504579 pr_info("So, the end result of using this driver varies from vendor to vendor.\n");
505580 pr_info("If you find incorrect reports, please contact your hardware vendor\n");
506581 pr_info("to correct its BIOS.\n");
507
- pr_info("This system has %d DIMM sockets.\n", num_dimm);
582
+ pr_info("This system has %d DIMM sockets.\n", ghes_hw.num_dimms);
508583 }
509584
510585 if (!fake) {
511
- dimm_fill.count = 0;
512
- dimm_fill.mci = mci;
513
- dmi_walk(ghes_edac_dmidecode, &dimm_fill);
586
+ struct dimm_info *src, *dst;
587
+ int i = 0;
588
+
589
+ mci_for_each_dimm(mci, dst) {
590
+ src = &ghes_hw.dimms[i];
591
+
592
+ dst->idx = src->idx;
593
+ dst->smbios_handle = src->smbios_handle;
594
+ dst->nr_pages = src->nr_pages;
595
+ dst->mtype = src->mtype;
596
+ dst->edac_mode = src->edac_mode;
597
+ dst->dtype = src->dtype;
598
+ dst->grain = src->grain;
599
+
600
+ /*
601
+ * If no src->label, preserve default label assigned
602
+ * from EDAC core.
603
+ */
604
+ if (strlen(src->label))
605
+ memcpy(dst->label, src->label, sizeof(src->label));
606
+
607
+ i++;
608
+ }
609
+
514610 } else {
515
- struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
516
- mci->n_layers, 0, 0, 0);
611
+ struct dimm_info *dimm = edac_get_dimm(mci, 0, 0, 0);
517612
518613 dimm->nr_pages = 1;
519614 dimm->grain = 128;
....@@ -524,25 +619,61 @@
524619
525620 rc = edac_mc_add_mc(mci);
526621 if (rc < 0) {
527
- pr_info("Can't register at EDAC core\n");
622
+ pr_info("Can't register with the EDAC core\n");
528623 edac_mc_free(mci);
529
- return -ENODEV;
624
+ rc = -ENODEV;
625
+ goto unlock;
530626 }
531
- return 0;
627
+
628
+ spin_lock_irqsave(&ghes_lock, flags);
629
+ ghes_pvt = pvt;
630
+ spin_unlock_irqrestore(&ghes_lock, flags);
631
+
632
+ /* only set on success */
633
+ refcount_set(&ghes_refcount, 1);
634
+
635
+unlock:
636
+
637
+ /* Not needed anymore */
638
+ kfree(ghes_hw.dimms);
639
+ ghes_hw.dimms = NULL;
640
+
641
+ mutex_unlock(&ghes_reg_mutex);
642
+
643
+ return rc;
532644 }
533645
534646 void ghes_edac_unregister(struct ghes *ghes)
535647 {
536648 struct mem_ctl_info *mci;
649
+ unsigned long flags;
537650
538
- if (!ghes_pvt)
651
+ if (!force_load)
539652 return;
540653
541
- if (atomic_dec_return(&ghes_init))
542
- return;
654
+ mutex_lock(&ghes_reg_mutex);
543655
544
- mci = ghes_pvt->mci;
656
+ system_scanned = false;
657
+ memset(&ghes_hw, 0, sizeof(struct ghes_hw_desc));
658
+
659
+ if (!refcount_dec_and_test(&ghes_refcount))
660
+ goto unlock;
661
+
662
+ /*
663
+ * Wait for the irq handler being finished.
664
+ */
665
+ spin_lock_irqsave(&ghes_lock, flags);
666
+ mci = ghes_pvt ? ghes_pvt->mci : NULL;
545667 ghes_pvt = NULL;
546
- edac_mc_del_mc(mci->pdev);
547
- edac_mc_free(mci);
668
+ spin_unlock_irqrestore(&ghes_lock, flags);
669
+
670
+ if (!mci)
671
+ goto unlock;
672
+
673
+ mci = edac_mc_del_mc(mci->pdev);
674
+ if (mci)
675
+ edac_mc_free(mci);
676
+
677
+unlock:
678
+ mutex_unlock(&ghes_reg_mutex);
548679 }