All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] AMD thresholding fixes
@ 2012-04-25 15:52 Borislav Petkov
  2012-04-25 15:52 ` [PATCH 1/3] x86, MCE, AMD: Make APIC LVT thresholding interrupt optional Borislav Petkov
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Borislav Petkov @ 2012-04-25 15:52 UTC (permalink / raw)
  To: EDAC devel, LKML; +Cc: Tony Luck, Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Hi all,

the following three patches fix MCE error thresholding issues on
upcoming F15h models.

Each commit message of the patch should contain more details.

If there are no issues, I'll add the queue to linux-next (I don't see a
branch from ras.git in linux-next, btw, which is strange).


Thanks.

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

* [PATCH 1/3] x86, MCE, AMD: Make APIC LVT thresholding interrupt optional
  2012-04-25 15:52 [PATCH 0/3] AMD thresholding fixes Borislav Petkov
@ 2012-04-25 15:52 ` Borislav Petkov
  2012-04-25 15:52 ` [PATCH 2/3] x86, MCE, AMD: Hide interrupt_enable sysfs node Borislav Petkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2012-04-25 15:52 UTC (permalink / raw)
  To: EDAC devel, LKML; +Cc: Tony Luck, Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Currently, the APIC LVT interrupt for error thresholding is implicitly
enabled. However, there are models in the F15h range which do not enable
it. Make the code machinery which sets up the APIC interrupt support
an optional setting and add an ->interrupt_capable member to the bank
representation mirroring that capability and enable the interrupt offset
programming only if it is true.

Simplify code and fixup comment style while at it.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/kernel/cpu/mcheck/mce_amd.c |   56 ++++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 99b57179f912..2c1d178be46e 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -51,6 +51,7 @@ struct threshold_block {
 	unsigned int		cpu;
 	u32			address;
 	u16			interrupt_enable;
+	bool			interrupt_capable;
 	u16			threshold_limit;
 	struct kobject		kobj;
 	struct list_head	miscj;
@@ -83,6 +84,21 @@ struct thresh_restart {
 	u16			old_limit;
 };
 
+static bool lvt_interrupt_supported(unsigned int bank, u32 msr_high_bits)
+{
+	/*
+	 * bank 4 supports APIC LVT interrupts implicitly since forever.
+	 */
+	if (bank == 4)
+		return true;
+
+	/*
+	 * IntP: interrupt present; if this bit is set, the thresholding
+	 * bank can generate APIC LVT interrupts
+	 */
+	return msr_high_bits & BIT(28);
+}
+
 static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
 {
 	int msr = (hi & MASK_LVTOFF_HI) >> 20;
@@ -104,8 +120,10 @@ static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
 	return 1;
 };
 
-/* must be called with correct cpu affinity */
-/* Called via smp_call_function_single() */
+/*
+ * Called via smp_call_function_single(), must be called with correct
+ * cpu affinity.
+ */
 static void threshold_restart_bank(void *_tr)
 {
 	struct thresh_restart *tr = _tr;
@@ -128,6 +146,12 @@ static void threshold_restart_bank(void *_tr)
 		    (new_count & THRESHOLD_MAX);
 	}
 
+	/* clear IntType */
+	hi &= ~MASK_INT_TYPE_HI;
+
+	if (!tr->b->interrupt_capable)
+		goto done;
+
 	if (tr->set_lvt_off) {
 		if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
 			/* set new lvt offset */
@@ -136,9 +160,10 @@ static void threshold_restart_bank(void *_tr)
 		}
 	}
 
-	tr->b->interrupt_enable ?
-	    (hi = (hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) :
-	    (hi &= ~MASK_INT_TYPE_HI);
+	if (tr->b->interrupt_enable)
+		hi |= INT_TYPE_APIC;
+
+ done:
 
 	hi |= MASK_COUNT_EN_HI;
 	wrmsr(tr->b->address, lo, hi);
@@ -202,14 +227,17 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
 			if (shared_bank[bank] && c->cpu_core_id)
 				break;
 
-			offset = setup_APIC_mce(offset,
-						(high & MASK_LVTOFF_HI) >> 20);
-
 			memset(&b, 0, sizeof(b));
-			b.cpu		= cpu;
-			b.bank		= bank;
-			b.block		= block;
-			b.address	= address;
+			b.cpu			= cpu;
+			b.bank			= bank;
+			b.block			= block;
+			b.address		= address;
+			b.interrupt_capable	= lvt_interrupt_supported(bank, high);
+
+			if (b.interrupt_capable) {
+				int new = (high & MASK_LVTOFF_HI) >> 20;
+				offset  = setup_APIC_mce(offset, new);
+			}
 
 			mce_threshold_block_init(&b, offset);
 			mce_threshold_vector = amd_threshold_interrupt;
@@ -309,6 +337,9 @@ store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
 	struct thresh_restart tr;
 	unsigned long new;
 
+	if (!b->interrupt_capable)
+		return -EINVAL;
+
 	if (strict_strtoul(buf, 0, &new) < 0)
 		return -EINVAL;
 
@@ -467,6 +498,7 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
 	b->cpu			= cpu;
 	b->address		= address;
 	b->interrupt_enable	= 0;
+	b->interrupt_capable	= lvt_interrupt_supported(bank, high);
 	b->threshold_limit	= THRESHOLD_MAX;
 
 	INIT_LIST_HEAD(&b->miscj);
-- 
1.7.9.3.362.g71319


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

* [PATCH 2/3] x86, MCE, AMD: Hide interrupt_enable sysfs node
  2012-04-25 15:52 [PATCH 0/3] AMD thresholding fixes Borislav Petkov
  2012-04-25 15:52 ` [PATCH 1/3] x86, MCE, AMD: Make APIC LVT thresholding interrupt optional Borislav Petkov
