Skip to contentSkip to conversation

ppc32: Wrong vaddr in flush_hash_one_pte()

PATCH New Benjamin Herrenschmidt 4 participants 9 messages Feb 23, 2005 – Mar 2, 2005 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ppc32: Wrong vaddr in flush_hash_one_pte()

Hi !

Reworking the ppc32 mm helps me find interesting bugs in the existing bug, well, brown paper bag for me, I made this one a while ago. The routine flush_hash_one_pte() used by ptep_test_and_clear_young() wasn't properly recaclulating the vaddr from the pte pointer & page->index. This fixes it. The result is that we probably never flushed things from the hash, so that's at least the _second_ bug affecting ptep_test_and_clear_young(), swap on ppc32 must have been really broken :(

Please, apply to 2.6.11...

(I hope by early 2.6.12, we'll have David's patch that removes the need for those hacks though, and just pass us the vaddr (and mm or vma) to all the PTE accessors...)

arch/ppc/mm/tlb.c +1 -1
Index: linux-work/arch/ppc/mm/tlb.c
===================================================================
@@ -62,7 +62,7 @@
 	ptepage = virt_to_page(ptep);
 	mm = (struct mm_struct *) ptepage->mapping;
 	ptephys = __pa(ptep) & PAGE_MASK;
-	addr = ptepage->index + (((unsigned long)ptep & ~PAGE_MASK) << 9);
+	addr = ptepage->index + (((unsigned long)ptep & ~PAGE_MASK) << 10);
 	flush_hash_pages(mm->context, addr, ptephys, 1);
 }
 
#1 lore raw

PATCH 1/1 set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 3 lines · On Wed, 23 Feb 2005 19:02:09 +1100 Benjamin Herrenschmidt <[email protected]>…

(I hope by early 2.6.12, we'll have David's patch that removes the need for those hacks though, and just pass us the vaddr (and mm or vma) to all the PTE accessors...)

Ok ok ok, I've started working on this again :-)

I'm taking a slightly different approach this time around so things are easier to integrate. Here is the first patch which builds the infrastructure. Basically:

1) Add set_pte_at() which is set_pte() with "mm" and "addr" arguments added. All generic code uses set_pte_at().

Most platforms simply get this define:

	#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)

I chose this method over simply changing all set_pte() call sites because many platforms implement this in assembler and it would take forever to preserve the build and stabilize things if modifying that was necessary.

Soon, with platform maintainer's help, we can kill of set_pte() entirely. To be honest, there are only a handful of set_pte() call sites in the arch specific code.

Actually, in this patch ppc64 is completely set_pte() free and does not define it.

2) pte_clear() gets "mm" and "addr" arguments now.
This had a cascading effect on many ptep_test_and_*() routines. Specifically:
a) ptep_test_and_clear_{young,dirty}() now take "vma" and "address" args.
b) ptep_get_and_clear now take "mm" and "address" args.
c) ptep_mkdirty was deleted, unused by any code.
d) ptep_set_wrprotect now takes "mm" and "address" args.

I've tested this patch as follows:

1) compile and run tested on sparc64/SMP
2) compile tested on:
a) ppc64/SMP
b) i386 both with and without PAE enabled

I've been over this a few times this afternoon and the patch looks correct. Please test the build and boot of your platform, any build failures should be trivial typos and nothing major.

Next I'll work on the sparc64 taking advantage of set_pte_at() and then I'll merge in Ben's patch I have doing the same.

#2 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

"David S. Miller" <[email protected]> wrote on 24.02.2005 01:11:38:

Quoted 8 lines

I'm taking a slightly different approach this time around so things are easier to integrate. Here is the first patch which builds the infrastructure. Basically:

2) pte_clear() gets "mm" and "addr" arguments now.
This had a cascading effect on many ptep_test_and_*() routines.
Specifically:
a) ptep_test_and_clear_{young,dirty}() now take "vma" and "address"

args.

Quoted 3 lines

b) ptep_get_and_clear now take "mm" and "address" args.
c) ptep_mkdirty was deleted, unused by any code.
d) ptep_set_wrprotect now takes "mm" and "address" args.

