Skip to contentSkip to conversation

Apparent kernel bug with GDB on ppc405

DISCUSSION Matt Mackall 6 participants 27 messages Oct 24, 2007 – Oct 29, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

With direct gdb on target, I can set a breakpoint at main, run, and the breakpoint is triggered.

With gdbserver and gdb with "target remote localhost:1234", the above still works.

With gdb on target redirected to a PC and tunneled back to the target, everything still works.

With gdb on a PC, execution continues past the breakpoint. Comparing the gdb protocol streams here and and on the previous (working) case are identical up to the point of hitting the breakpoint (which never happens in the latter case).

Raising the load on the PC to 4 and running gdb under nice -n 19 makes things work again. So this begins to look like a kernel cache or timing bug rather than a problem with the PC tool. It appears that the breakpoint written to the executable at continue time is not visible to the CPU at execute time.

My first suspicion was a dcache/icache coherency issue in copy_to_user_page, so I added flush_dcache_icache_page(page) here to no avail. On closer inspection, it looks like both icache and dcache are already being flushed by flush_icache_user_range().

Adding printk(".") (or any printk) in this function here fixes things (serial console at 115k), while printk("") and udelay(100) do not. Which still suggests an icache bug..?

Any suggestions?

Signature · 1 line
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 
#1 lore raw
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

That's not much help, but maybe it will give you some clues.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#2 lore raw
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#3 lore raw
Quoted 19 lines · Matt Mackall
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Quoted 5 lines

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

It's really true; printk *is* the most valuable tool kernel hackers have for debugging.

g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#4 lore raw
In reply to Matt Mackall
Quoted 19 lines · Matt Mackall
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Quoted 5 lines

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

Well there was one remaining cache - the TLB. This patch seems to make things work, but don't ask me why:

asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +2 -1
@@ -11,6 +11,7 @@
 #define _PPC_CACHEFLUSH_H
 
 #include <linux/mm.h>
+#include <asm/tlbflush.h>
 
 /*
  * No cache flushing is required when address mappings are
@@ -35,10 +36,23 @@
 extern void flush_icache_user_range(struct vm_area_struct *vma,
                struct page *page, unsigned long addr, int len);
 
 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
 do { memcpy(dst, src, len); \
      flush_icache_user_range(vma, page, vaddr, len); \
+     _tlbia(); \
 } while (0)
 
-- 

Mathematics is the supreme nostalgia of our time.

#5 lore raw
Quoted 40 lines · Matt Mackall
Quoted 19 lines · Matt Mackall
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Quoted 5 lines

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

Well there was one remaining cache - the TLB. This patch seems to make things work, but don't ask me why:

asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -11,6 +11,7 @@
 #define _PPC_CACHEFLUSH_H
 
 #include <linux/mm.h>
+#include <asm/tlbflush.h>
 
 /*
  * No cache flushing is required when address mappings are

asm-ppc/cacheflush.h (working copy) line 43

Quoted 8 lines
asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -35,10 +36,23 @@
 extern void flush_icache_user_range(struct vm_area_struct *vma,
                struct page *page, unsigned long addr, int len);
 
 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
 do { memcpy(dst, src, len); \
      flush_icache_user_range(vma, page, vaddr, len); \
+     _tlbia(); \
 } while (0)

Hmmm; thinking out loud here...

- so tlbia invalidates all TLB entries
- When gdb inserts a breakpoint the .text pages are marked as read only, so the kernel does a copy on write so that gdb can modify the instruction. The kernel also updates the page tables so that the test process now uses the new page.
- This means that there are now 2 pages for that one section of executable code; the original and the one with the breakpoint.
- However, the program is still in memory, and there is probably already a TLB entry pointing to the original page for that range of addresses.

Could it be that the kernel page tables are getting updated to the new page; but active set of TLB entries is not getting updated?

If so, then printk(".") probably solves the problem simply because it touches enough pages in its execution path that the old TLB entry gets overwritten? There are only 64 TLB entries afterall.

Thoughts?

g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#6 lore raw
Quoted 63 lines · Grant Likely
Quoted 40 lines · Matt Mackall
Quoted 19 lines · Matt Mackall
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Quoted 5 lines

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

Well there was one remaining cache - the TLB. This patch seems to make things work, but don't ask me why:

asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -11,6 +11,7 @@
 #define _PPC_CACHEFLUSH_H
 
 #include <linux/mm.h>
+#include <asm/tlbflush.h>
 
 /*
  * No cache flushing is required when address mappings are

asm-ppc/cacheflush.h (working copy) line 43

Quoted 8 lines
asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -35,10 +36,23 @@
 extern void flush_icache_user_range(struct vm_area_struct *vma,
                struct page *page, unsigned long addr, int len);
 
 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
 do { memcpy(dst, src, len); \
      flush_icache_user_range(vma, page, vaddr, len); \
+     _tlbia(); \
 } while (0)

Hmmm; thinking out loud here...

- so tlbia invalidates all TLB entries
- When gdb inserts a breakpoint the .text pages are marked as read only, so the kernel does a copy on write so that gdb can modify the instruction. The kernel also updates the page tables so that the test process now uses the new page.
- This means that there are now 2 pages for that one section of executable code; the original and the one with the breakpoint.
- However, the program is still in memory, and there is probably already a TLB entry pointing to the original page for that range of addresses.

Quoted 8 lines

Could it be that the kernel page tables are getting updated to the new page; but active set of TLB entries is not getting updated?

If so, then printk(".") probably solves the problem simply because it touches enough pages in its execution path that the old TLB entry gets overwritten? There are only 64 TLB entries afterall.

Thoughts?

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#7 lore raw
Quoted 71 lines · Matt Mackall
Quoted 70 lines · Grant Likely
Quoted 40 lines · Matt Mackall
Quoted 19 lines · Matt Mackall
Quoted 10 lines · Grant Likely
Quoted 3 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

<snip>

Quoted 2 lines

Any suggestions?

http://thread.gmane.org/gmane.linux.ports.ppc.embedded/11202

Quoted 7 lines

I was fighting with a similar problem almost 2 years ago. Looks like it might be related. At some point the problem seemed to go away and I determined what the root cause was. :-(

I haven't been using gdb lately, so I don't know if it's the same problem. Nobody I had talked to had seen the issue on other 405 platforms. It could very well be something virtex-specific.

Quoted 5 lines

Could be the same problem, but I'm seeing only your symptom 3 so far.

I've tried throwing some larger hammers at the problem. Flushing all of the dcache and icache (flush_dcache_all and flush_instruction_cache) isn't helping. But printk(".") does!

Well there was one remaining cache - the TLB. This patch seems to make things work, but don't ask me why:

asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -11,6 +11,7 @@
 #define _PPC_CACHEFLUSH_H
 
 #include <linux/mm.h>
+#include <asm/tlbflush.h>
 
 /*
  * No cache flushing is required when address mappings are

asm-ppc/cacheflush.h (working copy) line 43

Quoted 8 lines
asm-ppc/cacheflush.h (working copy) renamed from asm-ppc/cacheflush.h (revision 10439) +1 -0
@@ -35,10 +36,23 @@
 extern void flush_icache_user_range(struct vm_area_struct *vma,
                struct page *page, unsigned long addr, int len);
 
 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
 do { memcpy(dst, src, len); \
      flush_icache_user_range(vma, page, vaddr, len); \
+     _tlbia(); \
 } while (0)

Hmmm; thinking out loud here...

- so tlbia invalidates all TLB entries
- When gdb inserts a breakpoint the .text pages are marked as read only, so the kernel does a copy on write so that gdb can modify the instruction. The kernel also updates the page tables so that the test process now uses the new page.
- This means that there are now 2 pages for that one section of executable code; the original and the one with the breakpoint.
- However, the program is still in memory, and there is probably already a TLB entry pointing to the original page for that range of addresses.

Could it be that the kernel page tables are getting updated to the new page; but active set of TLB entries is not getting updated?

If so, then printk(".") probably solves the problem simply because it touches enough pages in its execution path that the old TLB entry gets overwritten? There are only 64 TLB entries afterall.

Quoted 5 lines
Quoted 1 line

Thoughts?

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

a) I don't know.... very odd.

b) gdb is big. It probably touches far more pages (via library calls) than gdbserver. The network stack is also big, but it's probably more localized too.

Niceing down the host also makes sense because if the PC is being slow then the target may go off and run other things while between setting the breakpoint and getting the 'go' command.

Can you grab a snapshot of the TLB before and after setting the breakpoint?

g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#8 lore raw
Quoted 10 lines · Grant Likely
Quoted 3 lines

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

a) I don't know.... very odd.

b) gdb is big. It probably touches far more pages (via library calls) than gdbserver. The network stack is also big, but it's probably more localized too.

Quoted 5 lines

Niceing down the host also makes sense because if the PC is being slow then the target may go off and run other things while between setting the breakpoint and getting the 'go' command.

Can you grab a snapshot of the TLB before and after setting the breakpoint?

Or; probably more relevant, before and after the page copy?

g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#9 lore raw
Quoted 11 lines · Grant Likely
Quoted 10 lines · Grant Likely
Quoted 3 lines

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

a) I don't know.... very odd.

b) gdb is big. It probably touches far more pages (via library calls) than gdbserver. The network stack is also big, but it's probably more localized too.

Quoted 7 lines
Quoted 5 lines

Niceing down the host also makes sense because if the PC is being slow then the target may go off and run other things while between setting the breakpoint and getting the 'go' command.

Can you grab a snapshot of the TLB before and after setting the breakpoint?

Or; probably more relevant, before and after the page copy?

COW does ptep_clear_flush before setting the new TLB which does a flush_tlb_page() so that should work.

Ben.

#10 lore raw
In reply to Matt Mackall
Quoted 3 lines · Matt Mackall

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

You said it yourself. Local gdb does more work -> blows through more TLB entries.

I can't answer you about the other half, but I'm pretty sure TLB invalidation is already supposed to be happening... somewhere.

Signature · 2 lines
Daniel Jacobowitz
CodeSourcery
#11 lore raw
Quoted 10 lines · Daniel Jacobowitz
Quoted 3 lines · Matt Mackall

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

You said it yourself. Local gdb does more work -> blows through more TLB entries.

I can't answer you about the other half, but I'm pretty sure TLB invalidation is already supposed to be happening... somewhere.

Yes. do_wp_page() -> ptep_clear_flush() -> flush_tlb_page()

Ben.

#12 lore raw
Quoted 7 lines · On Fri, 26 Oct 2007 11:51:22 +1000 Benjamin Herrenschmidt…
Quoted 5 lines · Daniel Jacobowitz
Quoted 3 lines · Matt Mackall

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

Quoted 7 lines
Quoted 5 lines

You said it yourself. Local gdb does more work -> blows through more TLB entries.

I can't answer you about the other half, but I'm pretty sure TLB invalidation is already supposed to be happening... somewhere.

Yes. do_wp_page() -> ptep_clear_flush() -> flush_tlb_page()

Aren't there cases in do_wp_page that don't call ptep_clear_flush? Seems anonymous pages, and possibly shared writeable pages skip that step if reuse is true.

josh

#13 lore raw
Quoted 13 lines · Josh Boyer
Quoted 10 lines · On Fri, 26 Oct 2007 11:51:22 +1000 Benjamin Herrenschmidt…
Quoted 8 lines · Daniel Jacobowitz
Quoted 3 lines · Matt Mackall

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

You said it yourself. Local gdb does more work -> blows through more TLB entries.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I can't answer you about the other half, but I'm pretty sure TLB invalidation is already supposed to be happening... somewhere.

Yes. do_wp_page() -> ptep_clear_flush() -> flush_tlb_page()

Aren't there cases in do_wp_page that don't call ptep_clear_flush? Seems anonymous pages, and possibly shared writeable pages skip that step if reuse is true.

Nah, if that was broken, everybody would be in bad shape. I think I know what's up, see my other email.

Cheers,
Ben.

#14 lore raw
Quoted 17 lines · Benjamin Herrenschmidt
Quoted 16 lines · Josh Boyer
Quoted 13 lines · On Fri, 26 Oct 2007 11:51:22 +1000 Benjamin Herrenschmidt…
Quoted 10 lines · Daniel Jacobowitz
Quoted 3 lines · Matt Mackall

Not completely implausible, but a) why isn't this seen on basically every machine with software TLB? b) why does -local- GDB, which is presumably doing much less work than gdbserver + network stack, not fail?

You said it yourself. Local gdb does more work -> blows through more TLB entries.

I can't answer you about the other half, but I'm pretty sure TLB invalidation is already supposed to be happening... somewhere.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Yes. do_wp_page() -> ptep_clear_flush() -> flush_tlb_page()

Aren't there cases in do_wp_page that don't call ptep_clear_flush? Seems anonymous pages, and possibly shared writeable pages skip that step if reuse is true.

Nah, if that was broken, everybody would be in bad shape. I think I know what's up, see my other email.

Yeah, I figured that out after I sent this anyway. In those cases it should likely get flushed from ptep_set_access_flags.

josh

#15 lore raw
In reply to Matt Mackall
Quoted 23 lines · Matt Mackall

I'm trying to debug a trivial statically-linked hello world program on a Xilinx PPC 405 and I'm seeing the following behavior:

With direct gdb on target, I can set a breakpoint at main, run, and the breakpoint is triggered.

With gdbserver and gdb with "target remote localhost:1234", the above still works.

With gdb on target redirected to a PC and tunneled back to the target, everything still works.

With gdb on a PC, execution continues past the breakpoint. Comparing the gdb protocol streams here and and on the previous (working) case are identical up to the point of hitting the breakpoint (which never happens in the latter case).

Raising the load on the PC to 4 and running gdb under nice -n 19 makes things work again. So this begins to look like a kernel cache or timing bug rather than a problem with the PC tool. It appears that the breakpoint written to the executable at continue time is not visible to the CPU at execute time.

Quoted 5 lines

My first suspicion was a dcache/icache coherency issue in copy_to_user_page, so I added flush_dcache_icache_page(page) here to no avail. On closer inspection, it looks like both icache and dcache are already being flushed by flush_icache_user_range().

First of all I have never used a similar configuration so this may be totally off base. But...

If the icache is virtually indexed, then I think there are only two ways to invalidate it. The first is from the context of the debugged process where the page is mapped at the location the target program will see it.
If you try to invalidate from the context of the debugger, the page
will most likely not be mapped at the virtual address of the target program so you might have to invalidate the *entire* icache.

David Daney

#16 lore raw
Quoted 13 lines · David Daney

First of all I have never used a similar configuration so this may be totally off base. But...

If the icache is virtually indexed, then I think there are only two ways
to invalidate it. The first is from the context of the debugged process
where the page is mapped at the location the target program will see it.
If you try to invalidate from the context of the debugger, the
page
will most likely not be mapped at the virtual address of the target program so you might have to invalidate the *entire* icache.

Yup, sounds likely. We don't handle that virtual icache well at all in linux. Things tend to work by mere luck. I have various ideas to fix that but haven't actually implemented them.

Ben.

#17 lore raw
In reply to Matt Mackall
Quoted 11 lines · Matt Mackall

My first suspicion was a dcache/icache coherency issue in copy_to_user_page, so I added flush_dcache_icache_page(page) here to no avail. On closer inspection, it looks like both icache and dcache are already being flushed by flush_icache_user_range().

Adding printk(".") (or any printk) in this function here fixes things (serial console at 115k), while printk("") and udelay(100) do not. Which still suggests an icache bug..?

Any suggestions?

I think you're hitting a known bug of 44x support. Those CPUs have a crazy virtually tagged icache and the kernel doesn't deal with it at all (pretty much...). We just are lucky things generally work :-)

That means among other things that flush_icache_* will not work because they kmap pages and use that mapping. The only way to flush icache user pages with 44x is to actually flush with the user virtual address (meaning you have to be in the current context, and you probably need to have a TLB entry there... yuck)... or just blow the whole icache away.

Try sticking an iccci in there and let me know if that helps.

Ben

#18 lore raw
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 11 lines · Matt Mackall

My first suspicion was a dcache/icache coherency issue in copy_to_user_page, so I added flush_dcache_icache_page(page) here to no avail. On closer inspection, it looks like both icache and dcache are already being flushed by flush_icache_user_range().

Adding printk(".") (or any printk) in this function here fixes things (serial console at 115k), while printk("") and udelay(100) do not. Which still suggests an icache bug..?

Any suggestions?

I think you're hitting a known bug of 44x support. Those CPUs have a crazy virtually tagged icache and the kernel doesn't deal with it at all (pretty much...). We just are lucky things generally work :-)

Quoted 5 lines

That means among other things that flush_icache_* will not work because they kmap pages and use that mapping. The only way to flush icache user pages with 44x is to actually flush with the user virtual address (meaning you have to be in the current context, and you probably need to have a TLB entry there... yuck)... or just blow the whole icache away.

This is actually 405. Does that have the same issue?

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#19 lore raw
Quoted 2 lines

This is actually 405. Does that have the same issue?

hrm... I don't remember :-) There -is- something fishy about the icache on 405 but I don't remember for sure. Try sticking an iccci in there and tell us if that helps.

Ben.

#20 lore raw
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines

This is actually 405. Does that have the same issue?

hrm... I don't remember :-) There -is- something fishy about the icache on 405 but I don't remember for sure. Try sticking an iccci in there and tell us if that helps.

I did. I stuck an iccci -and- a dccci loop in. I threw in the tlbia when I ran out of other ideas. And the tlbia + existing flush_icache_range appears to be sufficient (tested on a non-trivial app).

According to my docs, the 405fx's icache is virtually indexed/physically mapped, while the dcache is phys/phys.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#21 lore raw
Quoted 11 lines · Matt Mackall
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 2 lines

This is actually 405. Does that have the same issue?

hrm... I don't remember :-) There -is- something fishy about the

icache

Quoted 1 line

on 405 but I don't remember for sure. Try sticking an iccci in there

and

Quoted 1 line

tell us if that helps.

Quoted 7 lines

I did. I stuck an iccci -and- a dccci loop in. I threw in the tlbia when I ran out of other ideas. And the tlbia + existing flush_icache_range appears to be sufficient (tested on a non-trivial app).

According to my docs, the 405fx's icache is virtually indexed/physically mapped, while the dcache is phys/phys.

I think there is a bug in the 40x/44x support at this stage, it only doing invalidations for the current PID. That means that a process trying to invalidate TLB entries of another address space will fail to do so ... oops.

That can be fixed by adding a pid argument to to _tlbie, and using it in the assembly. In the 40x case, probably by switching SPRN_PID to that and then back, in the 44x case, by using that value instead of SPRN_PID for the MMUCR register.

It's part of a patche I have around taking dirt that rework signficantly the 44x (though not the 40x yet) TLB handling, cleaning things and fixing bugs (such as this one, I remember it now). I need to spend a bit of time to clean it up, remove some experimental stuff from it, and submit it.

I'll try to do that early next week, and maybe come up with a fix for that specific bug today or tomorrow.

Ben.

#22 lore raw

[PATCH/RFC] powerpc: Pass PID argument to _tlbie (WAS: Apparent kernel bug with GDB on ppc405)

Allright, so Matt, let me know if that fixes your problem with gdb, and I'll clean the patch up a bit and submit it. I want to double check if something similar may be needed for freescale booke.

Basically, the problem is that things like get_user_pages() can cause COW operations which in turn call _tlbie() to be called for translations that aren't in the current address space.

The current 40x and 44x implementation of _tlbie doesn't handle that properly as it only invalidates entries in the current PID.

This is an attempt at fixing it. Untested, I just checked it builds for arch/powerpc and arch/ppc. I also haven't looked whether the freescale BookE _tlbie needs similar treatement (it will get passed the pid in r4 with that patch, so if it needs to do something with it, it can). Kumar, can you have a look ?

arch/powerpc/mm/fault.c +1 -1
Index: linux-work/arch/powerpc/mm/fault.c
===================================================================
@@ -309,7 +309,7 @@ good_area:
 					set_bit(PG_arch_1, &page->flags);
 				}
 				pte_update(ptep, 0, _PAGE_HWEXEC);
-				_tlbie(address);
+				_tlbie(address, mm->context.id);
 				pte_unmap_unlock(ptep, ptl);
 				up_read(&mm->mmap_sem);
 				return 0;
include/asm-powerpc/tlbflush.h +6 -6
Index: linux-work/include/asm-powerpc/tlbflush.h
===================================================================
@@ -1,5 +1,8 @@
 #ifndef _ASM_POWERPC_TLBFLUSH_H
 #define _ASM_POWERPC_TLBFLUSH_H
+
+#include <linux/mm.h>
+
 /*
  * TLB flushing:
  *
@@ -16,9 +19,6 @@
  */
 #ifdef __KERNEL__
 
-struct mm_struct;
-struct vm_area_struct;
-
 #if defined(CONFIG_4xx) || defined(CONFIG_8xx) || defined(CONFIG_FSL_BOOKE)
 /*
  * TLB flushing for software loaded TLB chips
@@ -28,7 +28,7 @@ struct vm_area_struct;
  * specific tlbie's
  */
 
-extern void _tlbie(unsigned long address);
+extern void _tlbie(unsigned long address, unsigned int pid);
 
 #if defined(CONFIG_40x) || defined(CONFIG_8xx)
 #define _tlbia()	asm volatile ("tlbia; sync" : : : "memory")
@@ -44,13 +44,13 @@ static inline void flush_tlb_mm(struct m
 static inline void flush_tlb_page(struct vm_area_struct *vma,
 				  unsigned long vmaddr)
 {
-	_tlbie(vmaddr);
+	_tlbie(vmaddr, vma->vm_mm->context.id);
 }
 
 static inline void flush_tlb_page_nohash(struct vm_area_struct *vma,
 					 unsigned long vmaddr)
 {
-	_tlbie(vmaddr);
+	_tlbie(vmaddr, vma->vm_mm->context.id);
 }
 
 static inline void flush_tlb_range(struct vm_area_struct *vma,
arch/powerpc/kernel/misc_32.S +16 -7
Index: linux-work/arch/powerpc/kernel/misc_32.S
===================================================================
@@ -288,7 +288,16 @@ _GLOBAL(_tlbia)
  */
 _GLOBAL(_tlbie)
 #if defined(CONFIG_40x)
+	/* We run the search with interrupts disabled because we have to change
+	 * the PID and I don't want to preempt when that happens.
+	 */
+	mfmsr	r5
+	mfspr	r6,SPRN_PID
+	wrteei	0
+	mtspr	SPRN_PID,r4
 	tlbsx.	r3, 0, r3
+	mtspr	SPRN_PID,r6
+	wrtee	r5
 	bne	10f
 	sync
 	/* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
@@ -297,23 +306,23 @@ _GLOBAL(_tlbie)
 	tlbwe	r3, r3, TLB_TAG
 	isync
 10:
+
 #elif defined(CONFIG_44x)
-	mfspr	r4,SPRN_MMUCR
-	mfspr	r5,SPRN_PID			/* Get PID */
-	rlwimi	r4,r5,0,24,31			/* Set TID */
+	mfspr	r5,SPRN_MMUCR
+	rlwimi	r5,r4,0,24,31			/* Set TID */
 
 	/* We have to run the search with interrupts disabled, even critical
 	 * and debug interrupts (in fact the only critical exceptions we have
 	 * are debug and machine check).  Otherwise  an interrupt which causes
 	 * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
-	mfmsr	r5
+	mfmsr	r4
 	lis	r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
 	addi	r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
-	andc	r6,r5,r6
+	andc	r6,r4,r6
 	mtmsr	r6
-	mtspr	SPRN_MMUCR,r4
+	mtspr	SPRN_MMUCR,r5
 	tlbsx.	r3, 0, r3
-	mtmsr	r5
+	mtmsr	r4
 	bne	10f
 	sync
 	/* There are only 64 TLB entries, so r3 < 64,
arch/powerpc/mm/mmu_decl.h +2 -2
Index: linux-work/arch/powerpc/mm/mmu_decl.h
===================================================================
@@ -61,12 +61,12 @@ extern unsigned long total_lowmem;
 #define mmu_mapin_ram()		(0UL)
 
 #elif defined(CONFIG_4xx)
-#define flush_HPTE(X, va, pg)	_tlbie(va)
+#define flush_HPTE(pid, va, pg)	_tlbie(va, pid)
 extern void MMU_init_hw(void);
 extern unsigned long mmu_mapin_ram(void);
 
 #elif defined(CONFIG_FSL_BOOKE)
-#define flush_HPTE(X, va, pg)	_tlbie(va)
+#define flush_HPTE(pid, va, pg)	_tlbie(va, pid)
 extern void MMU_init_hw(void);
 extern unsigned long mmu_mapin_ram(void);
 extern void adjust_total_lowmem(void);
arch/ppc/kernel/misc.S +15 -7
Index: linux-work/arch/ppc/kernel/misc.S
===================================================================
@@ -224,7 +224,16 @@ _GLOBAL(_tlbia)
  */
 _GLOBAL(_tlbie)
 #if defined(CONFIG_40x)
+	/* We run the search with interrupts disabled because we have to change
+	 * the PID and I don't want to preempt when that happens.
+	 */
+	mfmsr	r5
+	mfspr	r6,SPRN_PID
+	wrteei	0
+	mtspr	SPRN_PID,r4
 	tlbsx.	r3, 0, r3
+	mtspr	SPRN_PID,r6
+	wrtee	r5
 	bne	10f
 	sync
 	/* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
@@ -234,22 +243,21 @@ _GLOBAL(_tlbie)
 	isync
 10:
 #elif defined(CONFIG_44x)
-	mfspr	r4,SPRN_MMUCR
-	mfspr	r5,SPRN_PID			/* Get PID */
-	rlwimi	r4,r5,0,24,31			/* Set TID */
+	mfspr	r5,SPRN_MMUCR
+	rlwimi	r5,r4,0,24,31			/* Set TID */
 
 	/* We have to run the search with interrupts disabled, even critical
 	 * and debug interrupts (in fact the only critical exceptions we have
 	 * are debug and machine check).  Otherwise  an interrupt which causes
 	 * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
-	mfmsr	r5
+	mfmsr	r4
 	lis	r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
 	addi	r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
-	andc	r6,r5,r6
+	andc	r6,r4,r6
 	mtmsr	r6
-	mtspr	SPRN_MMUCR,r4
+	mtspr	SPRN_MMUCR,r5
 	tlbsx.	r3, 0, r3
-	mtmsr	r5
+	mtmsr	r4
 	bne	10f
 	sync
 	/* There are only 64 TLB entries, so r3 < 64,
arch/ppc/mm/fault.c +1 -1
Index: linux-work/arch/ppc/mm/fault.c
===================================================================
@@ -227,7 +227,7 @@ good_area:
 					set_bit(PG_arch_1, &page->flags);
 				}
 				pte_update(ptep, 0, _PAGE_HWEXEC);
-				_tlbie(address);
+				_tlbie(address, mm->context.id);
 				pte_unmap_unlock(ptep, ptl);
 				up_read(&mm->mmap_sem);
 				return 0;
arch/ppc/mm/mmu_decl.h +2 -2
Index: linux-work/arch/ppc/mm/mmu_decl.h
===================================================================
@@ -54,12 +54,12 @@ extern unsigned int num_tlbcam_entries;
 #define mmu_mapin_ram()		(0UL)
 
 #elif defined(CONFIG_4xx)
-#define flush_HPTE(X, va, pg)	_tlbie(va)
+#define flush_HPTE(pid, va, pg)	_tlbie(va, pid)
 extern void MMU_init_hw(void);
 extern unsigned long mmu_mapin_ram(void);
 
 #elif defined(CONFIG_FSL_BOOKE)
-#define flush_HPTE(X, va, pg)	_tlbie(va)
+#define flush_HPTE(pid, va, pg)	_tlbie(va, pid)
 extern void MMU_init_hw(void);
 extern unsigned long mmu_mapin_ram(void);
 extern void adjust_total_lowmem(void);
arch/ppc/platforms/4xx/ebony.c +1 -1
Index: linux-work/arch/ppc/platforms/4xx/ebony.c
===================================================================
@@ -236,7 +236,7 @@ ebony_early_serial_map(void)
 	gen550_init(0, &port);
 
 	/* Purge TLB entry added in head_44x.S for early serial access */
-	_tlbie(UART0_IO_BASE);
+	_tlbie(UART0_IO_BASE, 0);
 #endif
 
 	port.membase = ioremap64(PPC440GP_UART1_ADDR, 8);
arch/ppc/platforms/4xx/ocotea.c +1 -1
Index: linux-work/arch/ppc/platforms/4xx/ocotea.c
===================================================================
@@ -259,7 +259,7 @@ ocotea_early_serial_map(void)
 	gen550_init(0, &port);
 
 	/* Purge TLB entry added in head_44x.S for early serial access */
-	_tlbie(UART0_IO_BASE);
+	_tlbie(UART0_IO_BASE, 0);
 #endif
 
 	port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
arch/ppc/platforms/4xx/taishan.c +1 -1
Index: linux-work/arch/ppc/platforms/4xx/taishan.c
===================================================================
@@ -316,7 +316,7 @@ taishan_early_serial_map(void)
 	gen550_init(0, &port);
 
 	/* Purge TLB entry added in head_44x.S for early serial access */
-	_tlbie(UART0_IO_BASE);
+	_tlbie(UART0_IO_BASE, 0);
 #endif
 
 	port.membase = ioremap64(PPC440GX_UART1_ADDR, 8);
#23 lore raw

Re: [PATCH/RFC] powerpc: Pass PID argument to _tlbie (WAS: Apparent kernel bug with GDB on ppc405)

Quoted 8 lines · On Sat, 27 Oct 2007 17:32:02 +1000 Benjamin Herrenschmidt…

Allright, so Matt, let me know if that fixes your problem with gdb, and I'll clean the patch up a bit and submit it. I want to double check if something similar may be needed for freescale booke.

Basically, the problem is that things like get_user_pages() can cause COW operations which in turn call _tlbie() to be called for translations that aren't in the current address space.

Quoted 8 lines

The current 40x and 44x implementation of _tlbie doesn't handle that properly as it only invalidates entries in the current PID.

This is an attempt at fixing it. Untested, I just checked it builds for arch/powerpc and arch/ppc. I also haven't looked whether the freescale BookE _tlbie needs similar treatement (it will get passed the pid in r4 with that patch, so if it needs to do something with it, it can). Kumar, can you have a look ?

This looks pretty good at first glance. I'll try to test it out today, but I'd still like to hear if it solves Matt's problem as I doubt I'll be able to duplicate it.

josh

#24 lore raw

Re: [PATCH/RFC] powerpc: Pass PID argument to _tlbie (WAS: Apparent kernel bug with GDB on ppc405)

Quoted 20 lines · On Mon, 29 Oct 2007 07:08:24 -0500 Josh Boyer <[email protected]>…
Quoted 8 lines · On Sat, 27 Oct 2007 17:32:02 +1000 Benjamin Herrenschmidt…

Allright, so Matt, let me know if that fixes your problem with gdb, and I'll clean the patch up a bit and submit it. I want to double check if something similar may be needed for freescale booke.

Basically, the problem is that things like get_user_pages() can cause COW operations which in turn call _tlbie() to be called for translations that aren't in the current address space.

Quoted 8 lines

The current 40x and 44x implementation of _tlbie doesn't handle that properly as it only invalidates entries in the current PID.

This is an attempt at fixing it. Untested, I just checked it builds for arch/powerpc and arch/ppc. I also haven't looked whether the freescale BookE _tlbie needs similar treatement (it will get passed the pid in r4 with that patch, so if it needs to do something with it, it can). Kumar, can you have a look ?

Quoted 3 lines

This looks pretty good at first glance. I'll try to test it out today, but I'd still like to hear if it solves Matt's problem as I doubt I'll be able to duplicate it.

Did a boot test on my ebony board with this patch included. It seems to be happy about things so far. If Matt gets around to trying this out and it works, we should probably look at getting this into 2.6.24.

Oh, and I'd need a signed-off-by for it Ben :)

josh

#25 lore raw

Re: [PATCH/RFC] powerpc: Pass PID argument to _tlbie (WAS: Apparent kernel bug with GDB on ppc405)

Quoted 6 lines

Did a boot test on my ebony board with this patch included. It seems to be happy about things so far. If Matt gets around to trying this out and it works, we should probably look at getting this into 2.6.24.

Oh, and I'd need a signed-off-by for it Ben :)

Sure, I'll send you a cleaned up version (the version I posted for test breaks 64 bits builds :-)

But I'm also waiting for Matt to test first.

Cheers,
Ben.

author Tested-by
#26 lore raw

Re: [PATCH/RFC] powerpc: Pass PID argument to _tlbie (WAS: Apparent kernel bug with GDB on ppc405)

[adding back gdb list]

Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines

Did a boot test on my ebony board with this patch included. It seems to be happy about things so far. If Matt gets around to trying this out and it works, we should probably look at getting this into 2.6.24.

Oh, and I'd need a signed-off-by for it Ben :)

Sure, I'll send you a cleaned up version (the version I posted for test breaks 64 bits builds :-)

But I'm also waiting for Matt to test first.

Ok, just backported the 405 bits of this to my client's sad sad MV 2.6.10 kernel and it appears to work fine. Only tricky bit was context.id -> context. So:

And here's my backported patch, just for reference:

arch/ppc/kernel/misc.S +6 -0
Index: k/arch/ppc/kernel/misc.S
===================================================================
@@ -496,7 +496,13 @@ _GLOBAL(_tlbia)
  */
 _GLOBAL(_tlbie)
 #if defined(CONFIG_40x)
+	mfmsr	r5
+	mfspr	r6,SPRN_PID
+	wrteei	0
+	mtspr	SPRN_PID,r4
 	tlbsx.	r3, 0, r3
+	mtspr	SPRN_PID,r6
+	wrtee	r5
 	bne	10f
 	sync
 	/* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
arch/ppc/mm/fault.c +1 -1
Index: k/arch/ppc/mm/fault.c
===================================================================
@@ -234,7 +234,7 @@ good_area:
 				set_bit(PG_arch_1, &page->flags);
 			}
 			pte_update(ptep, 0, _PAGE_HWEXEC);
-			_tlbie(address);
+			_tlbie(address, mm->context);
 			pte_unmap(ptep);
 			up_read(&mm->mmap_sem);
 			ltt_ev_trap_exit();
arch/ppc/mm/mmu_decl.h +1 -1
Index: k/arch/ppc/mm/mmu_decl.h
===================================================================
@@ -54,7 +54,7 @@ extern unsigned int num_tlbcam_entries;
 #define mmu_mapin_ram()		(0UL)
 
 #elif defined(CONFIG_4xx)
-#define flush_HPTE(X, va, pg)	_tlbie(va)
+#define flush_HPTE(pid, va, pg)	_tlbie(va, pid)
 extern void MMU_init_hw(void);
 extern unsigned long mmu_mapin_ram(void);
 
include/asm-ppc/tlbflush.h +3 -3
Index: k/include/asm-ppc/tlbflush.h
===================================================================
@@ -13,7 +13,7 @@
 #include <linux/config.h>
 #include <linux/mm.h>
 
-extern void _tlbie(unsigned long address);
+extern void _tlbie(unsigned long address, unsigned int pid);
 extern void _tlbia(void);
 
 #if defined(CONFIG_4xx)
@@ -28,10 +28,10 @@ static inline void flush_tlb_mm(struct m
 	{ __tlbia(); }
 static inline void flush_tlb_page(struct vm_area_struct *vma,
 				unsigned long vmaddr)
-	{ _tlbie(vmaddr); }
+	{ _tlbie(vmaddr, vma->vm_mm->context); }
 static inline void flush_tlb_page_nohash(struct vm_area_struct *vma,
 					 unsigned long vmaddr)
-	{ _tlbie(vmaddr); }
+	{ _tlbie(vmaddr, vma->vm_mm->context); }
 static inline void flush_tlb_range(struct vm_area_struct *vma,
 				unsigned long start, unsigned long end)
 	{ __tlbia(); }
Signature · 1 line
Mathematics is the supreme nostalgia of our time.