Fix small race in 44x tlbie function
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx., then clobbering the relevant entry, if any. Unfortunately the PID for the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in _tlbie(), so an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.
This patch fixes the problem in both arch/ppc and arch/powerpc by inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
---
Paul, this one's a bugfix, which I think should go into 2.6.23.
arch/powerpc/kernel/misc_32.S +11 -1
@@ -301,9 +301,19 @@ _GLOBAL(_tlbie) mfspr r4,SPRN_MMUCR mfspr r5,SPRN_PID /* Get PID */ rlwimi r4,r5,0,24,31 /* Set TID */ - mtspr SPRN_MMUCR,r4 + /* 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 + 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 + mtmsr r6 + mtspr SPRN_MMUCR,r4 tlbsx. r3, 0, r3 + mtmsr r5 bne 10f sync /* There are only 64 TLB entries, so r3 < 64,
arch/ppc/kernel/misc.S +11 -1
@@ -237,9 +237,19 @@ _GLOBAL(_tlbie) mfspr r4,SPRN_MMUCR mfspr r5,SPRN_PID /* Get PID */ rlwimi r4,r5,0,24,31 /* Set TID */ - mtspr SPRN_MMUCR,r4 + /* 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 + 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 + mtmsr r6 + mtspr SPRN_MMUCR,r4 tlbsx. r3, 0, r3 + mtmsr r5 bne 10f sync /* There are only 64 TLB entries, so r3 < 64,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Josh Boyer
Acked-byQuoted 9 lines · On Tue, 7 Aug 2007 14:20:50 +1000 David Gibson <[email protected]>…
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx., then clobbering the relevant entry, if any. Unfortunately the PID for the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in
_tlbie(), so an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.
Quoted 5 lines
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.Signed-off-by David Gibson <[email protected]>
And I agree this should go into 2.6.23.
josh
Quoted 9 lines · David Gibson
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx., then clobbering the relevant entry, if any. Unfortunately the PID for the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in
_tlbie(), so an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.
Quoted 7 lines
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.Signed-off-by David Gibson <[email protected]>---
Paul, this one's a bugfix, which I think should go into 2.6.23.
Did you actually see this happen?
- k
Quoted 16 lines · On Wed, 8 Aug 2007 10:20:45 -0500 Kumar Gala <[email protected]> wrote:
Quoted 13 lines · David Gibson
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx., then clobbering the relevant entry, if any. Unfortunately the PID for the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in
_tlbie(), so an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
Quoted 5 lines
Quoted 3 lines
Signed-off-by David Gibson <[email protected]>---
Paul, this one's a bugfix, which I think should go into 2.6.23.Did you actually see this happen?
Yes.
josh
Quoted 19 lines · Josh Boyer
Quoted 16 lines · On Wed, 8 Aug 2007 10:20:45 -0500 Kumar Gala <[email protected]> wrote:
Quoted 13 lines · David Gibson
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx., then clobbering the relevant entry, if any. Unfortunately the PID for the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in
_tlbie(), so an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Signed-off-by David Gibson <[email protected]>---
Paul, this one's a bugfix, which I think should go into 2.6.23.Did you actually see this happen?
Yes.
When?
We don't have critical wired to anything, I don't expect watchdog to cause another fault.. so just wondering.
- k
Quoted 30 lines · Kumar Gala
Quoted 27 lines · Josh Boyer
Quoted 24 lines · On Wed, 8 Aug 2007 10:20:45 -0500 Kumar Gala <[email protected]> wrote:
Quoted 20 lines · David Gibson
The 440 family of processors don't have a tlbie instruction. So, we implement TLB invalidates by explicitly searching the TLB with tlbsx.,
then clobbering the relevant entry, if any. Unfortunately the PID for
the search needs to be stored in the MMUCR register, which is also used by the TLB miss handler. Interrupts were enabled in_tlbie(), so
an interrupt between loading the MMUCR and the tlbsx could cause incorrect search results, and thus a failure to invalide TLB entries which needed to be invalidated.This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the
relevant instructions.Signed-off-by David Gibson <[email protected]>---
Paul, this one's a bugfix, which I think should go into 2.6.23.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Did you actually see this happen?
Yes.
When?
We don't have critical wired to anything, I don't expect watchdog to cause another fault.. so just wondering.
On debug (trace) interrupts on blue gene.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Did you actually see this happen?
Yes.
When?
We don't have critical wired to anything, I don't expect watchdog to cause another fault.. so just wondering.
On debug (trace) interrupts on blue gene.
Do you know why the debug code caused a fault?
- k
Quoted 4 lines · Kumar Gala
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Did you actually see this happen?
Yes.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
When?
We don't have critical wired to anything, I don't expect watchdog to cause another fault.. so just wondering.
On debug (trace) interrupts on blue gene.
Do you know why the debug code caused a fault?
Sure, it may access vmalloc space for example, which can cause a TLB miss...
Ben.
Quoted 5 lines · Kumar Gala
Quoted 3 lines
Quoted 1 line
Did you actually see this happen?
Yes.
When?
During some bluegene debug.
Quoted 2 lines
We don't have critical wired to anything, I don't expect watchdog to cause another fault.. so just wondering.
We being who? I'm slightly confused here.
josh
Quoted 6 lines · Josh Boyer
Quoted 2 lines
We don't have critical wired to anything, I don't expect watchdog
to
Quoted 1 line
cause another fault.. so just wondering.
We being who? I'm slightly confused here.
I think Kumar doesn't know that we are talking about the BG kernel which has more things "wired" to CRIT than what is upstream at the moment :-)
Ben.
Quoted 11 lines · On Thu, 09 Aug 2007 23:05:36 +1000 Benjamin Herrenschmidt…
Quoted 6 lines · Josh Boyer
Quoted 2 lines
We don't have critical wired to anything, I don't expect watchdog
to
Quoted 1 line
cause another fault.. so just wondering.
We being who? I'm slightly confused here.
I think Kumar doesn't know that we are talking about the BG kernel which has more things "wired" to CRIT than what is upstream at the moment :-)
Ah, sure. But even though we don't have much upstream that uses CE, that doesn't mean someone can't reprogram the UICs on their boards to use CE for some things, for example. I know of at least one project that has done that in the past.
josh
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
How could a critical or debug interrupt modify the contents of MMUCR?
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 7 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.How could a critical or debug interrupt modify the contents of MMUCR?
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
CE and DE are admittedly a much smaller race, but still possible. Masking EE off is the largest one.
josh
Quoted 9 lines · Josh Boyer
Quoted 6 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
Quoted 5 lines
Quoted 1 line
How could a critical or debug interrupt modify the contents of MMUCR?
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
By "causes a tlb miss", you mean the interrupt handler associated with the critical-priority UIC interrupt performs MMIO which causes a TLB miss? Regular code couldn't cause a TLB miss AFAICS, since the kernel is always mapped, and an interrupt handler doesn't access userspace.
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 12 lines · Hollis Blanchard
Quoted 11 lines · Josh Boyer
Quoted 7 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.How could a critical or debug interrupt modify the contents of MMUCR?
Quoted 8 lines
Quoted 3 lines
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
By "causes a tlb miss", you mean the interrupt handler associated with the critical-priority UIC interrupt performs MMIO which causes a TLB miss? Regular code couldn't cause a TLB miss AFAICS, since the kernel is always mapped, and an interrupt handler doesn't access userspace.
Yes.
josh
Quoted 12 lines · Hollis Blanchard
Quoted 11 lines · Josh Boyer
Quoted 7 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.How could a critical or debug interrupt modify the contents of MMUCR?
Quoted 8 lines
Quoted 3 lines
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
By "causes a tlb miss", you mean the interrupt handler associated with the critical-priority UIC interrupt performs MMIO which causes a TLB miss? Regular code couldn't cause a TLB miss AFAICS, since the kernel is always mapped, and an interrupt handler doesn't access userspace.
ioremap is an example, vmalloc space is another...
Ben.
Quoted 9 lines · Josh Boyer
Quoted 6 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.
Quoted 8 lines
Quoted 1 line
How could a critical or debug interrupt modify the contents of MMUCR?
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
CE and DE are admittedly a much smaller race, but still possible. Masking EE off is the largest one.
There is a much bigger problem if CEs can do tlb misses though... they can interrupt the tlb miss handler itself, either between the two halves of a tlb write, or between the write to MMUCR and the write to the tlb, and I suspect both cases will cause trouble.
We might want to check if we were in the TLB miss handler upon return from the CE and MCE handlers, and in this case, restart them (just return to the faulting instruction, that is use srr0 instead of csrr0/mcsrr0).
Ben.
Quoted 16 lines · Benjamin Herrenschmidt
Quoted 15 lines · Josh Boyer
Quoted 7 lines · On Wed, 8 Aug 2007 20:43:25 +0000 (UTC) Hollis Blanchard <[email protected]>…
Quoted 4 lines · David Gibson
This patch fixes the problem in both
arch/ppcandarch/powerpcby inhibiting interrupts (even critical and debug interrupts) across the relevant instructions.How could a critical or debug interrupt modify the contents of MMUCR?
Interrupts from UICs can be configured as critical. If one of those triggers, (or any other CE triggers) and causes a tlb miss, you have a race. The watchdog timer interrupt also is a CE IIRC.
Quoted 7 lines
Quoted 2 lines
CE and DE are admittedly a much smaller race, but still possible. Masking EE off is the largest one.
There is a much bigger problem if CEs can do tlb misses though... they can interrupt the tlb miss handler itself, either between the two halves of a tlb write, or between the write to MMUCR and the write to the tlb, and I suspect both cases will cause trouble.
Yes.
Quoted 4 lines
We might want to check if we were in the TLB miss handler upon return from the CE and MCE handlers, and in this case, restart them (just return to the faulting instruction, that is use srr0 instead of csrr0/mcsrr0).
Something should be looked at, yeah.
josh