Skip to content

Commit 9057a3f

Browse files
justin-hesuryasaimadhu
authored andcommitted
EDAC/ghes: Prepare to make ghes_edac a proper module
To make ghes_edac a proper module, prepare to decouple its dependencies from GHES. Move the ghes_edac.force_load parameter to ghes.c in order to properly control whether ghes_edac should be force-loaded: In ghes_edac_register() it is too late to set the module flag. Introduce a helper ghes_get_devices(), which returns the list of GHES devices which got probed when the platform-check passes on the system. The previous force_load check is not needed in ghes_edac_unregister() since it will be checked in the module's init function of ghes_edac later. [ bp: Massage. ] Suggested-by: Toshi Kani <toshi.kani@hpe.com> Suggested-by: Borislav Petkov <bp@alien8.de> Signed-off-by: Jia He <justin.he@arm.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20221010023559.69655-4-justin.he@arm.com
1 parent 8e40612 commit 9057a3f

3 files changed

Lines changed: 58 additions & 33 deletions

File tree

drivers/acpi/apei/ghes.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ static inline bool is_hest_type_generic_v2(struct ghes *ghes)
109109
bool ghes_disable;
110110
module_param_named(disable, ghes_disable, bool, 0);
111111

112+
/*
113+
* "ghes.edac_force_enable" forcibly enables ghes_edac and skips the platform
114+
* check.
115+
*/
116+
static bool ghes_edac_force_enable;
117+
module_param_named(edac_force_enable, ghes_edac_force_enable, bool, 0);
118+
112119
/*
113120
* All error sources notified with HED (Hardware Error Device) share a
114121
* single notifier callback, so they need to be linked and checked one
@@ -120,6 +127,13 @@ module_param_named(disable, ghes_disable, bool, 0);
120127
static LIST_HEAD(ghes_hed);
121128
static DEFINE_MUTEX(ghes_list_mutex);
122129

130+
/*
131+
* A list of GHES devices which are given to the corresponding EDAC driver
132+
* ghes_edac for further use.
133+
*/
134+
static LIST_HEAD(ghes_devs);
135+
static DEFINE_MUTEX(ghes_devs_mutex);
136+
123137
/*
124138
* Because the memory area used to transfer hardware error information
125139
* from BIOS to Linux can be determined only in NMI, IRQ or timer
@@ -1380,6 +1394,12 @@ static int ghes_probe(struct platform_device *ghes_dev)
13801394

13811395
ghes_edac_register(ghes, &ghes_dev->dev);
13821396

1397+
ghes->dev = &ghes_dev->dev;
1398+
1399+
mutex_lock(&ghes_devs_mutex);
1400+
list_add_tail(&ghes->elist, &ghes_devs);
1401+
mutex_unlock(&ghes_devs_mutex);
1402+
13831403
/* Handle any pending errors right away */
13841404
spin_lock_irqsave(&ghes_notify_lock_irq, flags);
13851405
ghes_proc(ghes);
@@ -1444,6 +1464,10 @@ static int ghes_remove(struct platform_device *ghes_dev)
14441464

14451465
ghes_edac_unregister(ghes);
14461466

1467+
mutex_lock(&ghes_devs_mutex);
1468+
list_del(&ghes->elist);
1469+
mutex_unlock(&ghes_devs_mutex);
1470+
14471471
kfree(ghes);
14481472

14491473
platform_set_drvdata(ghes_dev, NULL);
@@ -1500,6 +1524,32 @@ void __init acpi_ghes_init(void)
15001524
pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
15011525
}
15021526

1527+
/*
1528+
* Known x86 systems that prefer GHES error reporting:
1529+
*/
1530+
static struct acpi_platform_list plat_list[] = {
1531+
{"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions},
1532+
{ } /* End */
1533+
};
1534+
1535+
struct list_head *ghes_get_devices(void)
1536+
{
1537+
int idx = -1;
1538+
1539+
if (IS_ENABLED(CONFIG_X86)) {
1540+
idx = acpi_match_platform_list(plat_list);
1541+
if (idx < 0) {
1542+
if (!ghes_edac_force_enable)
1543+
return NULL;
1544+
1545+
pr_warn_once("Force-loading ghes_edac on an unsupported platform. You're on your own!\n");
1546+
}
1547+
}
1548+
1549+
return &ghes_devs;
1550+
}
1551+
EXPORT_SYMBOL_GPL(ghes_get_devices);
1552+
15031553
void ghes_register_report_chain(struct notifier_block *nb)
15041554
{
15051555
atomic_notifier_chain_register(&ghes_report_chain, nb);

drivers/edac/ghes_edac.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ static DEFINE_MUTEX(ghes_reg_mutex);
5454
*/
5555
static DEFINE_SPINLOCK(ghes_lock);
5656

57-
/* "ghes_edac.force_load=1" skips the platform check */
58-
static bool __read_mostly force_load;
59-
module_param(force_load, bool, 0);
60-
6157
static bool system_scanned;
6258

6359
/* Memory Device - Type 17 of SMBIOS spec */
@@ -387,34 +383,15 @@ static struct notifier_block ghes_edac_mem_err_nb = {
387383
.priority = 0,
388384
};
389385

390-
/*
391-
* Known systems that are safe to enable this module.
392-
*/
393-
static struct acpi_platform_list plat_list[] = {
394-
{"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions},
395-
{ } /* End */
396-
};
397-
398386
int ghes_edac_register(struct ghes *ghes, struct device *dev)
399387
{
400388
bool fake = false;
401389
struct mem_ctl_info *mci;
402390
struct ghes_pvt *pvt;
403391
struct edac_mc_layer layers[1];
404392
unsigned long flags;
405-
int idx = -1;
406393
int rc = 0;
407394

408-
if (IS_ENABLED(CONFIG_X86)) {
409-
/* Check if safe to enable on this system */
410-
idx = acpi_match_platform_list(plat_list);
411-
if (!force_load && idx < 0)
412-
return -ENODEV;
413-
} else {
414-
force_load = true;
415-
idx = 0;
416-
}
417-
418395
/* finish another registration/unregistration instance first */
419396
mutex_lock(&ghes_reg_mutex);
420397

@@ -458,15 +435,10 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev)
458435
pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n");
459436
pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n");
460437
pr_info("work on such system. Use this driver with caution\n");
461-
} else if (idx < 0) {
462-
pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n");
463-
pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n");
464-
pr_info("So, the end result of using this driver varies from vendor to vendor.\n");
465-
pr_info("If you find incorrect reports, please contact your hardware vendor\n");
466-
pr_info("to correct its BIOS.\n");
467-
pr_info("This system has %d DIMM sockets.\n", ghes_hw.num_dimms);
468438
}
469439

440+
pr_info("This system has %d DIMM sockets.\n", ghes_hw.num_dimms);
441+
470442
if (!fake) {
471443
struct dimm_info *src, *dst;
472444
int i = 0;
@@ -535,9 +507,6 @@ void ghes_edac_unregister(struct ghes *ghes)
535507
struct mem_ctl_info *mci;
536508
unsigned long flags;
537509

538-
if (!force_load)
539-
return;
540-
541510
mutex_lock(&ghes_reg_mutex);
542511

543512
system_scanned = false;

include/acpi/ghes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct ghes {
2727
struct timer_list timer;
2828
unsigned int irq;
2929
};
30+
struct device *dev;
31+
struct list_head elist;
3032
};
3133

3234
struct ghes_estatus_node {
@@ -80,6 +82,8 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev);
8082

8183
void ghes_edac_unregister(struct ghes *ghes);
8284

85+
struct list_head *ghes_get_devices(void);
86+
8387
#else
8488
static inline int ghes_edac_register(struct ghes *ghes, struct device *dev)
8589
{
@@ -89,6 +93,8 @@ static inline int ghes_edac_register(struct ghes *ghes, struct device *dev)
8993
static inline void ghes_edac_unregister(struct ghes *ghes)
9094
{
9195
}
96+
97+
static inline struct list_head *ghes_get_devices(void) { return NULL; }
9298
#endif
9399

94100
static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)

0 commit comments

Comments
 (0)