Skip to contentSkip to conversation

AMD64_EDAC: Fix incorrect wrap arounds due to left shift beyond 32 bits.

PATCH Superseded Aravind Gopalakrishnan 2 participants 5 messages Aug 20, 2013 – Aug 23, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover AMD64_EDAC: Fix incorrect wrap arounds due to left shift beyond 32 bits.

Aravind Gopalakrishnan (1):
AMD64_EDAC: Fix incorrect wrap arounds due to left shift beyond 32
bits.

 drivers/edac/amd64_edac.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 AMD64_EDAC: Fix incorrect wrap arounds due to left shift beyond 32 bits.

Link to the bug report:
http://marc.info/?l=linux-edac&m=137692201732220&w=2

dct_base and dct_limit obtain 32 bit register values when they read their respective pci config space registers. A left shift beyond 32 bits will cause them to wrap around. Similar case for chan_addr as can be seen from the bug report. In the patch, we rectify this by casting chan_addr to u64 and by comparing dct_base and dct_limit against (sys_addr >> 27)

Tested on F15h, M30h with ECC turned on and works fine.

drivers/edac/amd64_edac.c +5 -4
index b86228c..eb4793e 100644
@@ -1558,11 +1558,12 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 	}
 
 	/* Verify sys_addr is within DCT Range. */
-	dct_base = (dct_sel_baseaddr(pvt) << 27);
-	dct_limit = (((dct_cont_limit_reg >> 11) & 0x1FFF) << 27) | 0x7FFFFFF;
+	dct_base = dct_sel_baseaddr(pvt);
+	dct_limit = (dct_cont_limit_reg >> 11) & 0x1FFF;
 
 	if (!(dct_cont_base_reg & BIT(0)) &&
-	    !(dct_base <= sys_addr && dct_limit >= sys_addr))
+	    !(dct_base <= (sys_addr >> 27) &&
+	      dct_limit >= (sys_addr >> 27)))
 		return -EINVAL;
 
 	/* Verify number of dct's that participate in channel interleaving. */
@@ -1614,7 +1615,7 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 		amd64_read_pci_cfg(pvt->F1,
 				   DRAM_CONT_HIGH_OFF + (int) channel * 4,
 				   &tmp);
-		chan_addr +=  ((tmp >> 11) & 0xfff) << 27;
+		chan_addr +=  (u64) ((tmp >> 11) & 0xfff) << 27;
 	}
 
 	f15h_select_dct(pvt, channel);
Signature · 1 line
1.7.10.4
maintainer
#2 lore raw
Quoted 18 lines · Aravind Gopalakrishnan

Link to the bug report:
http://marc.info/?l=linux-edac&m=137692201732220&w=2

dct_base and dct_limit obtain 32 bit register values when they read their respective pci config space registers. A left shift beyond 32 bits will cause them to wrap around. Similar case for chan_addr as can be seen from the bug report. In the patch, we rectify this by casting chan_addr to u64 and by comparing dct_base and dct_limit against (sys_addr >> 27)

Tested on F15h, M30h with ECC turned on and works fine.

drivers/edac/amd64_edac.c +0 -0
index b86228c..eb4793e 100644

drivers/edac/amd64_edac.c static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range, · line 1561

Quoted 6 lines
drivers/edac/amd64_edac.c +1 -2
@@ -1558,11 +1558,12 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 	}
 
 	/* Verify sys_addr is within DCT Range. */
-	dct_base = (dct_sel_baseaddr(pvt) << 27);
-	dct_limit = (((dct_cont_limit_reg >> 11) & 0x1FFF) << 27) | 0x7FFFFFF;
+	dct_base = dct_sel_baseaddr(pvt);

This can't be correct.

So the original patch takes the shifted dct_base while your change doesn't anymore...

drivers/edac/amd64_edac.c static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range, · line 1566

Quoted 6 lines
drivers/edac/amd64_edac.c +3 -1
+	dct_limit = (dct_cont_limit_reg >> 11) & 0x1FFF;
 
 	if (!(dct_cont_base_reg & BIT(0)) &&
-	    !(dct_base <= sys_addr && dct_limit >= sys_addr))
+	    !(dct_base <= (sys_addr >> 27) &&
+	      dct_limit >= (sys_addr >> 27)))

... and while this comparison shifts sys_addr to use the proper bits, the code does this assignment later:

	chan_offset = dct_base;

Now, chan_offset has the << 27 version of dct_base which makes the following calculation wrong:

	chan_addr = sys_addr - chan_offset;

because sys_addr is the full 64-bit, unshifted value.

The right thing to do would be to do:

	chan_offset = dct_base << 27;

Or am I missing something?

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#3 lore raw
Quoted 39 lines · Borislav Petkov
Quoted 18 lines · Aravind Gopalakrishnan

Link to the bug report:
http://marc.info/?l=linux-edac&m=137692201732220&w=2

dct_base and dct_limit obtain 32 bit register values when they read their respective pci config space registers. A left shift beyond 32 bits will cause them to wrap around. Similar case for chan_addr as can be seen from the bug report. In the patch, we rectify this by casting chan_addr to u64 and by comparing dct_base and dct_limit against (sys_addr >> 27)

Tested on F15h, M30h with ECC turned on and works fine.

drivers/edac/amd64_edac.c +0 -0
index b86228c..eb4793e 100644

drivers/edac/amd64_edac.c static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range, · line 1561

Quoted 6 lines
drivers/edac/amd64_edac.c +1 -2
@@ -1558,11 +1558,12 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
  	}
 
  	/* Verify sys_addr is within DCT Range. */
-	dct_base = (dct_sel_baseaddr(pvt) << 27);
-	dct_limit = (((dct_cont_limit_reg >> 11) & 0x1FFF) << 27) | 0x7FFFFFF;
+	dct_base = dct_sel_baseaddr(pvt);

This can't be correct.

So the original patch takes the shifted dct_base while your change doesn't anymore...

drivers/edac/amd64_edac.c static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range, · line 1566

Quoted 6 lines
drivers/edac/amd64_edac.c +3 -1
+	dct_limit = (dct_cont_limit_reg >> 11) & 0x1FFF;
 
  	if (!(dct_cont_base_reg & BIT(0)) &&
-	    !(dct_base <= sys_addr && dct_limit >= sys_addr))
+	    !(dct_base <= (sys_addr >> 27) &&
+	      dct_limit >= (sys_addr >> 27)))

... and while this comparison shifts sys_addr to use the proper bits, the code does this assignment later:

Quoted 6 lines
	chan_offset = dct_base;

Now, chan_offset has the << 27 version of dct_base which makes the following calculation wrong:

	chan_addr = sys_addr - chan_offset;

Oops. my apologies.

Quoted 8 lines

because sys_addr is the full 64-bit, unshifted value.

The right thing to do would be to do:

	chan_offset = dct_base << 27;

Or am I missing something?

No, you are right.

I am re-sending the patch.

Thanks,
-Aravind.

maintainer
#4 lore raw
In reply to Aravind Gopalakrishnan
Quoted 6 lines · Aravind Gopalakrishnan

Aravind Gopalakrishnan (1):
AMD64_EDAC: Fix incorrect wrap arounds due to left shift beyond 32
bits.

 drivers/edac/amd64_edac.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Just a minor thing: when you send one patch only, you don't really need the 0/1 email.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--