From: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: Gregory Haskins <ghaskins-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH] Add irqdevice interface + userint implementation
Date: Tue, 10 Apr 2007 10:52:33 +0300 [thread overview]
Message-ID: <461B4241.5030101@qumranet.com> (raw)
In-Reply-To: <461A415C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
Gregory Haskins wrote:
>>> +
>>> +struct kvm_irqdevice;
>>> +
>>> +struct kvm_irqsink {
>>> + void (*raise_intr)(struct kvm_irqsink *this,
>>> + struct kvm_irqdevice *dev);
>>> +
>>> + void *private;
>>> +};
>>> +
>>> +struct kvm_irqdevice {
>>> + int (*pending)(struct kvm_irqdevice *this, int flags);
>>> + int (*read_vector)(struct kvm_irqdevice *this, int flags);
>>>
>>>
>> I'm a bit confused here. The kvm_irqsink mechanism implies a push
>> mechanism. - >pending and - >read_vector imply a pull mechanism.
>>
>
> What I am modeling is the concept of an PIC INTR + INTA. INTR serves to just cause the processor to realize it needs to service an interrupt. The INTA cycle is what then gets invoked after INTR to figure out which vector is appropriate. Finally, the vector is called out of the IDT.
>
> However, there is no actual INTA cycle on a virtualized guest. We emulate an INTA cycle by calling our pending/read routines and injecting the vector into the VMCS. Whats missing from the current HEAD is that there is no concept of INTR. This is whats new, and its why we have both a push and a pull mechanism. The old way only had the pull. Does this make sense?
>
Hmm. The current code is synchronous in nature (the vcpu is never
executing while we raise an interrupt, so the INTA is never needed, as
we can ensure the cpu can process the interrupt when we inject it. With
smp/paravirt/whatever (I realize now), this is no longer true. The NIC
raises an interrupt, we have to interrupt the guest to see if its
current IF/cr8 permit interrupt injection, and if not, we have to keep
the interrupt in the irqdevice and request an exit when IF/cr8 permit
injection.
This means that ->pending() and ->read_vector() have to be called in a
critical section, otherwise the pending interrupt might be change
between the first and second call, resulting in an injected interrupt to
software that is not ready to accept it. If we replace read_vector by
->ack(this, int vector) we avoid this need (and also save a pointless
recalculation of the vector).
>>> +static inline int bitarray_findhighest(struct bitarray *this)
>>> +{
>>> + if (!this- >summary)
>>> + return - 1;
>>> + else {
>>> + int word_index = __ffs(this- >summary);
>>> + int bit_index = __ffs(this- >pending[word_index]);
>>> +
>>> + return word_index * BITS_PER_LONG + bit_index;
>>> + }
>>> +}
>>>
>>>
>> Um, this is the lowest?
>>
>
> Opps...carry over from the original code. I forgot to reverse the polarity.
>
>
Note that the original code did not work as intended. Because of the
IF/tpr issues, there is at most interrupt queued, and only when it is
ready to be accepted. With the in-kernel apic that changes of course.
>
>>> +
>>> +static int userint_pending(struct kvm_irqdevice *this, int flags)
>>> +{
>>> + kvm_userint *s = (kvm_userint*)this- >private;
>>> + int ret;
>>> +
>>> + spin_lock_irq(&s- >lock);
>>> +
>>> + if (flags & KVM_IRQFLAGS_NMI)
>>> + ret = s- >nmi_pending;
>>> + else
>>> + ret = bitarray_pending(&s- >irq_pending);
>>>
>>>
>> You probably want:
>>
>> ret = s- >nmi_pending;
>> if (!(flags & KVM_IRQFLAGS_NMI))
>> ret |= bitarray_pending(...);
>>
>> To avoid calling this twice when interrupts are enabled.
>>
>
> I think there is a misunderstanding. The return value from this function should just be 0 for false, and non-zero for true. The bitarray still holds a bit for IRQ2 so you technically wouldn't need to call this twice when interrupts are enabled. Simply calling this without the flag set will give you the proper behavior, so I think it is fine as written. It also doesn't hurt to do it the way you wrote it either. Let me know if I misunderstood you.
>
>
Ah, I forgot that nmi is also vector 2 here.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
next prev parent reply other threads:[~2007-04-10 7:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-05 18:53 [PATCH] Add irqdevice interface + userint implementation Gregory Haskins
2007-04-05 21:38 ` Fwd: " Gregory Haskins
[not found] ` <4614FF5C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-08 6:47 ` Avi Kivity
[not found] ` <46189005.2090609-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-09 18:36 ` Gregory Haskins
[not found] ` <461A415C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 7:52 ` Avi Kivity [this message]
[not found] ` <461B4241.5030101-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 11:36 ` Gregory Haskins
[not found] ` <461B3E61.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 12:01 ` Avi Kivity
[not found] ` <461B7C81.7040102-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 14:20 ` Gregory Haskins
[not found] ` <461B64E4.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 14:46 ` Avi Kivity
[not found] ` <461BA363.5080308-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 15:39 ` Gregory Haskins
2007-04-10 15:53 ` Fwd: " Gregory Haskins
[not found] ` <461B7AC6.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 16:11 ` Avi Kivity
[not found] ` <461BB738.7040206-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-10 17:58 ` Gregory Haskins
[not found] ` <461B7755.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 16:08 ` Avi Kivity
2007-04-08 9:58 ` Christoph Hellwig
[not found] ` <20070408095853.GA31284-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2007-04-08 10:23 ` Avi Kivity
[not found] ` <4618C293.8030902-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-04-08 10:33 ` Christoph Hellwig
2007-04-09 14:53 ` Gregory Haskins
-- strict thread matches above, loose matches on Subject: below --
2007-04-09 20:27 Gregory Haskins
[not found] ` <461A5B6C.BA47.005A.0-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org>
2007-04-10 7:33 ` Avi Kivity
2007-04-10 8:23 ` Christoph Hellwig
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=461B4241.5030101@qumranet.com \
--to=avi-atkuwr5tajbwk0htik3j/w@public.gmane.org \
--cc=ghaskins-Et1tbQHTxzrQT0dZR+AlfA@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