From: Gregory Haskins <ghaskins@novell.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
davidel@xmailserver.org
Subject: Re: [KVM PATCH v2 2/2] kvm: add support for irqfd via eventfd-notification interface
Date: Mon, 27 Apr 2009 06:35:56 -0400 [thread overview]
Message-ID: <49F58A8C.7090808@novell.com> (raw)
In-Reply-To: <49F572EF.4010909@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4176 bytes --]
Avi Kivity wrote:
> Gregory Haskins wrote:
>> This allows an eventfd to be registered as an irq source with a
>> guest. Any
>> signaling operation on the eventfd (via userspace or kernel) will inject
>> the registered GSI at the next available window.
>>
>>
>> +struct kvm_irqfd {
>> + __u32 fd;
>> + __u32 gsi;
>> +};
>> +
>>
>
> I think it's better to have ioctl create and return the fd. This way
> we aren't tied to eventfd (though it makes a lot of sense to use it).
I dont mind either way, but I am not sure it buys us much as the one
driving the fd would need to understand if the interface is
eventfd-esque or something else anyway. Let me know if you still want
to see this changed.
>
> Also, please add a flags field and some padding so we can extend it
> later.
>
Good idea. Will do.
>> +
>> +#include <linux/kvm_host.h>
>> +#include <linux/eventfd.h>
>> +#include <linux/workqueue.h>
>> +#include <linux/wait.h>
>> +#include <linux/poll.h>
>> +#include <linux/file.h>
>> +#include <linux/list.h>
>> +
>> +struct _irqfd {
>> + struct kvm *kvm;
>> + int gsi;
>> + struct file *file;
>> + struct list_head list;
>> + poll_table pt;
>> + wait_queue_head_t *wqh;
>> + wait_queue_t wait;
>> + struct work_struct work;
>> +};
>> +
>> +static void
>> +irqfd_inject(struct work_struct *work)
>> +{
>> + struct _irqfd *irqfd = container_of(work, struct _irqfd, work);
>> + struct kvm *kvm = irqfd->kvm;
>> +
>> + mutex_lock(&kvm->lock);
>> + kvm_set_irq(kvm, kvm->irqfd.src, irqfd->gsi, 1);
>>
>
> Need to lower the irq too (though irqfd only supports edge triggered
> interrupts).
>
Should I just do back-to-back 1+0 inside the same lock?
>> + mutex_unlock(&kvm->lock);
>> +}
>> +
>> +static int
>> +irqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key)
>> +{
>> + struct _irqfd *irqfd = container_of(wait, struct _irqfd, wait);
>> +
>> + /*
>> + * The eventfd calls its wake_up with interrupts disabled,
>> + * so we need to defer the IRQ injection until later since we need
>> + * to acquire the kvm->lock to do so.
>> + */
>> + schedule_work(&irqfd->work);
>> +
>> + return 0;
>> +}
>>
>
> One day we'll have lockless injection and we'll want to drop this. I
> guess if we create the fd ourselves we can make it work, but I don't
> see how we can do this with eventfd.
>
Hmm...this is a good point. There probably is no way to use eventfd
"off the shelf" in a way that doesn't cause this callback to be in a
critical section. Should we just worry about switching away from
eventfd when this occurs, or should I implement a custom anon-fd now?
>> +int
>> +kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
>> +{
>> + struct _irqfd *irqfd;
>> + struct file *file;
>> + int ret;
>> +
>> + irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
>> + if (!irqfd)
>> + return -ENOMEM;
>> +
>> + irqfd->kvm = kvm;
>> + irqfd->gsi = gsi;
>> + INIT_LIST_HEAD(&irqfd->list);
>> + init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
>> + init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc);
>> + INIT_WORK(&irqfd->work, irqfd_inject);
>> +
>> + file = eventfd_fget(fd);
>> + if (IS_ERR(file)) {
>> + ret = PTR_ERR(file);
>> + goto fail;
>> + }
>> +
>> + ret = file->f_op->poll(file, &irqfd->pt);
>> + /* do we need to look for errors in ret? */
>>
>
> Do we?
Probably. Will fix in v3.
>
>> +
>> + irqfd->file = file;
>> +
>> + mutex_lock(&kvm->lock);
>> + if (kvm->irqfd.src == -1) {
>> + ret = kvm_request_irq_source_id(kvm);
>> + BUG_ON(ret < 0);
>>
>
> I think you can reuse the userspace irq source (since it's just
> another way for userspace to inject an interrupt). It isn't really
> needed since the irq source stuff is only needed to support level
> triggered interrupts.
>
Ack, will do.
Thanks Avi,
-Greg
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 266 bytes --]
next prev parent reply other threads:[~2009-04-27 10:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-24 4:25 [KVM PATCH v2 0/2] irqfd Gregory Haskins
2009-04-24 4:25 ` [KVM PATCH v2 1/2] eventfd: export fget and signal interfaces for module use Gregory Haskins
2009-04-24 4:25 ` [KVM PATCH v2 2/2] kvm: add support for irqfd via eventfd-notification interface Gregory Haskins
2009-04-24 17:07 ` Gregory Haskins
2009-04-24 17:47 ` Davide Libenzi
2009-04-27 8:55 ` Avi Kivity
2009-04-27 10:35 ` Gregory Haskins [this message]
2009-04-27 10:48 ` Avi Kivity
2009-04-27 13:27 ` Gregory Haskins
2009-04-28 9:35 ` Avi Kivity
2009-04-28 10:34 ` Gregory Haskins
2009-04-28 11:00 ` Avi Kivity
2009-04-28 11:04 ` Gregory Haskins
2009-04-28 11:05 ` Avi Kivity
2009-04-28 11:08 ` Avi Kivity
2009-04-28 11:38 ` Gregory Haskins
2009-04-28 11:48 ` Avi Kivity
2009-04-28 12:07 ` Gregory Haskins
2009-04-27 10:58 ` Gregory Haskins
2009-04-27 11:23 ` Avi Kivity
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=49F58A8C.7090808@novell.com \
--to=ghaskins@novell.com \
--cc=avi@redhat.com \
--cc=davidel@xmailserver.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 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.