The change in the pte_clear prototype broke compilation on s390. The attached little patch takes care of that. Runs fine now.

blue skies,
Martin

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

(See attached file: set_pte_at_s390.diff)

include/asm-s390/pgtable.h +2 -2
diff -urN linux-2.6/include/asm-s390/pgtable.h linux-2.6-pte/include/asm-s390/pgtable.h
@@ -550,7 +550,7 @@
 static inline pte_t ptep_get_and_clear(pte_t *ptep)
 {
 	pte_t pte = *ptep;
-	pte_clear(mm, addr, ptep);
+	pte_val(*ptep) = _PAGE_INVALID_EMPTY;
 	return pte;
 }
 
@@ -573,7 +573,7 @@
 				      : "=m" (*ptep) : "m" (*ptep),
 				        "a" (ptep), "a" (address) );
 #endif /* __s390x__ */
-	pte_clear(vma->vm_mm, address, ptep);
+	pte_val(*ptep) = _PAGE_INVALID_EMPTY;
 	return pte;
 }
 
#3 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 2 lines · On Fri, 25 Feb 2005 10:32:57 +0100 Martin Schwidefsky <[email protected]>…

The change in the pte_clear prototype broke compilation on s390. The attached little patch takes care of that. Runs fine now.

ptep_get_and_clear() takes mm and addr argument now, and ptep_clear_flush() takes vma, address, and ptep args now.

I'm very sure I didn't miss the asm-s390/pgtable.h instance. And even weirder is that your patch is against a tree where the ptep_get_and_clear() prototype was not updated:

--------------
@@ -550,7 +550,7 @@
static inline pte_t ptep_get_and_clear(pte_t *ptep)
--------------

The only thing I could see breaking the build is that the structure layout of "vma" is not available at the time pgtable.h is parsed, so the vma->vm_mm causes a parse error.

In that case, please fix this simply by turning ptep_clear_flush() (and thus ptep_establish) into a macro to fix the build as we have done on the other platforms.

It is very useful to actually use set_pte_at() and pte_clear() whenever possible, instead of open-coding things, so that you may experiment quite simply with batched TLB flushing on your platform.

Please give this patch a shot.

===== include/asm-s390/pgtable.h 1.36 vs edited =====

include/asm-s390/pgtable.h +28 -29
@@ -555,28 +555,31 @@
 	return pte;
 }
 
-static inline pte_t
-ptep_clear_flush(struct vm_area_struct *vma,
-		 unsigned long address, pte_t *ptep)
-{
-	pte_t pte = *ptep;
 #ifndef __s390x__
-	if (!(pte_val(pte) & _PAGE_INVALID)) {
-		/* S390 has 1mb segments, we are emulating 4MB segments */
-		pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
-		__asm__ __volatile__ ("ipte %2,%3"
-				      : "=m" (*ptep) : "m" (*ptep),
-				        "a" (pto), "a" (address) );
-	}
-#else /* __s390x__ */
-	if (!(pte_val(pte) & _PAGE_INVALID)) 
-		__asm__ __volatile__ ("ipte %2,%3"
-				      : "=m" (*ptep) : "m" (*ptep),
-				        "a" (ptep), "a" (address) );
-#endif /* __s390x__ */
-	pte_clear(vma->vm_mm, address, ptep);
-	return pte;
-}
+#define ptep_clear_flush(__vma,__addr,__ptep) \
+({	pte_t __pte = *(__ptep); \
+	if (!(pte_val(__pte) & _PAGE_INVALID)) { \
+		/* S390 has 1mb segments, we are emulating 4MB segments */ \
+		pte_t *__pto = (pte_t *) \
+		  (((unsigned long) (__ptep)) & 0x7ffffc00); \
+		__asm__ __volatile__ ("ipte %2,%3" \
+				      : "=m" (*(__ptep)) : "m" (*(__ptep)), \
+				        "a" (__pto), "a" (__addr) ); \
+	} \
+	pte_clear((__vma)->vm_mm, (__addr), (__ptep)); \
+	__pte; \
+})
+#else
+#define ptep_clear_flush(__vma,__addr,__ptep) \
+({	pte_t __pte = *(__ptep); \
+	if (!(pte_val(__pte) & _PAGE_INVALID))  \
+		__asm__ __volatile__ ("ipte %2,%3" \
+				      : "=m" (*(__ptep)) : "m" (*(__ptep)), \
+				        "a" (__ptep), "a" (__addr)); \
+	pte_clear((__vma)->vm_mm, (__addr), (__ptep)); \
+	__pte; \
+})
+#endif
 
 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 {
@@ -584,14 +587,10 @@
 	set_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
 }
 
