From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gregory Haskins Subject: Re: [PATCHv0 RFC] kvm: irqfd support for level interrupts Date: Wed, 29 Jul 2009 12:03:02 -0400 Message-ID: <4A7072B6.1060506@gmail.com> References: <20090726162225.GA21972@redhat.com> <4A707241.8000102@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig20C43C365CB86919EDA673B7" Cc: avi@redhat.com, gleb@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org To: "Michael S. Tsirkin" Return-path: Received: from mail-gx0-f213.google.com ([209.85.217.213]:62828 "EHLO mail-gx0-f213.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754476AbZG2QDH (ORCPT ); Wed, 29 Jul 2009 12:03:07 -0400 Received: by gxk9 with SMTP id 9so1594958gxk.13 for ; Wed, 29 Jul 2009 09:03:06 -0700 (PDT) In-Reply-To: <4A707241.8000102@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig20C43C365CB86919EDA673B7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Gregory Haskins wrote: > Michael S. Tsirkin wrote: >> Here's an untested patch with partial support for level triggered >> interrupts in irqfd. What this patch has: support for clearing interru= pt >> on ack. What this patch does not have: support signalling eventfd on a= ck >> so that userspace can take action and e.g. reenable interrupt. >> >> Gleb, Marcelo, I'd like your input on the approach taken wrt locking. >> Does it look sane? >> >> Avi, how's the interface? I intend to also add an eventfd probably in >> the padding in the irqfd struct. >> >> Signed-off-by: Michael S. Tsirkin >=20 > Patch seems reasonable to me. >=20 > Acked-by: Gregory Haskins Actually, one thing I didn't think of earlier is whether a CAP_IRQFD_LEVEL kind of feature is required. I would think not, since the baseline IRQFD hasnt been officially published yet. But its something to consider. -Greg >=20 >> --- >> >> diff --git a/include/linux/kvm.h b/include/linux/kvm.h >> index 230a91a..8bf16af 100644 >> --- a/include/linux/kvm.h >> +++ b/include/linux/kvm.h >> @@ -488,6 +488,7 @@ struct kvm_x86_mce { >> #endif >> =20 >> #define KVM_IRQFD_FLAG_DEASSIGN (1 << 0) >> +#define KVM_IRQFD_FLAG_LEVEL (1 << 1) >> =20 >> struct kvm_irqfd { >> __u32 fd; >> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c >> index 99017e8..fcbf5b5 100644 >> --- a/virt/kvm/eventfd.c >> +++ b/virt/kvm/eventfd.c >> @@ -45,12 +45,14 @@ struct _irqfd { >> struct kvm *kvm; >> struct eventfd_ctx *eventfd; >> int gsi; >> + int is_level; >> struct list_head list; >> poll_table pt; >> wait_queue_head_t *wqh; >> wait_queue_t wait; >> struct work_struct inject; >> struct work_struct shutdown; >> + struct kvm_irq_ack_notifier kian; >> }; >> =20 >> static struct workqueue_struct *irqfd_cleanup_wq; >> @@ -63,10 +65,15 @@ irqfd_inject(struct work_struct *work) >> =20 >> mutex_lock(&kvm->irq_lock); >> kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, irqfd->gsi, 1); >> - kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, irqfd->gsi, 0); >> + if (!irqfd->is_level) >> + kvm_set_irq(kvm, KVM_USERSPACE_IRQ_SOURCE_ID, irqfd->gsi, 0); >> mutex_unlock(&kvm->irq_lock); >> } >> =20 >> +static void irqfd_irq_acked(struct kvm_irq_ack_notifier *kian) >> +{ >> + kvm_set_irq(kian->kvm, KVM_USERSPACE_IRQ_SOURCE_ID, kian->gsi, 0); >> +} >> /* >> * Race-free decouple logic (ordering is critical) >> */ >> @@ -87,6 +94,9 @@ irqfd_shutdown(struct work_struct *work) >> */ >> flush_work(&irqfd->inject); >> =20 >> + if (irqfd->is_level) >> + kvm_unregister_irq_ack_notifier(&irqfd->kian); >> + >> /* >> * It is now safe to release the object's resources >> */ >> @@ -166,7 +176,7 @@ irqfd_ptable_queue_proc(struct file *file, wait_qu= eue_head_t *wqh, >> } >> =20 >> static int >> -kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi) >> +kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi, int is_level) >> { >> struct _irqfd *irqfd; >> struct file *file =3D NULL; >> @@ -180,6 +190,7 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)= >> =20 >> irqfd->kvm =3D kvm; >> irqfd->gsi =3D gsi; >> + irqfd->is_level =3D is_level; >> INIT_LIST_HEAD(&irqfd->list); >> INIT_WORK(&irqfd->inject, irqfd_inject); >> INIT_WORK(&irqfd->shutdown, irqfd_shutdown); >> @@ -198,6 +209,12 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi= ) >> =20 >> irqfd->eventfd =3D eventfd; >> =20 >> + if (is_level) { >> + irqfd->kian.gsi =3D gsi; >> + irqfd->kian.irq_acked =3D irqfd_irq_acked; >> + kvm_register_irq_ack_notifier(&irqfd->kian); >> + } >> + >> /* >> * Install our own custom wake-up handling so we are notified via >> * a callback whenever someone signals the underlying eventfd >> @@ -281,10 +298,13 @@ kvm_irqfd_deassign(struct kvm *kvm, int fd, int = gsi) >> int >> kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) >> { >> + if (flags & ~(KVM_IRQFD_FLAG_DEASSIGN | KVM_IRQFD_FLAG_LEVEL)) >> + return -EINVAL; >> + >> if (flags & KVM_IRQFD_FLAG_DEASSIGN) >> return kvm_irqfd_deassign(kvm, fd, gsi); >> =20 >> - return kvm_irqfd_assign(kvm, fd, gsi); >> + return kvm_irqfd_assign(kvm, fd, gsi, !!(flags & KVM_IRQFD_FLAG_LEVE= L)); >> } >> =20 >> /* >> -- >> To unsubscribe from this list: send the line "unsubscribe kvm" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >=20 >=20 --------------enig20C43C365CB86919EDA673B7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkpwcrYACgkQP5K2CMvXmqFz/wCfY7u31aq7jixD3JECyPCbduH4 7qIAn2GwACfV2PT8FQVxn0TxJT+xYsO+ =7JaR -----END PGP SIGNATURE----- --------------enig20C43C365CB86919EDA673B7--