Skip to contentSkip to conversation

mm: 8xx MM fix for

PATCH In review Pantelis Antoniou 6 participants 17 messages Oct 30, 2005 – Nov 10, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: 8xx MM fix for

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

---
commit 978e2f36b1ae53e37ba27b3ab8f1c5ddbb8c8a10
tree 7dd0e403c240162b1925db0834d694f4b4a0e95e
parent ca02ea5aebcda886d1552c6af73ca96c02bf9fed
author Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200 committer Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200

 arch/ppc/mm/fault.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/ppc/mm/fault.c +13 -0
@@ -240,6 +240,19 @@ good_area:
 			goto bad_area;
 		if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
 			goto bad_area;
+
+#ifdef CONFIG_8xx
+		{
+		/* 8xx is retarded; news at 11 */
+		pte_t *ptep = NULL;
+
+		if (get_pteptr(mm, address, &ptep) && pte_present(*ptep))
+			_tlbie(address);
+
+		if (ptep != NULL)
+			pte_unmap(ptep);
+		}
+#endif
 	}
 
 	/*
#1 lore raw
Quoted 2 lines · Pantelis Antoniou

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

Ugh ?

What is the problem precisely ? This is just a dodgy workaround for an unexplained problem. Normally, the kenrel _WILL_ cause a tlb flush after manipulating a PTE.

Ben.

Quoted 33 lines

---
commit 978e2f36b1ae53e37ba27b3ab8f1c5ddbb8c8a10
tree 7dd0e403c240162b1925db0834d694f4b4a0e95e
parent ca02ea5aebcda886d1552c6af73ca96c02bf9fed
author Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200 committer Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200

 arch/ppc/mm/fault.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/ppc/mm/fault.c +13 -0
@@ -240,6 +240,19 @@ good_area:
 			goto bad_area;
 		if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
 			goto bad_area;
+
+#ifdef CONFIG_8xx
+		{
+		/* 8xx is retarded; news at 11 */
+		pte_t *ptep = NULL;
+
+		if (get_pteptr(mm, address, &ptep) && pte_present(*ptep))
+			_tlbie(address);
+
+		if (ptep != NULL)
+			pte_unmap(ptep);
+		}
+#endif
 	}
 
 	/*
#2 lore raw
In reply to Pantelis Antoniou
Quoted 2 lines · Pantelis Antoniou

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

Hi Panto,

Its working fine around here. How much of a vanilla 2.6.14 your is?

[root@CAS root]# cat /proc/cpuinfo
processor : 0
cpu : 8xx
clock : 48MHz
bus clock : 48MHz
revision : 0.0 (pvr 0050 0000)
bogomips : 47.82
[root@CAS root]# uname -a
Linux CAS 2.6.14 #2 Tue Nov 1 16:20:28 CST 2005 ppc unknown

#3 lore raw
Quoted 8 lines · Marcelo Tosatti
Quoted 2 lines · Pantelis Antoniou

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

Hi Panto,

Its working fine around here. How much of a vanilla 2.6.14 your is?

Quoted 11 lines

[root@CAS root]# cat /proc/cpuinfo
processor : 0
cpu : 8xx
clock : 48MHz
bus clock : 48MHz
revision : 0.0 (pvr 0050 0000)
bogomips : 47.82
[root@CAS root]# uname -a
Linux CAS 2.6.14 #2 Tue Nov 1 16:20:28 CST 2005 ppc unknown

Vanila 2.6.14 worked fine too.

It's the mm patches that started coming in later. Unfortunately the version did not change, so I can't provide it. Did you used a current git tree?

Regards

Pantelis

#4 lore raw
Quoted 21 lines · Pantelis Antoniou
Quoted 8 lines · Marcelo Tosatti
Quoted 2 lines · Pantelis Antoniou

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

Hi Panto,

Its working fine around here. How much of a vanilla 2.6.14 your is?

Quoted 11 lines

[root@CAS root]# cat /proc/cpuinfo
processor : 0
cpu : 8xx
clock : 48MHz
bus clock : 48MHz
revision : 0.0 (pvr 0050 0000)
bogomips : 47.82
[root@CAS root]# uname -a
Linux CAS 2.6.14 #2 Tue Nov 1 16:20:28 CST 2005 ppc unknown

Quoted 5 lines

Vanila 2.6.14 worked fine too.

It's the mm patches that started coming in later. Unfortunately the version did not change, so I can't provide it. Did you used a current git tree?

No I did not - will do and chase the bug.

Thanks.

#5 lore raw
In reply to Pantelis Antoniou

Hi folks,

Seems the bug is exposed by the change which avoids flushing the TLB when not necessary (in case the pte has not changed), introduced recently:

__handle_mm_fault():

        entry = pte_mkyoung(entry);
        if (!pte_same(old_entry, entry)) {
                ptep_set_access_flags(vma, address, pte, entry, write_access);
                update_mmu_cache(vma, address, entry);
                lazy_mmu_prot_update(entry);
        } else {
                /*
                 * This is needed only for protection faults but the arch code
                 * is not yet telling us if this is a protection fault or not.
                 * This still avoids useless tlb flushes for .text page faults
                 * with threads.
                 */
                if (write_access)
                        flush_tlb_page(vma, address);
        }