-static inline void
-ptep_establish(struct vm_area_struct *vma, 
-	       unsigned long address, pte_t *ptep,
-	       pte_t entry)
-{
-	ptep_clear_flush(vma, address, ptep);
-	set_pte(ptep, entry);
-}
+#define ptep_establish(__vma, __addr, __ptep, __entry) \
+do {	ptep_clear_flush((__vma), (__addr), (__ptep)); \
+	set_pte((__ptep), (__entry)); \
+} while (0)
 
 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
 	ptep_establish(__vma, __address, __ptep, __entry)
#4 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 3 lines

The only thing I could see breaking the build is that the structure layout of "vma" is not available at the time pgtable.h is parsed, so the vma->vm_mm causes a parse error.

That is indeed the cause of the compile error on s390.

Quoted 3 lines

In that case, please fix this simply by turning ptep_clear_flush() (and thus ptep_establish) into a macro to fix the build as we have done on the other platforms.

Please don't. There are too many macros from hell as things are now. I prefer to sort out the compile errors with my inline functions than to introduce more of that macro crap.

Simply expand the pte_clear inline into ptep_get_and_clear & ptep_clear_flush gets you around the problem with deferencing "vma" because on s390 we don't need the mm struct in pte_clear.

blue skies,
Martin

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

#5 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 11 lines · On Mon, 28 Feb 2005 10:27:03 +0100 Martin Schwidefsky <[email protected]>…
Quoted 3 lines

In that case, please fix this simply by turning ptep_clear_flush() (and thus ptep_establish) into a macro to fix the build as we have done on the other platforms.

Please don't. There are too many macros from hell as things are now. I prefer to sort out the compile errors with my inline functions than to introduce more of that macro crap.

Simply expand the pte_clear inline into ptep_get_and_clear & ptep_clear_flush gets you around the problem with deferencing "vma" because on s390 we don't need the mm struct in pte_clear.

I'll do as you wish no problem.

But you will need to address this should you ever want to experiment with batched TLB flushing. And I highly encourage anyone with TLBs lacking true range flushing in hardware to do so :-) It is such an incredible improvement.

#6 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 4 lines

But you will need to address this should you ever want to experiment with batched TLB flushing. And I highly encourage anyone with TLBs lacking true range flushing in hardware to do so :-) It is such an incredible improvement.

IDTE would be the instruction of choise on s390 for tlb range flushing. I wanted to do some tlb work anyway to get rid of the repeated flushes after process exit. There is no need to flush every 500 odd pages, once is enough.

blue skies,
Martin

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

#7 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

In reply to David S. Miller
Quoted 4 lines · David S. Miller

I've been over this a few times this afternoon and the patch looks correct. Please test the build and boot of your platform, any build failures should be trivial typos and nothing major.

This works fine for sh and sh64 too.

#8 lore raw

Re: [PATCH] set_pte() part 1 (was Re: [PATCH] ppc32: Wrong vaddr in flush_hash_one_pte())

Quoted 6 lines · On Fri, 25 Feb 2005 15:29:50 +0200 Paul Mundt <[email protected]> wrote:
Quoted 4 lines · David S. Miller

I've been over this a few times this afternoon and the patch looks correct. Please test the build and boot of your platform, any build failures should be trivial typos and nothing major.

This works fine for sh and sh64 too.

Thanks for testing paul.