mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Simpify mce code somewhat
@ 2025-02-10 15:47 Nikolay Borisov
  2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-10 15:47 UTC (permalink / raw)
  To: linux-edac; +Cc: linux-kernel, x86, tony.luck, Nikolay Borisov

Here's v2 of the patchset simplifying the MCE proper code. Main changes are:

* Typos/grammar fixes (Yazen)
* Squashed the patch making mce_notify_irq static into the first patch (Yazen)
* Factored out the printing related code from mce_notify_irq() into mce_early_notifier() (Qiuxu)

Nikolay Borisov (3):
  x86/mce/inject: Remove call to mce_notify_irq()
  x86/mce: Move message printing from mce_notify_irq to
    mce_early_notifier()
  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, 22 insertions(+), 25 deletions(-)

--
2.43.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-10 15:47 [PATCH v2 0/3] Simpify mce code somewhat Nikolay Borisov
@ 2025-02-10 15:47 ` Nikolay Borisov
  2025-02-11  7:03   ` Zhuo, Qiuxu
  2025-02-16 16:10   ` Borislav Petkov
  2025-02-10 15:47 ` [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier() Nikolay Borisov
  2025-02-10 15:47 ` [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY Nikolay Borisov
  2 siblings, 2 replies; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-10 15:47 UTC (permalink / raw)
  To: linux-edac; +Cc: linux-kernel, x86, tony.luck, Nikolay Borisov

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. Remove this call and as a result
make mce_notify_irq() static

Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
 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, 22 insertions(+), 25 deletions(-)

diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h
index eb2db07ef39c..6c77c03139f7 100644
--- a/arch/x86/include/asm/mce.h
+++ b/arch/x86/include/asm/mce.h
@@ -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.c b/arch/x86/kernel/cpu/mce/core.c
index 0dc00c9894c7..89625ff79c3b 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -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");
+
+		return 1;
+	}
+
+	return 0;
+}
+
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
@@ -1773,28 +1795,6 @@ static void mce_timer_delete_all(void)
 		del_timer_sync(&per_cpu(mce_timer, cpu));
 }
 
-/*
- * Notify the user(s) about new machine check events.
- * Can be called from interrupt context, but not from machine check/NMI
- * context.
- */
-bool 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");
-
-		return true;
-	}
-	return false;
-}
-EXPORT_SYMBOL_GPL(mce_notify_irq);
-
 static void __mcheck_cpu_mce_banks_init(void)
 {
 	struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c
index 313fe682db33..06e3cf7229ce 100644
--- a/arch/x86/kernel/cpu/mce/inject.c
+++ b/arch/x86/kernel/cpu/mce/inject.c
@@ -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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier()
  2025-02-10 15:47 [PATCH v2 0/3] Simpify mce code somewhat Nikolay Borisov
  2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
@ 2025-02-10 15:47 ` Nikolay Borisov
  2025-02-11  7:10   ` Zhuo, Qiuxu
  2025-02-25 13:10   ` Borislav Petkov
  2025-02-10 15:47 ` [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY Nikolay Borisov
  2 siblings, 2 replies; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-10 15:47 UTC (permalink / raw)
  To: linux-edac; +Cc: linux-kernel, x86, tony.luck, Nikolay Borisov

Informing the user that an MCE has been logged from mce_notify_irq() is
somewhat misleading because whether the MCE has been logged actually
depends on whether CONFIG_X86_MCELOG_LEGACY is turned on or not.

Furthermore it was reported that actually having a message triggered
when an MCE is generated can be helpful in certain scenarios. Improve
the situation by lifting the printing to the generic
mce_early_notifier() as it's executed always and is independent of any
compile-time option.

Link: https://lore.kernel.org/all/CY8PR11MB7134D97F82DC001AE009637889E32@CY8PR11MB7134.namprd11.prod.outlook.com/
Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
 arch/x86/kernel/cpu/mce/core.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index 89625ff79c3b..d55b1903fde6 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -591,15 +591,8 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
  */
 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");
-
 		return 1;
 	}
 
@@ -609,6 +602,8 @@ static int mce_notify_irq(void)
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
+	/* Not more than two messages every minute */
+	static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
 	struct mce_hw_err *err = to_mce_hw_err(data);
 
 	if (!err)
@@ -619,6 +614,9 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 
 	set_bit(0, &mce_need_notify);
 
+	if (__ratelimit(&ratelimit))
+		pr_info(HW_ERR "Machine check event detected\n");
+
 	mce_notify_irq();
 
 	return NOTIFY_DONE;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
  2025-02-10 15:47 [PATCH v2 0/3] Simpify mce code somewhat Nikolay Borisov
  2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
  2025-02-10 15:47 ` [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier() Nikolay Borisov
@ 2025-02-10 15:47 ` Nikolay Borisov
  2025-02-11  7:20   ` Zhuo, Qiuxu
  2025-02-25 13:12   ` Borislav Petkov
  2 siblings, 2 replies; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-10 15:47 UTC (permalink / raw)
  To: linux-edac; +Cc: linux-kernel, x86, tony.luck, Nikolay Borisov

mce_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.

Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
 arch/x86/kernel/cpu/mce/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index d55b1903fde6..8b8553e144ce 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -591,11 +591,13 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
  */
 static int mce_notify_irq(void)
 {
+#ifdef CONFIG_X86_MCELOG_LEGACY
+
 	if (test_and_clear_bit(0, &mce_need_notify)) {
 		mce_work_trigger();
 		return 1;
 	}
-
+#endif
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
@ 2025-02-11  7:03   ` Zhuo, Qiuxu
  2025-02-11  8:49     ` Nikolay Borisov
  2025-02-16 16:10   ` Borislav Petkov
  1 sibling, 1 reply; 16+ messages in thread
From: Zhuo, Qiuxu @ 2025-02-11  7:03 UTC (permalink / raw)
  To: Nikolay Borisov, linux-edac; +Cc: linux-kernel, x86, Luck, Tony

> From: Nikolay Borisov <nik.borisov@suse.com>
> [...]
> --- a/arch/x86/kernel/cpu/mce/core.c
> +++ b/arch/x86/kernel/cpu/mce/core.c
> @@ -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)

Why make mce_notify_irq() return an int?

> [...]
> -/*
> - * Notify the user(s) about new machine check events.
> - * Can be called from interrupt context, but not from machine check/NMI
> - * context.
> - */
> -bool mce_notify_irq(void)
> [...]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier()
  2025-02-10 15:47 ` [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier() Nikolay Borisov
@ 2025-02-11  7:10   ` Zhuo, Qiuxu
  2025-02-25 13:10   ` Borislav Petkov
  1 sibling, 0 replies; 16+ messages in thread
From: Zhuo, Qiuxu @ 2025-02-11  7:10 UTC (permalink / raw)
  To: Nikolay Borisov, linux-edac; +Cc: linux-kernel, x86, Luck, Tony

> From: Nikolay Borisov <nik.borisov@suse.com>
> [...]
> Subject: [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq
> to mce_early_notifier()
> 
> Informing the user that an MCE has been logged from mce_notify_irq() is
> somewhat misleading because whether the MCE has been logged actually
> depends on whether CONFIG_X86_MCELOG_LEGACY is turned on or not.
> 
> Furthermore it was reported that actually having a message triggered when
> an MCE is generated can be helpful in certain scenarios. Improve the situation
> by lifting the printing to the generic
> mce_early_notifier() as it's executed always and is independent of any
> compile-time option.
> 
> Link:
> https://lore.kernel.org/all/CY8PR11MB7134D97F82DC001AE009637889E32@
> CY8PR11MB7134.namprd11.prod.outlook.com/
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>

LGTM. Thanks!

    Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
  2025-02-10 15:47 ` [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY Nikolay Borisov
@ 2025-02-11  7:20   ` Zhuo, Qiuxu
  2025-02-11 10:18     ` Nikolay Borisov
  2025-02-25 13:12   ` Borislav Petkov
  1 sibling, 1 reply; 16+ messages in thread
From: Zhuo, Qiuxu @ 2025-02-11  7:20 UTC (permalink / raw)
  To: Nikolay Borisov, linux-edac; +Cc: linux-kernel, x86, Luck, Tony

> From: Nikolay Borisov <nik.borisov@suse.com>
> [...]
> Subject: [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on
> CONFIG_X86_MCELOG_LEGACY
> 
> mce_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.
> 
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>  arch/x86/kernel/cpu/mce/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
> index d55b1903fde6..8b8553e144ce 100644
> --- a/arch/x86/kernel/cpu/mce/core.c
> +++ b/arch/x86/kernel/cpu/mce/core.c
> @@ -591,11 +591,13 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
>   */
>  static int mce_notify_irq(void)
>  {
> +#ifdef CONFIG_X86_MCELOG_LEGACY
> +
>  	if (test_and_clear_bit(0, &mce_need_notify)) {
>  		mce_work_trigger();
>  		return 1;
>  	}
> -
> +#endif
>  	return 0;
>  }

The empty stub function below can also be removed from the file: arch/x86/kernel/cpu/mce/internal.h

         static inline void mce_work_trigger(void)       { }

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-11  7:03   ` Zhuo, Qiuxu
@ 2025-02-11  8:49     ` Nikolay Borisov
  2025-02-11 12:37       ` Zhuo, Qiuxu
  0 siblings, 1 reply; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-11  8:49 UTC (permalink / raw)
  To: Zhuo, Qiuxu, linux-edac; +Cc: linux-kernel, x86, Luck, Tony



On 11.02.25 г. 9:03 ч., Zhuo, Qiuxu wrote:
>> From: Nikolay Borisov <nik.borisov@suse.com>
>> [...]
>> --- a/arch/x86/kernel/cpu/mce/core.c
>> +++ b/arch/x86/kernel/cpu/mce/core.c
>> @@ -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)
> 
> Why make mce_notify_irq() return an int?


Pff... because I based my patches off master and not tip, which has it 
as bool...
> 
>> [...]
>> -/*
>> - * Notify the user(s) about new machine check events.
>> - * Can be called from interrupt context, but not from machine check/NMI
>> - * context.
>> - */
>> -bool mce_notify_irq(void)
>> [...]


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
  2025-02-11  7:20   ` Zhuo, Qiuxu
@ 2025-02-11 10:18     ` Nikolay Borisov
  0 siblings, 0 replies; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-11 10:18 UTC (permalink / raw)
  To: Zhuo, Qiuxu, linux-edac; +Cc: linux-kernel, x86, Luck, Tony



On 11.02.25 г. 9:20 ч., Zhuo, Qiuxu wrote:
>> From: Nikolay Borisov <nik.borisov@suse.com>
>> [...]
>> Subject: [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on
>> CONFIG_X86_MCELOG_LEGACY
>>
>> mce_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.
>>
>> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
>> ---
>>   arch/x86/kernel/cpu/mce/core.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
>> index d55b1903fde6..8b8553e144ce 100644
>> --- a/arch/x86/kernel/cpu/mce/core.c
>> +++ b/arch/x86/kernel/cpu/mce/core.c
>> @@ -591,11 +591,13 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
>>    */
>>   static int mce_notify_irq(void)
>>   {
>> +#ifdef CONFIG_X86_MCELOG_LEGACY
>> +
>>   	if (test_and_clear_bit(0, &mce_need_notify)) {
>>   		mce_work_trigger();
>>   		return 1;
>>   	}
>> -
>> +#endif
>>   	return 0;
>>   }
> 
> The empty stub function below can also be removed from the file: arch/x86/kernel/cpu/mce/internal.h
> 
>           static inline void mce_work_trigger(void)       { }


Actually I think this patch is better off being dropped. With it 
mce_notify_irq will always return false, causing mce_timer_fn() to 
always increase the polling interval until it stabilizes at around 
check_interval.

I will wait a bit for some more feedback and will repost v3 which will 
consist of only patches 1 and 2.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-11  8:49     ` Nikolay Borisov
@ 2025-02-11 12:37       ` Zhuo, Qiuxu
  0 siblings, 0 replies; 16+ messages in thread
From: Zhuo, Qiuxu @ 2025-02-11 12:37 UTC (permalink / raw)
  To: Nikolay Borisov, linux-edac; +Cc: linux-kernel, x86, Luck, Tony

> From: Nikolay Borisov <nik.borisov@suse.com>
> [...]
> >> +static int mce_notify_irq(void)
> >
> > Why make mce_notify_irq() return an int?
> 
> 
> Pff... because I based my patches off master and not tip, which has it as
> bool...

The return type of this function has been "bool" since mainline v6.14-rc1.
It's better to rebase the patch on top of the new version.

-Qiuxu

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
  2025-02-11  7:03   ` Zhuo, Qiuxu
@ 2025-02-16 16:10   ` Borislav Petkov
  2025-02-17 10:01     ` Nikolay Borisov
  1 sibling, 1 reply; 16+ messages in thread
From: Borislav Petkov @ 2025-02-16 16:10 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-edac, linux-kernel, x86, tony.luck

On Mon, Feb 10, 2025 at 05:47:04PM +0200, Nikolay Borisov wrote:
> 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. Remove this call and as a result
> make mce_notify_irq() static
> 
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>  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, 22 insertions(+), 25 deletions(-)

So what you're looking at are the remnants of the old soft-inject of MCE
errors. And it seems that we lost some of that functionality along the way and
no one has noticed because, well, it seems no one uses it anymore.

In order to understand how this thing was supposed to work, checkout

ea149b36c7f5 ("x86, mce: add basic error injection infrastructure")

and follow what raise_mce() does and pay attention to notify_user which is
what mce_need_notify was called back then.

Remember to have fun :-P

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-16 16:10   ` Borislav Petkov
@ 2025-02-17 10:01     ` Nikolay Borisov
  2025-02-17 11:20       ` Nikolay Borisov
  0 siblings, 1 reply; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-17 10:01 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: linux-edac, linux-kernel, x86, tony.luck



On 16.02.25 г. 18:10 ч., Borislav Petkov wrote:
> On Mon, Feb 10, 2025 at 05:47:04PM +0200, Nikolay Borisov wrote:
>> 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. Remove this call and as a result
>> make mce_notify_irq() static
>>
>> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
>> ---
>>   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, 22 insertions(+), 25 deletions(-)
> 
> So what you're looking at are the remnants of the old soft-inject of MCE
> errors. And it seems that we lost some of that functionality along the way and
> no one has noticed because, well, it seems no one uses it anymore.
> 
> In order to understand how this thing was supposed to work, checkout
> 
> ea149b36c7f5 ("x86, mce: add basic error injection infrastructure")


The original code in  ea149b36c7f5 was setting the notify_user bit via

raise_mce()->machine_check_poll()->mce_log(),
  mce_notify_user() - consumes notify_user set in mce_log above.


  subsequently in 011d82611172 ("RAS: Add a Corrected Errors Collector") 
you factored out the code from mce_log() mce_first_notifier, where the 
bit setting remains to this day, but since it's been removed from 
mce_log() it made the call in raise_local() defunct.


Considering that no one complained about this after all these years and 
that the dev-mcelog is deprecated I think it still makes sense to make 
mce_notify_irq() private

> 
> and follow what raise_mce() does and pay attention to notify_user which is
> what mce_need_notify was called back then.
> 
> Remember to have fun :-P
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-17 10:01     ` Nikolay Borisov
@ 2025-02-17 11:20       ` Nikolay Borisov
  2025-02-17 11:47         ` Borislav Petkov
  0 siblings, 1 reply; 16+ messages in thread
From: Nikolay Borisov @ 2025-02-17 11:20 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: linux-edac, linux-kernel, x86, tony.luck



On 17.02.25 г. 12:01 ч., Nikolay Borisov wrote:
> 
> 
> On 16.02.25 г. 18:10 ч., Borislav Petkov wrote:
>> On Mon, Feb 10, 2025 at 05:47:04PM +0200, Nikolay Borisov wrote:
>>> 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. Remove this call and as a result
>>> make mce_notify_irq() static
>>>
>>> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
>>> ---
>>>   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, 22 insertions(+), 25 deletions(-)
>>
>> So what you're looking at are the remnants of the old soft-inject of MCE
>> errors. And it seems that we lost some of that functionality along the 
>> way and
>> no one has noticed because, well, it seems no one uses it anymore.
>>
>> In order to understand how this thing was supposed to work, checkout
>>
>> ea149b36c7f5 ("x86, mce: add basic error injection infrastructure")
> 
> 
> The original code in  ea149b36c7f5 was setting the notify_user bit via
> 
> raise_mce()->machine_check_poll()->mce_log(),
>   mce_notify_user() - consumes notify_user set in mce_log above.
> 
> 
>   subsequently in 011d82611172 ("RAS: Add a Corrected Errors Collector") 
> you factored out the code from mce_log() mce_first_notifier, where the 
> bit setting remains to this day, but since it's been removed from 
> mce_log() it made the call in raise_local() defunct.
> 
> 
> Considering that no one complained about this after all these years and 
> that the dev-mcelog is deprecated I think it still makes sense to make 
> mce_notify_irq() private


Actually there is no loss of functionality since after an MCE is injected
the early notifier will correctly call the usermode helper. So I
think the following change log better reflects the situation:


     x86/mce/inject: Remove call to mce_notify_irq()
     
     The call to mce_notify_irq() has been there since the initial version of
     the soft inject mce machinery, introduced in ea149b36c7f5 ("x86,
     mce: add basic error injection infrastructure"). At that time it was
     functional since injecting an MCE resulted in the following call chain:
     
     raise_mce()
       ->machine_check_poll()
           ->mce_log() - sets notfiy_user_bit
     
     ->mce_notify_user() (current mce_notify_irq) consumed the bit and called the
     usermode helper.
     
     However, with the introduction of 011d82611172 ("RAS: Add a Corrected Errors Collector")
     the code got moved around and the user mode helper began to be called
     via the early notifier (mce_first_notifier()) rendering the remaining call
     in raise_local() defunct as the mce_need_notify bit (ex notify_user) is
     only being set from the early notifier.
     
     Remove the noop call and make mce_notify_irq static. No functional
     changes.

> 
>>
>> and follow what raise_mce() does and pay attention to notify_user 
>> which is
>> what mce_need_notify was called back then.
>>
>> Remember to have fun :-P
>>
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq()
  2025-02-17 11:20       ` Nikolay Borisov
@ 2025-02-17 11:47         ` Borislav Petkov
  0 siblings, 0 replies; 16+ messages in thread
From: Borislav Petkov @ 2025-02-17 11:47 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-edac, linux-kernel, x86, tony.luck

On Mon, Feb 17, 2025 at 01:20:55PM +0200, Nikolay Borisov wrote:
> Actually there is no loss of functionality since after an MCE is injected
> the early notifier will correctly call the usermode helper. So I
> think the following change log better reflects the situation:
> 
> 
>     x86/mce/inject: Remove call to mce_notify_irq()
>     The call to mce_notify_irq() has been there since the initial version of
>     the soft inject mce machinery, introduced in ea149b36c7f5 ("x86,
>     mce: add basic error injection infrastructure"). At that time it was
>     functional since injecting an MCE resulted in the following call chain:
>     raise_mce()
>       ->machine_check_poll()
>           ->mce_log() - sets notfiy_user_bit
>     ->mce_notify_user() (current mce_notify_irq) consumed the bit and called the
>     usermode helper.
>     However, with the introduction of 011d82611172 ("RAS: Add a Corrected Errors Collector")
>     the code got moved around and the user mode helper began to be called
>     via the early notifier (mce_first_notifier()) rendering the remaining call
>     in raise_local() defunct as the mce_need_notify bit (ex notify_user) is
>     only being set from the early notifier.
>     Remove the noop call and make mce_notify_irq static. No functional
>     changes.

Ah, there was that. We're doing a serious dance just to log an error, that's
for sure.

Yeah, that makes sense.

Thx.

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier()
  2025-02-10 15:47 ` [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier() Nikolay Borisov
  2025-02-11  7:10   ` Zhuo, Qiuxu
@ 2025-02-25 13:10   ` Borislav Petkov
  1 sibling, 0 replies; 16+ messages in thread
From: Borislav Petkov @ 2025-02-25 13:10 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-edac, linux-kernel, x86, tony.luck

On Mon, Feb 10, 2025 at 05:47:05PM +0200, Nikolay Borisov wrote:
> Informing the user that an MCE has been logged from mce_notify_irq() is
> somewhat misleading because whether the MCE has been logged actually
> depends on whether CONFIG_X86_MCELOG_LEGACY is turned on or not.

That text needs update in light of what we talked about when looking at patch
1...

> Furthermore it was reported that actually having a message triggered
> when an MCE is generated can be helpful in certain scenarios.

That's too vague - needs proper justification.

> Improve the situation by lifting the printing to the generic
> mce_early_notifier() as it's executed always and is independent of any
> compile-time option.

Meh.

> Link: https://lore.kernel.org/all/CY8PR11MB7134D97F82DC001AE009637889E32@CY8PR11MB7134.namprd11.prod.outlook.com/

Ah, there's the justification. I guess...

Just don't put "customers" in the commit message.

> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>  arch/x86/kernel/cpu/mce/core.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
> index 89625ff79c3b..d55b1903fde6 100644
> --- a/arch/x86/kernel/cpu/mce/core.c
> +++ b/arch/x86/kernel/cpu/mce/core.c
> @@ -591,15 +591,8 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
>   */
>  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");
> -
>  		return 1;
>  	}
>  
> @@ -609,6 +602,8 @@ static int mce_notify_irq(void)
>  static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
>  			      void *data)
>  {
> +	/* Not more than two messages every minute */
> +	static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
>  	struct mce_hw_err *err = to_mce_hw_err(data);
>  
>  	if (!err)
> @@ -619,6 +614,9 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
>  
>  	set_bit(0, &mce_need_notify);
>  
> +	if (__ratelimit(&ratelimit))
> +		pr_info(HW_ERR "Machine check event detected\n");

Well, the previous "logged" was correct.

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY
  2025-02-10 15:47 ` [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY Nikolay Borisov
  2025-02-11  7:20   ` Zhuo, Qiuxu
@ 2025-02-25 13:12   ` Borislav Petkov
  1 sibling, 0 replies; 16+ messages in thread
From: Borislav Petkov @ 2025-02-25 13:12 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-edac, linux-kernel, x86, tony.luck

On Mon, Feb 10, 2025 at 05:47:06PM +0200, Nikolay Borisov wrote:
> mce_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.
> 
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>  arch/x86/kernel/cpu/mce/core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
> index d55b1903fde6..8b8553e144ce 100644
> --- a/arch/x86/kernel/cpu/mce/core.c
> +++ b/arch/x86/kernel/cpu/mce/core.c
> @@ -591,11 +591,13 @@ EXPORT_SYMBOL_GPL(mce_is_correctable);
>   */
>  static int mce_notify_irq(void)
>  {
> +#ifdef CONFIG_X86_MCELOG_LEGACY

You can't do that - I see mce_notify_irq() in mce_timer_fn().

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-02-25 13:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-10 15:47 [PATCH v2 0/3] Simpify mce code somewhat Nikolay Borisov
2025-02-10 15:47 ` [PATCH v2 1/3] x86/mce/inject: Remove call to mce_notify_irq() Nikolay Borisov
2025-02-11  7:03   ` Zhuo, Qiuxu
2025-02-11  8:49     ` Nikolay Borisov
2025-02-11 12:37       ` Zhuo, Qiuxu
2025-02-16 16:10   ` Borislav Petkov
2025-02-17 10:01     ` Nikolay Borisov
2025-02-17 11:20       ` Nikolay Borisov
2025-02-17 11:47         ` Borislav Petkov
2025-02-10 15:47 ` [PATCH v2 2/3] x86/mce: Move message printing from mce_notify_irq to mce_early_notifier() Nikolay Borisov
2025-02-11  7:10   ` Zhuo, Qiuxu
2025-02-25 13:10   ` Borislav Petkov
2025-02-10 15:47 ` [PATCH v2 3/3] x86/mce: Make mce_notify_irq() depend on CONFIG_X86_MCELOG_LEGACY Nikolay Borisov
2025-02-11  7:20   ` Zhuo, Qiuxu
2025-02-11 10:18     ` Nikolay Borisov
2025-02-25 13:12   ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®