From: Alexander Graf <agraf@suse.de>
To: Marc Zyngier <marc.zyngier@arm.com>, kvmarm@lists.cs.columbia.edu
Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
pbonzini@redhat.com
Subject: Re: [PATCH v4 2/2] KVM: arm/arm64: Route vtimer events to user space
Date: Thu, 22 Sep 2016 13:17:03 +0200 [thread overview]
Message-ID: <57E3BDAF.8070805@suse.de> (raw)
In-Reply-To: <57E166F9.8080109@arm.com>
On 09/20/2016 06:42 PM, Marc Zyngier wrote:
> On 20/09/16 15:31, Alexander Graf wrote:
>> On 09/20/2016 02:37 PM, Marc Zyngier wrote:
> [...]
>
>>>>>> We also need to know "timer line low + timer line masked", as otherwise
>>>>>> we might get spurious interrupts in the guest, no?
>>>>> Yes. Though you can't really know about this one, and you'll have to
>>>>> wait until the next natural exit to find out. As long as the spurious is
>>>> We can provoke a special exit for it, no?
>>> How? The guest decides to disable its timer. That doesn't trigger any
>>> exit whatsoever. You'll have to wait until the next exit from the guest
>>> to notice it.
>> Before we inject a timer interrupt, we can check whether the pending
>> semantics of user space / kernel space match. If they don't match, we
>> can exit before we inject the interrupt and allow user space to disable
>> the pending state again.
> Let's rewind a bit, because I've long lost track of what you're trying
> to do to handle what.
>
> You need two signals:
>
> (1) TIMER_LEVEL: the output of the timer line, having accounted for the
> IMASK bit. This is conveniently the value of timer->irq.level.
>
> (2) TIMER_IRQ_MASK: an indication from userspace that a timer interrupt
> is pending, and that the physical line should be masked.
>
> You need a number of rules:
>
> (a) On exit to userspace, the kernel always exposes the value of
> TIMER_LEVEL.
>
> (b) On kernel entry, userspace always exposes the required
> TIMER_IRQ_MASK, depending on what has been exposed to it by TIMER_LEVEL.
>
> (c) If on guest exit, TIMER_LEVEL==1 and TIMER_IRQ_MASK==0, perform a
> userspace exit, because the emulated GIC needs to make the interrupt
> pending.
This should be "before guest entry", because the timer might have
expired in between.
> (d) If on guest exit, TIMER_LEVEL==0 and TIMER_IRQ_MASK==1, perform a
> userspace exit, because the guest has disabled its timer before taking
> the interrupt, and the emulated GIC needs to retire the pending state.
>
> and that's it. Nothing else. The kernel tells userspace the state of the
> timer, and userspace drives the masking of the physical interrupt.
> Conveniently, this matches what the current code does.
Yup. It seems to work. It also does feel slower than the previous code,
but maybe that's just me. It definitely is way more correct.
I'll trace around a bit more to see whether I can spot any obviously low
hanging performance fruits, then prettify the patches and send them out :).
Alex
WARNING: multiple messages have this Message-ID (diff)
From: agraf@suse.de (Alexander Graf)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 2/2] KVM: arm/arm64: Route vtimer events to user space
Date: Thu, 22 Sep 2016 13:17:03 +0200 [thread overview]
Message-ID: <57E3BDAF.8070805@suse.de> (raw)
In-Reply-To: <57E166F9.8080109@arm.com>
On 09/20/2016 06:42 PM, Marc Zyngier wrote:
> On 20/09/16 15:31, Alexander Graf wrote:
>> On 09/20/2016 02:37 PM, Marc Zyngier wrote:
> [...]
>
>>>>>> We also need to know "timer line low + timer line masked", as otherwise
>>>>>> we might get spurious interrupts in the guest, no?
>>>>> Yes. Though you can't really know about this one, and you'll have to
>>>>> wait until the next natural exit to find out. As long as the spurious is
>>>> We can provoke a special exit for it, no?
>>> How? The guest decides to disable its timer. That doesn't trigger any
>>> exit whatsoever. You'll have to wait until the next exit from the guest
>>> to notice it.
>> Before we inject a timer interrupt, we can check whether the pending
>> semantics of user space / kernel space match. If they don't match, we
>> can exit before we inject the interrupt and allow user space to disable
>> the pending state again.
> Let's rewind a bit, because I've long lost track of what you're trying
> to do to handle what.
>
> You need two signals:
>
> (1) TIMER_LEVEL: the output of the timer line, having accounted for the
> IMASK bit. This is conveniently the value of timer->irq.level.
>
> (2) TIMER_IRQ_MASK: an indication from userspace that a timer interrupt
> is pending, and that the physical line should be masked.
>
> You need a number of rules:
>
> (a) On exit to userspace, the kernel always exposes the value of
> TIMER_LEVEL.
>
> (b) On kernel entry, userspace always exposes the required
> TIMER_IRQ_MASK, depending on what has been exposed to it by TIMER_LEVEL.
>
> (c) If on guest exit, TIMER_LEVEL==1 and TIMER_IRQ_MASK==0, perform a
> userspace exit, because the emulated GIC needs to make the interrupt
> pending.
This should be "before guest entry", because the timer might have
expired in between.
> (d) If on guest exit, TIMER_LEVEL==0 and TIMER_IRQ_MASK==1, perform a
> userspace exit, because the guest has disabled its timer before taking
> the interrupt, and the emulated GIC needs to retire the pending state.
>
> and that's it. Nothing else. The kernel tells userspace the state of the
> timer, and userspace drives the masking of the physical interrupt.
> Conveniently, this matches what the current code does.
Yup. It seems to work. It also does feel slower than the previous code,
but maybe that's just me. It definitely is way more correct.
I'll trace around a bit more to see whether I can spot any obviously low
hanging performance fruits, then prettify the patches and send them out :).
Alex
next prev parent reply other threads:[~2016-09-22 11:08 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-19 11:14 [PATCH v4 0/2] KVM: ARM: Enable vtimers with user space gic Alexander Graf
2016-09-19 11:14 ` Alexander Graf
2016-09-19 11:14 ` [PATCH v4 1/2] KVM: arm/arm64: Add vcpu ENABLE_CAP functionality Alexander Graf
2016-09-19 11:14 ` Alexander Graf
2016-09-19 11:14 ` [PATCH v4 2/2] KVM: arm/arm64: Route vtimer events to user space Alexander Graf
2016-09-19 11:14 ` Alexander Graf
2016-09-19 14:48 ` Marc Zyngier
2016-09-19 14:48 ` Marc Zyngier
2016-09-19 17:39 ` Alexander Graf
2016-09-19 17:39 ` Alexander Graf
2016-09-20 9:21 ` Marc Zyngier
2016-09-20 9:21 ` Marc Zyngier
2016-09-20 9:26 ` Alexander Graf
2016-09-20 9:26 ` Alexander Graf
2016-09-20 9:39 ` Marc Zyngier
2016-09-20 9:39 ` Marc Zyngier
2016-09-20 10:05 ` Alexander Graf
2016-09-20 10:05 ` Alexander Graf
2016-09-20 10:28 ` Marc Zyngier
2016-09-20 10:28 ` Marc Zyngier
2016-09-20 12:22 ` Alexander Graf
2016-09-20 12:22 ` Alexander Graf
2016-09-20 12:37 ` Marc Zyngier
2016-09-20 12:37 ` Marc Zyngier
2016-09-20 14:31 ` Alexander Graf
2016-09-20 14:31 ` Alexander Graf
2016-09-20 16:42 ` Marc Zyngier
2016-09-20 16:42 ` Marc Zyngier
2016-09-22 11:17 ` Alexander Graf [this message]
2016-09-22 11:17 ` Alexander Graf
2016-09-22 12:32 ` Alexander Graf
2016-09-22 12:32 ` Alexander Graf
2016-09-22 12:35 ` Marc Zyngier
2016-09-22 12:35 ` Marc Zyngier
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=57E3BDAF.8070805@suse.de \
--to=agraf@suse.de \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marc.zyngier@arm.com \
--cc=pbonzini@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.