Skip to contentSkip to conversation

ACPI: APEI: move edac_init ahead of ghes platform drv register

PATCH In review Jia He 4 participants 26 messages Aug 5, 2022 – Aug 11, 2022

Subsystems (5)
lore
Share & tools
lore

Jia He

author
#0 lore raw

PATCH 1/1 ACPI: APEI: move edac_init ahead of ghes platform drv register

Commit dc4e8c07e9e2 ("ACPI: APEI: explicit init of HEST and GHES in apci_init()") introduced a bug that invoking ghes_edac_register() before edac_init(). Because at that time, the bus "edac" hasn't been registered, this created sysfs /devices/mc0 instead of /sys/devices/system/edac/mc/mc0 and caused a sysfs dup splat on an Ampere eMag server:
sysfs: cannot create duplicate filename '/devices/mc0'

 CPU: 19 PID: 1 Comm: swapper/0 Not tainted 5.19.0+ #138
 random: crng init done
 Hardware name: MiTAC RAPTOR EV-883832-X3-0001/RAPTOR, BIOS 0.14 02/22/2019
 Call trace:
  sysfs_warn_dup+0x6c/0x88
  sysfs_create_dir_ns+0xec/0x108
  kobject_add_internal+0xc0/0x328
  kobject_add+0x94/0x108
  device_add+0x104/0x8b0
  pmu_dev_alloc+0xb4/0x128
  perf_pmu_register+0x308/0x438
  xgene_pmu_dev_add+0x168/0x2c8
  acpi_pmu_dev_add+0x1f0/0x370
  acpi_ns_walk_namespace+0x16c/0x1ec
  acpi_walk_namespace+0xb0/0xf8
  xgene_pmu_probe+0x6b8/0x8a0
  platform_probe+0x70/0xe0
  really_probe+0x164/0x3b0
  __driver_probe_device+0x11c/0x190
  driver_probe_device+0x44/0xf8
  __driver_attach+0xc4/0x1b8
  bus_for_each_dev+0x78/0xd0
  driver_attach+0x2c/0x38
  bus_add_driver+0x150/0x240
  driver_register+0x6c/0x128
  __platform_driver_register+0x30/0x40
  xgene_pmu_driver_init+0x24/0x30
  do_one_initcall+0x50/0x248
  kernel_init_freeable+0x284/0x328
  kernel_init+0x2c/0x140
  ret_from_fork+0x10/0x20
 kobject_add_internal failed for mc0 with -EEXIST, don't try to register things with the same name in the same

This patch fixes it by moving edac_init() into acpi_ghes_init() and ahead of platform_driver_register().

Fixes dc4e8c07e9e2 ("ACPI: APEI: explicit init of HEST and GHES in apci_init()")
Cc Shuai Xue <[email protected]>
---
 drivers/acpi/apei/ghes.c   | 1 +
 drivers/edac/edac_module.c | 3 +--
 include/linux/edac.h       | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/apei/ghes.c +1 -0
index d91ad378c00d..1127dfffeeb0 100644
@@ -1462,6 +1462,7 @@ void __init acpi_ghes_init(void)
 	int rc;
 
 	sdei_init();
+	edac_init();
 
 	if (acpi_disabled)
 		return;
drivers/edac/edac_module.c +1 -2
index 32a931d0cb71..34ada2064b36 100644
@@ -99,7 +99,7 @@ EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
  * edac_init
  *      module initialization entry point
  */
-static int __init edac_init(void)
+int __init edac_init(void)
 {
 	int err = 0;
 
@@ -160,7 +160,6 @@ static void __exit edac_exit(void)
 /*
  * Inform the kernel of our entry and exit points
  */
-subsys_initcall(edac_init);
 module_exit(edac_exit);
 
 MODULE_LICENSE("GPL");
include/linux/edac.h +1 -0
index e730b3468719..104b22c2c177 100644
@@ -30,6 +30,7 @@ struct device;
 
 extern int edac_op_state;
 
+int __init edac_init(void);
 struct bus_type *edac_get_sysfs_subsys(void);
 
 static inline void opstate_init(void)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 79 lines · Jia He

Commit dc4e8c07e9e2 ("ACPI: APEI: explicit init of HEST and GHES in apci_init()") introduced a bug that invoking ghes_edac_register() before edac_init(). Because at that time, the bus "edac" hasn't been registered, this created sysfs /devices/mc0 instead of /sys/devices/system/edac/mc/mc0 and caused a sysfs dup splat on an Ampere eMag server:
sysfs: cannot create duplicate filename '/devices/mc0'

 CPU: 19 PID: 1 Comm: swapper/0 Not tainted 5.19.0+ #138
 random: crng init done
 Hardware name: MiTAC RAPTOR EV-883832-X3-0001/RAPTOR, BIOS 0.14 02/22/2019
 Call trace:
  sysfs_warn_dup+0x6c/0x88
  sysfs_create_dir_ns+0xec/0x108
  kobject_add_internal+0xc0/0x328
  kobject_add+0x94/0x108
  device_add+0x104/0x8b0
  pmu_dev_alloc+0xb4/0x128
  perf_pmu_register+0x308/0x438
  xgene_pmu_dev_add+0x168/0x2c8
  acpi_pmu_dev_add+0x1f0/0x370
  acpi_ns_walk_namespace+0x16c/0x1ec
  acpi_walk_namespace+0xb0/0xf8
  xgene_pmu_probe+0x6b8/0x8a0
  platform_probe+0x70/0xe0
  really_probe+0x164/0x3b0
  __driver_probe_device+0x11c/0x190
  driver_probe_device+0x44/0xf8
  __driver_attach+0xc4/0x1b8
  bus_for_each_dev+0x78/0xd0
  driver_attach+0x2c/0x38
  bus_add_driver+0x150/0x240
  driver_register+0x6c/0x128
  __platform_driver_register+0x30/0x40
  xgene_pmu_driver_init+0x24/0x30
  do_one_initcall+0x50/0x248
  kernel_init_freeable+0x284/0x328
  kernel_init+0x2c/0x140
  ret_from_fork+0x10/0x20
 kobject_add_internal failed for mc0 with -EEXIST, don't try to register things with the same name in the same

This patch fixes it by moving edac_init() into acpi_ghes_init() and ahead of platform_driver_register().

Fixes dc4e8c07e9e2 ("ACPI: APEI: explicit init of HEST and GHES in apci_init()")
Cc Shuai Xue <[email protected]>
---
 drivers/acpi/apei/ghes.c   | 1 +
 drivers/edac/edac_module.c | 3 +--
 include/linux/edac.h       | 1 +
 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/apei/ghes.c +1 -0
index d91ad378c00d..1127dfffeeb0 100644
@@ -1462,6 +1462,7 @@ void __init acpi_ghes_init(void)
        int rc;
 
        sdei_init();
+       edac_init();
 
        if (acpi_disabled)
                return;
drivers/edac/edac_module.c +1 -1
index 32a931d0cb71..34ada2064b36 100644
@@ -99,7 +99,7 @@ EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
  * edac_init
  *      module initialization entry point
  */
-static int __init edac_init(void)
+int __init edac_init(void)
 {
        int err = 0;
 

drivers/edac/edac_module.c static void __exit edac_exit(void) · line 163

Quoted 4 lines
drivers/edac/edac_module.c +0 -1
@@ -160,7 +160,6 @@ static void __exit edac_exit(void)
 /*
  * Inform the kernel of our entry and exit points
  */
-subsys_initcall(edac_init);

This effectively makes EDAC depend on GHES which may not be always valid AFAICS.

Quoted 16 lines
drivers/edac/edac_module.c +0 -0
 module_exit(edac_exit);
 
 MODULE_LICENSE("GPL");
include/linux/edac.h +1 -1
index e730b3468719..104b22c2c177 100644
@@ -30,6 +30,7 @@ struct device;
 
 extern int edac_op_state;
 
+int __init edac_init(void);
 struct bus_type *edac_get_sysfs_subsys(void);
 
 static inline void opstate_init(void)
--
maintainer
#2 lore raw

+ Toshi.

Quoted 2 lines · Rafael J. Wysocki

This effectively makes EDAC depend on GHES which may not be always valid AFAICS.

Yes, and this has been getting on my nerves since forever.

The GHES code which does collect all those errors *forces* the registration of an EDAC module which does only the reporting.

Which cannot be any more backwards.

What should happen is, GHES inits and starts working on the errors. Then, at some point later, ghes_edac loads and starts reporting whatever it gets. If there's no EDAC module, it doesn't report them. The same way MCA works.

That's it.

And then ghes_edac can be made a normal module again and we can get rid of this insanity.

Jia, willing to try it?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 16 lines · Borislav Petkov
Quoted 2 lines · Rafael J. Wysocki

This effectively makes EDAC depend on GHES which may not be always valid AFAICS.

Yes, and this has been getting on my nerves since forever.

The GHES code which does collect all those errors *forces* the registration of an EDAC module which does only the reporting.

Which cannot be any more backwards.

What should happen is, GHES inits and starts working on the errors. Then, at some point later, ghes_edac loads and starts reporting whatever it gets. If there's no EDAC module, it doesn't report them. The same way MCA works.

Quoted 4 lines

That's it.

And then ghes_edac can be made a normal module again and we can get rid of this insanity.

The following approach may be considerable:
- Separate ghes_edac_register() into two functions, e.g., ghes_edac_register() and ghes_edac_init().
- ghes_edac_register() only takes the first if-block with IS_ENABLED() & force_load check, and then calls a new function, edac_set_owner(mod_name), which simply sets mod_name to edac_mc_owner. This allows ghes_edac_register() to run before edac_init(), and sets edac_mc_owner to prevent chipset-specific edac driver to be loaded before ghes_edac.
- ghes_edac_init() first calls edac_get_owner() to match with its mod_name. If so, it performs the rest of the original ghes_edac_register() procedure. This ghes_edac_init() is called from the normal module init path, e.g., module_init().

Thanks,
Toshi

maintainer
#4 lore raw
Quoted 2 lines · Toshi

This allows ghes_edac_register() to run before edac_init(), and sets edac_mc_owner to prevent chipset-specific edac driver

So this is the important part: how does it get decided which EDAC driver to load? The chipset-specific one or the FW glue one?

User, policy, etc?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
Quoted 8 lines · Borislav Petkov
Quoted 2 lines · Toshi

This allows ghes_edac_register() to run before edac_init(), and sets edac_mc_owner to prevent chipset-specific edac driver

So this is the important part: how does it get decided which EDAC driver to load? The chipset-specific one or the FW glue one?

User, policy, etc?

Whichever loaded first wins.

Chipset-specific one checks with chipset IDs but does not check with GHES. Hence, ghes_edac_register() needs to run before chipset-specific one.

Toshi

maintainer
#6 lore raw
Quoted 1 line · Toshi

Whichever loaded first wins.

That I know.

The question is, which one *should* win each time.

IOW, on which platforms should ghes_edac load and on which the chipset-one?

I'm guessing the answer is the plat_list...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#7 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 1 line · Toshi

Whichever loaded first wins.

That I know.

The question is, which one *should* win each time.

IOW, on which platforms should ghes_edac load and on which the chipset- one?

Platforms with ACPI GHES support should use ghes_edac. This is the case on Arm. The x86 side has additional platform ID check to protect from legacy buggy GHES FW existed before ghes_edac enablement.

Toshi

maintainer
#8 lore raw
Quoted 3 lines · Toshi

Platforms with ACPI GHES support should use ghes_edac. This is the case on Arm. The x86 side has additional platform ID check to protect from legacy buggy GHES FW existed before ghes_edac enablement.

Sounds to me like we should put all that logic in ghes.c and out of ghes_edac and the EDAC drivers will query it by doing upon load:

<edac_driver>_init:

	if (ghes_edac_driver_is_preferred())
		return -ENODEV;

And then ghes_edac can become a normal driver module again.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#9 lore raw
Quoted 22 lines

-----邮件原件-----
发件人: Borislav Petkov <[email protected]>
发送时间: Tuesday, August 9, 2022 3:41 PM
收件人: Kani, Toshi <[email protected]>
抄送: Rafael J. Wysocki <[email protected]>; Justin He <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
主题: Re: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

Quoted 3 lines · Toshi

Platforms with ACPI GHES support should use ghes_edac. This is the case on Arm. The x86 side has additional platform ID check to protect from legacy buggy GHES FW existed before ghes_edac enablement.

Quoted 8 lines

Sounds to me like we should put all that logic in ghes.c and out of ghes_edac and the EDAC drivers will query it by doing upon load:

<edac_driver>_init:

      if (ghes_edac_driver_is_preferred())
              return -ENODEV;

Do you mean the similar logic as what Kani Toshi suggested? e.g.
bool ghes_edac_driver_is_preferred()

{
        If (mod_name is "ghes_edac")
                return true;

        return false;
}

If no, what is the detail logic of ghes_edac_driver_is_preferred()? Thanks for the clarification 😊
Because I notice that lots of other edac drivers are probing like:
...

        owner = edac_get_owner();
        if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
                return -EBUSY;

...

Quoted 2 lines

And then ghes_edac can become a normal driver module again.

--
Cheers,
Justin (Jia He)
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

maintainer
#10 lore raw
Quoted 1 line · Justin He

If no, what is the detail logic of ghes_edac_driver_is_preferred()?

That should be moved from ghes_edac.c to ghes.c:

/*
* Known systems that are safe to enable this module. */

static struct acpi_platform_list plat_list[] = {
        {"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
        { } /* End */
};

and then

bool ghes_edac_driver_is_preferred()

{
	if (IS_ENABLED(CONFIG_X86)) {
                /* Check if safe to enable on this system */
                idx = acpi_match_platform_list(plat_list);
	} else if (ARM) {
		/* insert ARM logic here */
	}
}

That function should be called by the EDAC modules which compete with ghes_edac.

In the x86 case, that's sb_edac, skx_edac and amd64_edac, I guess.

It all depends on what platforms Toshi wants to load it - I'm guessing HPE has both Intel and AMD platforms where they prefer ghes_edac.

On ARM, that's up to ARM folks.

Quoted 5 lines

Because I notice that lots of other edac drivers are probing like:
...

        owner = edac_get_owner();
        if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR)))
                return -EBUSY;

No, that's a silly mechanism to allow a single EDAC driver to load on the system. But your test will go before it, at the very beginning of the init function.

HTH.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#11 lore raw
Quoted 10 lines · Borislav Petkov

bool ghes_edac_driver_is_preferred()

{
	if (IS_ENABLED(CONFIG_X86)) {
                /* Check if safe to enable on this system */
                idx = acpi_match_platform_list(plat_list);
	} else if (ARM) {
		/* insert ARM logic here */
	}
}
Quoted 2 lines

That function should be called by the EDAC modules which compete with ghes_edac.

The logic needs to be latched on ghes presence, i.e., the condition is (ghes-present) && (ghes-preferred). Currently, ghes_probe() calls ghes_edac_register() for this.

Quoted 1 line

In the x86 case, that's sb_edac, skx_edac and amd64_edac, I guess.

Agree that changing all edac drivers to check with GHES is an option. In this approach, though, they will need to check with foo_preferred() when a new FW interface FOO is introduced.

Quoted 2 lines

It all depends on what platforms Toshi wants to load it - I'm guessing HPE has both Intel and AMD platforms where they prefer ghes_edac.

Yes, and HPE will keep the same platform ID for GHES/FF model.

Quoted 6 lines

On ARM, that's up to ARM folks.

Quoted 4 lines

Because I notice that lots of other edac drivers are probing like:
...

        owner = edac_get_owner();
        if (owner && strncmp(owner, EDAC_MOD_STR,
Quoted 6 lines

sizeof(EDAC_MOD_STR)))

Quoted 1 line
                return -EBUSY;

No, that's a silly mechanism to allow a single EDAC driver to load on the system. But your test will go before it, at the very beginning of the init function.

Well, this check being interface independent (like GHES) is good at least.

Toshi

maintainer
#12 lore raw
Quoted 1 line · Toshi

The logic needs to be latched on ghes presence, i.e., the condition is

If GHES is not enabled, there'll of course be a stub which returns false.

Quoted 1 line

Agree that changing all edac drivers to check with GHES is an option.

Not all - all relevant drivers for your - HPE - use case. We don't load ghes_edac on anything else. Known-good platforms only, remember?

Quoted 2 lines

In this approach, though, they will need to check with foo_preferred() when a new FW interface FOO is introduced.

I'm afraid I don't understand what you mean here.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#13 lore raw
Quoted 5 lines · Borislav Petkov
Quoted 1 line · Toshi

The logic needs to be latched on ghes presence, i.e., the condition is

If GHES is not enabled, there'll of course be a stub which returns false.

Right. Just checking since the example pseudo code did not have it.

Quoted 4 lines
Quoted 1 line

Agree that changing all edac drivers to check with GHES is an option.

Not all - all relevant drivers for your - HPE - use case. We don't load ghes_edac on anything else. Known-good platforms only, remember?

I think this should be all edac drivers on x86.

Quoted 4 lines
Quoted 2 lines

In this approach, though, they will need to check with foo_preferred() when a new FW interface FOO is introduced.

I'm afraid I don't understand what you mean here.

I was referring a hypothetical future case that ACPI GHES might not be the only FW interface for FF-based memory error reporting table going forward.

Toshi

maintainer
#14 lore raw
Quoted 1 line · Toshi

I think this should be all edac drivers on x86.

Because?

Quoted 3 lines

I was referring a hypothetical future case that ACPI GHES might not be the only FW interface for FF-based memory error reporting table going forward.

Don't tell me you have something else in the works which will override GHES...

Can you guys make up your mind and stick with it?!

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#15 lore raw
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Toshi

I think this should be all edac drivers on x86.

Because?

ghes_edac.force_load option skips the platform ID check on x86.

I am not familiar with Arm platforms, but Arm edac drivers may need this change as well.

Quoted 8 lines
Quoted 3 lines

I was referring a hypothetical future case that ACPI GHES might not be the only FW interface for FF-based memory error reporting table going forward.

Don't tell me you have something else in the works which will override GHES...

Can you guys make up your mind and stick with it?!

I am not aware of any such effort.

Toshi

author
#16 lore raw
In reply to Borislav Petkov

Hi Borislav

Quoted 40 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Tuesday, August 9, 2022 7:16 PM
To: Justin He <[email protected]>
Cc: Kani, Toshi <[email protected]>; Rafael J. Wysocki <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
Subject: Re: 回复: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

Quoted 1 line · Justin He

If no, what is the detail logic of ghes_edac_driver_is_preferred()?

That should be moved from ghes_edac.c to ghes.c:

/*
* Known systems that are safe to enable this module. */

static struct acpi_platform_list plat_list[] = {
        {"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
        { } /* End */
};

and then

bool ghes_edac_driver_is_preferred()

{
      if (IS_ENABLED(CONFIG_X86)) {
                /* Check if safe to enable on this system */
                idx = acpi_match_platform_list(plat_list);
      } else if (ARM) {
              /* insert ARM logic here */
      }
}
Quoted 4 lines

That function should be called by the EDAC modules which compete with ghes_edac.

In the x86 case, that's sb_edac, skx_edac and amd64_edac, I guess.

Ok, thanks a lot for elaborating it more.
Let me summarize it before sending v2 (maybe tomorrow):
1. implement a ghes_edac_driver_is_preferred() to replace the old ghes_edac_register() and move it to ghes.c together with plat_list
2. save the ghes and dev to a global structure and pass it to the new module_init 3.move the remain logic of old ghes_edac_register() to a new XX_init() which is under the module_init path.
4. introduce a stub ghes_edac_driver_is_preferred() for sb_edac, skx_edac and amd64_edac to check.
5. add the check condition in the XXX_init of sb_edac, skx_edac and amd64_edac

Please let me know if I missed anything above.

--
Cheers,
Justin (Jia He)

Quoted 17 lines

It all depends on what platforms Toshi wants to load it - I'm guessing HPE has both Intel and AMD platforms where they prefer ghes_edac.

On ARM, that's up to ARM folks.

Quoted 4 lines

Because I notice that lots of other edac drivers are probing like:
...

        owner = edac_get_owner();
        if (owner && strncmp(owner, EDAC_MOD_STR,

sizeof(EDAC_MOD_STR)))

Quoted 1 line
                return -EBUSY;

No, that's a silly mechanism to allow a single EDAC driver to load on the system. But your test will go before it, at the very beginning of the init function.

Quoted 7 lines

HTH.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

maintainer
#17 lore raw
Quoted 3 lines · Justin He

Let me summarize it before sending v2 (maybe tomorrow):
1. implement a ghes_edac_driver_is_preferred() to replace the old ghes_edac_register() and move it to ghes.c together with plat_list

No, not replace.

In ghes.c:

- add ghes_edac_driver_is_preferred()
- remove ghes_edac_register() and _unregister() calls from there. Make them proper module init/exit functions.
- Make ghes_edac.c a proper module - i.e., get rid of this thing:

config EDAC_GHES

        bool "Output ACPI APEI/GHES BIOS detected errors via EDAC"
        depends on ACPI_APEI_GHES && (EDAC=y)
				     ^^^^^^^^
Quoted 1 line

2. save the ghes and dev to a global structure and pass it to the new module_init

Not at all...

Quoted 7 lines

3.move the remain logic of old ghes_edac_register() to a new XX_init() which is under the module_init path.
4. introduce a stub ghes_edac_driver_is_preferred() for sb_edac, skx_edac and amd64_edac to check.
5. add the check condition in the XXX_init of sb_edac, skx_edac and amd64_edac

Please let me know if I missed anything above.

Yes, I think you do. Lemme write something and you can finish it/test it.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#18 lore raw
Quoted 2 lines · Borislav Petkov

Yes, I think you do. Lemme write something and you can finish it/test it.

Here's something to only show what I'm thinking of. It doesn't build because of:

drivers/acpi/apei/ghes.c: In function ‘ghes_do_proc’:
drivers/acpi/apei/ghes.c:651:25: error: implicit declaration of function ‘ghes_edac_report_mem_error’; did you mean ‘arch_apei_report_mem_error’? [-Werror=implicit-function-declaration]
651 | ghes_edac_report_mem_error(sev, mem_err);

and that needs more thinking what to do. My idea currently is to do a notifier like we do for MCA...

And I'm not really happy about returning a list of ghes devices just so ghes_edac instances can get their struct device * pointers. Maybe we'll think of something better.

But this is the general goal: not call module code from builtin code - i.e., call ghes_edac.c code from ghes.c. It works now because ghes_edac is forced builtin which is ugly as hell.

Anyway, enough for today...

---

drivers/acpi/apei/ghes.c +30 -3
index d91ad378c00d..0919317b8313 100644
@@ -118,6 +118,9 @@ module_param_named(disable, ghes_disable, bool, 0);
 static LIST_HEAD(ghes_hed);
 static DEFINE_MUTEX(ghes_list_mutex);
 
+static LIST_HEAD(ghes_devs);
+static DEFINE_MUTEX(ghes_devs_mutex);
+
 /*
  * Because the memory area used to transfer hardware error information
  * from BIOS to Linux can be determined only in NMI, IRQ or timer
@@ -1376,7 +1379,11 @@ static int ghes_probe(struct platform_device *ghes_dev)
 
 	platform_set_drvdata(ghes_dev, ghes);
 
-	ghes_edac_register(ghes, &ghes_dev->dev);
+	ghes->dev = &ghes_dev->dev;
+
+	mutex_lock(&ghes_devs_mutex);
+	list_add_tail(&ghes->elist, &ghes_devs);
+	mutex_unlock(&ghes_devs_mutex);
 
 	/* Handle any pending errors right away */
 	spin_lock_irqsave(&ghes_notify_lock_irq, flags);
@@ -1440,8 +1447,6 @@ static int ghes_remove(struct platform_device *ghes_dev)
 
 	ghes_fini(ghes);
 
-	ghes_edac_unregister(ghes);
-
 	kfree(ghes);
 
 	platform_set_drvdata(ghes_dev, NULL);
@@ -1497,3 +1502,25 @@ void __init acpi_ghes_init(void)
 	else
 		pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
 }
+
+/*
+ * Known x86 systems that prefer GHES error reporting:
+ */
+static struct acpi_platform_list plat_list[] = {
+	{"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
+	{ } /* End */
+};
+
+struct list_head *ghes_get_devices(bool force)
+{
+	int idx = -1;
+
+	if (IS_ENABLED(CONFIG_X86)) {
+		idx = acpi_match_platform_list(plat_list);
+		if (idx < 0 && !force)
+			return NULL;
+	}
+
+	return &ghes_devs;
+}
+EXPORT_SYMBOL_GPL(ghes_get_devices);
drivers/edac/Kconfig +2 -2
index 17562cf1fe97..df45db81858b 100644
@@ -53,8 +53,8 @@ config EDAC_DECODE_MCE
 	  has been initialized.
 
 config EDAC_GHES
-	bool "Output ACPI APEI/GHES BIOS detected errors via EDAC"
-	depends on ACPI_APEI_GHES && (EDAC=y)
+	tristate "Output ACPI APEI/GHES BIOS detected errors via EDAC"
+	depends on ACPI_APEI_GHES
 	select UEFI_CPER
 	help
 	  Not all machines support hardware-driven error report. Some of those
drivers/edac/ghes_edac.c +32 -22

89 lines not on this page · raw message

include/acpi/ghes.h +5 -25
index 34fb3431a8f3..f39b75c3f9c6 100644
@@ -27,6 +27,8 @@ struct ghes {
 		struct timer_list timer;
 		unsigned int irq;
 	};
+	struct device *dev;
+	struct list_head elist;
 };
 
 struct ghes_estatus_node {
@@ -69,35 +71,13 @@ int ghes_register_vendor_record_notifier(struct notifier_block *nb);
  * @nb: pointer to the notifier_block structure of the vendor record handler.
  */
 void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
+struct list_head *ghes_get_devices(bool force);
+#else
+static inline struct list_head *ghes_get_devices(bool force) { return NULL; }
 #endif
 
 int ghes_estatus_pool_init(int num_ghes);
 
-/* From drivers/edac/ghes_edac.c */
-
-#ifdef CONFIG_EDAC_GHES
-void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err);
-
-int ghes_edac_register(struct ghes *ghes, struct device *dev);
-
-void ghes_edac_unregister(struct ghes *ghes);
-
-#else
-static inline void ghes_edac_report_mem_error(int sev,
-				       struct cper_sec_mem_err *mem_err)
-{
-}
-
-static inline int ghes_edac_register(struct ghes *ghes, struct device *dev)
-{
-	return -ENODEV;
-}
-
-static inline void ghes_edac_unregister(struct ghes *ghes)
-{
-}
-#endif
-
 static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
 {
 	return gdata->revision >> 8;
Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#19 lore raw

Hi Borislav

Quoted 30 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 10, 2022 2:46 AM
To: Justin He <[email protected]>
Cc: Kani, Toshi <[email protected]>; Rafael J. Wysocki <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
Subject: Re: 回复: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

Quoted 2 lines · Borislav Petkov

Yes, I think you do. Lemme write something and you can finish it/test it.

Here's something to only show what I'm thinking of. It doesn't build because of:

drivers/acpi/apei/ghes.c: In function ‘ghes_do_proc’:
drivers/acpi/apei/ghes.c:651:25: error: implicit declaration of function ‘ghes_edac_report_mem_error’; did you mean ‘arch_apei_report_mem_error’? [-Werror=implicit-function-declaration]
651 | ghes_edac_report_mem_error(sev,
mem_err);

Quoted 2 lines

and that needs more thinking what to do. My idea currently is to do a notifier like we do for MCA...

There is still a small gap even if we use notifier for ghes edac report mem error.

The notifier will be registered only when calling module_init() of ghes_edac module. Then there will be different behavior for ghes_do_proc:
1. if ghes_do_proc is invoked in the acpi_init code path, the notifier has NOT been registered, ghes_edac_report_mem_err() does nothing.
2.If ghes_do_proc is invoked after module_init(), the notifier is registered, everything is fine.

Is this strange or any other side effects?

--
Cheers,
Justin (Jia He)

Quoted 245 lines

And I'm not really happy about returning a list of ghes devices just so ghes_edac instances can get their struct device * pointers. Maybe we'll think of something better.

But this is the general goal: not call module code from builtin code - i.e., call ghes_edac.c code from ghes.c. It works now because ghes_edac is forced builtin which is ugly as hell.

Anyway, enough for today...

---

drivers/acpi/apei/ghes.c index renamed from drivers/acpi/apei/ghes.c +0 -0

d91ad378c00d..0919317b8313 100644

drivers/acpi/apei/ghes.c +3 -1
@@ -118,6 +118,9 @@ module_param_named(disable, ghes_disable, bool,
 0);  static LIST_HEAD(ghes_hed);  static DEFINE_MUTEX(ghes_list_mutex);
 
+static LIST_HEAD(ghes_devs);
+static DEFINE_MUTEX(ghes_devs_mutex);
+
 /*
  * Because the memory area used to transfer hardware error information
  * from BIOS to Linux can be determined only in NMI, IRQ or timer @@
-1376,7 +1379,11 @@ static int ghes_probe(struct platform_device

*ghes_dev)

      platform_set_drvdata(ghes_dev, ghes);
drivers/acpi/apei/ghes.c +5 -1
-     ghes_edac_register(ghes, &ghes_dev->dev);
+     ghes->dev = &ghes_dev->dev;
+
+     mutex_lock(&ghes_devs_mutex);
+     list_add_tail(&ghes->elist, &ghes_devs);
+     mutex_unlock(&ghes_devs_mutex);
 
      /* Handle any pending errors right away */
      spin_lock_irqsave(&ghes_notify_lock_irq, flags); @@ -1440,8 +1447,6

@@ static int ghes_remove(struct platform_device *ghes_dev)

      ghes_fini(ghes);
drivers/acpi/apei/ghes.c +21 -2
-     ghes_edac_unregister(ghes);
-
      kfree(ghes);
 
      platform_set_drvdata(ghes_dev, NULL);
@@ -1497,3 +1502,25 @@ void __init acpi_ghes_init(void)
      else
              pr_info(GHES_PFX "Failed to enable APEI firmware first
 mode.\n");  }
+
+/*
+ * Known x86 systems that prefer GHES error reporting:
+ */
+static struct acpi_platform_list plat_list[] = {
+     {"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
+     { } /* End */
+};
+
+struct list_head *ghes_get_devices(bool force) {
+     int idx = -1;
+
+     if (IS_ENABLED(CONFIG_X86)) {
+             idx = acpi_match_platform_list(plat_list);
+             if (idx < 0 && !force)
+                     return NULL;
+     }
+
+     return &ghes_devs;
+}
+EXPORT_SYMBOL_GPL(ghes_get_devices);
drivers/edac/Kconfig index renamed from drivers/edac/Kconfig +0 -0

17562cf1fe97..df45db81858b 100644

drivers/edac/Kconfig +2 -2
@@ -53,8 +53,8 @@ config EDAC_DECODE_MCE
        has been initialized.
 
 config EDAC_GHES
-     bool "Output ACPI APEI/GHES BIOS detected errors via EDAC"
-     depends on ACPI_APEI_GHES && (EDAC=y)
+     tristate "Output ACPI APEI/GHES BIOS detected errors via EDAC"
+     depends on ACPI_APEI_GHES
      select UEFI_CPER
      help
        Not all machines support hardware-driven error report. Some of those
drivers/edac/ghes_edac.c index renamed from drivers/edac/ghes_edac.c +0 -0

c8fa7dcfdbd0..da6d1a9e107d 100644

drivers/edac/ghes_edac.c +4 -21
@@ -59,6 +59,8 @@ module_param(force_load, bool, 0);
 
 static bool system_scanned;
 
+static struct list_head *ghes_devs;
+
 /* Memory Device - Type 17 of SMBIOS spec */  struct memdev_dmi_entry
 {
      u8 type;
@@ -376,34 +378,15 @@ void ghes_edac_report_mem_error(int sev, struct
 cper_sec_mem_err *mem_err)
      spin_unlock_irqrestore(&ghes_lock, flags);  }
 
-/*
- * Known systems that are safe to enable this module.
- */
-static struct acpi_platform_list plat_list[] = {
-     {"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
-     { } /* End */
-};
-
-int ghes_edac_register(struct ghes *ghes, struct device *dev)
+static int ghes_edac_register(struct device *dev)
 {
      bool fake = false;
      struct mem_ctl_info *mci;
      struct ghes_pvt *pvt;
      struct edac_mc_layer layers[1];
      unsigned long flags;
-     int idx = -1;
      int rc = 0;
 
-     if (IS_ENABLED(CONFIG_X86)) {
-             /* Check if safe to enable on this system */
-             idx = acpi_match_platform_list(plat_list);
-             if (!force_load && idx < 0)
-                     return -ENODEV;
-     } else {
-             force_load = true;
-             idx = 0;
-     }
-
      /* finish another registration/unregistration instance first */
      mutex_lock(&ghes_reg_mutex);
 
@@ -447,7 +430,7 @@ int ghes_edac_register(struct ghes *ghes, struct
 device *dev)
              pr_info("This system has a very crappy BIOS: It doesn't even list the
 DIMMS.\n");
              pr_info("Its SMBIOS info is wrong. It is doubtful that the error report
 would\n");
              pr_info("work on such system. Use this driver with caution\n");
-     } else if (idx < 0) {
+     } else if (force_load) {

pr_info("This EDAC driver relies on BIOS to enumerate memory and
get error reports.\n");
pr_info("Unfortunately, not all BIOSes reflect the memory layout
correctly.\n");
pr_info("So, the end result of using this driver varies from vendor to
vendor.\n"); @@ -517,7 +500,7 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev)

      return rc;

}

drivers/edac/ghes_edac.c +27 -1
-void ghes_edac_unregister(struct ghes *ghes)
+static void ghes_edac_unregister(struct ghes *ghes)
 {
      struct mem_ctl_info *mci;
      unsigned long flags;
@@ -551,3 +534,30 @@ void ghes_edac_unregister(struct ghes *ghes)
 unlock:
      mutex_unlock(&ghes_reg_mutex);
 }
+
+static int __init ghes_edac_init(void)
+{
+     struct ghes *g, *g_tmp;
+
+     ghes_devs = ghes_get_devices(force_load);
+     if (ghes_devs)
+             return -ENODEV;
+
+     list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
+             ghes_edac_register(g->dev);
+     }
+
+     return 0;
+}
+module_init(ghes_edac_init);
+
+static void __exit ghes_edac_exit(void) {
+     struct ghes *g, *g_tmp;
+
+
+     list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
+             ghes_edac_unregister(g);
+     }
+}
+module_exit(ghes_edac_exit);
include/acpi/ghes.h index renamed from include/acpi/ghes.h +0 -0

34fb3431a8f3..f39b75c3f9c6 100644

include/acpi/ghes.h +4 -22
@@ -27,6 +27,8 @@ struct ghes {
              struct timer_list timer;
              unsigned int irq;
      };
+     struct device *dev;
+     struct list_head elist;
 };
 
 struct ghes_estatus_node {
@@ -69,35 +71,13 @@ int ghes_register_vendor_record_notifier(struct
 notifier_block *nb);
  * @nb: pointer to the notifier_block structure of the vendor record handler.
  */
 void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
+struct list_head *ghes_get_devices(bool force); #else static inline
+struct list_head *ghes_get_devices(bool force) { return NULL; }
 #endif
 
 int ghes_estatus_pool_init(int num_ghes);
 
-/* From drivers/edac/ghes_edac.c */
-
-#ifdef CONFIG_EDAC_GHES
-void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err
 *mem_err);
-
-int ghes_edac_register(struct ghes *ghes, struct device *dev);
-
-void ghes_edac_unregister(struct ghes *ghes);
-
-#else
-static inline void ghes_edac_report_mem_error(int sev,
-                                    struct cper_sec_mem_err *mem_err)
-{
-}
-
-static inline int ghes_edac_register(struct ghes *ghes, struct device *dev) -{
-     return -ENODEV;
-}
-
-static inline void ghes_edac_unregister(struct ghes *ghes) -{ -} -#endif
-
 static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
 {
      return gdata->revision >> 8;
 
--

Regards/Gruss,
Boris.

Quoted 1 line

https://people.kernel.org/tglx/notes-about-netiquette

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

maintainer
#20 lore raw
Quoted 1 line · Justin He

Is this strange or any other side effects?

This is no different than what we do now on x86 MCA.

If the logging machinery is modules, they consume error records only when loaded.

Quoted 5 lines

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Btw, pls get rid of this if you want to be posting on public mailing lists. You can ask your other ARM colleagues how they solved it. :)

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#21 lore raw
Quoted 17 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 10, 2022 4:28 PM
To: Justin He <[email protected]>
Cc: Kani, Toshi <[email protected]>; Rafael J. Wysocki <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
Subject: Re: 回复: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

Quoted 7 lines
Quoted 1 line · Justin He

Is this strange or any other side effects?

This is no different than what we do now on x86 MCA.

If the logging machinery is modules, they consume error records only when loaded.

Ok, got it, thanks a lot
From my local testing, after the provided patch from you + notifier register. It works after I resolved a few other issues.

When I verify different building kconfig(X86/Arm64, ghes_edac[M]/[*]), and booting, I will send out the new version.

Quoted 4 lines

Btw, pls get rid of this if you want to be posting on public mailing lists. You can ask your other ARM colleagues how they solved it. :)

Sorry, missed one configuration in the mailbox ☹

--
Cheers,
Justin (Jia He)

author
#22 lore raw
In reply to Borislav Petkov

Hi Borislav

Quoted 15 lines

-----Original Message-----
From: Borislav Petkov <[email protected]>
Sent: Wednesday, August 10, 2022 2:46 AM
To: Justin He <[email protected]>
Cc: Kani, Toshi <[email protected]>; Rafael J. Wysocki <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
Subject: Re: 回复: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

[...]

Quoted 151 lines

---

drivers/acpi/apei/ghes.c index renamed from drivers/acpi/apei/ghes.c +0 -0

d91ad378c00d..0919317b8313 100644

drivers/acpi/apei/ghes.c +3 -1
@@ -118,6 +118,9 @@ module_param_named(disable, ghes_disable, bool,
 0);  static LIST_HEAD(ghes_hed);  static DEFINE_MUTEX(ghes_list_mutex);
 
+static LIST_HEAD(ghes_devs);
+static DEFINE_MUTEX(ghes_devs_mutex);
+
 /*
  * Because the memory area used to transfer hardware error information
  * from BIOS to Linux can be determined only in NMI, IRQ or timer @@
-1376,7 +1379,11 @@ static int ghes_probe(struct platform_device

*ghes_dev)

drivers/acpi/apei/ghes.c +5 -1
 	platform_set_drvdata(ghes_dev, ghes);
 
-	ghes_edac_register(ghes, &ghes_dev->dev);
+	ghes->dev = &ghes_dev->dev;
+
+	mutex_lock(&ghes_devs_mutex);
+	list_add_tail(&ghes->elist, &ghes_devs);
+	mutex_unlock(&ghes_devs_mutex);
 
 	/* Handle any pending errors right away */
 	spin_lock_irqsave(&ghes_notify_lock_irq, flags); @@ -1440,8 +1447,6

@@ static int ghes_remove(struct platform_device *ghes_dev)

drivers/acpi/apei/ghes.c +21 -2
 	ghes_fini(ghes);
 
-	ghes_edac_unregister(ghes);
-
 	kfree(ghes);
 
 	platform_set_drvdata(ghes_dev, NULL);
@@ -1497,3 +1502,25 @@ void __init acpi_ghes_init(void)
 	else
 		pr_info(GHES_PFX "Failed to enable APEI firmware first
 mode.\n");  }
+
+/*
+ * Known x86 systems that prefer GHES error reporting:
+ */
+static struct acpi_platform_list plat_list[] = {
+	{"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
+	{ } /* End */
+};
+
+struct list_head *ghes_get_devices(bool force) {
+	int idx = -1;
+
+	if (IS_ENABLED(CONFIG_X86)) {
+		idx = acpi_match_platform_list(plat_list);
+		if (idx < 0 && !force)
+			return NULL;
+	}
+
+	return &ghes_devs;
+}
+EXPORT_SYMBOL_GPL(ghes_get_devices);
drivers/edac/Kconfig index renamed from drivers/edac/Kconfig +0 -0

17562cf1fe97..df45db81858b 100644

drivers/edac/Kconfig +2 -2
@@ -53,8 +53,8 @@ config EDAC_DECODE_MCE
 	  has been initialized.
 
 config EDAC_GHES
-	bool "Output ACPI APEI/GHES BIOS detected errors via EDAC"
-	depends on ACPI_APEI_GHES && (EDAC=y)
+	tristate "Output ACPI APEI/GHES BIOS detected errors via EDAC"
+	depends on ACPI_APEI_GHES
 	select UEFI_CPER
 	help
 	  Not all machines support hardware-driven error report. Some of those
drivers/edac/ghes_edac.c index renamed from drivers/edac/ghes_edac.c +0 -0

c8fa7dcfdbd0..da6d1a9e107d 100644

drivers/edac/ghes_edac.c +4 -21
@@ -59,6 +59,8 @@ module_param(force_load, bool, 0);
 
 static bool system_scanned;
 
+static struct list_head *ghes_devs;
+
 /* Memory Device - Type 17 of SMBIOS spec */  struct memdev_dmi_entry
 {
 	u8 type;
@@ -376,34 +378,15 @@ void ghes_edac_report_mem_error(int sev, struct
 cper_sec_mem_err *mem_err)
 	spin_unlock_irqrestore(&ghes_lock, flags);  }
 
-/*
- * Known systems that are safe to enable this module.
- */
-static struct acpi_platform_list plat_list[] = {
-	{"HPE   ", "Server  ", 0, ACPI_SIG_FADT, all_versions},
-	{ } /* End */
-};
-
-int ghes_edac_register(struct ghes *ghes, struct device *dev)
+static int ghes_edac_register(struct device *dev)
 {
 	bool fake = false;
 	struct mem_ctl_info *mci;
 	struct ghes_pvt *pvt;
 	struct edac_mc_layer layers[1];
 	unsigned long flags;
-	int idx = -1;
 	int rc = 0;
 
-	if (IS_ENABLED(CONFIG_X86)) {
-		/* Check if safe to enable on this system */
-		idx = acpi_match_platform_list(plat_list);
-		if (!force_load && idx < 0)
-			return -ENODEV;
-	} else {
-		force_load = true;
-		idx = 0;
-	}
-
 	/* finish another registration/unregistration instance first */
 	mutex_lock(&ghes_reg_mutex);
 
@@ -447,7 +430,7 @@ int ghes_edac_register(struct ghes *ghes, struct
 device *dev)
 		pr_info("This system has a very crappy BIOS: It doesn't even list the
 DIMMS.\n");
 		pr_info("Its SMBIOS info is wrong. It is doubtful that the error report
 would\n");
 		pr_info("work on such system. Use this driver with caution\n");
-	} else if (idx < 0) {
+	} else if (force_load) {

pr_info("This EDAC driver relies on BIOS to enumerate memory and
get error reports.\n");
pr_info("Unfortunately, not all BIOSes reflect the memory layout
correctly.\n");
pr_info("So, the end result of using this driver varies from vendor to
vendor.\n"); @@ -517,7 +500,7 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev)

drivers/edac/ghes_edac.c +1 -1
 	return rc;
 }
 
-void ghes_edac_unregister(struct ghes *ghes)
+static void ghes_edac_unregister(struct ghes *ghes)
 {
 	struct mem_ctl_info *mci;
 	unsigned long flags;

drivers/edac/ghes_edac.c void ghes_edac_unregister(struct ghes *ghes) · line 543

Quoted 10 lines
drivers/edac/ghes_edac.c +7 -0
@@ -551,3 +534,30 @@ void ghes_edac_unregister(struct ghes *ghes)
 unlock:
 	mutex_unlock(&ghes_reg_mutex);
 }
+
+static int __init ghes_edac_init(void)
+{
+	struct ghes *g, *g_tmp;
+
+	ghes_devs = ghes_get_devices(force_load);
+	if (ghes_devs)

Should it be changed to if(!ghes_devs) ?
Otherwise, this ghes_edac_init() on Arm will always return with ENODEV because ! ghes_get_devices().

What do you think of it?

--
Cheers,
Justin (Jia He)

Quoted 74 lines
drivers/edac/ghes_edac.c +19 -0
+		return -ENODEV;
+
+	list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
+		ghes_edac_register(g->dev);
+	}
+
+	return 0;
+}
+module_init(ghes_edac_init);
+
+static void __exit ghes_edac_exit(void) {
+	struct ghes *g, *g_tmp;
+
+
+	list_for_each_entry_safe(g, g_tmp, ghes_devs, elist) {
+		ghes_edac_unregister(g);
+	}
+}
+module_exit(ghes_edac_exit);
include/acpi/ghes.h index renamed from include/acpi/ghes.h +0 -0

34fb3431a8f3..f39b75c3f9c6 100644

include/acpi/ghes.h +4 -22
@@ -27,6 +27,8 @@ struct ghes {
 		struct timer_list timer;
 		unsigned int irq;
 	};
+	struct device *dev;
+	struct list_head elist;
 };
 
 struct ghes_estatus_node {
@@ -69,35 +71,13 @@ int ghes_register_vendor_record_notifier(struct
 notifier_block *nb);
  * @nb: pointer to the notifier_block structure of the vendor record handler.
  */
 void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
+struct list_head *ghes_get_devices(bool force); #else static inline
+struct list_head *ghes_get_devices(bool force) { return NULL; }
 #endif
 
 int ghes_estatus_pool_init(int num_ghes);
 
-/* From drivers/edac/ghes_edac.c */
-
-#ifdef CONFIG_EDAC_GHES
-void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err
 *mem_err);
-
-int ghes_edac_register(struct ghes *ghes, struct device *dev);
-
-void ghes_edac_unregister(struct ghes *ghes);
-
-#else
-static inline void ghes_edac_report_mem_error(int sev,
-				       struct cper_sec_mem_err *mem_err)
-{
-}
-
-static inline int ghes_edac_register(struct ghes *ghes, struct device *dev) -{
-	return -ENODEV;
-}
-
-static inline void ghes_edac_unregister(struct ghes *ghes) -{ -} -#endif
-
 static inline int acpi_hest_get_version(struct acpi_hest_generic_data *gdata)
 {
 	return gdata->revision >> 8;
 
--

Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

maintainer
#23 lore raw
Quoted 9 lines · Justin He

drivers/edac/ghes_edac.c void ghes_edac_unregister(struct ghes *ghes) · line 543

Quoted 6 lines
drivers/edac/ghes_edac.c +6 -0
+static int __init ghes_edac_init(void)
+{
+	struct ghes *g, *g_tmp;
+
+	ghes_devs = ghes_get_devices(force_load);
+	if (ghes_devs)

Should it be changed to if(!ghes_devs) ?
Otherwise, this ghes_edac_init() on Arm will always return with ENODEV because ! ghes_get_devices().

Yes, of course, sorry about that.

I mean, for a lack of a better idea, it returns a list of devices... ;-\

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#24 lore raw
In reply to Kani, Toshi

Hi Kani,

Quoted 37 lines

-----邮件原件-----
发件人: Kani, Toshi <[email protected]>
发送时间: Tuesday, August 9, 2022 4:40 AM
收件人: Borislav Petkov <[email protected]>; Rafael J. Wysocki <[email protected]>
抄送: Justin He <[email protected]>; Len Brown <[email protected]>; James Morse <[email protected]>; Tony Luck <[email protected]>; Mauro Carvalho Chehab <[email protected]>; Robert Richter <[email protected]>; Shuai Xue <[email protected]>; Jarkko Sakkinen <[email protected]>; ACPI Devel Maling List <[email protected]>; Linux Kernel Mailing List <[email protected]>; open list:EDAC-CORE <[email protected]>
主题: RE: [PATCH] ACPI: APEI: move edac_init ahead of ghes platform drv register

Quoted 16 lines · Borislav Petkov
Quoted 2 lines · Rafael J. Wysocki

This effectively makes EDAC depend on GHES which may not be always valid AFAICS.

Yes, and this has been getting on my nerves since forever.

The GHES code which does collect all those errors *forces* the registration of an EDAC module which does only the reporting.

Which cannot be any more backwards.

What should happen is, GHES inits and starts working on the errors. Then, at some point later, ghes_edac loads and starts reporting whatever it gets. If there's no EDAC module, it doesn't report them. The same way MCA works.

Quoted 4 lines

That's it.

And then ghes_edac can be made a normal module again and we can get rid of this insanity.

Quoted 14 lines

The following approach may be considerable:
- Separate ghes_edac_register() into two functions, e.g., ghes_edac_register() and ghes_edac_init().
- ghes_edac_register() only takes the first if-block with IS_ENABLED() & force_load check, and then calls a new function, edac_set_owner(mod_name), which simply sets mod_name to edac_mc_owner. This allows ghes_edac_register() to run before edac_init(), and sets edac_mc_owner to prevent chipset-specific edac driver to be loaded before ghes_edac.
- ghes_edac_init() first calls edac_get_owner() to match with its mod_name. If so, it performs the rest of the original ghes_edac_register() procedure. This
ghes_edac_init() is called from the normal module init path, e.g., module_init().

Thanks for the suggestion, one gap is that under module_init path, how can we pass
the 2nd parameter of ghes_edac_register (struct device *dev) to the new
* ghes_edac_init()?

IIUC, the parameter of any functions under module_init() path should be void.

--
Cheers,
Justin (Jia He)

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#25 lore raw
Quoted 8 lines · Justin He
Quoted 2 lines

ghes_edac_init() is called from the normal module init path, e.g., module_init().

Thanks for the suggestion, one gap is that under module_init path, how can we pass the 2nd parameter of ghes_edac_register (struct device *dev) to the new * ghes_edac_init()?

IIUC, the parameter of any functions under module_init() path should be void.

Since simpler version of ghes_edac_register() is still called with the parameters first, it can save *dev to a ghes_edac structure for ghes_edac_init() to use.

Toshi