* [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
@ 2013-07-22 10:43 Vincenzo Maffione
2013-07-22 14:01 ` Alex Williamson
0 siblings, 1 reply; 5+ messages in thread
From: Vincenzo Maffione @ 2013-07-22 10:43 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, ehabkost, gleb, alex.williamson, avi,
pbonzini, afaerber
>From e59e35380380c2986cd0164f11dcd8a07a8e4e59 Mon Sep 17 00:00:00 2001
From: Vincenzo Maffione <v.maffione@gmail.com>
Date: Mon, 22 Jul 2013 11:51:33 +0200
Subject: [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
Added an EventNotifier* parameter to
kvm-all.c:kvm_irqchip_add_irqfd_notifier(), in order to give KVM
another eventfd to be used as "resamplefd". See the documentation
in the linux kernel sources in Documentation/virtual/kvm/api.txt
(section 4.75) for more details.
When the added parameter is passed NULL, the behaviour of the
function is unchanged with respect to the previous versions.
Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
---
hw/misc/vfio.c | 4 ++--
hw/virtio/virtio-pci.c | 2 +-
include/sysemu/kvm.h | 3 ++-
kvm-all.c | 17 +++++++++++++----
4 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index ad8ce77..54af34a 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice
*pdev, unsigned int nr,
vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
if (vector->virq < 0 ||
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
- vector->virq) < 0) {
+ NULL, vector->virq) < 0) {
if (vector->virq >= 0) {
kvm_irqchip_release_virq(kvm_state, vector->virq);
vector->virq = -1;
@@ -814,7 +814,7 @@ retry:
vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
if (vector->virq < 0 ||
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
- vector->virq) < 0) {
+ NULL, vector->virq) < 0) {
qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
vfio_msi_interrupt, NULL, vector);
}
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index c38cfd1..c4db407 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
int ret;
- ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
+ ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
return ret;
}
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 1e08a85..9e5d78e 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
void kvm_irqchip_release_virq(KVMState *s, int virq);
-int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
+int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
+ EventNotifier *rn, int virq);
int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
void kvm_pc_gsi_handler(void *opaque, int n, int level);
void kvm_pc_setup_irq_routing(bool pci_enabled);
diff --git a/kvm-all.c b/kvm-all.c
index 232c39a..3f69b41 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1230,7 +1230,8 @@ int kvm_irqchip_update_msi_route(KVMState *s,
int virq, MSIMessage msg)
return kvm_update_routing_entry(s, &kroute);
}
-static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
+static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
+ bool assign)
{
struct kvm_irqfd irqfd = {
.fd = fd,
@@ -1238,6 +1239,11 @@ static int kvm_irqchip_assign_irqfd(KVMState
*s, int fd, int virq, bool assign)
.flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
};
+ if (rfd != -1) {
+ irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
+ irqfd.resamplefd = rfd;
+ }
+
if (!kvm_irqfds_enabled()) {
return -ENOSYS;
}
@@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s,
int virq, MSIMessage msg)
}
#endif /* !KVM_CAP_IRQ_ROUTING */
-int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
+int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
+ EventNotifier *rn, int virq)
{
- return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
+ return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
+ rn ? event_notifier_get_fd(rn) : -1, virq, true);
}
int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
{
- return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
+ return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
+ false);
}
static int kvm_irqchip_create(KVMState *s)
--
1.8.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
2013-07-22 10:43 [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support Vincenzo Maffione
@ 2013-07-22 14:01 ` Alex Williamson
2013-07-22 14:18 ` Vincenzo Maffione
0 siblings, 1 reply; 5+ messages in thread
From: Alex Williamson @ 2013-07-22 14:01 UTC (permalink / raw)
To: Vincenzo Maffione
Cc: peter.maydell, aliguori, ehabkost, gleb, qemu-devel, pbonzini,
afaerber
On Mon, 2013-07-22 at 12:43 +0200, Vincenzo Maffione wrote:
> From e59e35380380c2986cd0164f11dcd8a07a8e4e59 Mon Sep 17 00:00:00 2001
> From: Vincenzo Maffione <v.maffione@gmail.com>
> Date: Mon, 22 Jul 2013 11:51:33 +0200
> Subject: [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
>
> Added an EventNotifier* parameter to
> kvm-all.c:kvm_irqchip_add_irqfd_notifier(), in order to give KVM
> another eventfd to be used as "resamplefd". See the documentation
> in the linux kernel sources in Documentation/virtual/kvm/api.txt
> (section 4.75) for more details.
> When the added parameter is passed NULL, the behaviour of the
> function is unchanged with respect to the previous versions.
>
> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
> ---
> hw/misc/vfio.c | 4 ++--
> hw/virtio/virtio-pci.c | 2 +-
> include/sysemu/kvm.h | 3 ++-
> kvm-all.c | 17 +++++++++++++----
> 4 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
> index ad8ce77..54af34a 100644
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice
> *pdev, unsigned int nr,
> vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
> if (vector->virq < 0 ||
> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
> - vector->virq) < 0) {
> + NULL, vector->virq) < 0) {
> if (vector->virq >= 0) {
> kvm_irqchip_release_virq(kvm_state, vector->virq);
> vector->virq = -1;
> @@ -814,7 +814,7 @@ retry:
> vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
> if (vector->virq < 0 ||
> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
> - vector->virq) < 0) {
> + NULL, vector->virq) < 0) {
> qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
> vfio_msi_interrupt, NULL, vector);
> }
Why doesn't this address the only current user of
KVM_IRQFD_FLAG_RESAMPLE, vfio_enable_intx_kvm()? Thanks,
Alex
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index c38cfd1..c4db407 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
> VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
> EventNotifier *n = virtio_queue_get_guest_notifier(vq);
> int ret;
> - ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
> + ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
> return ret;
> }
>
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 1e08a85..9e5d78e 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
> int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
> void kvm_irqchip_release_virq(KVMState *s, int virq);
>
> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
> + EventNotifier *rn, int virq);
> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
> void kvm_pc_gsi_handler(void *opaque, int n, int level);
> void kvm_pc_setup_irq_routing(bool pci_enabled);
> diff --git a/kvm-all.c b/kvm-all.c
> index 232c39a..3f69b41 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1230,7 +1230,8 @@ int kvm_irqchip_update_msi_route(KVMState *s,
> int virq, MSIMessage msg)
> return kvm_update_routing_entry(s, &kroute);
> }
>
> -static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
> +static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
> + bool assign)
> {
> struct kvm_irqfd irqfd = {
> .fd = fd,
> @@ -1238,6 +1239,11 @@ static int kvm_irqchip_assign_irqfd(KVMState
> *s, int fd, int virq, bool assign)
> .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
> };
>
> + if (rfd != -1) {
> + irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
> + irqfd.resamplefd = rfd;
> + }
> +
> if (!kvm_irqfds_enabled()) {
> return -ENOSYS;
> }
> @@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s,
> int virq, MSIMessage msg)
> }
> #endif /* !KVM_CAP_IRQ_ROUTING */
>
> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
> + EventNotifier *rn, int virq)
> {
> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
> + rn ? event_notifier_get_fd(rn) : -1, virq, true);
> }
>
> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
> {
> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
> + false);
> }
>
> static int kvm_irqchip_create(KVMState *s)
> --
> 1.8.3.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
2013-07-22 14:01 ` Alex Williamson
@ 2013-07-22 14:18 ` Vincenzo Maffione
2013-07-22 14:56 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Vincenzo Maffione @ 2013-07-22 14:18 UTC (permalink / raw)
To: Alex Williamson
Cc: peter.maydell, aliguori, ehabkost, gleb, qemu-devel, pbonzini,
Giuseppe Lettieri, Luigi Rizzo, afaerber
Actually our research group (at University of Pisa) is working on some
paravirtualization extensions of the e1000 NIC emulation that needs
KVM_IRQFD_FLAG_RESAMPLE support. This is one of the reasons why I'm
proposing this patch.
Do you suggest modifying vfio_enable_intx_kvm() to take advantage of
the patch? I haven't addressed vfio only because I wasn't sure I am
"permitted" to do that.
Thanks,
Vincenzo
2013/7/22 Alex Williamson <alex.williamson@redhat.com>:
>
> On Mon, 2013-07-22 at 12:43 +0200, Vincenzo Maffione wrote:
>> From e59e35380380c2986cd0164f11dcd8a07a8e4e59 Mon Sep 17 00:00:00 2001
>> From: Vincenzo Maffione <v.maffione@gmail.com>
>> Date: Mon, 22 Jul 2013 11:51:33 +0200
>> Subject: [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
>>
>> Added an EventNotifier* parameter to
>> kvm-all.c:kvm_irqchip_add_irqfd_notifier(), in order to give KVM
>> another eventfd to be used as "resamplefd". See the documentation
>> in the linux kernel sources in Documentation/virtual/kvm/api.txt
>> (section 4.75) for more details.
>> When the added parameter is passed NULL, the behaviour of the
>> function is unchanged with respect to the previous versions.
>>
>> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
>> ---
>> hw/misc/vfio.c | 4 ++--
>> hw/virtio/virtio-pci.c | 2 +-
>> include/sysemu/kvm.h | 3 ++-
>> kvm-all.c | 17 +++++++++++++----
>> 4 files changed, 18 insertions(+), 8 deletions(-)
>>
>> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
>> index ad8ce77..54af34a 100644
>> --- a/hw/misc/vfio.c
>> +++ b/hw/misc/vfio.c
>> @@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice
>> *pdev, unsigned int nr,
>> vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
>> if (vector->virq < 0 ||
>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>> - vector->virq) < 0) {
>> + NULL, vector->virq) < 0) {
>> if (vector->virq >= 0) {
>> kvm_irqchip_release_virq(kvm_state, vector->virq);
>> vector->virq = -1;
>> @@ -814,7 +814,7 @@ retry:
>> vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
>> if (vector->virq < 0 ||
>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>> - vector->virq) < 0) {
>> + NULL, vector->virq) < 0) {
>> qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
>> vfio_msi_interrupt, NULL, vector);
>> }
>
>
> Why doesn't this address the only current user of
> KVM_IRQFD_FLAG_RESAMPLE, vfio_enable_intx_kvm()? Thanks,
>
> Alex
>
>
>> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
>> index c38cfd1..c4db407 100644
>> --- a/hw/virtio/virtio-pci.c
>> +++ b/hw/virtio/virtio-pci.c
>> @@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
>> VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
>> EventNotifier *n = virtio_queue_get_guest_notifier(vq);
>> int ret;
>> - ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
>> + ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
>> return ret;
>> }
>>
>> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
>> index 1e08a85..9e5d78e 100644
>> --- a/include/sysemu/kvm.h
>> +++ b/include/sysemu/kvm.h
>> @@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
>> int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
>> void kvm_irqchip_release_virq(KVMState *s, int virq);
>>
>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>> + EventNotifier *rn, int virq);
>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>> void kvm_pc_gsi_handler(void *opaque, int n, int level);
>> void kvm_pc_setup_irq_routing(bool pci_enabled);
>> diff --git a/kvm-all.c b/kvm-all.c
>> index 232c39a..3f69b41 100644
>> --- a/kvm-all.c
>> +++ b/kvm-all.c
>> @@ -1230,7 +1230,8 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>> int virq, MSIMessage msg)
>> return kvm_update_routing_entry(s, &kroute);
>> }
>>
>> -static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
>> +static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
>> + bool assign)
>> {
>> struct kvm_irqfd irqfd = {
>> .fd = fd,
>> @@ -1238,6 +1239,11 @@ static int kvm_irqchip_assign_irqfd(KVMState
>> *s, int fd, int virq, bool assign)
>> .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
>> };
>>
>> + if (rfd != -1) {
>> + irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
>> + irqfd.resamplefd = rfd;
>> + }
>> +
>> if (!kvm_irqfds_enabled()) {
>> return -ENOSYS;
>> }
>> @@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>> int virq, MSIMessage msg)
>> }
>> #endif /* !KVM_CAP_IRQ_ROUTING */
>>
>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>> + EventNotifier *rn, int virq)
>> {
>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
>> + rn ? event_notifier_get_fd(rn) : -1, virq, true);
>> }
>>
>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>> {
>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
>> + false);
>> }
>>
>> static int kvm_irqchip_create(KVMState *s)
>> --
>> 1.8.3.3
>
>
>
>
--
Vincenzo Maffione
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
2013-07-22 14:18 ` Vincenzo Maffione
@ 2013-07-22 14:56 ` Paolo Bonzini
2013-07-22 15:06 ` Vincenzo Maffione
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2013-07-22 14:56 UTC (permalink / raw)
To: Vincenzo Maffione
Cc: peter.maydell, aliguori, ehabkost, gleb, qemu-devel,
Alex Williamson, Giuseppe Lettieri, Luigi Rizzo, afaerber
Il 22/07/2013 16:18, Vincenzo Maffione ha scritto:
> Actually our research group (at University of Pisa) is working on some
> paravirtualization extensions of the e1000 NIC emulation that needs
> KVM_IRQFD_FLAG_RESAMPLE support. This is one of the reasons why I'm
> proposing this patch.
>
> Do you suggest modifying vfio_enable_intx_kvm() to take advantage of
> the patch? I haven't addressed vfio only because I wasn't sure I am
> "permitted" to do that.
If you have a patch to do that, I guess it's welcome. :)
Otherwise, this patch makes sense from the point of view of supporting
the KVM API in a more complete manner.
Paolo
>
>
> Thanks,
> Vincenzo
>
> 2013/7/22 Alex Williamson <alex.williamson@redhat.com>:
>>
>> On Mon, 2013-07-22 at 12:43 +0200, Vincenzo Maffione wrote:
>>> From e59e35380380c2986cd0164f11dcd8a07a8e4e59 Mon Sep 17 00:00:00 2001
>>> From: Vincenzo Maffione <v.maffione@gmail.com>
>>> Date: Mon, 22 Jul 2013 11:51:33 +0200
>>> Subject: [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
>>>
>>> Added an EventNotifier* parameter to
>>> kvm-all.c:kvm_irqchip_add_irqfd_notifier(), in order to give KVM
>>> another eventfd to be used as "resamplefd". See the documentation
>>> in the linux kernel sources in Documentation/virtual/kvm/api.txt
>>> (section 4.75) for more details.
>>> When the added parameter is passed NULL, the behaviour of the
>>> function is unchanged with respect to the previous versions.
>>>
>>> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
>>> ---
>>> hw/misc/vfio.c | 4 ++--
>>> hw/virtio/virtio-pci.c | 2 +-
>>> include/sysemu/kvm.h | 3 ++-
>>> kvm-all.c | 17 +++++++++++++----
>>> 4 files changed, 18 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
>>> index ad8ce77..54af34a 100644
>>> --- a/hw/misc/vfio.c
>>> +++ b/hw/misc/vfio.c
>>> @@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice
>>> *pdev, unsigned int nr,
>>> vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
>>> if (vector->virq < 0 ||
>>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>>> - vector->virq) < 0) {
>>> + NULL, vector->virq) < 0) {
>>> if (vector->virq >= 0) {
>>> kvm_irqchip_release_virq(kvm_state, vector->virq);
>>> vector->virq = -1;
>>> @@ -814,7 +814,7 @@ retry:
>>> vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
>>> if (vector->virq < 0 ||
>>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>>> - vector->virq) < 0) {
>>> + NULL, vector->virq) < 0) {
>>> qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
>>> vfio_msi_interrupt, NULL, vector);
>>> }
>>
>>
>> Why doesn't this address the only current user of
>> KVM_IRQFD_FLAG_RESAMPLE, vfio_enable_intx_kvm()? Thanks,
>>
>> Alex
>>
>>
>>> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
>>> index c38cfd1..c4db407 100644
>>> --- a/hw/virtio/virtio-pci.c
>>> +++ b/hw/virtio/virtio-pci.c
>>> @@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
>>> VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
>>> EventNotifier *n = virtio_queue_get_guest_notifier(vq);
>>> int ret;
>>> - ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
>>> + ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
>>> return ret;
>>> }
>>>
>>> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
>>> index 1e08a85..9e5d78e 100644
>>> --- a/include/sysemu/kvm.h
>>> +++ b/include/sysemu/kvm.h
>>> @@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
>>> int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
>>> void kvm_irqchip_release_virq(KVMState *s, int virq);
>>>
>>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>>> + EventNotifier *rn, int virq);
>>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>>> void kvm_pc_gsi_handler(void *opaque, int n, int level);
>>> void kvm_pc_setup_irq_routing(bool pci_enabled);
>>> diff --git a/kvm-all.c b/kvm-all.c
>>> index 232c39a..3f69b41 100644
>>> --- a/kvm-all.c
>>> +++ b/kvm-all.c
>>> @@ -1230,7 +1230,8 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>>> int virq, MSIMessage msg)
>>> return kvm_update_routing_entry(s, &kroute);
>>> }
>>>
>>> -static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
>>> +static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
>>> + bool assign)
>>> {
>>> struct kvm_irqfd irqfd = {
>>> .fd = fd,
>>> @@ -1238,6 +1239,11 @@ static int kvm_irqchip_assign_irqfd(KVMState
>>> *s, int fd, int virq, bool assign)
>>> .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
>>> };
>>>
>>> + if (rfd != -1) {
>>> + irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
>>> + irqfd.resamplefd = rfd;
>>> + }
>>> +
>>> if (!kvm_irqfds_enabled()) {
>>> return -ENOSYS;
>>> }
>>> @@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>>> int virq, MSIMessage msg)
>>> }
>>> #endif /* !KVM_CAP_IRQ_ROUTING */
>>>
>>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>>> + EventNotifier *rn, int virq)
>>> {
>>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
>>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
>>> + rn ? event_notifier_get_fd(rn) : -1, virq, true);
>>> }
>>>
>>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>>> {
>>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
>>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
>>> + false);
>>> }
>>>
>>> static int kvm_irqchip_create(KVMState *s)
>>> --
>>> 1.8.3.3
>>
>>
>>
>>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
2013-07-22 14:56 ` Paolo Bonzini
@ 2013-07-22 15:06 ` Vincenzo Maffione
0 siblings, 0 replies; 5+ messages in thread
From: Vincenzo Maffione @ 2013-07-22 15:06 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Peter Maydell, aliguori, Eduardo Habkost, gleb, qemu-devel,
Alex Williamson, Giuseppe Lettieri, Luigi Rizzo, afaerber
Actually I don't, but however the idea of the patch was exactly what
you pointed out.
Thanks,
Vincenzo
2013/7/22 Paolo Bonzini <pbonzini@redhat.com>:
> Il 22/07/2013 16:18, Vincenzo Maffione ha scritto:
>> Actually our research group (at University of Pisa) is working on some
>> paravirtualization extensions of the e1000 NIC emulation that needs
>> KVM_IRQFD_FLAG_RESAMPLE support. This is one of the reasons why I'm
>> proposing this patch.
>>
>> Do you suggest modifying vfio_enable_intx_kvm() to take advantage of
>> the patch? I haven't addressed vfio only because I wasn't sure I am
>> "permitted" to do that.
>
> If you have a patch to do that, I guess it's welcome. :)
>
> Otherwise, this patch makes sense from the point of view of supporting
> the KVM API in a more complete manner.
>
> Paolo
>
>>
>>
>> Thanks,
>> Vincenzo
>>
>> 2013/7/22 Alex Williamson <alex.williamson@redhat.com>:
>>>
>>> On Mon, 2013-07-22 at 12:43 +0200, Vincenzo Maffione wrote:
>>>> From e59e35380380c2986cd0164f11dcd8a07a8e4e59 Mon Sep 17 00:00:00 2001
>>>> From: Vincenzo Maffione <v.maffione@gmail.com>
>>>> Date: Mon, 22 Jul 2013 11:51:33 +0200
>>>> Subject: [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support
>>>>
>>>> Added an EventNotifier* parameter to
>>>> kvm-all.c:kvm_irqchip_add_irqfd_notifier(), in order to give KVM
>>>> another eventfd to be used as "resamplefd". See the documentation
>>>> in the linux kernel sources in Documentation/virtual/kvm/api.txt
>>>> (section 4.75) for more details.
>>>> When the added parameter is passed NULL, the behaviour of the
>>>> function is unchanged with respect to the previous versions.
>>>>
>>>> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
>>>> ---
>>>> hw/misc/vfio.c | 4 ++--
>>>> hw/virtio/virtio-pci.c | 2 +-
>>>> include/sysemu/kvm.h | 3 ++-
>>>> kvm-all.c | 17 +++++++++++++----
>>>> 4 files changed, 18 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
>>>> index ad8ce77..54af34a 100644
>>>> --- a/hw/misc/vfio.c
>>>> +++ b/hw/misc/vfio.c
>>>> @@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice
>>>> *pdev, unsigned int nr,
>>>> vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
>>>> if (vector->virq < 0 ||
>>>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>>>> - vector->virq) < 0) {
>>>> + NULL, vector->virq) < 0) {
>>>> if (vector->virq >= 0) {
>>>> kvm_irqchip_release_virq(kvm_state, vector->virq);
>>>> vector->virq = -1;
>>>> @@ -814,7 +814,7 @@ retry:
>>>> vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
>>>> if (vector->virq < 0 ||
>>>> kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
>>>> - vector->virq) < 0) {
>>>> + NULL, vector->virq) < 0) {
>>>> qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
>>>> vfio_msi_interrupt, NULL, vector);
>>>> }
>>>
>>>
>>> Why doesn't this address the only current user of
>>> KVM_IRQFD_FLAG_RESAMPLE, vfio_enable_intx_kvm()? Thanks,
>>>
>>> Alex
>>>
>>>
>>>> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
>>>> index c38cfd1..c4db407 100644
>>>> --- a/hw/virtio/virtio-pci.c
>>>> +++ b/hw/virtio/virtio-pci.c
>>>> @@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
>>>> VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
>>>> EventNotifier *n = virtio_queue_get_guest_notifier(vq);
>>>> int ret;
>>>> - ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
>>>> + ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
>>>> return ret;
>>>> }
>>>>
>>>> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
>>>> index 1e08a85..9e5d78e 100644
>>>> --- a/include/sysemu/kvm.h
>>>> +++ b/include/sysemu/kvm.h
>>>> @@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
>>>> int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
>>>> void kvm_irqchip_release_virq(KVMState *s, int virq);
>>>>
>>>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>>>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>>>> + EventNotifier *rn, int virq);
>>>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
>>>> void kvm_pc_gsi_handler(void *opaque, int n, int level);
>>>> void kvm_pc_setup_irq_routing(bool pci_enabled);
>>>> diff --git a/kvm-all.c b/kvm-all.c
>>>> index 232c39a..3f69b41 100644
>>>> --- a/kvm-all.c
>>>> +++ b/kvm-all.c
>>>> @@ -1230,7 +1230,8 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>>>> int virq, MSIMessage msg)
>>>> return kvm_update_routing_entry(s, &kroute);
>>>> }
>>>>
>>>> -static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
>>>> +static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
>>>> + bool assign)
>>>> {
>>>> struct kvm_irqfd irqfd = {
>>>> .fd = fd,
>>>> @@ -1238,6 +1239,11 @@ static int kvm_irqchip_assign_irqfd(KVMState
>>>> *s, int fd, int virq, bool assign)
>>>> .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
>>>> };
>>>>
>>>> + if (rfd != -1) {
>>>> + irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
>>>> + irqfd.resamplefd = rfd;
>>>> + }
>>>> +
>>>> if (!kvm_irqfds_enabled()) {
>>>> return -ENOSYS;
>>>> }
>>>> @@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s,
>>>> int virq, MSIMessage msg)
>>>> }
>>>> #endif /* !KVM_CAP_IRQ_ROUTING */
>>>>
>>>> -int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>>>> +int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
>>>> + EventNotifier *rn, int virq)
>>>> {
>>>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
>>>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
>>>> + rn ? event_notifier_get_fd(rn) : -1, virq, true);
>>>> }
>>>>
>>>> int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
>>>> {
>>>> - return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
>>>> + return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
>>>> + false);
>>>> }
>>>>
>>>> static int kvm_irqchip_create(KVMState *s)
>>>> --
>>>> 1.8.3.3
>>>
>>>
>>>
>>>
>>
>>
>>
>
--
Vincenzo Maffione
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-22 15:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-22 10:43 [Qemu-devel] [PATCH] kvm: add KVM_IRQFD_FLAG_RESAMPLE support Vincenzo Maffione
2013-07-22 14:01 ` Alex Williamson
2013-07-22 14:18 ` Vincenzo Maffione
2013-07-22 14:56 ` Paolo Bonzini
2013-07-22 15:06 ` Vincenzo Maffione
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).