Skip to contentSkip to conversation

x86/mce: retrieve poison range from hardware

PATCH Superseded Jane Chu 5 participants 12 messages Aug 2, 2022 – Aug 26, 2022

Subsystems (4)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Jane Chu

author
#0 lore raw

PATCH v7 1/1 x86/mce: retrieve poison range from hardware

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

---
 arch/x86/kernel/cpu/mce/apei.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/apei.c +12 -1
index 717192915f28..8ed341714686 100644
@@ -29,15 +29,26 @@
 void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
 {
 	struct mce m;
+	int lsb;
 
 	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
 		return;
 
+	/*
+	 * Even if the ->validation_bits are set for address mask,
+	 * to be extra safe, check and reject an error radius '0',
+	 * and fall back to the default page size.
+	 */
+	if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)
+		lsb = find_first_bit((void *)&mem_err->physical_addr_mask, PAGE_SHIFT);
+	else
+		lsb = PAGE_SHIFT;
+
 	mce_setup(&m);
 	m.bank = -1;
 	/* Fake a memory read error with unknown channel */
 	m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
-	m.misc = (MCI_MISC_ADDR_PHYS << 6) | PAGE_SHIFT;
+	m.misc = (MCI_MISC_ADDR_PHYS << 6) | lsb;
 
 	if (severity >= GHES_SEV_RECOVERABLE)
 		m.status |= MCI_STATUS_UC;
Signature · 1 line
2.18.4
#1 lore raw
Quoted 1 line · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine

s/Commit/commit

Quoted 39 lines

poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

---
 arch/x86/kernel/cpu/mce/apei.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/apei.c +7 -0
index 717192915f28..8ed341714686 100644
@@ -29,15 +29,26 @@
 void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
 {
 	struct mce m;
+	int lsb;
 
 	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
 		return;
 
+	/*
+	 * Even if the ->validation_bits are set for address mask,
+	 * to be extra safe, check and reject an error radius '0',
+	 * and fall back to the default page size.
+	 */
+	if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)

arch/x86/kernel/cpu/mce/apei.c line 51

Quoted 10 lines
arch/x86/kernel/cpu/mce/apei.c +5 -1
+		lsb = find_first_bit((void *)&mem_err->physical_addr_mask, PAGE_SHIFT);
+	else
+		lsb = PAGE_SHIFT;
+
 	mce_setup(&m);
 	m.bank = -1;
 	/* Fake a memory read error with unknown channel */
 	m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
-	m.misc = (MCI_MISC_ADDR_PHYS << 6) | PAGE_SHIFT;
+	m.misc = (MCI_MISC_ADDR_PHYS << 6) | lsb;

LGTM.

I suppose this wants to go upstream via the tree the bug came from (NVDIMM tree? ACPI tree?), or should we pick it up into the x86 tree?

Thanks,

Ingo

author
#2 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 1 line · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine

s/Commit/commit

Maintainers,
Would you prefer a v8, or take care the comment upon accepting the patch?

Quoted 53 lines
Quoted 40 lines

poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

---
  arch/x86/kernel/cpu/mce/apei.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/apei.c +7 -0
index 717192915f28..8ed341714686 100644
@@ -29,15 +29,26 @@
  void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
  {
  	struct mce m;
+	int lsb;
 
  	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
  		return;
 
+	/*
+	 * Even if the ->validation_bits are set for address mask,
+	 * to be extra safe, check and reject an error radius '0',
+	 * and fall back to the default page size.
+	 */
+	if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)

arch/x86/kernel/cpu/mce/apei.c line 51

Quoted 10 lines
arch/x86/kernel/cpu/mce/apei.c +5 -1
+		lsb = find_first_bit((void *)&mem_err->physical_addr_mask, PAGE_SHIFT);
+	else
+		lsb = PAGE_SHIFT;
+
  	mce_setup(&m);
  	m.bank = -1;
  	/* Fake a memory read error with unknown channel */
  	m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
-	m.misc = (MCI_MISC_ADDR_PHYS << 6) | PAGE_SHIFT;
+	m.misc = (MCI_MISC_ADDR_PHYS << 6) | lsb;

LGTM.

Quoted 2 lines

I suppose this wants to go upstream via the tree the bug came from (NVDIMM tree? ACPI tree?), or should we pick it up into the x86 tree?

No idea. Maintainers?

thanks!
-jane

Quoted 4 lines

Thanks,

Ingo

#3 lore raw
Quoted 64 lines · Jane Chu
Quoted 6 lines · Ingo Molnar
Quoted 1 line · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine

s/Commit/commit

Maintainers,
Would you prefer a v8, or take care the comment upon accepting the patch?

Quoted 53 lines
Quoted 40 lines

poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

---
  arch/x86/kernel/cpu/mce/apei.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/apei.c +7 -0
index 717192915f28..8ed341714686 100644
@@ -29,15 +29,26 @@
  void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
  {
  	struct mce m;
+	int lsb;
 
  	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
  		return;
 
+	/*
+	 * Even if the ->validation_bits are set for address mask,
+	 * to be extra safe, check and reject an error radius '0',
+	 * and fall back to the default page size.
+	 */
+	if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)

arch/x86/kernel/cpu/mce/apei.c line 51

Quoted 10 lines
arch/x86/kernel/cpu/mce/apei.c +5 -1
+		lsb = find_first_bit((void *)&mem_err->physical_addr_mask, PAGE_SHIFT);
+	else
+		lsb = PAGE_SHIFT;
+
  	mce_setup(&m);
  	m.bank = -1;
  	/* Fake a memory read error with unknown channel */
  	m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
-	m.misc = (MCI_MISC_ADDR_PHYS << 6) | PAGE_SHIFT;
+	m.misc = (MCI_MISC_ADDR_PHYS << 6) | lsb;

LGTM.

Quoted 4 lines
Quoted 2 lines

I suppose this wants to go upstream via the tree the bug came from (NVDIMM tree? ACPI tree?), or should we pick it up into the x86 tree?

No idea. Maintainers?

There's no real NVDIMM dependency here, just a general cleanup of how APEI error granularities are managed. So I think it is appropriate for this to go through the x86 tree via the typical path for mce related topics.

author
#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line

I suppose this wants to go upstream via the tree the bug came from

(NVDIMM

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

tree? ACPI tree?), or should we pick it up into the x86 tree?

No idea. Maintainers?

There's no real NVDIMM dependency here, just a general cleanup of how APEI error granularities are managed. So I think it is appropriate for this to go through the x86 tree via the typical path for mce related topics.

+ Huang, Ying.

x86 maintainers,

Please let me know if you need another revision.

thanks,
-jane

Quoted 74 lines · Dan Williams
Quoted 64 lines · Jane Chu
Quoted 6 lines · Ingo Molnar
Quoted 1 line · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine

s/Commit/commit

Maintainers,
Would you prefer a v8, or take care the comment upon accepting the patch?

Quoted 53 lines
Quoted 40 lines

poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

---
   arch/x86/kernel/cpu/mce/apei.c | 13 ++++++++++++-
   1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/apei.c +7 -0
index 717192915f28..8ed341714686 100644
@@ -29,15 +29,26 @@
   void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
   {
   	struct mce m;
+	int lsb;
 
   	if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
   		return;
 
+	/*
+	 * Even if the ->validation_bits are set for address mask,
+	 * to be extra safe, check and reject an error radius '0',
+	 * and fall back to the default page size.
+	 */
+	if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)

arch/x86/kernel/cpu/mce/apei.c line 51

Quoted 10 lines
arch/x86/kernel/cpu/mce/apei.c +5 -1
+		lsb = find_first_bit((void *)&mem_err->physical_addr_mask, PAGE_SHIFT);
+	else
+		lsb = PAGE_SHIFT;
+
   	mce_setup(&m);
   	m.bank = -1;
   	/* Fake a memory read error with unknown channel */
   	m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
-	m.misc = (MCI_MISC_ADDR_PHYS << 6) | PAGE_SHIFT;
+	m.misc = (MCI_MISC_ADDR_PHYS << 6) | lsb;

LGTM.

Quoted 4 lines
Quoted 2 lines

I suppose this wants to go upstream via the tree the bug came from (NVDIMM tree? ACPI tree?), or should we pick it up into the x86 tree?

No idea. Maintainers?

There's no real NVDIMM dependency here, just a general cleanup of how APEI error granularities are managed. So I think it is appropriate for this to go through the x86 tree via the typical path for mce related topics.

maintainer
#5 lore raw
In reply to Jane Chu
Quoted 6 lines · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

What I'm missing from this text here is, what *is* the mce->misc LSB field in human speak? What does that field denote?

What effect does that field have on error injection?

And so on.

Quoted 4 lines

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

Rely on hardware? You're changing this to rely on what the firmware reports.

That mem_err thing comes from a BIOS table AFAICT.

...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#6 lore raw
Quoted 2 lines

What I'm missing from this text here is, what *is* the mce->misc LSB field in human speak? What does that field denote?

The SDM says:

Recoverable Address LSB (bits 5:0): The lowest valid recoverable address bit. Indicates the position of the least significant bit (LSB) of the recoverable error address. For example, if the processor logs bits [43:9] of the address, the LSB sub-field in IA32_MCi_MISC is 01001b (9 decimal). For this example, bits [8:0] of the recoverable error address in IA32_MCi_ADDR should be ignored.

So in human speak "how much data did you lose". "6" is a common value saying a cache line (2<<6 == 64) was lost. Sometimes you see "12' (2<<12 == 4096) for a whole page lost.

-Tony

author
#7 lore raw
In reply to Borislav Petkov
Quoted 8 lines · Borislav Petkov
Quoted 6 lines · Jane Chu

With Commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity") that changed nfit_handle_mce() callback to report badrange according to 1ULL << MCI_MISC_ADDR_LSB(mce->misc), it's been discovered that the mce->misc LSB field is 0x1000 bytes, hence injecting 2 back-to-back poisons and the driver ends up logging 8 badblocks, because 0x1000 bytes is 8 512-byte.

Quoted 4 lines

What I'm missing from this text here is, what *is* the mce->misc LSB field in human speak? What does that field denote?

What effect does that field have on error injection

Tony has replied.

Quoted 8 lines

And so on.

Quoted 4 lines

Dan Williams noticed that apei_mce_report_mem_error() hardcode the LSB field to PAGE_SHIFT instead of consulting the input struct cper_sec_mem_err record. So change to rely on hardware whenever support is available.

Quoted 5 lines

Rely on hardware? You're changing this to rely on what the firmware reports.

That mem_err thing comes from a BIOS table AFAICT.

Would fix the comment to indicate "relying on firmware" help? Is there other concern?

thanks!
-jane

Quoted 4 lines

...

Thx.

maintainer
#8 lore raw
Quoted 1 line · Jane Chu

Tony has replied.

Do you really think that I can't look up what field means?

What I said was

"What I'm missing from this text here is... "

IOW, what I'm trying to say is, you should formulate your commit message better, more human-friendly. Right now it reads like for insiders only. But that's not its purpose.

Do you catch my drift?

Signature · 4 lines
Regards/Gruss,
    Boris.

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

Tony has replied.

Do you really think that I can't look up what field means?

What I said was

Quoted 7 lines

"What I'm missing from this text here is... "

IOW, what I'm trying to say is, you should formulate your commit message better, more human-friendly. Right now it reads like for insiders only. But that's not its purpose.

Do you catch my drift?

How about:

---

When memory poison consumption machine checks fire, mce-notifier-handlers like nfit_handle_mce() record the impacted physical address range. The error information includes data about blast radius, i.e. how many cachelines did the hardware determine are impacted. A recent change, commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity"), updated nfit_handle_mce() to stop hard coding the blast radius value of 1 cacheline, and instead rely on the blast radius reported in 'struct mce' which can be up to 4K (64 cachelines).

It turns out that apei_mce_report_mem_error() had a similar problem in that it hard coded a blast radius of 4K rather than checking the blast radius in the error information. Fix apei_mce_report_mem_error() to convey the proper poison granularity.

---

maintainer
#10 lore raw
Quoted 7 lines · Dan Williams

How about:

---

When memory poison consumption machine checks fire, mce-notifier-handlers like nfit_handle_mce() record the impacted physical address range.

... which is reported by the hardware in the MCi_MISC MSR.

Quoted 3 lines

The error information includes data about blast radius, i.e. how many cachelines did the hardware determine are impacted.

Yap, nice.

Quoted 8 lines

A recent change, commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity"), updated nfit_handle_mce() to stop hard coding the blast radius value of 1 cacheline, and instead rely on the blast radius reported in 'struct mce' which can be up to 4K (64 cachelines).

It turns out that apei_mce_report_mem_error() had a similar problem in that it hard coded a blast radius of 4K rather than checking the blast

s/checking/reading/

Quoted 1 line

radius in the error information. Fix apei_mce_report_mem_error() to

s/in/from/

Quoted 3 lines

convey the proper poison granularity.

---

Yap, that's a lot better.

Thanks!

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#11 lore raw
Quoted 32 lines · Borislav Petkov
Quoted 7 lines · Dan Williams

How about:

---

When memory poison consumption machine checks fire, mce-notifier-handlers like nfit_handle_mce() record the impacted physical address range.

... which is reported by the hardware in the MCi_MISC MSR.

Quoted 3 lines

The error information includes data about blast radius, i.e. how many cachelines did the hardware determine are impacted.

Yap, nice.

Quoted 8 lines

A recent change, commit 7917f9cdb503 ("acpi/nfit: rely on mce->misc to determine poison granularity"), updated nfit_handle_mce() to stop hard coding the blast radius value of 1 cacheline, and instead rely on the blast radius reported in 'struct mce' which can be up to 4K (64 cachelines).

It turns out that apei_mce_report_mem_error() had a similar problem in that it hard coded a blast radius of 4K rather than checking the blast

s/checking/reading/

Quoted 1 line

radius in the error information. Fix apei_mce_report_mem_error() to

s/in/from/

Quoted 7 lines
Quoted 3 lines

convey the proper poison granularity.

---

Yap, that's a lot better.

Thanks!

Got it and points taken. Thank you both, Boris and Dan.

v8 coming up.

thanks,
-jane