From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: "Dong, Eddie" <eddie.dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: Remove APIC lock
Date: Sat, 25 Aug 2007 18:54:19 +0300 [thread overview]
Message-ID: <46D050AB.2000900@qumranet.com> (raw)
In-Reply-To: <10EA09EFD8728347A513008B6B0DA77A01F8464D-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
Dong, Eddie wrote:
> Avi Kivity wrote:
>
>> Dong, Eddie wrote:
>>
>>>> What about preemption:
>>>>
>>>> - vcpu executes lapic code in qemu process context
>>>>
>>>>
>>> Don't understand. LAPIC is in kernel, how can qemu access?
>>> If you mean qemu is calling APIC KVM syscall, then it already
>>> disabled preemption & take kvm->lock.
>>>
>>>
>>>
>>>
>> I meant qemu executes the KVM_VCPU_RUN ioctl. kvm->lock does not
>> disable preemption (it is a mutex).
>>
>
> Just noticed it is changed to mutex, but seems same here :-)
> If the process is switched to other task, it is OK since it won't access
> local
> APIC. Current VP access to APIC will take the mutex first (see below).
> Or you are talking other corner case?
>
>
apic access from process context is protected by kvm->lock, but apic
access from hrtimer is not. Consider this scenario:
- guest accesses apic
- apic code starts modifying apic data
<preemption>
- timer fires
- apic_timer_fn() corrupts apic data
(I'm not even sure preemption is required here)
I think that in Xen this can't happen because is is not preemptible and
timers are processed when exiting back to the guest.
>> Do we really take kvm->lock for local accesses? That's a significant
>> problem, much more than the timer.
>>
>
> Today all APIC/IOAPIC access comes from shadow page fault which already
> take kvm->lock. KVM_IRQ_LINE will take too. (just noticed the
> save/restore part
> missed this one, will add later if we agree here). PIC access comes from
> kernel_pio which takes the mutex too.
>
> Another missing place is vmx_intr_assist which needs to take the mutex
> too.
> Will add later.
>
>
The apic can be protected by vcpu->mutex, platform-wide things (pic,
ioapic) should be protected by kvm->lock. This will work if we move all
apic processing to process context like I proposed in a previous mail.
>> I meant in addition to timer migration (I really like the timer
>> migration part -- it's much more important than lock removal for
>> performance). kvm_vcpu_kick() is needed to wake up from halt, or if we
>> have races between the timer and task migration.
>>
>
> :-) Actually we have solved this issue in previous patch and this one
> naturally.
> In adding back APIC timer IRQ patch, we will wakeup the halt vCPU.
>
> In this patch since hrtimer always run in same pCPU with guest VP
> (when VP is active), each time when hrtime fires (comes from a hardware
> IRQ),
> it already VM Exit to kernel (similar function with kvm_vcpu_kick but
> no need to explicitly call it) and then we do IRQ injection at
> vmx_intr_assist time.
>
Yes, the two solutions are very similar. But I think mine protects
against a race:
- scheduler starts migrating vcpu from cpu 0 to cpu 1
- hrtimer fires on cpu 0, but apic_timer_fn not called yet
- vcpu on cpu 1 migrates the hrtimer
- vcpu enters guest mode on cpu 1
- cpu 0 calls apic_timer_fn
In this case, there will be no wakeup. So I think you do need to call
kvm_vcpu_kick() which will usually do nothing.
We also need to make sure all the non atomic code in __apic_timer_fn()
is executed in process context (it can use the pending count to decide
how much to add).
So I think there are three separate issues here:
- hrtimer migration: it helps performance, but doesn't help locking
- changing __apic_timer_fn() to only do atomic operations, and do the
nonatomic operations in process context under vcpu->mutex
- remove the apic lock
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
next prev parent reply other threads:[~2007-08-25 15:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-24 13:08 Remove APIC lock Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A01F84594-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-25 8:05 ` Avi Kivity
[not found] ` <46CFE2C6.5020006-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-25 14:16 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A01F84646-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-25 14:44 ` Avi Kivity
[not found] ` <46D04066.4060206-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-25 15:14 ` Avi Kivity
2007-08-25 15:25 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A01F8464D-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-25 15:54 ` Avi Kivity [this message]
[not found] ` <46D050AB.2000900-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-26 23:41 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A01F846D6-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-27 0:30 ` Avi Kivity
[not found] ` <46D21B37.8030106-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-27 1:54 ` Dong, Eddie
2007-09-03 13:48 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2007-08-24 13:47 Gregory Haskins
[not found] ` <1187963266.4231.0.camel-5CR4LY5GPkvLDviKLk5550HKjMygAv58XqFh9Ls21Oc@public.gmane.org>
2007-08-24 13:55 ` Dong, Eddie
[not found] ` <10EA09EFD8728347A513008B6B0DA77A01F845A5-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-24 14:24 ` Dong, Eddie
2007-08-24 14:39 ` Gregory Haskins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46D050AB.2000900@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=eddie.dong-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox