Skip to contentSkip to conversation

I386 convert pae wmb to non smp

PATCH In review Zachary Amsden 3 participants 5 messages Apr 26, 2006 – Apr 27, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 I386 convert pae wmb to non smp

Similar to the last bug, on set_pte, we don't want the compiler to re-order the write of the PTE, even in non-SMP configurations, since if the write of the low word occurs first, the TLB could prefetch a bad highmem mapping which has been aliased into low memory.

include/asm-i386/pgtable-3level.h +1 -1
Index: linux-2.6.17-rc/include/asm-i386/pgtable-3level.h
===================================================================
@@ -53,7 +53,7 @@ static inline int pte_exec_kernel(pte_t 
 static inline void set_pte(pte_t *ptep, pte_t pte)
 {
 	ptep->pte_high = pte.pte_high;
-	smp_wmb();
+	wmb();
 	ptep->pte_low = pte.pte_low;
 }
 #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
#1 lore raw
Quoted 5 lines · Zachary Amsden

Similar to the last bug, on set_pte, we don't want the compiler to re-order the write of the PTE, even in non-SMP configurations, since if the write of the low word occurs first, the TLB could prefetch a bad highmem mapping which has been aliased into low memory.

wmb() means that it also orders IO memory. It is no difference for i386, but smp_wmb() actually has the right semantics of the abstract Linux memory model.

Quoted 10 lines

Index: linux-2.6.17-rc/include/asm-i386/pgtable-3level.h
===================================================================

include/asm-i386/pgtable-3level.h static inline int pte_exec_kernel(pte_t · line 59

Quoted 8 lines
include/asm-i386/pgtable-3level.h +1 -1
@@ -53,7 +53,7 @@ static inline int pte_exec_kernel(pte_t 
 static inline void set_pte(pte_t *ptep, pte_t pte)
 {
 	ptep->pte_high = pte.pte_high;
-	smp_wmb();
+	wmb();
 	ptep->pte_low = pte.pte_low;
 }
 #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)

Send instant messages to your online friends http://au.messenger.yahoo.com

#2 lore raw
Quoted 11 lines · Nick Piggin
Quoted 5 lines · Zachary Amsden

Similar to the last bug, on set_pte, we don't want the compiler to re-order the write of the PTE, even in non-SMP configurations, since if the write of the low word occurs first, the TLB could prefetch a bad highmem mapping which has been aliased into low memory.

wmb() means that it also orders IO memory. It is no difference for i386, but smp_wmb() actually has the right semantics of the abstract Linux memory model.

The name is pretty confused. smp_wmb seems to imply an SMP-only barrier, whereas we want here a write barrier on regular memory. Both smp_wmb and wmb() are identical in that they both reduce to barrier today, but I confess not to know which one semantically is correct. Your call on this patch - it is unecessary, I thought it was more semantically correct, but you probably know that better than me. So, drop part 2 of this patch?

Zach

#3 lore raw
Quoted 8 lines · Zachary Amsden
Quoted 3 lines · Nick Piggin

wmb() means that it also orders IO memory. It is no difference for i386, but smp_wmb() actually has the right semantics of the abstract Linux memory model.

The name is pretty confused. smp_wmb seems to imply an SMP-only barrier, whereas we want here a write barrier on regular memory.

That is just a compiler barrier (barrier()). A CPU should always be consistent with itself so memory ordering doesn't really apply there (hence smp_ prefix, which also are compiler barriers, of course).

Quoted 2 lines

Both smp_wmb and wmb() are identical in that they both reduce to
barrier today, but I confess not to know which one semantically is correct.

Well you're only looking at i386. True it is i386 specific code, but sticking to the Linux memory model is more clear and consistent I think.

Quoted 2 lines

Your call on this patch - it is unecessary, I thought it was more
semantically correct, but you probably know that better than me. So, drop part 2 of this patch?

Yes, and make part 1 use smp_wmb.

--

Send instant messages to your online friends http://au.messenger.yahoo.com

#4 lore raw
Quoted 5 lines · Nick Piggin
Quoted 1 line

The name is pretty confused. smp_wmb seems to imply an SMP-only barrier, whereas we want here a write barrier on regular memory.

That is just a compiler barrier (barrier()). A CPU should always be consistent with itself so memory ordering doesn't really apply there (hence smp_ prefix, which also are compiler barriers, of course).

This would be an issue of consistency between a CPU and its TLB, so I doubt the usual self-consistency argument would hold. I would consider the TLB as logically external and separate from the core execution logic of the CPU. Of course it's an academic point either way since no PAE-capable x86 processor ever reorders stores to WB memory -- my original point was simply that smp_wmb() is a misleading name in this context, even barrier() would be clearer imo, but I'm in no way a Linux abstract memory model expert.

-- Keir