Skip to content

Commit ca916d3

Browse files
vmaffionebonzini
authored andcommitted
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. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0d89436 commit ca916d3

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

hw/misc/vfio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
646646
vector->virq = msg ? kvm_irqchip_add_msi_route(kvm_state, *msg) : -1;
647647
if (vector->virq < 0 ||
648648
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
649-
vector->virq) < 0) {
649+
NULL, vector->virq) < 0) {
650650
if (vector->virq >= 0) {
651651
kvm_irqchip_release_virq(kvm_state, vector->virq);
652652
vector->virq = -1;
@@ -814,7 +814,7 @@ static void vfio_enable_msi(VFIODevice *vdev)
814814
vector->virq = kvm_irqchip_add_msi_route(kvm_state, msg);
815815
if (vector->virq < 0 ||
816816
kvm_irqchip_add_irqfd_notifier(kvm_state, &vector->interrupt,
817-
vector->virq) < 0) {
817+
NULL, vector->virq) < 0) {
818818
qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
819819
vfio_msi_interrupt, NULL, vector);
820820
}

hw/virtio/virtio-pci.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
508508
VirtQueue *vq = virtio_get_queue(proxy->vdev, queue_no);
509509
EventNotifier *n = virtio_queue_get_guest_notifier(vq);
510510
int ret;
511-
ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, irqfd->virq);
511+
ret = kvm_irqchip_add_irqfd_notifier(kvm_state, n, NULL, irqfd->virq);
512512
return ret;
513513
}
514514

include/sysemu/kvm.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
309309
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
310310
void kvm_irqchip_release_virq(KVMState *s, int virq);
311311

312-
int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
312+
int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
313+
EventNotifier *rn, int virq);
313314
int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);
314315
void kvm_pc_gsi_handler(void *opaque, int n, int level);
315316
void kvm_pc_setup_irq_routing(bool pci_enabled);

kvm-all.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1230,14 +1230,20 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
12301230
return kvm_update_routing_entry(s, &kroute);
12311231
}
12321232

1233-
static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)
1233+
static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int rfd, int virq,
1234+
bool assign)
12341235
{
12351236
struct kvm_irqfd irqfd = {
12361237
.fd = fd,
12371238
.gsi = virq,
12381239
.flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN,
12391240
};
12401241

1242+
if (rfd != -1) {
1243+
irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
1244+
irqfd.resamplefd = rfd;
1245+
}
1246+
12411247
if (!kvm_irqfds_enabled()) {
12421248
return -ENOSYS;
12431249
}
@@ -1276,14 +1282,17 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
12761282
}
12771283
#endif /* !KVM_CAP_IRQ_ROUTING */
12781284

1279-
int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
1285+
int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
1286+
EventNotifier *rn, int virq)
12801287
{
1281-
return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, true);
1288+
return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n),
1289+
rn ? event_notifier_get_fd(rn) : -1, virq, true);
12821290
}
12831291

12841292
int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
12851293
{
1286-
return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), virq, false);
1294+
return kvm_irqchip_assign_irqfd(s, event_notifier_get_fd(n), -1, virq,
1295+
false);
12871296
}
12881297

12891298
static int kvm_irqchip_create(KVMState *s)

0 commit comments

Comments
 (0)