The "update_mmu_cache()" call was unconditional before, which caused the TLB to be flushed by:

        if (pfn_valid(pfn)) {
                struct page *page = pfn_to_page(pfn);
                if (!PageReserved(page)
                    && !test_bit(PG_arch_1, &page->flags)) {
                        if (vma->vm_mm == current->active_mm) {

#ifdef CONFIG_8xx
/* On 8xx, cache control instructions (particularly
* "dcbst" from flush_dcache_icache) fault as write
* operation if there is an unpopulated TLB entry
* for the address in question. To workaround that,
* we invalidate the TLB here, thus avoiding dcbst
* misbehaviour.
*/
_tlbie(address);

#endif
                                __flush_dcache_icache((void *) address);
                        } else
                                flush_dcache_icache_page(page);
                        set_bit(PG_arch_1, &page->flags);
                }

Which worked to due to pure luck: PG_arch_1 was always unset before, but now it isnt.

The root of the problem are the changes against the 8xx TLB handlers introduced during v2.6. What happens is the TLBMiss handlers load the zeroed pte into the TLB, causing the TLBError handler to be invoked (thats two TLB faults per pagefault), which then jumps to the generic MM code to setup the pte.

The bug is that the zeroed TLB is not invalidated (the same reason for the "dcbst" misbehaviour), resulting in infinite TLBError faults.

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very clear to me that "two exception" speedup offsets the additional code required for "one exception" version. Have you actually done any measurements?

There is chance that the additional code ends up in the same cacheline, which would mean no huge gain by the "two exception" approach. Might be even harmful for performance (you need two exceptions instead of one after all).

The "two exception" approach requires a TLB flush (to nuke the zeroed) at each PTE update for correct behaviour (which BTW is another slowdown):

arch/ppc/mm/init.c renamed from git/linux-2.6/arch/ppc/mm/init.c +3 -10
@@ -597,19 +597,12 @@
 
 	if (pfn_valid(pfn)) {
 		struct page *page = pfn_to_page(pfn);
+#ifdef CONFIG_8xx
+		_tlbie(address);
+#endif
 		if (!PageReserved(page)
 		    && !test_bit(PG_arch_1, &page->flags)) {
 			if (vma->vm_mm == current->active_mm) {
-#ifdef CONFIG_8xx
-			/* On 8xx, cache control instructions (particularly 
-		 	 * "dcbst" from flush_dcache_icache) fault as write 
-			 * operation if there is an unpopulated TLB entry 
-			 * for the address in question. To workaround that, 
-			 * we invalidate the TLB here, thus avoiding dcbst 
-			 * misbehaviour.
-			 */
-				_tlbie(address);
-#endif
 				__flush_dcache_icache((void *) address);
 			} else
 				flush_dcache_icache_page(page);
Quoted 36 lines · Pantelis Antoniou

Latest MMU changes caused 8xx to stop working. Flushing tlb of the faulting address fixes the problem.

---
commit 978e2f36b1ae53e37ba27b3ab8f1c5ddbb8c8a10
tree 7dd0e403c240162b1925db0834d694f4b4a0e95e
parent ca02ea5aebcda886d1552c6af73ca96c02bf9fed
author Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200 committer Pantelis Antoniou <panto@pantathon> Sun, 30 Oct 2005 21:53:48 +0200

 arch/ppc/mm/fault.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/ppc/mm/fault.c +13 -0
@@ -240,6 +240,19 @@ good_area:
 			goto bad_area;
 		if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
 			goto bad_area;
+
+#ifdef CONFIG_8xx
+		{
+		/* 8xx is retarded; news at 11 */
+		pte_t *ptep = NULL;
+
+		if (get_pteptr(mm, address, &ptep) && pte_present(*ptep))
+			_tlbie(address);
+
+		if (ptep != NULL)
+			pte_unmap(ptep);
+		}
+#endif
 	}
 
 	/*
#6 lore raw
Quoted 3 lines · Marcelo Tosatti

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very clear to me that "two exception" speedup offsets the additional code required for "one exception" version. Have you actually done any measurements?

No, and I didn't actually make these changes, either :-)
I'm working on some 8xx debugging right now, so let's experiment with some changes. I don't understand why other processors, especially G2 cores like 82xx, aren't finding the same problems we are having with 8xx. Logically, we are all doing the same thing, unless there are some tlb invalidates on these other processors that I'm forgetting about. We just seem to be running into stale entries, and we have to fix it.

Thanks.

	-- Dan
#8 lore raw
In reply to Marcelo Tosatti
Quoted 6 lines · Marcelo Tosatti

Hi folks,

Seems the bug is exposed by the change which avoids flushing the TLB when not necessary (in case the pte has not changed), introduced recently:

[snip]

Quoted 2 lines

Good job Marcelo! :)

FWIW I'd rather have the single exception version if at all possible.

Regards

Pantelis

#9 lore raw
In reply to Marcelo Tosatti
Quoted 4 lines · Marcelo Tosatti

Seems the bug is exposed by the change which avoids flushing the TLB when not necessary (in case the pte has not changed), introduced recently:
[...]

Brilliant!
I just checked, and now it boots again.
Btw, it did boot before this patch, but taking about 2 or 3 hours to get halfway through the init scripts ;-)

Thanks for the good work!

Signature · 1 line
David Jander
#7 lore raw
In reply to Dan Malek
Quoted 10 lines · Dan Malek
Quoted 5 lines · Marcelo Tosatti

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very
clear to me that "two exception" speedup offsets the additional code required
for "one exception" version. Have you actually done any measurements?

No, and I didn't actually make these changes, either :-)

Ahh, ok. sorry. I remember you arguing that it was faster this way (less code).

Quoted 6 lines

I'm working on some 8xx debugging right now, so let's experiment with some changes. I don't understand why other processors, especially G2 cores like 82xx, aren't finding the same problems we are having with 8xx. Logically, we are all doing the same thing, unless there are some tlb invalidates on these other processors that I'm forgetting about.

I really dont know how the 82xx TLB works, so...

Quoted 1 line

We just seem to be running into stale entries, and we have to fix it.

Right - the issue Joakim noted would be one reason for the "two exception" approach.

#10 lore raw
In reply to Marcelo Tosatti
Quoted 3 lines · Marcelo Tosatti

The bug is that the zeroed TLB is not invalidated (the same reason for the "dcbst" misbehaviour), resulting in infinite TLBError faults.

I see, so you are in the same situation as ia64 which has valid but unmapped TLBs ?

Quoted 3 lines

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very clear to me that "two exception" speedup offsets the additional code required for "one exception" version. Have you actually done any measurements?

What do you mean by "one exception" version ? You probably get 3 in fact since after you have serviced the fault in the common code, you take another fault to fill the PTE.

In fact, you could even go back to one exception by pre-filling the TLB in update_mmu_cache :)

Quoted 7 lines

There is chance that the additional code ends up in the same cacheline, which would mean no huge gain by the "two exception" approach. Might be even harmful for performance (you need two exceptions instead of one after all).

The "two exception" approach requires a TLB flush (to nuke the zeroed) at each PTE update for correct behaviour (which BTW is another slowdown):

I think the current code, even with your fix, is sub-optimal. But of course, the only way to be sure is to do real measurements

Ben.

#11 lore raw
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 3 lines · Marcelo Tosatti

The bug is that the zeroed TLB is not invalidated (the same reason for the "dcbst" misbehaviour), resulting in infinite TLBError faults.

I see, so you are in the same situation as ia64 which has valid but unmapped TLBs ?

Quoted 3 lines

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very clear to me that "two exception" speedup offsets the additional code required for "one exception" version. Have you actually done any measurements?

Quoted 7 lines

What do you mean by "one exception" version ? You probably get 3 in fact since after you have serviced the fault in the common code, you take another fault to fill the PTE.

In fact, you could even go back to one exception by pre-filling the TLB in update_mmu_cache :)

Yep. That should be the target. Remember the poor 8xx is not exactly a speed demon :).

Quoted 5 lines
Quoted 5 lines

There is chance that the additional code ends up in the same cacheline, which would mean no huge gain by the "two exception" approach. Might be even harmful for performance (you need two exceptions instead of one after all).

Quoted 9 lines
Quoted 2 lines

The "two exception" approach requires a TLB flush (to nuke the zeroed) at each PTE update for correct behaviour (which BTW is another slowdown):

I think the current code, even with your fix, is sub-optimal. But of course, the only way to be sure is to do real measurements

Ben.

The TLB flush is bogus IMO. I'm going to try the last patch by marcelo to see if it works for me.

Pantelis.

#13 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 3 lines · Marcelo Tosatti

The bug is that the zeroed TLB is not invalidated (the same reason for the "dcbst" misbehaviour), resulting in infinite TLBError faults.

I see, so you are in the same situation as ia64 which has valid but unmapped TLBs ?

Quoted 7 lines
Quoted 3 lines

Dan, I wonder why we just don't go back to v2.4 behaviour. It is not very clear to me that "two exception" speedup offsets the additional code required for "one exception" version. Have you actually done any measurements?

What do you mean by "one exception" version ? You probably get 3 in fact since after you have serviced the fault in the common code, you take another fault to fill the PTE.

Yep, that would be 3!

Quoted 2 lines

In fact, you could even go back to one exception by pre-filling the TLB in update_mmu_cache :)

OK, thats a good idea as we talked on IRC. Working on that.

Quoted 10 lines
Quoted 7 lines

There is chance that the additional code ends up in the same cacheline, which would mean no huge gain by the "two exception" approach. Might be even harmful for performance (you need two exceptions instead of one after all).

The "two exception" approach requires a TLB flush (to nuke the zeroed) at each PTE update for correct behaviour (which BTW is another slowdown):

I think the current code, even with your fix, is sub-optimal. But of course, the only way to be sure is to do real measurements

Indeed.

Thanks!

#12 lore raw
In reply to Pantelis Antoniou
Quoted 2 lines · Pantelis Antoniou

Yep. That should be the target. Remember the poor 8xx is not exactly a speed demon :).

It really isn't a big speed difference. The context save/restore is minimal. The original thought was " ...well, I'm already here, I know we will take another exception, so may as well fake the
error case and call do_page_fault." However, I really do like
a minimal TLB miss case for valid PTEs, and push everything else to the heavyweight functions.

Thanks.

	-- Dan
#14 lore raw
In reply to Benjamin Herrenschmidt

On Tue, Nov 08, 2005 at 07:39:59AM +1100, Benjamin Herrenschmidt wrote:
<snip>

Quoted 2 lines

I think the current code, even with your fix, is sub-optimal. But of course, the only way to be sure is to do real measurements

Hi folks,

I've written a simple app to estimate pagefault latency using gettimeofday().

Can be found at http://hera.kernel.org/~marcelo/measurefault/

/* This simple program attemps to estimate how long a pagefault takes.
* It does that by mmaping() /tmp/latency-test, and touching a page.
* Time measurement is done with gettimeofday() before and after the
* data touch.
*
* In the hope to have a more precise measurement two values are subtracted
* from the pagefault time delta:
*
* - Estimated time between two subsequent gettimeofday() calls, average
* of 100 runs (this average is around 8ms on 48Mhz PPC 8xx,
* 0ms on 1Ghz Pegasos G4)
*
* - Time taken to touch the data after its TLB cached, aka second run.
* This takes 1 and 2ms on 8xx (it varies) and 0ms on 1Ghz Pegasos.
*/

And results with 48Mhz 855T, comparing internal v2.4.17, vanilla v2.6.14 and v2.6.14-jump-direct (jumping directly to handle_page_fault if the pte is zeroed).

Each "avg:" entry is an average of 100 "measure-fault-latency.c" runs.

2.6's root is mounted on NFS.

** 2.6.14 DataTLBHandler jump direct ("two exceptions"):

first batch:
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms

second batch:
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms

** 2.6.14 vanilla ("three exceptions"):

first batch:
avg: 288ms
avg: 285ms
avg: 287ms
avg: 287ms
avg: 288ms

second batch:
avg: 288ms
avg: 288ms
avg: 287ms
avg: 287ms
avg: 287ms

** 2.4.17 (root on RAMDISK):

avg: 309ms
avg: 313ms
avg: 312ms
avg: 311ms
avg: 310ms

The v2.6.14's kernel jump-direct is more consistent at 287ms, while vanilla 2.6.14 oscillates between 285 and 288ms, but no significant difference between the two.

v2.6's fault handling is clearly faster than 2.4's (note that the compiler is also different, 2.4 uses gcc 2.95 and 2.6 gcc 3.3).

#15 lore raw
Quoted 34 lines · Marcelo Tosatti

[...]

** 2.6.14 DataTLBHandler jump direct ("two exceptions"):

first batch:
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms

second batch:
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms
avg: 287ms

** 2.6.14 vanilla ("three exceptions"):

first batch:
avg: 288ms
avg: 285ms
avg: 287ms
avg: 287ms
avg: 288ms

second batch:
avg: 288ms
avg: 288ms
avg: 287ms
avg: 287ms
avg: 287ms

Quoted 7 lines

** 2.4.17 (root on RAMDISK):

avg: 309ms
avg: 313ms
avg: 312ms
avg: 311ms
avg: 310ms

Hmmm. This is a lot in the line of the tests I did with (the more generic benchmark) nbench. After looking at those results (see my other post in this thread) I already suspected something like this.

Quoted 6 lines

The v2.6.14's kernel jump-direct is more consistent at 287ms, while vanilla 2.6.14 oscillates between 285 and 288ms, but no significant difference between the two.

v2.6's fault handling is clearly faster than 2.4's (note that the compiler is also different, 2.4 uses gcc 2.95 and 2.6 gcc 3.3).

I don't think the compiler does much difference here though. In my test the exact same compiler was used for both kernels, and the same rootfs and binary of nbench. gcc-3.3.3. I did also use oprofile to get an idea of where the code spent its most cpu time during nbench, and AFAIR flush_dcache_icache() took quite a chunk of it, so I assume page fault latency is of importance there too, and might account for the huge difference between 2.4 and 2.6.

Greetings,

Signature · 1 line
David Jander
#16 lore raw
Quoted 4 lines · David Jander

[...]
Hmmm. This is a lot in the line of the tests I did with (the more generic benchmark) nbench. After looking at those results (see my other post in this thread) I already suspected something like this.

Sorry, I obviously did not mean this thread, but the following post on another thread:

http://ozlabs.org/pipermail/linuxppc-embedded/2005-November/020775.html

Regards,

Signature · 1 line
David Jander