@ 2012-04-25 15:52 ` Borislav Petkov
  2012-04-25 15:52 ` [PATCH 3/3] x86, MCE, AMD: Disable error thresholding bank 4 on some models Borislav Petkov
  2012-04-25 16:49 ` [PATCH 0/3] AMD thresholding fixes Luck, Tony
  3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2012-04-25 15:52 UTC (permalink / raw)
  To: EDAC devel, LKML; +Cc: Tony Luck, Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Depending on whether the box supports the APIC LVT interrupt for
thresholding, we want to show the 'interrupt_enable' sysfs node or not.
Make that the case by adding it to the default sysfs attributes only if
it is supported.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/kernel/cpu/mcheck/mce_amd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index 2c1d178be46e..f4873a64f46d 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -421,10 +421,10 @@ RW_ATTR(threshold_limit);
 RW_ATTR(error_count);
 
 static struct attribute *default_attrs[] = {
-	&interrupt_enable.attr,
 	&threshold_limit.attr,
 	&error_count.attr,
-	NULL
+	NULL,	/* possibly interrupt_enable if supported, see below */
+	NULL,
 };
 
 #define to_block(k)	container_of(k, struct threshold_block, kobj)
@@ -501,6 +501,11 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
 	b->interrupt_capable	= lvt_interrupt_supported(bank, high);
 	b->threshold_limit	= THRESHOLD_MAX;
 
+	if (b->interrupt_capable)
+		threshold_ktype.default_attrs[2] = &interrupt_enable.attr;
+	else
+		threshold_ktype.default_attrs[2] = NULL;
+
 	INIT_LIST_HEAD(&b->miscj);
 
 	if (per_cpu(threshold_banks, cpu)[bank]->blocks) {
-- 
1.7.9.3.362.g71319


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

* [PATCH 3/3] x86, MCE, AMD: Disable error thresholding bank 4 on some models
  2012-04-25 15:52 [PATCH 0/3] AMD thresholding fixes Borislav Petkov
  2012-04-25 15:52 ` [PATCH 1/3] x86, MCE, AMD: Make APIC LVT thresholding interrupt optional Borislav Petkov
  2012-04-25 15:52 ` [PATCH 2/3] x86, MCE, AMD: Hide interrupt_enable sysfs node Borislav Petkov
@ 2012-04-25 15:52 ` Borislav Petkov
  2012-04-25 16:49 ` [PATCH 0/3] AMD thresholding fixes Luck, Tony
  3 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2012-04-25 15:52 UTC (permalink / raw)
  To: EDAC devel, LKML; +Cc: Tony Luck, Borislav Petkov

From: Borislav Petkov <borislav.petkov@amd.com>

Turn off MC4_MISC thresholding banks on models which have them but that
particular processor implementation does not supply applicable error
sources to be counted.

Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
---
 arch/x86/kernel/cpu/mcheck/mce.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index d086a09c087d..888fbf9d0adf 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1423,6 +1423,43 @@ static int __cpuinit __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
 		 */
 		 if (c->x86 == 6 && banks > 0)
 			mce_banks[0].ctl = 0;
+
+		 /*
+		  * Turn off MC4_MISC thresholding banks on those models since
+		  * they're not supported there.
+		  */
+		 if (c->x86 == 0x15 &&
+		     (c->x86_model >= 0x10 && c->x86_model <= 0x1f)) {
+			 int i;
+			 u64 val, hwcr;
+			 bool need_toggle;
+			 u32 msrs[] = {
+				0x00000413, /* MC4_MISC0 */
+				0xc0000408, /* MC4_MISC1 */
+			 };
+
+			 rdmsrl(MSR_K7_HWCR, hwcr);
+
+			 /* McStatusWrEn has to be set */
+			 need_toggle = !(hwcr & BIT(18));
+
+			 if (need_toggle)
+				 wrmsrl(MSR_K7_HWCR, hwcr | BIT(18));
+
+			 for (i = 0; i < ARRAY_SIZE(msrs); i++) {
+				 rdmsrl(msrs[i], val);
+
+				 /* CntP bit set? */
+				 if (val & BIT(62)) {
+					 val &= ~BIT(62);
+					 wrmsrl(msrs[i], val);
+				 }
+			 }
+
+			 /* restore old settings */
+			 if (need_toggle)
+				 wrmsrl(MSR_K7_HWCR, hwcr);
+		 }
 	}
 
 	if (c->x86_vendor == X86_VENDOR_INTEL) {
-- 
1.7.9.3.362.g71319


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

* RE: [PATCH 0/3] AMD thresholding fixes
  2012-04-25 15:52 [PATCH 0/3] AMD thresholding fixes Borislav Petkov
                   ` (2 preceding siblings ...)
  2012-04-25 15:52 ` [PATCH 3/3] x86, MCE, AMD: Disable error thresholding bank 4 on some models Borislav Petkov
@ 2012-04-25 16:49 ` Luck, Tony
  2012-04-25 16:57   ` Borislav Petkov
  3 siblings, 1 reply; 6+ messages in thread
From: Luck, Tony @ 2012-04-25 16:49 UTC (permalink / raw)
  To: Borislav Petkov, EDAC devel, LKML; +Cc: Borislav Petkov

> If there are no issues, I'll add the queue to linux-next (I don't see a
> branch from ras.git in linux-next, btw, which is strange).

Patches so far have been flowing from "ras" to "tip" to "linus". It
hasn't quite been clear how linux-next fits into this. If we export
to -next, then are we planning on sending those directly to linus,
bypassing tip?

-Tony

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

* Re: [PATCH 0/3] AMD thresholding fixes
  2012-04-25 16:49 ` [PATCH 0/3] AMD thresholding fixes Luck, Tony
@ 2012-04-25 16:57   ` Borislav Petkov
  0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2012-04-25 16:57 UTC (permalink / raw)
  To: Luck, Tony, Ingo Molnar; +Cc: Borislav Petkov, EDAC devel, LKML

On Wed, Apr 25, 2012 at 04:49:52PM +0000, Luck, Tony wrote:
> > If there are no issues, I'll add the queue to linux-next (I don't see a
> > branch from ras.git in linux-next, btw, which is strange).
> 
> Patches so far have been flowing from "ras" to "tip" to "linus". It
> hasn't quite been clear how linux-next fits into this. If we export
> to -next, then are we planning on sending those directly to linus,
> bypassing tip?

That's actually a good point. Once in -tip, they're seeing linux-next
anyway.

Ok, Ingo, what would you guys rather have:

* ras tree -> linux-next -> we send pull request to Linus

or

* ras tree -> -tip -> linux-next (automatically due to tip daily merges)
-> you send pull request to Linus

I guess I'm fine with both, second one makes us even lazier :)

Thanks.

-- 
Regards/Gruss,
Boris.

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

end of thread, other threads:[~2012-04-25 16:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-25 15:52 [PATCH 0/3] AMD thresholding fixes Borislav Petkov
2012-04-25 15:52 ` [PATCH 1/3] x86, MCE, AMD: Make APIC LVT thresholding interrupt optional Borislav Petkov
2012-04-25 15:52 ` [PATCH 2/3] x86, MCE, AMD: Hide interrupt_enable sysfs node Borislav Petkov
2012-04-25 15:52 ` [PATCH 3/3] x86, MCE, AMD: Disable error thresholding bank 4 on some models Borislav Petkov
2012-04-25 16:49 ` [PATCH 0/3] AMD thresholding fixes Luck, Tony
2012-04-25 16:57   ` Borislav Petkov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.