Skip to contentSkip to conversation

kvm/hypercall: Add the PVI hypercall support

RFC PATCH In review Wei Wang 2 participants 11 messages Oct 14, 2016 – Oct 19, 2016 KVM

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

RFC PATCH 1/1 kvm/hypercall: Add the PVI hypercall support

PV interrupts (PVI) enables a guest to send interrupts to another via hypercalls.

---
 pv_interrupt_controller.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 pv_interrupt_controller.c
pv_interrupt_controller.c new file +27 -0
new file mode 100644
index 0000000..5f2431d
@@ -0,0 +1,27 @@
+
+The pv interrupt (PVI) hypercall is proposed to support one guest sending
+interrupts to another guest using hypercalls. The following pseduocode shows how
+a PVI is sent from the guest:
+
+#define KVM_HC_PVI 9
+kvm_hypercall2(KVM_HC_PVI, guest_uuid, guest_gsi);
+
+The new hypercall number, KVM_HC_PVI, is used for the purpose of sending PVIs.
+guest_uuid is used to identify the guest that the interrupt will be sent to.
+guest_gsi identifies the interrupt source of that guest.
+
+The PVI hypercall handler in KVM iterates the VM list (the vm_list field in
+the kvm struct), finds the guest with the passed guest_uuid, and injects an
+interrupt to the guest with the guest_gsi number.
+
+Finally, it's about the permission of sending PVI from one guest to another.
+In the PVI setup phase, the PVI receiver should get the sender's UUID (e.g. via
+the vhost-user protocol extension implemented between QEMUs), and pass it to KVM.
+Two new fields will be added to the struct kvm{ }:
+
++uuid_t uuid; // the guest uuid
++uuid_t pvi_sender_uuid[MAX_NUM]; // the sender's uuid should be registered here
+
+PVI will not be injected to the receiver guest if the sender's uuid does not appear 
+in the receiver's pvi_sender_uuid table.
+
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 33 lines · Wei Wang

PV interrupts (PVI) enables a guest to send interrupts to another via hypercalls.

---
 pv_interrupt_controller.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 pv_interrupt_controller.c
pv_interrupt_controller.c new file +17 -0
new file mode 100644
index 0000000..5f2431d
@@ -0,0 +1,27 @@
+
+The pv interrupt (PVI) hypercall is proposed to support one guest sending
+interrupts to another guest using hypercalls. The following pseduocode shows how
+a PVI is sent from the guest:
+
+#define KVM_HC_PVI 9
+kvm_hypercall2(KVM_HC_PVI, guest_uuid, guest_gsi);
+
+The new hypercall number, KVM_HC_PVI, is used for the purpose of sending PVIs.
+guest_uuid is used to identify the guest that the interrupt will be sent to.
+guest_gsi identifies the interrupt source of that guest.
+
+The PVI hypercall handler in KVM iterates the VM list (the vm_list field in
+the kvm struct), finds the guest with the passed guest_uuid, and injects an
+interrupt to the guest with the guest_gsi number.
+
+Finally, it's about the permission of sending PVI from one guest to another.

pv_interrupt_controller.c line 27

Quoted 10 lines
pv_interrupt_controller.c new file +10 -0
+In the PVI setup phase, the PVI receiver should get the sender's UUID (e.g. via
+the vhost-user protocol extension implemented between QEMUs), and pass it to KVM.
+Two new fields will be added to the struct kvm{ }:
+
++uuid_t uuid; // the guest uuid
++uuid_t pvi_sender_uuid[MAX_NUM]; // the sender's uuid should be registered here
+
+PVI will not be injected to the receiver guest if the sender's uuid does not appear 
+in the receiver's pvi_sender_uuid table.
+

Why would you do that instead of just using the local APIC?...

Paolo

#2 lore raw
Quoted 36 lines · Paolo Bonzini
Quoted 14 lines · Wei Wang

PV interrupts (PVI) enables a guest to send interrupts to another via hypercalls.

---
 pv_interrupt_controller.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 pv_interrupt_controller.c
pv_interrupt_controller.c new renamed from pv_interrupt_controller.c +0 -0

file mode 100644 index 0000000..5f2431d

pv_interrupt_controller.c line 9

Quoted 9 lines
pv_interrupt_controller.c new file +9 -0
@@ -0,0 +1,27 @@
+
+The pv interrupt (PVI) hypercall is proposed to support one guest
+sending interrupts to another guest using hypercalls. The following
+pseduocode shows how a PVI is sent from the guest:
+
+#define KVM_HC_PVI 9
+kvm_hypercall2(KVM_HC_PVI, guest_uuid, guest_gsi);
+
+The new hypercall number, KVM_HC_PVI, is used for the purpose of sending

PVIs.

pv_interrupt_controller.c

Quoted 10 lines
pv_interrupt_controller.c new file +10 -0
+guest_uuid is used to identify the guest that the interrupt will be sent to.
+guest_gsi identifies the interrupt source of that guest.
+
+The PVI hypercall handler in KVM iterates the VM list (the vm_list
+field in the kvm struct), finds the guest with the passed guest_uuid,
+and injects an interrupt to the guest with the guest_gsi number.
+
+Finally, it's about the permission of sending PVI from one guest to another.
+In the PVI setup phase, the PVI receiver should get the sender's UUID
+(e.g. via the vhost-user protocol extension implemented between QEMUs),

and pass it to KVM.

Quoted 13 lines

pv_interrupt_controller.c line 27

Quoted 10 lines
pv_interrupt_controller.c new file +9 -0
+Two new fields will be added to the struct kvm{ }:
+
++uuid_t uuid; // the guest uuid
++uuid_t pvi_sender_uuid[MAX_NUM]; // the sender's uuid should be
++registered here
+
+PVI will not be injected to the receiver guest if the sender's uuid
+does not appear in the receiver's pvi_sender_uuid table.
+

Why would you do that instead of just using the local APIC?...

The interrupt will be delivered to LAPIC - the hypercall hander injects the interrupt via kvm_set_irq(kvm, GSI,..), which finally uses LAPIC, right?

Best,
Wei

maintainer
#3 lore raw
Quoted 5 lines · Wei W
Quoted 1 line

Why would you do that instead of just using the local APIC?...

The interrupt will be delivered to LAPIC - the hypercall hander injects the interrupt via kvm_set_irq(kvm, GSI,..), which finally uses LAPIC, right?

But why do you need that? You can just deliver it to the appropriate local APIC interrupt, there's no need to know the GSI. The guest knows how it has configured the GSIs.

You haven't explained the use case.

Paolo

#4 lore raw
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Wei W
Quoted 1 line

Why would you do that instead of just using the local APIC?...

The interrupt will be delivered to LAPIC - the hypercall hander injects the interrupt via kvm_set_irq(kvm, GSI,..), which finally uses LAPIC, right?

Quoted 5 lines

But why do you need that? You can just deliver it to the appropriate local APIC interrupt, there's no need to know the GSI. The guest knows how it has configured the GSIs.

You haven't explained the use case.

Sure. One example here is to send an interrupt from a virtio driver (e.g. the vhost-pci-net that we are working on) on a guest to a virtio-net device on another guest. In terms of injecting an interrupt to the virtio-net device, should we give the sender the related GSI assigned to the virtio-net device (i.e. the GSI of an RX queue, to notify the virtio-net driver to receive packets from that RX queue)?

Can you please explain more about "just delivering it to the appropriate local APIC"? What would be source of the interrupt that we are injecting to? Thanks.

Best,
Wei

maintainer
#5 lore raw
Quoted 15 lines · Wei W
Quoted 7 lines · Paolo Bonzini
Quoted 5 lines · Wei W
Quoted 1 line

Why would you do that instead of just using the local APIC?...

The interrupt will be delivered to LAPIC - the hypercall hander injects the interrupt via kvm_set_irq(kvm, GSI,..), which finally uses LAPIC, right?

Quoted 5 lines

But why do you need that? You can just deliver it to the appropriate local APIC interrupt, there's no need to know the GSI. The guest knows how it has configured the GSIs.

You haven't explained the use case.

Quoted 7 lines

Sure. One example here is to send an interrupt from a virtio driver (e.g. the vhost-pci-net that we are working on) on a guest to a virtio-net device on another guest. In terms of injecting an interrupt to the virtio-net device, should we give the sender the related GSI assigned to the virtio-net device (i.e. the GSI of an RX queue, to notify the virtio-net driver to receive packets from that RX queue)?

In terms of vhost-pci, a write to an MMIO register on the vhost side (the guest->host doorbell) would trigger an irq on the virtio side (the host->guest doorbell).

There is no need to know GSIs, they are entirely hidden in QEMU.

Paolo

Quoted 6 lines

Can you please explain more about "just delivering it to the appropriate local APIC"? What would be source of the interrupt that we are injecting to? Thanks.

Best, Wei

#6 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 13 lines · Wei W
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Wei W
Quoted 1 line

Why would you do that instead of just using the local APIC?...

