fix SMP TLB optimisations
Quoted 3 lines · James Bottomley
Since we're now changing the %sr3 from an IPI, we have to be careful about other places in the kernel where we're using temporary values in % sr3.
Isn't sr3 part of the context?
ie if we need to change the sr3 for a given context shouldn't the code be modifying the value in the struct context instead the actual register unless we know we are in that context? The IPI code should know the sr3 was saved and where.
The change to assembly.h has me very nervous since I don't understand it. You probably have it right and I'm being a bit dense.
I was trying to track down other uses of "mtsp sr3" and schedule() seems to be one:
schedule() -> context_switch() -> switch_mm() -> load_context()
I'm not seeing where this path disables local interrupts. Sounds like it should before calling load_context() or we should in our switch_mm() or add a prepare_arch_switch() to asm-parisc/system.h.
Quoted 2 lines
As far as I can tell, this is pretty much only non local cache
flushing.
ISTR copy and one or two other places use sr3 as well.
Quoted 5 lines
The following patch fixes the IPI to work (by not saving %sr3 across an interruption) and patches up temporary %sr3 usage.
The sharp eyed will also notice I've corrected a Protection ID bug with the non current flushes.
That's not me :)
Was the fix to place "pgd = mfctl(25)" after the local_irq_disable()?
thanks,
grant
Quoted 70 lines
Signed-off-by James Bottomley <[email protected]>arch/parisc/kernel/cache.c +11
-8@@ -303,25 +303,28 @@ flush_user_cache_page_non_current(struct vm_area_struct *vma, unsigned long vmaddr) {/* save the current process space and pgd */ -unsigned long space =mfsp (3 ), pgd =mfctl (25 ); +unsigned long space, pgd; -/* we don't mind taking interrups since they may not -* do anything with user space, but we can't -* be preempted here */ -preempt_disable (); +/* Have to disable interrupts here, since now %sr3 changes +* are carried by IPI and we can't have that happen while +* we're using a temporary %sr3 */ +local_irq_disable (); + + space =mfsp (3 ); + pgd =mfctl (25 );/* make us current */ mtctl (__pa (vma->vm_mm->pgd),25 ); -mtsp (vma->vm_mm->context,3 ); +load_context (vma->vm_mm->context);flush_user_dcache_page (vmaddr);if (vma->vm_flags &VM_EXEC )flush_user_icache_page (vmaddr);/* put the old current process back */ -mtsp (space,3 ); +load_context (space);mtctl (pgd,25 ); -preempt_enable (); +local_irq_enable (); }include/asm-parisc/assembly.h +4
-2@@ -435,7 +435,8 @@ SAVE_SP (%sr0, PT_SR0 (\regs)) SAVE_SP (%sr1, PT_SR1 (\regs)) SAVE_SP (%sr2, PT_SR2 (\regs)) - SAVE_SP (%sr3, PT_SR3 (\regs)) +; Can't save and restore %sr3, it may be update from IPI +; SAVE_SP (%sr3, PT_SR3 (\regs)) SAVE_SP (%sr4, PT_SR4 (\regs)) SAVE_SP (%sr5, PT_SR5 (\regs)) SAVE_SP (%sr6, PT_SR6 (\regs))@@ -475,7 +476,8 @@ REST_SP (%sr0, PT_SR0 (\regs)) REST_SP (%sr1, PT_SR1 (\regs)) REST_SP (%sr2, PT_SR2 (\regs)) - REST_SP (%sr3, PT_SR3 (\regs)) +; Can't save and restore %sr3, it may be updated from IPI +; REST_SP (%sr3, PT_SR3 (\regs)) REST_SP (%sr4, PT_SR4 (\regs)) REST_SP (%sr5, PT_SR5 (\regs)) REST_SP (%sr6, PT_SR6 (\regs))
Quoted 4 lines
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
Quoted 1 line · Grant Grundler
Isn't sr3 part of the context?
It is the user context above the kernel, yes.
Quoted 2 lines
ie if we need to change the sr3 for a given context shouldn't the code be modifying the value in the struct context instead
That's what tausq's change does. It updates active_mm->context but then it has to propagate the change on an SMP system, which is what the IPI is supposed to do.
Quoted 1 line
the actual register unless we know we are in that context?
That's why the IPI checks current->active_mm against the mm being changed. If the CPU isn't executing in that context, nothing happens. If it has, since we just changed mm->context, the new context gets loaded into sr3, as it should be.
Quoted 1 line
The IPI code should know the sr3 was saved and where.
It does: in mm->context.
Quoted 2 lines
The change to
assembly.hhas me very nervous since I don't understand it. You probably have it right and I'm being a bit dense.
Actually, I think it's pointless saving any space register for an interrupt ... no interrupt should muck with the space registers since no interrupt should ever be mucking with anything in user context ... However, sr3 is special ... even if we get interrupts mucking with space registers, they'll never touch sr3.
Quoted 5 lines
I was trying to track down other uses of "mtsp sr3" and
schedule()seems to be one:schedule() -> context_switch() -> switch_mm() -> load_context()I'm not seeing where this path disables local interrupts.
It doesn't need to. The IPI either updates sr3 or it doesn't. The load_context() will actually update it anyway, and sr3 isn't used until the kernel accesses userspace, which is nowhere in that sequence, so it's all quite safe.
Quoted 2 lines
Sounds like it should before calling
load_context()or we should in ourswitch_mm()or add aprepare_arch_switch()toasm-parisc/system.h.
Not really ... like I said, the IPI's effect will be known even if we're beginning a context switch.
Quoted 4 lines
Quoted 2 lines
As far as I can tell, this is pretty much only non local cache
flushing.ISTR copy and one or two other places use sr3 as well.
No, pa_memcpy uses sr1 and sr2 ... it's only the non-local flushing that uses sr3.
Quoted 8 lines
Quoted 5 lines
The following patch fixes the IPI to work (by not saving %sr3 across an interruption) and patches up temporary %sr3 usage.
The sharp eyed will also notice I've corrected a Protection ID bug with the non current flushes.
That's not me :)
Was the fix to place "pgd = mfctl(25)" after thelocal_irq_disable()?
No, it was changing the mtsp(xx, 3) to load_context(xx). The problem is that if we don't update %cr8 then the new context in sr3 is completely ineffective since the protection IDs will mismatch in the TLBs, so, as far as I can tell, the non local flush was never effective.
James
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
Make sure we alter the context on the local CPU, but all possible uses of the deprecated space on the other cpus.
The sharp eyed will also notice I've corrected a Protection ID bug with the non current flushes.
---
Here's take II. It corrects the problem with the prior one not being agressive enough .. plus sr3 is the wrong register to alter from userspace ... we really need to do sr4-7.
James
arch/parisc/kernel/cache.c +44 -8
@@ -18,6 +18,8 @@#include <linux/module.h> #include <linux/seq_file.h> #include <linux/pagemap.h> +#include <linux/interrupt.h> +#include <linux/irq.h> #include <asm/pdc.h> #include <asm/cache.h>
@@ -303,25 +305,28 @@ flush_user_cache_page_non_current(struct vm_area_struct *vma, unsigned long vmaddr) {/* save the current process space and pgd */ -unsigned long space =mfsp (3 ), pgd =mfctl (25 ); +unsigned long space, pgd; -/* we don't mind taking interrups since they may not -* do anything with user space, but we can't -* be preempted here */ -preempt_disable (); +/* Have to disable interrupts here, since now %sr3 changes +* are carried by IPI and we can't have that happen while +* we're using a temporary %sr3 */ +local_irq_disable (); + + space =mfsp (3 ); + pgd =mfctl (25 );/* make us current */ mtctl (__pa (vma->vm_mm->pgd),25 ); -mtsp (vma->vm_mm->context,3 ); +load_context (vma->vm_mm->context);flush_user_dcache_page (vmaddr);if (vma->vm_flags &VM_EXEC )flush_user_icache_page (vmaddr);/* put the old current process back */ -mtsp (space,3 ); +load_context (space);mtctl (pgd,25 ); -preempt_enable (); +local_irq_enable (); }
@@ -574,3 +579,34 @@ flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long__flush_cache_page (vma, vmaddr); } + +void __flush_tlb_mm (void *mmv) +{ +struct mm_struct *mm = (struct mm_struct *)mmv; +struct pt_regs *regs =get_irq_regs (); +unsigned long sr3; +int i; + +if (mm != current->active_mm) +return ; + +/* sr3 is alterable by the user, so if we trapped from +* user space, check sr7 instead */ +if (in_interrupt ()) { +if (regs->sr[7 ] !=0 ) + sr3 = regs->sr[7 ]; +else + sr3 =mfsp (3 ); +/* needed to set up protection ID */ +load_context (mm->context); + }else { +/* on_each_cpu makes one non interrupt call, +* this is it */ +load_context (mm->context); +return ; + } + +for (i =0 ; i <8 ; i++) +if (regs->sr[i] == sr3) + regs->sr[i] = mm->context; +}
include/asm-parisc/assembly.h +0 -0
include/asm-parisc/tlbflush.h +1 -6
@@ -39,12 +39,7 @@ extern void flush_tlb_all_local(void *);* etc. do not do that). */ -static inline void __flush_tlb_mm (void *mmv) -{ -struct mm_struct *mm = (struct mm_struct *)mmv; -if (mm == current->active_mm) -load_context (mm->context); -} +void __flush_tlb_mm (void *mmv);static inline void flush_tlb_mm (struct mm_struct *mm) {
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux