Re: [PATCH] Use global TLB flushes in MTRR code

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andi Kleen
Date: Thursday, February 7, 2008 - 1:03 pm

On Thu, Feb 07, 2008 at 08:13:37PM +0100, Ingo Molnar wrote:

Yes you're right.  Thanks makes more sense.  The weird style
fooled me.

It seems to come from the pseudo code in the Intel manual,
but I think it would be still cleaner/more idiomatic to use two
__flush_tlb_all() and remove the explicit code. The only drawback would 
be some more cr4 accesses, which does not seem like a big issue.

Updated patch follows.

-Andi

---

Use standard global TLB flushes in MTRR code

This is more idiomatic and it does not really make sense for this 
code to implement a own TLB flushing variant.

The control registers will be read/written a few times more, but 
that should not really matter for this code.

Signed-off-by: Andi Kleen <ak@suse.de>

---
 arch/x86/kernel/cpu/mtrr/generic.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux/arch/x86/kernel/cpu/mtrr/generic.c
===================================================================
--- linux.orig/arch/x86/kernel/cpu/mtrr/generic.c
+++ linux/arch/x86/kernel/cpu/mtrr/generic.c
@@ -349,14 +349,8 @@ static void prepare_set(void) __acquires
 	write_cr0(cr0);
 	wbinvd();
 
-	/*  Save value of CR4 and clear Page Global Enable (bit 7)  */
-	if ( cpu_has_pge ) {
-		cr4 = read_cr4();
-		write_cr4(cr4 & ~X86_CR4_PGE);
-	}
-
-	/* Flush all TLBs via a mov %cr3, %reg; mov %reg, %cr3 */
-	__flush_tlb();
+	/* Flush all TLBs */
+	__flush_tlb_all();
 
 	/*  Save MTRR state */
 	rdmsr(MTRRdefType_MSR, deftype_lo, deftype_hi);
@@ -368,7 +362,7 @@ static void prepare_set(void) __acquires
 static void post_set(void) __releases(set_atomicity_lock)
 {
 	/*  Flush TLBs (no need to flush caches - they are disabled)  */
-	__flush_tlb();
+	__flush_tlb_all();
 
 	/* Intel (P6) standard MTRRs */
 	mtrr_wrmsr(MTRRdefType_MSR, deftype_lo, deftype_hi);
@@ -376,9 +370,9 @@ static void post_set(void) __releases(se
 	/*  Enable caches  */
 	write_cr0(read_cr0() & 0xbfffffff);
 
-	/*  Restore value of CR4  */
-	if ( cpu_has_pge )
-		write_cr4(cr4);
+	/* Flush TLBs again to handle prefetches etc. */
+	__flush_tlb_all();
+
 	spin_unlock(&set_atomicity_lock);
 }
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Use global TLB flushes in MTRR code, Andi Kleen, (Thu Feb 7, 12:02 pm)
Re: [PATCH] Use global TLB flushes in MTRR code, Oliver Pinter, (Thu Feb 7, 12:08 pm)
Re: [PATCH] Use global TLB flushes in MTRR code, Ingo Molnar, (Thu Feb 7, 12:13 pm)
Re: [PATCH] Use global TLB flushes in MTRR code, Andi Kleen, (Thu Feb 7, 1:03 pm)
Re: [PATCH] Use global TLB flushes in MTRR code, Ingo Molnar, (Thu Feb 7, 1:37 pm)
Re: [PATCH] Use global TLB flushes in MTRR code, Andi Kleen, (Fri Feb 8, 4:44 am)
Re: [PATCH] Use global TLB flushes in MTRR code, Ingo Molnar, (Sat Feb 9, 2:40 am)
Re: [PATCH] Use global TLB flushes in MTRR code, Ingo Molnar, (Sat Feb 9, 4:47 am)
Re: [PATCH] Use global TLB flushes in MTRR code, Andi Kleen, (Sat Feb 9, 4:48 am)
Re: [PATCH] Use global TLB flushes in MTRR code, Andi Kleen, (Sat Feb 9, 7:12 am)