The interrupt will be delivered to LAPIC - the hypercall hander injects the interrupt via kvm_set_irq(kvm, GSI,..), which finally uses LAPIC, right?

But why do you need that? You can just deliver it to the appropriate local APIC interrupt, there's no need to know the GSI.
The guest knows how it has configured the GSIs.

Quoted 8 lines
Quoted 1 line

You haven't explained the use case.

Sure. One example here is to send an interrupt from a virtio driver (e.g. the vhost-pci-net that we are working on) on a guest to a virtio-net device on another guest. In terms of injecting an interrupt to the virtio-net device, should we give the sender the related GSI assigned to the virtio-net device (i.e. the GSI of an RX queue, to notify the virtio-net driver to receive packets from that RX queue)?

Quoted 3 lines

In terms of vhost-pci, a write to an MMIO register on the vhost side (the guest-

Quoted 1 line

host doorbell) would trigger an irq on the virtio side (the

host->guest doorbell).

Yes, that's the traditional mechanism - ioeventfd and irqfd. they're fine for the current "guest virtio <->host" notification.

But when it comes to the "guest virtio<-->guest virtio" notification case, it should be clear where the interrupt should go to (e.g. which specific device interrupt it is), rather than just trapping to the host. So, instead of simply trapping to the host by an MMIO write, hypercall gives us the flexibility to pass some parameters.

Quoted 1 line

There is no need to know GSIs, they are entirely hidden in QEMU.

The GSI number is assigned in QEMU. By making use of the traditional irqfd implementation code in QEMU, a virtq's GSI is stored in the irqfd struct - "VirtIOIRQFD->virq", we can pass it or them(the multi-queue case) to the sender. I prefer GSI, because the KVM irq routing table is indexed by GSI. Would this be acceptable? Alternatively, we can pass the vector of the virtq.

Best,
Wei

maintainer
#7 lore raw
Quoted 5 lines · Wei W Wang

When it comes to the "guest virtio<-->guest virtio" notification case, it should be clear where the interrupt should go to (e.g. which specific device interrupt it is), rather than just trapping to the host. So, instead of simply trapping to the host by an MMIO write, hypercall gives us the flexibility to pass some parameters.

What parameters do you need? There is no difference between "which specific device interrupt you are raising" and "which specific virtqueue you are kicking". The latter uses ioeventfd just fine, and VFIO also uses eventfd successfully.

Quoted 6 lines

The GSI number is assigned in QEMU. By making use of the traditional irqfd implementation code in QEMU, a virtq's GSI is stored in the irqfd struct - "VirtIOIRQFD->virq", we can pass it or them(the multi-queue case) to the sender. I prefer GSI, because the KVM irq routing table is indexed by GSI. Would this be acceptable?
Alternatively, we can pass the vector of the virtq.

No, the hypercall will not be accepted in any form. The established protocols for communication between KVM and the outside world, including other KVM instances, are MMIO write and irqfd.

Paolo

#8 lore raw
Quoted 11 lines · Paolo Bonzini
Quoted 5 lines · Wei W Wang

When it comes to the "guest virtio<-->guest virtio" notification case, it should be clear where the interrupt should go to (e.g. which specific device interrupt it is), rather than just trapping to the host. So, instead of simply trapping to the host by an MMIO write, hypercall gives us the flexibility to pass some parameters.

What parameters do you need? There is no difference between "which specific device interrupt you are raising" and "which specific virtqueue you are kicking". The latter uses ioeventfd just fine, and VFIO also uses eventfd successfully.

We need two parameters: destination UUID and GSI, to identify the destination VM and the destination queue interrupt.

Please let me elaborate on the two possible solutions based on the existing eventfd mechanism and the new hypercall mechanism - how can we use them to achieve the notification from virtio1 driver to virtio2 driver (across world contexts). We can't directly deliver interrupts from virtio1 driver to virtio2 driver, so here, for both solutions, we need a trampoline - the host. A uuid field is necessary to be added to the kvm struct, so that the trampoline can know who is who.

Generally, two steps are needed:
Step1: virtio1's driver sends the interrupt request to the trampoline;
Step2: the trampoline sends the interrupt request to virtio2's driver.

*Solution 1. eventfd
Step1: achieved by virtio1's ioeventfd;
Step2: achieved by virtio2's irqfd.

In the setup phase, the trampoline makes a connection between virtio1's ioeventfd and virtio2's irqfd. So, in this solution, we would need a host kernel module to do the trampoline work - connection setup and interrupt request delivery.

