Skip to contentSkip to conversation

pageattr: cache flush before tlb flush

PATCH In review Shaohua Li 3 participants 4 messages Aug 18, 2008 – Aug 19, 2008

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 pageattr: cache flush before tlb flush

clflush uses a virtual address but cache line is physical indexed in x86. In my understanding, clflush will do some pagetable walk, so doing cache flush first should reduce some pagetable walk.

arch/x86/mm/pageattr.c +4 -3
index f5f5154..d8b24df 100644
@@ -168,10 +168,8 @@ static void cpa_flush_range(unsigned long start, int numpages, int cache)
 	BUG_ON(irqs_disabled());
 	WARN_ON(PAGE_ALIGN(start) != start);
 
-	on_each_cpu(__cpa_flush_range, NULL, 1);
-
 	if (!cache)
-		return;
+		goto tlb_flush;
 
 	/*
 	 * We only need to flush on one CPU,
@@ -188,6 +186,9 @@ static void cpa_flush_range(unsigned long start, int numpages, int cache)
 		if (pte && (pte_val(*pte) & _PAGE_PRESENT))
 			clflush_cache_range((void *) addr, PAGE_SIZE);
 	}
+
+tlb_flush:
+	on_each_cpu(__cpa_flush_range, NULL, 1);
 }
 
 /*
#1 lore raw
Quoted 5 lines · Shaohua Li

clflush uses a virtual address but cache line is physical indexed in x86. In my understanding, clflush will do some pagetable walk, so doing cache flush first should reduce some pagetable walk.

I would say NAK on this.

Doing the CLFLUSH first does cut down on page table walking, but opens a hole in the sequencing: first set PAT to an uncachable mode, then flush.

If an unlucky prefetch comes in during this window, then you will have a dirty cache again.

So no, this is not a good idea.

-hpa

#2 lore raw
Quoted 18 lines

-----Original Message-----
From: H. Peter Anvin [mailto:[email protected]]
Sent: Tuesday, August 19, 2008 1:10 PM
To: Li, Shaohua
Cc: lkml; Andrew Morton; Ingo Molnar; Pallipadi, Venkatesh
Subject: Re: [patch]pageattr: cache flush before tlb flush

Quoted 5 lines · Shaohua Li

clflush uses a virtual address but cache line is physical indexed in x86. In my understanding, clflush will do some pagetable walk, so doing cache flush first should reduce some pagetable walk.

I would say NAK on this.

Quoted 7 lines

Doing the CLFLUSH first does cut down on page table walking, but opens a hole in the sequencing: first set PAT to an uncachable mode, then flush.

If an unlucky prefetch comes in during this window, then you will have a dirty cache again.

So no, this is not a good idea.

Ok, looks possible in theory.

Thanks,
Shaohua

#3 lore raw
In reply to Shaohua Li
Quoted 3 lines · Shaohua Li

clflush uses a virtual address but cache line is physical indexed in x86. In my understanding, clflush will do some pagetable walk, so doing cache flush first should reduce some pagetable walk.

The SDM describes the exact sequence how this should be done. Linux unfortunately skips one step currently, but it's not a good idea to diverge even more.

-Andi