Cleanup mce_notify_irq usage
Subsystems (3)
cover Cleanup mce_notify_irq usage
Here are 3 small patches that result in mce_notify_irq becoming private to core.c and unexporting it. I have one pending question that I've put under the scissor line in Patch 3. But overall they are pretty self-explanatory and obvious.
Nikolay Borisov (3):
x86/mce/inject: Remova call to mce_notify_irq() x86/mce: Make mce_notify_irq() static
x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 44 +++++++++++++++++--------------- arch/x86/kernel/cpu/mce/inject.c | 1 - 3 files changed, 23 insertions(+), 24 deletions(-)
--
2.43.0
PATCH 1/3 x86/mce/inject: Remova call to mce_notify_irq()
The call is actually a noop because when the MCE is raised the early notifier is the only call site that correctly calls mce_notify_irq() because it also sets mce_need_notify. So let's just remove this call, which allows to unexport mce_notify_irq.
--- arch/x86/kernel/cpu/mce/core.c | 1 - arch/x86/kernel/cpu/mce/inject.c | 1 - 2 files changed, 2 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -1
@@ -1793,7 +1793,6 @@ int mce_notify_irq(void) }return 0 ; } -EXPORT_SYMBOL_GPL (mce_notify_irq);static void __mcheck_cpu_mce_banks_init (void ) {
arch/x86/kernel/cpu/mce/inject.c +0 -1
@@ -229,7 +229,6 @@ static int raise_local(void) }else if (m->status) {pr_info ("Starting machine check poll CPU %d\n" , cpu);raise_poll (m); -mce_notify_irq ();pr_info ("Machine check poll done on CPU %d\n" , cpu); }else m->finished =0 ;
Signature · 1 line
2.43.0
PATCH 2/3 x86/mce: Make mce_notify_irq() static
In reply to Nikolay BorisovIt's no longer used outside of core.c so let's make it static. No functional changes.
--- arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 42 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-)
arch/x86/include/asm/mce.h +0 -2
@@ -296,8 +296,6 @@ enum mcp_flags {void machine_check_poll (enum mcp_flags flags,mce_banks_t *b); -int mce_notify_irq (void ); - DECLARE_PER_CPU(struct mce, injectm);/* Disable CMCI/polling for MCA bank claimed by firmware */
arch/x86/kernel/cpu/mce/core.c +22 -20
54 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 3/3 x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
In reply to Nikolay Borisovmce_notify_irq() really depends on the legacy mcelog being enabled as otherwise mce_work_trigger() will never schedule the trigger work as mce_helper can't be set unless CONFIG_X86_MCELOG_LEGACY is defined.
---
In addition to making the body of this function depend on MCELOG, mce_need_notify also depends entirely on MCELOG, however I haven't added it since I don't want to proliferate ifdefs, this begs the qustion whether this patch is acceptable ?
arch/x86/kernel/cpu/mce/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/core.c +2 -1
@@ -591,6 +591,7 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);*/ static int mce_notify_irq (void ) { +#ifdef CONFIG_X86_MCELOG_LEGACY /* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
@@ -602,7 +603,7 @@ static int mce_notify_irq(void) return 1; } - +#endif return 0 ; }
--
2.43.0
Quoted 6 lines
From: Nikolay Borisov <[email protected]>
Sent: Wednesday, January 15, 2025 12:37 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Nikolay Borisov <[email protected]>
Subject: [PATCH 0/3] Cleanupmce_notify_irqusage
I tried to apply this series on top of the ras/core branch of the TIP tree, but there were some conflicts. Would it be better to rebase this series on top of the ras/core branch of the TIP tree?
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git ras/core
Quoted 11 lines · Qiuxu
Quoted 6 lines
From: Nikolay Borisov <[email protected]>
Sent: Wednesday, January 15, 2025 12:37 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Nikolay Borisov <[email protected]>
Subject: [PATCH 0/3] Cleanupmce_notify_irqusageI tried to apply this series on top of the ras/core branch of the TIP tree, but there were some conflicts. Would it be better to rebase this series on top of the ras/core branch of the TIP tree?
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git ras/core
Sure, will do. It's based off master curently
cover Make mce_notify_irq() static
In reply to Nikolay BorisovPatches now rebased on core/ras
Nikolay Borisov (3):
x86/mce/inject: Remova call to mce_notify_irq() x86/mce: Make mce_notify_irq() static
x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 45 ++++++++++++++++---------------- arch/x86/kernel/cpu/mce/inject.c | 1 - 3 files changed, 23 insertions(+), 25 deletions(-)
--
2.43.0
PATCH RESEND 1/3 x86/mce/inject: Remova call to mce_notify_irq()
The call is actually a noop because when the MCE is raised the early notifier is the only call site that correctly calls mce_notify_irq() because it also sets mce_need_notify. So let's just remove this call, which allows to unexport mce_notify_irq.
--- arch/x86/kernel/cpu/mce/core.c | 1 - arch/x86/kernel/cpu/mce/inject.c | 1 - 2 files changed, 2 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -1
@@ -1793,7 +1793,6 @@ bool mce_notify_irq(void) }return false; } -EXPORT_SYMBOL_GPL (mce_notify_irq);static void __mcheck_cpu_mce_banks_init (void ) {
arch/x86/kernel/cpu/mce/inject.c +0 -1
@@ -229,7 +229,6 @@ static int raise_local(void) }else if (m->status) {pr_info ("Starting machine check poll CPU %d\n" , cpu);raise_poll (m); -mce_notify_irq ();pr_info ("Machine check poll done on CPU %d\n" , cpu); }else m->finished =0 ;
--
2.43.0
Re: [RESEND PATCH 1/3] x86/mce/inject: Remova call to mce_notify_irq()
On Wed, Jan 15, 2025 at 09:36:38AM +0200, Nikolay Borisov wrote:
Hi Nikolay,
There is a typo in the $SUBJECT.
Quoted 5 lines
The call is actually a noop because when the MCE is raised the early notifier is the only call site that correctly calls
mce_notify_irq()because it also setsmce_need_notify. So let's just remove this call, which allows to unexportmce_notify_irq.
The commit message should be in passive and imperative voice.
"So let's just remove this..." -> "Remove this..."
Quoted 23 lines
Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/kernel/cpu/mce/core.c | 1 - arch/x86/kernel/cpu/mce/inject.c | 1 - 2 files changed, 2 deletions(-)arch/x86/kernel/cpu/mce/core.c +0
-1@@ -1793,7 +1793,6 @@ bool mce_notify_irq(void) }return false; } -EXPORT_SYMBOL_GPL (mce_notify_irq);static void __mcheck_cpu_mce_banks_init (void ) {arch/x86/kernel/cpu/mce/inject.c +0
-0
arch/x86/kernel/cpu/mce/inject.c static int raise_local(void) · line 232
Quoted 4 lines
arch/x86/kernel/cpu/mce/inject.c +0
-1@@ -229,7 +229,6 @@ static int raise_local(void) }else if (m->status) {pr_info ("Starting machine check poll CPU %d\n" , cpu);raise_poll (m); -mce_notify_irq ();
With this change, there are no users of mce_notify_irq() outside of mce/core.c. So you could go further and make the function static to core.c.
In other words, you could squash the second patch into this one.
Thanks,
Yazen
Re: [RESEND PATCH 1/3] x86/mce/inject: Remova call to mce_notify_irq()
Quoted 48 lines · Yazen Ghannam
On Wed, Jan 15, 2025 at 09:36:38AM +0200, Nikolay Borisov wrote:
Hi Nikolay,
There is a typo in the $SUBJECT.
Quoted 5 lines
The call is actually a noop because when the MCE is raised the early notifier is the only call site that correctly calls
mce_notify_irq()because it also setsmce_need_notify. So let's just remove this call, which allows to unexportmce_notify_irq.The commit message should be in passive and imperative voice.
"So let's just remove this..." -> "Remove this..."
Quoted 23 lines
Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/kernel/cpu/mce/core.c | 1 - arch/x86/kernel/cpu/mce/inject.c | 1 - 2 files changed, 2 deletions(-)arch/x86/kernel/cpu/mce/core.c +0
-1@@ -1793,7 +1793,6 @@ bool mce_notify_irq(void) }return false; } -EXPORT_SYMBOL_GPL (mce_notify_irq);static void __mcheck_cpu_mce_banks_init (void ) {arch/x86/kernel/cpu/mce/inject.c +0
-0arch/x86/kernel/cpu/mce/inject.c static int raise_local(void) · line 232
Quoted 4 lines
arch/x86/kernel/cpu/mce/inject.c +0
-1@@ -229,7 +229,6 @@ static int raise_local(void) }else if (m->status) {pr_info ("Starting machine check poll CPU %d\n" , cpu);raise_poll (m); -mce_notify_irq ();With this change, there are no users of
mce_notify_irq()outside ofmce/core.c. So you could go further and make the function static tocore.c.
Quoted 1 line
In other words, you could squash the second patch into this one.
Thanks, I've incorporated those in V2 that I sent.
Quoted 3 lines
Thanks,
Yazen
PATCH RESEND 2/3 x86/mce: Make mce_notify_irq() static
In reply to Nikolay BorisovIt's no longer used outside of core.c so let's make it static. No functional changes.
--- arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 43 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-)
arch/x86/include/asm/mce.h +0 -2
@@ -296,8 +296,6 @@ enum mcp_flags {void machine_check_poll (enum mcp_flags flags,mce_banks_t *b); -bool mce_notify_irq (void ); - DECLARE_PER_CPU(struct mce, injectm);/* Disable CMCI/polling for MCA bank claimed by firmware */
arch/x86/kernel/cpu/mce/core.c +22 -21
55 lines not on this page · raw message
--
2.43.0
RE: [RESEND PATCH 2/3] x86/mce: Make mce_notify_irq() static
Quoted 45 lines
From: Nikolay Borisov <[email protected]>
[...]
Subject: [RESEND PATCH 2/3] x86/mce: Makemce_notify_irq()staticIt's no longer used outside of
core.cso let's make it static. No functional changes.Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 43 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-)arch/x86/include/asm/mce.h index renamed from arch/x86/include/asm/mce.h +0
-0
eb2db07ef39c..6c77c03139f7100644arch/x86/include/asm/mce.h +0
-2@@ -296,8 +296,6 @@ enum mcp_flags {void machine_check_poll (enum mcp_flags flags,mce_banks_t *b); -bool mce_notify_irq (void ); - DECLARE_PER_CPU(struct mce, injectm); /* Disable CMCI/polling for MCA bank claimed by firmware */ diff --git
a/arch/x86/kernel/cpu/mce/core.cb/arch/x86/kernel/cpu/mce/core.cindex23e5e7f7c554..89625ff79c3b100644arch/x86/kernel/cpu/mce/core.c +12
-0@@ -584,6 +584,28 @@ bool mce_is_correctable(struct mce *m) }EXPORT_SYMBOL_GPL (mce_is_correctable); +/* +* Notify the user(s) about new machine check events. +* Can be called from interrupt context, but not from machine check/NMI +* context. +*/ +static int mce_notify_irq (void ) +{ +/* Not more than two messages every minute */ + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2); + +if (test_and_clear_bit (0 , &mce_need_notify)) { +mce_work_trigger ();
arch/x86/kernel/cpu/mce/core.c bool mce_is_correctable(struct mce *m) } · line 607
Quoted 10 lines
arch/x86/kernel/cpu/mce/core.c +10
-0+ +if (__ratelimit (&ratelimit)) +pr_info (HW_ERR "Machine check events logged\n" ); + +return 1 ; + } + +return 0 ; +} +
Did you mistakenly change the return value type to int?
Re: [RESEND PATCH 2/3] x86/mce: Make mce_notify_irq() static
Quoted 49 lines · Qiuxu
Quoted 49 lines
From: Nikolay Borisov <[email protected]>
[...]
Subject: [RESEND PATCH 2/3] x86/mce: Makemce_notify_irq()staticIt's no longer used outside of
core.cso let's make it static. No functional changes.Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/include/asm/mce.h | 2 -- arch/x86/kernel/cpu/mce/core.c | 43 +++++++++++++++++----------------- 2 files changed, 22 insertions(+), 23 deletions(-)arch/x86/include/asm/mce.h index renamed from arch/x86/include/asm/mce.h +0
-0
eb2db07ef39c..6c77c03139f7100644arch/x86/include/asm/mce.h +0
-2@@ -296,8 +296,6 @@ enum mcp_flags {void machine_check_poll (enum mcp_flags flags,mce_banks_t *b); -bool mce_notify_irq (void ); - DECLARE_PER_CPU(struct mce, injectm); /* Disable CMCI/polling for MCA bank claimed by firmware */ diff --git
a/arch/x86/kernel/cpu/mce/core.cb/arch/x86/kernel/cpu/mce/core.cindex23e5e7f7c554..89625ff79c3b100644arch/x86/kernel/cpu/mce/core.c +16
-0@@ -584,6 +584,28 @@ bool mce_is_correctable(struct mce *m) }EXPORT_SYMBOL_GPL (mce_is_correctable); +/* +* Notify the user(s) about new machine check events. +* Can be called from interrupt context, but not from machine check/NMI +* context. +*/ +static int mce_notify_irq (void ) +{ +/* Not more than two messages every minute */ + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2); + +if (test_and_clear_bit (0 , &mce_need_notify)) { +mce_work_trigger (); + +if (__ratelimit (&ratelimit)) +pr_info (HW_ERR "Machine check events logged\n" ); +
Quoted 8 lines
arch/x86/kernel/cpu/mce/core.c bool mce_is_correctable(struct mce *m) · line 608
Quoted 6 lines
arch/x86/kernel/cpu/mce/core.c +6
-0+return 1 ; + } + +return 0 ; +} +Did you mistakenly change the return value type to int?
It was int on master, where this patch originated from. Whereas on core/ras there's c845cb8dbd2e1a804babfd13648026c3a7cfbc0b which changes the function to bool. So I guess it's a rebase artifact, will fix it on next submission, but I will wait for more feedback.
PATCH RESEND 3/3 x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
In reply to Nikolay Borisovmce_notify_irq() really depends on the legacy mcelog being enabled as otherwise mce_work_trigger() will never schedule the trigger work as mce_helper can't be set unless CONFIG_X86_MCELOG_LEGACY is defined.
--- arch/x86/kernel/cpu/mce/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/core.c +2 -1
@@ -591,6 +591,7 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);*/ static int mce_notify_irq (void ) { +#ifdef CONFIG_X86_MCELOG_LEGACY /* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
@@ -602,7 +603,7 @@ static int mce_notify_irq(void) return 1; } - +#endif return 0 ; }
--
2.43.0
RE: [RESEND PATCH 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
Quoted 30 lines
From: Nikolay Borisov <[email protected]>
Sent: Wednesday, January 15, 2025 3:37 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Nikolay Borisov <[email protected]>
Subject: [RESEND PATCH 3/3] x86/mce: Makemce_notify_irq()depend onCONFIG_X86_MCELOG_LEGACY
mce_notify_irq()really depends on the legacy mcelog being enabled as otherwisemce_work_trigger()will never schedule the trigger work asmce_helpercan't be set unlessCONFIG_X86_MCELOG_LEGACYis defined.Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/kernel/cpu/mce/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kernel/cpu/mce/core.c +1
-0@@ -591,6 +591,7 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);*/ static int mce_notify_irq (void ) { +#ifdef CONFIG_X86_MCELOG_LEGACY /* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
arch/x86/kernel/cpu/mce/core.c static int mce_notify_irq(void) · line 603
Quoted 1 line
arch/x86/kernel/cpu/mce/core.c +0
-0@@ -602,7 +603,7 @@ static int mce_notify_irq(void)
The message printed inside this function should not depend on CONFIG_X86_MCELOG_LEGACY. User-space tools/scripts might look for this message to detect machine events. It is also useful for debugging purposes.
if (__ratelimit(&ratelimit))
pr_info(HW_ERR "Machine check events logged\n");Quoted 10 lines
arch/x86/kernel/cpu/mce/core.c +1
-2return 1; } - +#endif return 0 ; } --2.43.0
Re: [RESEND PATCH 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
Quoted 29 lines · Qiuxu
Quoted 29 lines
From: Nikolay Borisov <[email protected]>
Sent: Wednesday, January 15, 2025 3:37 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Nikolay Borisov <[email protected]>
Subject: [RESEND PATCH 3/3] x86/mce: Makemce_notify_irq()depend onCONFIG_X86_MCELOG_LEGACY
mce_notify_irq()really depends on the legacy mcelog being enabled as otherwisemce_work_trigger()will never schedule the trigger work asmce_helpercan't be set unlessCONFIG_X86_MCELOG_LEGACYis defined.Signed-off-by Nikolay Borisov <[email protected]>--- arch/x86/kernel/cpu/mce/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kernel/cpu/mce/core.c +1
-0@@ -591,6 +591,7 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);*/ static int mce_notify_irq (void ) { +#ifdef CONFIG_X86_MCELOG_LEGACY /* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
Quoted 6 lines
arch/x86/kernel/cpu/mce/core.c static int mce_notify_irq(void) · line 603
Quoted 2 lines
arch/x86/kernel/cpu/mce/core.c +0
-0@@ -602,7 +603,7 @@ static int mce_notify_irq(void)The message printed inside this function should not depend on
CONFIG_X86_MCELOG_LEGACY. User-spacetools/scriptsmight look for this message to detect machine events. It is also useful for debugging purposes.
The thing is if MCELOG_LEGACY is turned off then mce_work_trigger is a noop, hence nothing is really logged which makes this message somewhat bogus. After all the early handler's job is to log to userspace, if we don't log anything no need to spam the kernel log.
Quoted 15 lines
if (__ratelimit(&ratelimit)) pr_info(HW_ERR "Machine check events logged\n");Quoted 10 lines
arch/x86/kernel/cpu/mce/core.c +1
-2return 1; } - +#endif return 0 ; } --2.43.0
RE: [RESEND PATCH 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
Quoted 18 lines
From: Nikolay Borisov <[email protected]>
[...]Quoted 10 lines
Quoted 10 lines
arch/x86/kernel/cpu/mce/core.c +1
-0@@ -591,6 +591,7 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);*/ static int mce_notify_irq (void ) { +#ifdef CONFIG_X86_MCELOG_LEGACY /* Not more than two messages every minute */ static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);Quoted 6 lines
arch/x86/kernel/cpu/mce/core.c static int mce_notify_irq(void) · line 603
Quoted 2 lines
arch/x86/kernel/cpu/mce/core.c +0
-0@@ -602,7 +603,7 @@ static int mce_notify_irq(void)The message printed inside this function should not depend on
CONFIG_X86_MCELOG_LEGACY. User-spacetools/scriptsmight look for this message to detect machine events. It is also useful for debugging
Quoted 6 lines
purposes.
The thing is if
MCELOG_LEGACYis turned off thenmce_work_triggeris a noop, hence nothing is really logged which makes this message somewhat bogus. After all the early handler's job is to log to userspace, if we don't log anything no need to spam the kernel log.
Currently, some customers have reported that the Intel EDAC driver didn't report errors on some memory DIMMs. The print message here helped me confirm whether the MCE event originated from the x86/mce code or if the MCE event was lost somewhere in the EDAC driver.
IMHO, it would be better to keep this print message here, or update it a bit like below if !CONFIG_X86_MCELOG_LEGACY:
pr_info(HW_ERR "Machine check events generated\n");
Thanks!
-Qiuxu