*Solution 2. hypercall
Step1: achieved by hypercall
Step2: achieved by interrupt injection with GSI

We only need to patch the hypercall handler to inject the interrupt to the destination.

Pros & Cons:
From the performance point of view, the eventfd solution has a much longer code path (if we go through the whole code path how they are handled), which results in longer latency. From the design point of view, I think using hypercall makes the design simple and straightforward.

Quoted 11 lines
Quoted 4 lines

The GSI number is assigned in QEMU. By making use of the traditional irqfd implementation code in QEMU, a virtq's GSI is stored in the irqfd struct - "VirtIOIRQFD->virq", we can pass it or them(the multi-queue case) to the sender. I prefer GSI, because the KVM irq routing

table is indexed by GSI.

Quoted 2 lines

Would this be acceptable?
Alternatively, we can pass the vector of the virtq.

No, the hypercall will not be accepted in any form. The established protocols for communication between KVM and the outside world, including other KVM instances, are MMIO write and irqfd.

Could you please give more details about why hypercall is not welcomed, given the fact that it has already been implemented in KVM for some usages? Thanks.

Best,
Wei

maintainer
#9 lore raw
Quoted 8 lines · Wei W

Please let me elaborate on the two possible solutions based on the existing eventfd mechanism and the new hypercall mechanism - how can we use them to achieve the notification from virtio1 driver to virtio2 driver (across world contexts). We can't directly deliver interrupts from virtio1 driver to virtio2 driver, so here, for both solutions, we need a trampoline - the host. A uuid field is necessary to be added to the kvm struct, so that the trampoline can know who is who.

This is already problematic. KVM tries really, really hard to avoid any global state across VMs. If you define a global UUID, you'll also have to design how to make it safe against multiple users of KVM, and how it interacts with features like user namespace. And you'll also have to explain it to me, since I'm not at all a security expert. That may be harder than the design. :)

Quoted 4 lines

Generally, two steps are needed:
Step1: virtio1's driver sends the interrupt request to the trampoline;
Step2: the trampoline sends the interrupt request to virtio2's driver.

Quoted 8 lines

*Solution 1. eventfd
Step1: achieved by virtio1's ioeventfd;
Step2: achieved by virtio2's irqfd.

In the setup phase, the trampoline makes a connection between virtio1's ioeventfd and virtio2's irqfd. So, in this solution, we would need a host kernel module to do the trampoline work - connection setup and interrupt request delivery.

No, you don't! The point is that you can pass the same file descriptor to KVM_IOEVENTFD and KVM_IRQFD. The virtio-net VM can pass the irqfd to the vhost-net VM, via the vhost socket. This is exactly how things work for vhost-user. vhost-pci can additionally use the received file descriptor as the ioeventfd.

Quoted 7 lines
Quoted 3 lines

No, the hypercall will not be accepted in any form. The established protocols for communication between KVM and the outside world, including other KVM instances, are MMIO write and irqfd.

Could you please give more details about why hypercall is not welcomed, given the fact that it has already been implemented in KVM for some usages? Thanks.

Well, hypercalls aren't really that common in KVM. :) There are exactly two, and one of them does nothing except force a vmexit.

Anyway, here are four good reasons why this hypercall is not welcome:

1) irqfd seems to be fast enough for VFIO and existing vhost backends, so it should be fast enough for vhost-pci as well;

2) if irqfd is not fast enough, optimizing it would benefit VFIO and existing vhost backends, so we should first look into that anyway;

3) vhost-pci's host part should be basically a vhost-user backend implemented by QEMU. Any deviation from that should be considered very carefully;

4) vhost-pci's first use case should be with DPDK, which does polling anyway, not interrupts.

Paolo

#10 lore raw
Quoted 9 lines · Paolo Bonzini

On 17/10/2016 08:47, Wang, Wei W wrote:
Well, hypercalls aren't really that common in KVM. :) There are exactly two, and one of them does nothing except force a vmexit.

Anyway, here are four good reasons why this hypercall is not welcome:

1) irqfd seems to be fast enough for VFIO and existing vhost backends, so it should be fast enough for vhost-pci as well;

Quoted 9 lines

2) if irqfd is not fast enough, optimizing it would benefit VFIO and existing vhost backends, so we should first look into that anyway;

3) vhost-pci's host part should be basically a vhost-user backend implemented by QEMU. Any deviation from that should be considered very carefully;

4) vhost-pci's first use case should be with DPDK, which does polling anyway, not interrupts.

Thanks Paolo for the comments. I will take your suggestions and send out a new version of the design.

Best,
Wei