* What protects cpu_tlbstate?
@ 2007-04-05 19:44 Jeremy Fitzhardinge
2007-04-05 20:28 ` Andi Kleen
0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2007-04-05 19:44 UTC (permalink / raw)
To: Benjamin LaHaise, Andi Kleen, Ingo Molnar; +Cc: Linux Kernel Mailing List
Hi,
What protects the cpu_tlbstate? I see in i386/kernel/smp.c that its
always used in a non-preemptable area, but what prevents races with
interrupts? For example, what prevents leave_mm() called via the
flush_tlb_all IPI from racing with, say, enter_lazy_tlb? Couldn't a
race leave cpu_tlbstate in an inconsistent state?
Or does it simply not matter? But if that were true, it seems to me
that there should be at least some barriers or something to make sure
the final state is consistent.
Thanks,
J
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: What protects cpu_tlbstate?
2007-04-05 19:44 What protects cpu_tlbstate? Jeremy Fitzhardinge
@ 2007-04-05 20:28 ` Andi Kleen
2007-04-05 21:00 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2007-04-05 20:28 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Benjamin LaHaise, Ingo Molnar, Linux Kernel Mailing List
On Thursday 05 April 2007 21:44:10 Jeremy Fitzhardinge wrote:
> Hi,
>
> What protects the cpu_tlbstate? I see in i386/kernel/smp.c that its
> always used in a non-preemptable area, but what prevents races with
> interrupts? For example, what prevents leave_mm() called via the
> flush_tlb_all IPI from racing with, say, enter_lazy_tlb? Couldn't a
> race leave cpu_tlbstate in an inconsistent state?
>
> Or does it simply not matter? But if that were true, it seems to me
> that there should be at least some barriers or something to make sure
> the final state is consistent.
The interrupts can only happen when the other CPU is already lazy
and enter_lazy_tlb would be a nop then. The flushers itself are
synchronized by the page_table_lock or the mm semaphore.
Against switch_mm it tries to protect with ordering.
wmb()s are not needed on x86 (ok minus errata on ppro and
VIA magic mode but which is UP only). That would leave some rmb()s,
but I don't see any place they would be needed.
-Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What protects cpu_tlbstate?
2007-04-05 20:28 ` Andi Kleen
@ 2007-04-05 21:00 ` Jeremy Fitzhardinge
2007-04-05 21:03 ` Andi Kleen
0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2007-04-05 21:00 UTC (permalink / raw)
To: Andi Kleen; +Cc: Benjamin LaHaise, Ingo Molnar, Linux Kernel Mailing List
Andi Kleen wrote:
> The interrupts can only happen when the other CPU is already lazy
> and enter_lazy_tlb would be a nop then. The flushers itself are
> synchronized by the page_table_lock or the mm semaphore.
>
> Against switch_mm it tries to protect with ordering.
>
> wmb()s are not needed on x86 (ok minus errata on ppro and
> VIA magic mode but which is UP only). That would leave some rmb()s,
> but I don't see any place they would be needed.
>
Hm, I was more wondering about simple compiler reordering. Does the
relative order of setting and reading cpu_tlbstate.state, active_mm and
the mm->cpu_vm_mask matter?
J
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: What protects cpu_tlbstate?
2007-04-05 21:00 ` Jeremy Fitzhardinge
@ 2007-04-05 21:03 ` Andi Kleen
2007-04-05 21:08 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2007-04-05 21:03 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Benjamin LaHaise, Ingo Molnar, Linux Kernel Mailing List
On Thursday 05 April 2007 23:00:22 Jeremy Fitzhardinge wrote:
> Andi Kleen wrote:
> > The interrupts can only happen when the other CPU is already lazy
> > and enter_lazy_tlb would be a nop then. The flushers itself are
> > synchronized by the page_table_lock or the mm semaphore.
> >
> > Against switch_mm it tries to protect with ordering.
> >
> > wmb()s are not needed on x86 (ok minus errata on ppro and
> > VIA magic mode but which is UP only). That would leave some rmb()s,
> > but I don't see any place they would be needed.
> >
>
> Hm, I was more wondering about simple compiler reordering. Does the
> relative order of setting and reading cpu_tlbstate.state, active_mm and
> the mm->cpu_vm_mask matter?
Hmm, perhaps a barrier between state and active_mm might be a good idea.
Setting active_mm after state might be problematic.
cpu_vm_mask should be already a memory barrier.
-Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What protects cpu_tlbstate?
2007-04-05 21:03 ` Andi Kleen
@ 2007-04-05 21:08 ` Jeremy Fitzhardinge
0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Fitzhardinge @ 2007-04-05 21:08 UTC (permalink / raw)
To: Andi Kleen; +Cc: Benjamin LaHaise, Ingo Molnar, Linux Kernel Mailing List
Andi Kleen wrote:
>> Hm, I was more wondering about simple compiler reordering. Does the
>> relative order of setting and reading cpu_tlbstate.state, active_mm and
>> the mm->cpu_vm_mask matter?
>>
>
> Hmm, perhaps a barrier between state and active_mm might be a good idea.
> Setting active_mm after state might be problematic.
> cpu_vm_mask should be already a memory barrier.
>
Should leave_mm update active_mm and set the state to TLBSTATE_OK? Just
reloading cr3 seems a bit blunt.
J
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-05 21:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-05 19:44 What protects cpu_tlbstate? Jeremy Fitzhardinge
2007-04-05 20:28 ` Andi Kleen
2007-04-05 21:00 ` Jeremy Fitzhardinge
2007-04-05 21:03 ` Andi Kleen
2007-04-05 21:08 ` Jeremy Fitzhardinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox