linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i386: PAE entries must have their low word cleared first
@ 2006-04-26 13:46 Jan Beulich
  2006-04-26 14:46 ` Hugh Dickins
  0 siblings, 1 reply; 14+ messages in thread
From: Jan Beulich @ 2006-04-26 13:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Keir Fraser

During Xen development we noticed that writes to 64-bit variables may get
coded as high-word-before-low-word writes by gcc. Consequently, when
invalidating a PAE page table entry, the low word must be explicitly written
first, as otherwise, as pointed out by Keir, speculative execution may result
in a partially modified (and still valid) translation to be used, which has,
according to the specification, the potential of dead-locking the machine.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Keir Fraser <Keir.Fraser@cl.cam.ac.uk>

diff -Npru /home/jbeulich/tmp/linux-2.6.17-rc2/include/asm-i386/pgtable.h
2.6.17-rc2-i386-pae-ptep_get_and_clear_full/include/asm-i386/pgtable.h
--- /home/jbeulich/tmp/linux-2.6.17-rc2/include/asm-i386/pgtable.h	2006-04-26 10:56:03.000000000 +0200
+++ 2.6.17-rc2-i386-pae-ptep_get_and_clear_full/include/asm-i386/pgtable.h	2006-04-24 12:28:37.000000000 +0200
@@ -268,7 +268,15 @@ static inline pte_t ptep_get_and_clear_f
 	pte_t pte;
 	if (full) {
 		pte = *ptep;
+#ifdef CONFIG_X86_PAE
+		/* Cannot do this in a single step, as the compiler
+		   may issue the two stores in either order. */
+		ptep->pte_low = 0;
+		barrier();
+		ptep->pte_high = 0;
+#else
 		*ptep = __pte(0);
+#endif
 	} else {
 		pte = ptep_get_and_clear(mm, addr, ptep);
 	}



^ permalink raw reply	[flat|nested] 14+ messages in thread
* RE: [PATCH] i386: PAE entries must have their low word cleared first
@ 2006-04-26 22:11 Brunner, Richard
  2006-04-26 22:22 ` Zachary Amsden
  0 siblings, 1 reply; 14+ messages in thread
From: Brunner, Richard @ 2006-04-26 22:11 UTC (permalink / raw)
  To: Nick Piggin, Keir Fraser
  Cc: Hugh Dickins, Jan Beulich, Zachary Amsden, linux-kernel

 

> -----Original Message-----
> [mailto:linux-kernel-owner@vger.kernel.org] On Behalf Of 

> Nick Piggin wrote
> 
> Keir Fraser wrote:
> > 
> > [snip]
> > 
> > In more detail the problem is that, since we're still running on the 
> > page tables while clearing them, the CPU may choose to prefetch a 
> > half-cleared pte into its TLB, and then execute speculative memory 
> > accesses based on that mapping (including ones that may write-allocate 
> > cachelines, leading to problems like the AMD AGP GART deadlock Linux had 
> > a year or so back).
> 
> What do you mean, you're still running on the page tables? The CPU can
> still walk the pagetables?
> 
> Because if ptep_get_and_clear_full is passed non zero in the full
> argument, then that specific translation should never see another
> access. I didn't know CPUs now actually resolve TLB misses as part of
> speculative prefetching... does this really happen?

Yes, on AMD processors, speculative execution is allowed to install TLB translations. Assuming you are not in 64-bit mode, and can not use
mmx or sse instructions to zero out the naturally aligned 64-bit pte,
then what is being suggested makes sense: clear out the valid bit
first by writing the low 32-bits. No invalid translations are ever 
installed in the TLB.


> Do you have a pointer to where the AMD AGP GART deadlock was 
> discussed? Google is having some trouble finding it.

http://marc.theaimsgroup.com/?l=linux-kernel&m=102376926732464&w=2


> > The barrier is needed to ensure that the bottom half is  cleared before 
> > the top half. In fact it probably ought to be wmb() -- 
> that's clearer in intent and actually reduces to barrier() on all PAE capable platforms.

Maybe the barrier is needed for other architectures, but two writes
to WB memory are not going to happen out of order and so no
barrier is needed on x86 to the best of my knowledge.
 

	-Rich Brunner, AMD



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

end of thread, other threads:[~2006-04-27 15:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-26 13:46 [PATCH] i386: PAE entries must have their low word cleared first Jan Beulich
2006-04-26 14:46 ` Hugh Dickins
2006-04-26 15:06   ` Keir Fraser
2006-04-26 15:44     ` Zachary Amsden
2006-04-26 15:57       ` Hugh Dickins
2006-04-26 16:12         ` Keir Fraser
2006-04-26 15:45     ` Hugh Dickins
2006-04-26 16:06       ` Nick Piggin
2006-04-26 15:58     ` Nick Piggin
2006-04-27 10:27       ` Sonny Rao
2006-04-27 13:39         ` Nick Piggin
  -- strict thread matches above, loose matches on Subject: below --
2006-04-26 22:11 Brunner, Richard
2006-04-26 22:22 ` Zachary Amsden
2006-04-26 22:27   ` Zachary Amsden

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).