Skip to contentSkip to conversation

QEMU VFIO device assignment

RFC PATCH Superseded Alex Williamson 4 participants 32 messages Jul 11, 2010 – Jul 12, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover QEMU VFIO device assignment

The following series implements QEMU device assignment using the proposed VFIO/UIOMMU kernel interfaces. See the last patch for further vfio description. I've tested this on the v2 VFIO patch, with a number of fixes hacked in along the way. I'll update when Tom releases a new version of VFIO. Hopefully this will provide some support for the usefulness of such an interfaces. Thanks,

Alex

---

Alex Williamson (5):
VFIO based device assignment
APIC/IOAPIC EOI callback
RAM API: Make use of it for x86 PC
Minimal RAM API support
qemu_ram_map/unmap: Allow pre-allocated space to be mapped

 Makefile.target |    2 
 cpu-common.h    |    5 
 exec.c          |   56 ++
 hw/apic.c       |   18 +
 hw/apic.h       |    4 
 hw/ioapic.c     |   29 +
 hw/linux-vfio.h |  200 ++++++++
 hw/pc.c         |   12 -
 hw/pc.h         |   12 -
 hw/vfio.c       | 1295 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/vfio.h       |   90 ++++
 memory.c        |   77 +++
 memory.h        |   23 +
 13 files changed, 1812 insertions(+), 11 deletions(-)
 create mode 100644 hw/linux-vfio.h
 create mode 100644 hw/vfio.c
 create mode 100644 hw/vfio.h
 create mode 100644 memory.c
 create mode 100644 memory.h
#1 lore raw

RFC PATCH 1/5 qemu_ram_map/unmap: Allow pre-allocated space to be mapped

For assigned devices, we want to map the PCI BARs into the VM address space. This is just like mapping an option ROM except the host backing is an mmap area instead of a chunk of vmalloc memory. This allow registration and removal of such areas.

---

 cpu-common.h |    3 +++
 exec.c       |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)
cpu-common.h +3 -0
index 71e7933..8d03f4e 100644
@@ -40,7 +40,10 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
 }
 
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
+ram_addr_t qemu_ram_map(DeviceState *dev, const char *name,
+                        ram_addr_t size, void *host);
 ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size);
+void qemu_ram_unmap(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
 /* This should only be used for ram local to a device.  */
 void *qemu_get_ram_ptr(ram_addr_t addr);
exec.c +56 -0

68 lines not on this page · raw message

#2 lore raw

RFC PATCH 2/5 Minimal RAM API support

In reply to Alex Williamson

This adds a minimum chunk of Anthony's RAM API support so that we can identify actual VM RAM versus all the other things that make use of qemu_ram_alloc.

---

 Makefile.target |    1 +
 cpu-common.h    |    2 +
 memory.c        |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 memory.h        |   23 ++++++++++++++++
 4 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 memory.c
 create mode 100644 memory.h
Makefile.target +1 -0
index 7489910..0c1b916 100644
@@ -173,6 +173,7 @@ obj-$(CONFIG_VIRTFS) += virtio-9p.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
+obj-y += memory.o
 LIBS+=-lz
 
 QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
cpu-common.h +2 -0
index 8d03f4e..7e76f9d 100644
@@ -23,6 +23,8 @@
 /* address in the RAM (different from a physical address) */
 typedef unsigned long ram_addr_t;
 
+#include "memory.h"
+
 /* memory API */
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
memory.c new file +77 -0

77 lines not on this page · raw message

memory.h new file +23 -0
new file mode 100644
index 0000000..91e552e
@@ -0,0 +1,23 @@
+#ifndef QEMU_MEMORY_H
+#define QEMU_MEMORY_H
+
+#include "qemu-common.h"
+#include "cpu-common.h"
+
+typedef struct QemuRamSlot {
+    target_phys_addr_t start_addr;
+    ram_addr_t size;
+    ram_addr_t offset;
+    void *host;
+    QLIST_ENTRY(QemuRamSlot) next;
+} QemuRamSlot;
+
+typedef struct QemuRamSlots {
+    QLIST_HEAD(slots, QemuRamSlot) slots;
+} QemuRamSlots;
+extern QemuRamSlots ram_slots;
+
+void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
+                       ram_addr_t phys_offset);
+void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size);
+#endif
#3 lore raw

Re: [RFC PATCH 2/5] Minimal RAM API support

Quoted 5 lines · Alex Williamson

This adds a minimum chunk of Anthony's RAM API support so that we can identify actual VM RAM versus all the other things that make use of qemu_ram_alloc.

Oops, I'm making up email address now ;)

Quoted 148 lines

---

 Makefile.target |    1 +
 cpu-common.h    |    2 +
 memory.c        |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 memory.h        |   23 ++++++++++++++++
 4 files changed, 103 insertions(+), 0 deletions(-)
 create mode 100644 memory.c
 create mode 100644 memory.h
Makefile.target +1 -0
index 7489910..0c1b916 100644
@@ -173,6 +173,7 @@ obj-$(CONFIG_VIRTFS) += virtio-9p.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
+obj-y += memory.o
 LIBS+=-lz
 
 QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
cpu-common.h +2 -0
index 8d03f4e..7e76f9d 100644
@@ -23,6 +23,8 @@
 /* address in the RAM (different from a physical address) */
 typedef unsigned long ram_addr_t;
 
+#include "memory.h"
+
 /* memory API */
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
memory.c new file +77 -0
new file mode 100644
index 0000000..f5f9273
@@ -0,0 +1,77 @@
+/*
+ *  virtual page mapping and translated block handling
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "memory.h"
+
+QemuRamSlots ram_slots = { .slots = QLIST_HEAD_INITIALIZER(ram_slots) };
+
+static QemuRamSlot *qemu_ram_find_slot(target_phys_addr_t start_addr,
+                                       ram_addr_t size)
+{
+    QemuRamSlot *slot;
+
+    QLIST_FOREACH(slot, &ram_slots.slots, next) {
+        if (slot->start_addr == start_addr && slot->size == size) {
+            return slot;
+        }
+
+        if ((start_addr - slot->start_addr < slot->size) ||
+            (start_addr + size - slot->start_addr < slot->size))
+            abort();
+    }
+
+    return NULL;
+}
+
+void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
+                       ram_addr_t phys_offset)
+{
+    QemuRamSlot *slot;
+
+    if (!size)
+        return;
+
+    slot = qemu_ram_find_slot(start_addr, size);
+    assert(slot == NULL);
+
+    slot = qemu_mallocz(sizeof(QemuRamSlot));
+
+    slot->start_addr = start_addr;
+    slot->size = size;
+    slot->offset = phys_offset;
+
+    QLIST_INSERT_HEAD(&ram_slots.slots, slot, next);
+
+    cpu_register_physical_memory(slot->start_addr, slot->size, slot->offset);
+}
+
+void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size)
+{
+    QemuRamSlot *slot;
+
+    if (!size)
+        return;
+
+    slot = qemu_ram_find_slot(start_addr, size);
+    assert(slot != NULL);
+
+    QLIST_REMOVE(slot, next);
+    cpu_register_physical_memory(start_addr, size, IO_MEM_UNASSIGNED);
+
+    return;
+}
memory.h new file +23 -0
new file mode 100644
index 0000000..91e552e
@@ -0,0 +1,23 @@
+#ifndef QEMU_MEMORY_H
+#define QEMU_MEMORY_H
+
+#include "qemu-common.h"
+#include "cpu-common.h"
+
+typedef struct QemuRamSlot {
+    target_phys_addr_t start_addr;
+    ram_addr_t size;
+    ram_addr_t offset;
+    void *host;
+    QLIST_ENTRY(QemuRamSlot) next;
+} QemuRamSlot;
+
+typedef struct QemuRamSlots {
+    QLIST_HEAD(slots, QemuRamSlot) slots;
+} QemuRamSlots;
+extern QemuRamSlots ram_slots;
+
+void qemu_ram_register(target_phys_addr_t start_addr, ram_addr_t size,
+                       ram_addr_t phys_offset);
+void qemu_ram_unregister(target_phys_addr_t start_addr, ram_addr_t size);
+#endif
#4 lore raw

Re: [RFC PATCH 2/5] Minimal RAM API support

In reply to Alex Williamson
Quoted 12 lines · Alex Williamson

This adds a minimum chunk of Anthony's RAM API support so that we can identify actual VM RAM versus all the other things that make use of qemu_ram_alloc.

  typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
memory.c new file +0 -0
new file mode 100644
index 0000000..f5f9273

memory.c line 4

Quoted 4 lines
memory.c new file +4 -0
@@ -0,0 +1,77 @@
+/*
+ *  virtual page mapping and translated block handling
+ *
+ *  Copyright (c) 2003 Fabrice Bellard

Really? Looks like new code.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#5 lore raw

Re: [RFC PATCH 2/5] Minimal RAM API support

Quoted 5 lines · Avi Kivity
Quoted 4 lines · Alex Williamson

This adds a minimum chunk of Anthony's RAM API support so that we can identify actual VM RAM versus all the other things that make use of qemu_ram_alloc.

Quoted 14 lines

memory.c line 4

Quoted 12 lines
  typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
memory.c new file +4 -0
new file mode 100644
index 0000000..f5f9273
@@ -0,0 +1,77 @@
+/*
+ *  virtual page mapping and translated block handling
+ *
+ *  Copyright (c) 2003 Fabrice Bellard

Really? Looks like new code.

Yeah, I just stole the copyright Anthony used for this file.

#6 lore raw

Re: [RFC PATCH 2/5] Minimal RAM API support

Quoted 7 lines · Alex Williamson
Quoted 4 lines

Really? Looks like new code.

Yeah, I just stole the copyright Anthony used for this file.

Traditionally, one steals the code and updates the attributions, not the other way round.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#7 lore raw

RFC PATCH 3/5 RAM API: Make use of it for x86 PC

In reply to Alex Williamson

Register the actual VM RAM using the new API

---

 hw/pc.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
hw/pc.c +6 -6
index a96187f..b9ce6ae 100644
@@ -911,13 +911,13 @@ void pc_memory_init(ram_addr_t ram_size,
     /* allocate RAM */
     ram_addr = qemu_ram_alloc(NULL, "pc.ram",
                               below_4g_mem_size + above_4g_mem_size);
-    cpu_register_physical_memory(0, 0xa0000, ram_addr);
-    cpu_register_physical_memory(0x100000,
-                 below_4g_mem_size - 0x100000,
-                 ram_addr + 0x100000);
+
+    qemu_ram_register(0, 0xa0000, ram_addr);
+    qemu_ram_register(0x100000, below_4g_mem_size - 0x100000,
+                      ram_addr + 0x100000);
 #if TARGET_PHYS_ADDR_BITS > 32
-    cpu_register_physical_memory(0x100000000ULL, above_4g_mem_size,
-                                 ram_addr + below_4g_mem_size);
+    qemu_ram_register(0x100000000ULL, above_4g_mem_size,
+                      ram_addr + below_4g_mem_size);
 #endif
 
     /* BIOS load */
#8 lore raw

RFC PATCH 4/5 APIC/IOAPIC EOI callback

In reply to Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

---

 hw/apic.c   |   18 ++++++++++++++++--
 hw/apic.h   |    4 ++++
 hw/ioapic.c |   29 +++++++++++++++++++++++++++--
 hw/pc.h     |   12 +++++++++++-
 4 files changed, 58 insertions(+), 5 deletions(-)
hw/apic.c +16 -2
index d686b51..8f512df 100644
@@ -21,6 +21,7 @@
 #include "qemu-timer.h"
 #include "host-utils.h"
 #include "sysbus.h"
+#include "pc.h"
 
 //#define DEBUG_APIC
 //#define DEBUG_COALESCING
@@ -119,6 +120,7 @@ struct APICState {
     int wait_for_sipi;
 };
 
+static uint8_t vector_to_gsi_map[256] = { 0xff };
 static APICState *local_apics[MAX_APICS + 1];
 static int apic_irq_delivered;
 
@@ -308,6 +310,15 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
                      trigger_mode);
 }
 
+void apic_deliver_ioapic_irq(uint8_t dest, uint8_t dest_mode,
+                             uint8_t delivery_mode, uint8_t vector_num,
+                             uint8_t polarity, uint8_t trigger_mode, int gsi)
+{
+    vector_to_gsi_map[vector_num] = gsi;
+    apic_deliver_irq(dest, dest_mode, delivery_mode,
+                     vector_num, polarity, trigger_mode);
+}
+
 void cpu_set_apic_base(DeviceState *d, uint64_t val)
 {
     APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
@@ -432,8 +443,11 @@ static void apic_eoi(APICState *s)
     if (isrv < 0)
         return;
     reset_bit(s->isr, isrv);
-    /* XXX: send the EOI packet to the APIC bus to allow the I/O APIC to
-            set the remote IRR bit for level triggered interrupts. */
+  
+    if (vector_to_gsi_map[isrv] != 0xff) {
+        ioapic_eoi(vector_to_gsi_map[isrv]);
+        vector_to_gsi_map[isrv] = 0xff;
+    }
     apic_update_irq(s);
 }
 
hw/apic.h +4 -0
index 8a0c9d0..59d0e37 100644
@@ -8,6 +8,10 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
                              uint8_t delivery_mode,
                              uint8_t vector_num, uint8_t polarity,
                              uint8_t trigger_mode);
+void apic_deliver_ioapic_irq(uint8_t dest, uint8_t dest_mode,
+                             uint8_t delivery_mode,
+                             uint8_t vector_num, uint8_t polarity,
+                             uint8_t trigger_mode, int gsi);
 int apic_accept_pic_intr(DeviceState *s);
 void apic_deliver_pic_intr(DeviceState *s, int level);
 int apic_get_interrupt(DeviceState *s);
hw/ioapic.c +27 -2
index 5ae21e9..1e2fc2e 100644
@@ -26,6 +26,7 @@
 #include "qemu-timer.h"
 #include "host-utils.h"
 #include "sysbus.h"
+#include "qlist.h"
 
 //#define DEBUG_IOAPIC
 
@@ -61,6 +62,30 @@ struct IOAPICState {
     uint64_t ioredtbl[IOAPIC_NUM_PINS];
 };
 
+static QLIST_HEAD(ioapic_eoi_client_list,
+                  ioapic_eoi_client) ioapic_eoi_client_list =
+                  QLIST_HEAD_INITIALIZER(ioapic_eoi_client_list);
+
+void ioapic_register_eoi_client(ioapic_eoi_client *client)
+{
+    QLIST_INSERT_HEAD(&ioapic_eoi_client_list, client, list);
+}
+
+void ioapic_unregister_eoi_client(ioapic_eoi_client *client)
+{
+    QLIST_REMOVE(client, list);
+}
+
+void ioapic_eoi(int gsi)
+{
+    ioapic_eoi_client *client;
+    QLIST_FOREACH(client, &ioapic_eoi_client_list, list) {
+        if (client->irq == gsi) {
+            client->eoi(client);
+        }
+    }
+}
+
 static void ioapic_service(IOAPICState *s)
 {
     uint8_t i;
@@ -90,8 +115,8 @@ static void ioapic_service(IOAPICState *s)
                 else
                     vector = entry & 0xff;
 
-                apic_deliver_irq(dest, dest_mode, delivery_mode,
-                                 vector, polarity, trig_mode);
+                apic_deliver_ioapic_irq(dest, dest_mode, delivery_mode,
+                                        vector, polarity, trig_mode, i);
             }
         }
     }
hw/pc.h +11 -1
index 63b0249..a88019f 100644
@@ -48,8 +48,18 @@ typedef struct isa_irq_state {
 
 void isa_irq_handler(void *opaque, int n, int level);
 
-/* i8254.c */
+struct ioapic_eoi_client;
+typedef struct ioapic_eoi_client ioapic_eoi_client;
+struct ioapic_eoi_client {
+    void (*eoi)(struct ioapic_eoi_client *client);
+    int irq;
+    QLIST_ENTRY(ioapic_eoi_client) list;
+};
+void ioapic_register_eoi_client(ioapic_eoi_client *client);
+void ioapic_unregister_eoi_client(ioapic_eoi_client *client);
+void ioapic_eoi(int gsi);
 
+/* i8254.c */
 #define PIT_FREQ 1193182
 
 typedef struct PITState PITState;
#9 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#10 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 10 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative. I also need to figure out how to avoid bouncing the vfio interrupt events through qemu, but it's a functional start. Thanks,

Alex

#11 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 11 lines · Alex Williamson
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

Quoted 3 lines

I also need to figure out how to avoid bouncing the vfio interrupt events through qemu, but it's a functional start. Thanks,

I thought the scheduler has/wants to have something that moves the irq to whatever thread it wakes up. With irqfd, it would flow naturally.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#12 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alex Williamson
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

With device asserting the interrupt?
Need to make sure that all possible scenarious work well:

device asserts interrupt
driver clears interrupt
device asserts interrupt
eoi

device asserts interrupt
driver clears interrupt
eoi
device asserts interrupt

etc

Not that I see issues, these are things we need to check.

Quoted 10 lines
Quoted 2 lines

I also need to figure out how to avoid bouncing the vfio interrupt events through qemu, but it's a functional start. Thanks,

I thought the scheduler has/wants to have something that moves the irq to whatever thread it wakes up. With irqfd, it would flow naturally.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#13 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 24 lines · Michael S. Tsirkin
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alex Williamson
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

With device asserting the interrupt?
Need to make sure that all possible scenarious work well:

device asserts interrupt
driver clears interrupt
device asserts interrupt
eoi

Quoted 8 lines

device asserts interrupt
driver clears interrupt
eoi
device asserts interrupt

etc

Not that I see issues, these are things we need to check.

I think those are all protected by host and qemu vfio drivers managing DisINTx. The way I understand it to work now is:

device asserts interrupt
interrupt lands in host vfio driver
host vfio sets DisINTx on the device
host vfio sends eventfd
eventfd lands in qemu vfio, does a qemu_set_irq ... guest processes
guest writes eoi to apic, lands back in qemu vfio driver qemu vfio deasserts qemu interrupt
qemu vfio clears DisINTx

So I don't think there's a race as long as ordering is sane for toggling DisINTx. Thanks,

Alex

#14 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 47 lines · Alex Williamson
Quoted 24 lines · Michael S. Tsirkin
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alex Williamson
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

With device asserting the interrupt?
Need to make sure that all possible scenarious work well:

device asserts interrupt
driver clears interrupt
device asserts interrupt
eoi

Quoted 8 lines

device asserts interrupt
driver clears interrupt
eoi
device asserts interrupt

etc

Not that I see issues, these are things we need to check.

I think those are all protected by host and qemu vfio drivers managing DisINTx. The way I understand it to work now is:

device asserts interrupt
interrupt lands in host vfio driver
host vfio sets DisINTx on the device
host vfio sends eventfd
eventfd lands in qemu vfio, does a qemu_set_irq ... guest processes
guest writes eoi to apic, lands back in qemu vfio driver qemu vfio deasserts qemu interrupt
qemu vfio clears DisINTx

Quoted 5 lines

So I don't think there's a race as long as ordering is sane for toggling DisINTx. Thanks,

Alex

What about threaded interrupts? I think (correct me if I am wrong) that they work like this:

device asserts interrupt
guest disables interrupt
eoi
guest enables interrupt
driver clears interrupt
device asserts interrupt

If so, your code will clear DisINTx immediately which will always get us another host interrupt:
performance will be hurt. I am also not sure we'll not lose interrupts.

It seems we need to track interrupt disable/enable as well, and only clear DisINTx after eoi with interrupts enabled. Not sure what is the interface for this.

Signature · 1 line
MST
#15 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 51 lines · Michael S. Tsirkin
Quoted 50 lines · Alex Williamson
Quoted 24 lines · Michael S. Tsirkin
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alex Williamson
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

With device asserting the interrupt?
Need to make sure that all possible scenarious work well:

device asserts interrupt
driver clears interrupt
device asserts interrupt
eoi

Quoted 8 lines

device asserts interrupt
driver clears interrupt
eoi
device asserts interrupt

etc

Not that I see issues, these are things we need to check.

I think those are all protected by host and qemu vfio drivers managing DisINTx. The way I understand it to work now is:

device asserts interrupt
interrupt lands in host vfio driver
host vfio sets DisINTx on the device
host vfio sends eventfd
eventfd lands in qemu vfio, does a qemu_set_irq ... guest processes
guest writes eoi to apic, lands back in qemu vfio driver qemu vfio deasserts qemu interrupt
qemu vfio clears DisINTx

So I don't think there's a race as long as ordering is sane for toggling DisINTx. Thanks,

Quoted 8 lines
Quoted 2 lines

Alex

What about threaded interrupts? I think (correct me if I am wrong) that they work like this:

device asserts interrupt
guest disables interrupt

Is this the guest manipulating DisINTx itself? I suppose it could be a device dependent disable as well.

Quoted 3 lines

eoi
guest enables interrupt
driver clears interrupt

These two are hopefully reversed or else the driver is expecting to clear and potentially reassert interrupts anyway.

Quoted 6 lines

device asserts interrupt

If so, your code will clear DisINTx immediately which will always get us another host interrupt:
performance will be hurt. I am also not sure we'll not lose interrupts.

Level interrupts are lossy afaik, if it gets cleared but an interrupt condition still exists, it should be reasserted.

Quoted 3 lines

It seems we need to track interrupt disable/enable as well, and only clear DisINTx after eoi with interrupts enabled. Not sure what is the interface for this.

If a driver uses device dependent code to disable interrupts, there's no issue, we'll clear DisINTx, but the device still won't generate an interrupt until the dependent code is re-enabled by the guest (assuming there's no cross talk between DisINTx and device dependent components).

For the case that a guest driver disables via DisINTx, it seems easy to trap and track that. So we get:

device asserts interrupt
guest disables interrupt
(trapped, qemu-vfio sets intx.guest_disabled = 1)
eoi
(qemu-vfio deasserts qemu interrupts, but because of above doesn't clear DisINTx) guest enables interrupt
(allowed to pass through, intx.guest_disabled = 0)
driver clears interrupt
device asserts interrupt

I've already got an intx.pending bit, so I think this just changes the eoi to:

    vdev->intx.pending = 0;
    qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
    if (!vdev->intx.guest_disabled) {
        vfio_unmask_intx(vdev);
    }

Writing the command register DisINTx bit then just gets some kind of:

    if (cmd & PCI_COMMAND_INTX_DISABLE && intx.pending) {
        intx.guest_disabled = 1;
        cmd &= ~PCI_COMMAND_INTX_DISABLE;
    } else if (!(cmd & PCI_COMMAND_INTX_DISABLE) && intx.guest_disabled) {
        intx.guest_disabled = 0;
    }
    ... allow write

That work? Thanks,

Alex

#16 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 55 lines · Alex Williamson
Quoted 54 lines · Michael S. Tsirkin
Quoted 52 lines · Alex Williamson
Quoted 24 lines · Michael S. Tsirkin
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alex Williamson
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alex Williamson

For device assignment, we need to know when the VM writes an end of interrupt to the APIC, which allows us to de-assert the interrupt line and clear the DisINTx bit. Add a new wrapper for ioapic generated interrupts with a callback on eoi and create an interface for drivers to be notified on eoi.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

You aren't going to get this with kvm's in-kernel irqchip, so we need a new interface there.

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

With device asserting the interrupt?
Need to make sure that all possible scenarious work well:

device asserts interrupt
driver clears interrupt
device asserts interrupt
eoi

Quoted 8 lines

device asserts interrupt
driver clears interrupt
eoi
device asserts interrupt

etc

Not that I see issues, these are things we need to check.

I think those are all protected by host and qemu vfio drivers managing DisINTx. The way I understand it to work now is:

device asserts interrupt
interrupt lands in host vfio driver
host vfio sets DisINTx on the device
host vfio sends eventfd
eventfd lands in qemu vfio, does a qemu_set_irq ... guest processes
guest writes eoi to apic, lands back in qemu vfio driver qemu vfio deasserts qemu interrupt
qemu vfio clears DisINTx

So I don't think there's a race as long as ordering is sane for toggling DisINTx. Thanks,

Alex

Quoted 8 lines
Quoted 5 lines

What about threaded interrupts? I think (correct me if I am wrong) that they work like this:

device asserts interrupt
guest disables interrupt

Is this the guest manipulating DisINTx itself? I suppose it could be a device dependent disable as well.

It can manipulate it, so we need to virtualize it, but that's a separate issue.

Quoted 6 lines
Quoted 3 lines

eoi
guest enables interrupt
driver clears interrupt

These two are hopefully reversed or else the driver is expecting to clear and potentially reassert interrupts anyway.

Yes. Sorry.

Quoted 9 lines
Quoted 6 lines

device asserts interrupt

If so, your code will clear DisINTx immediately which will always get us another host interrupt:
performance will be hurt. I am also not sure we'll not lose interrupts.

Level interrupts are lossy afaik, if it gets cleared but an interrupt condition still exists, it should be reasserted.

Yes but I mean we won't interrupt the guest. So it wil lstay disabled forever.

Quoted 41 lines
Quoted 3 lines

It seems we need to track interrupt disable/enable as well, and only clear DisINTx after eoi with interrupts enabled. Not sure what is the interface for this.

If a driver uses device dependent code to disable interrupts, there's no
issue, we'll clear DisINTx, but the device still won't generate an interrupt until the dependent code is re-enabled by the guest (assuming there's no cross talk between DisINTx and device dependent components).

For the case that a guest driver disables via DisINTx, it seems easy to trap and track that. So we get:

device asserts interrupt
guest disables interrupt
(trapped, qemu-vfio sets intx.guest_disabled = 1)
eoi
(qemu-vfio deasserts qemu interrupts, but because of above doesn't clear DisINTx) guest enables interrupt
(allowed to pass through, intx.guest_disabled = 0)
driver clears interrupt
device asserts interrupt

I've already got an intx.pending bit, so I think this just changes the eoi to:

    vdev->intx.pending = 0;
    qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
    if (!vdev->intx.guest_disabled) {
        vfio_unmask_intx(vdev);
    }

Writing the command register DisINTx bit then just gets some kind of:

    if (cmd & PCI_COMMAND_INTX_DISABLE && intx.pending) {
        intx.guest_disabled = 1;
        cmd &= ~PCI_COMMAND_INTX_DISABLE;
    } else if (!(cmd & PCI_COMMAND_INTX_DISABLE) && intx.guest_disabled) {
        intx.guest_disabled = 0;
    }
    ... allow write
Quoted 3 lines

That work? Thanks,

Alex

No, I mean guest OS disables the specific interrupt with disable_irq.

Signature · 1 line
MST
#17 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

In reply to Alex Williamson
Quoted 1 line · Alex Williamson
Quoted 1 line

What about threaded interrupts?

Just to make the point, imagine a nested virt situation which uses current kvm device assignment in guest. Look at the interrupt handler we have there.

Signature · 1 line
Alex
#18 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 6 lines · Michael S. Tsirkin
Quoted 1 line · Alex Williamson
Quoted 1 line

What about threaded interrupts?

Just to make the point, imagine a nested virt situation which uses current kvm device assignment in guest. Look at the interrupt handler we have there.

Is the problem you're worried about this:

guest masks qemu ioapic rte
device interrupt
host vfio DisINTx+
qemu vfio calls qemu_set_irq
...

In that case, the qemu ioapic irr bit is only toggled by qemu_set_irq for level triggered interrupts, so the interrupt will be asserted in the guest when it gets unmasked and we'll get the eoi.

I can't figure out where your other scenario can leave the DisINTx+:

device asserts interrupt
a) DisINTx+ via host vfio
guest disables interrupt
b) DisINTx+ via guest, already set
eoi
c) DisINTx- via qemu vfio
driver clears interrupt
guest enables interrupt
d) DisINTx- via guest
device asserts interrupt

So between c) & d) we're potentially getting more interrupts than we want, but I can't see anywhere that we drop DisINTx. If you have a scenario, let me know. Thanks,

Alex

#19 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

In reply to Avi Kivity
Quoted 3 lines · Avi Kivity
Quoted 1 line

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

I don't think there's a problem.

First, the EOI message is itself asynchronous. While the write to the local APIC is synchronous, effects on the rest of the system are effected using an APIC message, which travels asynchronously.

Second, a component that needs timely information doesn't have to wait; it can read the eventfd and be sure it has seen all EOIs up to now.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#20 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 7 lines · Avi Kivity
Quoted 3 lines · Avi Kivity
Quoted 1 line

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

I don't think there's a problem.

Quoted 8 lines

First, the EOI message is itself asynchronous. While the write to the local APIC is synchronous, effects on the rest of the system are effected using an APIC message, which travels asynchronously.

Second, a component that needs timely information doesn't have to wait; it can read the eventfd and be sure it has seen all EOIs up to now.

I remember we already discussed the use of eventfd for reporting EOI and decided against it, but I don't remember why. :( Was it because if we are going to export EOI to userspace anyway we want to be able to use it for RTC timedrift fixing and for that we need to know what CPU called EOI and eventfd can't provide that?

--
Gleb.

#21 lore raw

Re: [RFC PATCH 4/5] APIC/IOAPIC EOI callback

Quoted 19 lines · Gleb Natapov
Quoted 8 lines · Avi Kivity
Quoted 4 lines · Avi Kivity
Quoted 2 lines

Registering an eventfd for the eoi seems like a reasonable alternative.

I'm worried about that racing (with what?)

I don't think there's a problem.

Quoted 9 lines

First, the EOI message is itself asynchronous. While the write to the local APIC is synchronous, effects on the rest of the system are effected using an APIC message, which travels asynchronously.

Second, a component that needs timely information doesn't have to wait; it can read the eventfd and be sure it has seen all EOIs up to now.

Quoted 6 lines

I remember we already discussed the use of eventfd for reporting EOI and decided against it, but I don't remember why. :( Was it because if we are going to export EOI to userspace anyway we want to be able to use it for RTC timedrift fixing and for that we need to know what CPU called EOI and eventfd can't provide that?

IIRC it was the synchronity argument. But it's bogus: if the RTC wants to know whether an ack occured before it makes some decision, all it has to do is read() the eventfd and find out.

Another issue is which cpu issued the ack. I suppose we can have per-vcpu eventfds, though that's ugly.

Signature · 1 line
error compiling committee.c: too many arguments to function
#22 lore raw

RFC PATCH 5/5 VFIO based device assignment

In reply to Alex Williamson

This patch adds qemu device assignment support using the proposed VFIO/UIOMMU kernel interfaces. The existing KVM-only device assignment code makes use of various pci sysfs files for config space, MMIO BAR mapping, and misc other config items. It then jumps over to KVM-specific ioctls for enabling interrupts and assigning devices to IOMMU domains. Finally, IO-port support uses in/out directly. This is a messy model to support and causes numerous issues when we try to allow unprivileged users to access PCI devices.

VFIO/UIOMMU reduces this to two interfaces, /dev/vfioX and /dev/uiommu. The VFIO device file provides all the necessary support for accessing PCI config space, read/write/mmap BARs (including IO-port space), configuring INTx/MSI/MSI-X interupts and setting up DMA mapping. The UIOMMU interface allows iommu domains to be created, and via vfio, devices can be bound to a domain. This provides an easier model to support (IMHO) and removes the bindings that make current device assignment only useable for KVM enabled guests.

Usage is similar to KVM device assignment. Rather than binding the device to the pci-stub driver, vfio devices need to be bound to the vfio driver. From there, it's a simple matter of specifying the device as:

-device vfio,host=01:00.0

This example requires either root privileges or proper permissions on /dev/uiommu and /dev/vfioX. To support unprivileged operation, the options vfiofd= and uiommufd= are available. Depending on the usage of uiommufd, each guest device can be assigned to the same iommu domain, or to independent iommu domains. In the example above, each device is assigned to a separate iommu domain.

As VFIO has no KVM dependencies, this patch works with or without -enable-kvm. I have successfully used a couple assigned devices in a guest without KVM support, however Michael Tsirkin warns that tcg may not provide atomic operations to memory visible to the passthrough device, which could result in failures for devices depending on such for synchronization.

This patch is functional, but hasn't seen a lot of testing. I've tested 82576 PFs and VFs, an Intel HDA audio device, and UHCI and EHCI USB devices (this actually includes INTx/MSI/MSI-X, 4k aligned MMIO BARs, non-4k aligned MMIO BARs, and IO-Port BARs).

---

 Makefile.target |    1 
 hw/linux-vfio.h |  200 ++++++++
 hw/vfio.c       | 1295 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/vfio.h       |   90 ++++
 4 files changed, 1586 insertions(+), 0 deletions(-)
 create mode 100644 hw/linux-vfio.h
 create mode 100644 hw/vfio.c
 create mode 100644 hw/vfio.h
Makefile.target +1 -0
index 0c1b916..4936d96 100644
@@ -197,6 +197,7 @@ obj-i386-y += vmmouse.o vmport.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
 obj-i386-y += debugcon.o multiboot.o
 obj-i386-y += pc_piix.o
+obj-i386-y += vfio.o
 
 # shared objects
 obj-ppc-y = ppc.o
hw/linux-vfio.h new file +200 -0

200 lines not on this page · raw message

hw/vfio.c new file +1295 -0

1,295 lines not on this page · raw message

hw/vfio.h new file +90 -0

90 lines not on this page · raw message

#23 lore raw

Re: [RFC PATCH 5/5] VFIO based device assignment

Quoted 39 lines · Alex Williamson

This patch adds qemu device assignment support using the proposed VFIO/UIOMMU kernel interfaces. The existing KVM-only device assignment code makes use of various pci sysfs files for config space, MMIO BAR mapping, and misc other config items. It then jumps over to KVM-specific ioctls for enabling interrupts and assigning devices to IOMMU domains. Finally, IO-port support uses in/out directly. This is a messy model to support and causes numerous issues when we try to allow unprivileged users to access PCI devices.

VFIO/UIOMMU reduces this to two interfaces, /dev/vfioX and /dev/uiommu. The VFIO device file provides all the necessary support for accessing PCI config space, read/write/mmap BARs (including IO-port space), configuring INTx/MSI/MSI-X interupts and setting up DMA mapping. The UIOMMU interface allows iommu domains to be created, and via vfio, devices can be bound to a domain. This provides an easier model to support (IMHO) and removes the bindings that make current device assignment only useable for KVM enabled guests.

Usage is similar to KVM device assignment. Rather than binding the device to the pci-stub driver, vfio devices need to be bound to the vfio driver. From there, it's a simple matter of specifying the device as:

-device vfio,host=01:00.0

This example requires either root privileges or proper permissions on /dev/uiommu and /dev/vfioX. To support unprivileged operation, the options vfiofd= and uiommufd= are available. Depending on the usage of uiommufd, each guest device can be assigned to the same iommu domain, or to independent iommu domains. In the example above, each device is assigned to a separate iommu domain.

As VFIO has no KVM dependencies, this patch works with or without -enable-kvm. I have successfully used a couple assigned devices in a guest without KVM support, however Michael Tsirkin warns that tcg may not provide atomic operations to memory visible to the passthrough device, which could result in failures for devices depending on such for synchronization.

Quoted 6 lines

This patch is functional, but hasn't seen a lot of testing. I've tested 82576 PFs and VFs, an Intel HDA audio device, and UHCI and EHCI USB devices (this actually includes INTx/MSI/MSI-X, 4k aligned MMIO BARs, non-4k aligned MMIO BARs, and IO-Port BARs).

Good stuff.

I presume the iommu interface is responsible for page pinning. What about page attributes?

There are two cases:

- snoop capable iommu - can use write-backed RAM, but need to enable snoop. BARs still need to respect page attributes.
- older mmu - need to respect guest memory type; probably cannot be done without kvm.

If the guest maps a BAR or RAM using write-combine memory type, can we reflect that? This may provide a considerable performance benefit.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#24 lore raw

Re: [RFC PATCH 5/5] VFIO based device assignment

Quoted 49 lines · Avi Kivity
Quoted 39 lines · Alex Williamson

This patch adds qemu device assignment support using the proposed VFIO/UIOMMU kernel interfaces. The existing KVM-only device assignment code makes use of various pci sysfs files for config space, MMIO BAR mapping, and misc other config items. It then jumps over to KVM-specific ioctls for enabling interrupts and assigning devices to IOMMU domains. Finally, IO-port support uses in/out directly. This is a messy model to support and causes numerous issues when we try to allow unprivileged users to access PCI devices.

VFIO/UIOMMU reduces this to two interfaces, /dev/vfioX and /dev/uiommu. The VFIO device file provides all the necessary support for accessing PCI config space, read/write/mmap BARs (including IO-port space), configuring INTx/MSI/MSI-X interupts and setting up DMA mapping. The UIOMMU interface allows iommu domains to be created, and via vfio, devices can be bound to a domain. This provides an easier model to support (IMHO) and removes the bindings that make current device assignment only useable for KVM enabled guests.

Usage is similar to KVM device assignment. Rather than binding the device to the pci-stub driver, vfio devices need to be bound to the vfio driver. From there, it's a simple matter of specifying the device as:

-device vfio,host=01:00.0

This example requires either root privileges or proper permissions on /dev/uiommu and /dev/vfioX. To support unprivileged operation, the options vfiofd= and uiommufd= are available. Depending on the usage of uiommufd, each guest device can be assigned to the same iommu domain, or to independent iommu domains. In the example above, each device is assigned to a separate iommu domain.

As VFIO has no KVM dependencies, this patch works with or without -enable-kvm. I have successfully used a couple assigned devices in a guest without KVM support, however Michael Tsirkin warns that tcg may not provide atomic operations to memory visible to the passthrough device, which could result in failures for devices depending on such for synchronization.

Quoted 6 lines

This patch is functional, but hasn't seen a lot of testing. I've tested 82576 PFs and VFs, an Intel HDA audio device, and UHCI and EHCI USB devices (this actually includes INTx/MSI/MSI-X, 4k aligned MMIO BARs, non-4k aligned MMIO BARs, and IO-Port BARs).

Good stuff.

Quoted 1 line

I presume the iommu interface is responsible for page pinning.

Yes, when we do the VFIO_DMA_MAP_IOVA, the vfio driver registers each page, which seems to handle the pinning.

Quoted 5 lines

What
about page attributes?

There are two cases:

Quoted 7 lines

- snoop capable iommu - can use write-backed RAM, but need to enable snoop. BARs still need to respect page attributes.
- older mmu - need to respect guest memory type; probably cannot be done without kvm.

If the guest maps a BAR or RAM using write-combine memory type, can we reflect that? This may provide a considerable performance benefit.

Do we do anything about this today in kvm device assignment? Maybe it's buried in the kernel side bits and I've missed it. I would expect that WC mappings in the guest carry through to host virtual mappings, but maybe we can only do that with kvm. The processor side mappings are independent of the iommu mappings since devices don't care about such things. Thanks,

Alex

#25 lore raw

Re: [RFC PATCH 5/5] VFIO based device assignment

Quoted 11 lines · Alex Williamson
Quoted 11 lines

What
about page attributes?

There are two cases:

- snoop capable iommu - can use write-backed RAM, but need to enable snoop. BARs still need to respect page attributes.
- older mmu - need to respect guest memory type; probably cannot be done without kvm.

Quoted 7 lines
Quoted 3 lines

If the guest maps a BAR or RAM using write-combine memory type, can we reflect that? This may provide a considerable performance benefit.

Do we do anything about this today in kvm device assignment? Maybe it's buried in the kernel side bits and I've missed it. I would expect that WC mappings in the guest carry through to host virtual mappings, but maybe we can only do that with kvm.

Yes, see arch/x86/kvm/mmu.c, set_spte() calling ->get_mt_mask().

Strangely, it's qualified with tdp. Perhaps because of all of the scary errata regarding mismatching memory types for a page.

Quoted 4 lines

The processor side mappings are
independent of the iommu mappings since devices don't care about such things. Thanks,

Yeah.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#26 lore raw
In reply to Alex Williamson
Quoted 8 lines · Alex Williamson

The following series implements QEMU device assignment using the proposed VFIO/UIOMMU kernel interfaces. See the last patch for further vfio description. I've tested this on the v2 VFIO patch, with a number of fixes hacked in along the way. I'll update when Tom releases a new version of VFIO. Hopefully this will provide some support for the usefulness of such an interfaces. Thanks,

What's the plan for supporting this alongside the existing kvm device assignment code?

vfio will only exist in very new kernels, so we have to support the old code for a while to give people chance to adjust (say 12-18 months). Ideally we'd have compatible command line syntax with qemu choosing vfio if available and falling back to kvm device assignment if not.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#27 lore raw
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Alex Williamson

The following series implements QEMU device assignment using the proposed VFIO/UIOMMU kernel interfaces. See the last patch for further vfio description. I've tested this on the v2 VFIO patch, with a number of fixes hacked in along the way. I'll update when Tom releases a new version of VFIO. Hopefully this will provide some support for the usefulness of such an interfaces. Thanks,

Quoted 5 lines

What's the plan for supporting this alongside the existing kvm device assignment code?

vfio will only exist in very new kernels, so we have to support the old code for a while to give people chance to adjust (say 12-18 months).

I was thinking that vfio device assignment might be the qemu acceptable version of device assignment, and we can let kvm style device assignment live out it's remaining time in the qemu-kvm tree, before it gets deprecated.

Quoted 2 lines

Ideally we'd have compatible command line syntax with qemu choosing vfio if available and falling back to kvm device assignment if not.

Ideally, yes, but I'm not sure how how feasible that is. For the command line root user, the syntax is nearly same (s/pci-assign/vfio/), but once we start trying to do libvirt based assignment, passing vfiofd & uiommufd, it will need to know the difference anyway. Thanks,

Alex

#28 lore raw
Quoted 16 lines · Alex Williamson
Quoted 14 lines · Avi Kivity
Quoted 9 lines · Alex Williamson

The following series implements QEMU device assignment using the proposed VFIO/UIOMMU kernel interfaces. See the last patch for further vfio description. I've tested this on the v2 VFIO patch, with a number of fixes hacked in along the way. I'll update when Tom releases a new version of VFIO. Hopefully this will provide some support for the usefulness of such an interfaces. Thanks,

What's the plan for supporting this alongside the existing kvm device assignment code?

Quoted 8 lines
Quoted 3 lines

vfio will only exist in very new kernels, so we have to support the old code for a while to give people chance to adjust (say 12-18 months).

I was thinking that vfio device assignment might be the qemu acceptable version of device assignment, and we can let kvm style device assignment live out it's remaining time in the qemu-kvm tree, before it gets deprecated.

Definitely, the effort to make qemu-kvm device assignment mergable probably isn't worth it.

Quoted 8 lines
Quoted 3 lines

Ideally we'd have compatible command line syntax with qemu choosing vfio if available and falling back to kvm device assignment if not.

Ideally, yes, but I'm not sure how how feasible that is. For the command line root user, the syntax is nearly same (s/pci-assign/vfio/), but once we start trying to do libvirt based assignment, passing vfiofd & uiommufd, it will need to know the difference anyway. Thanks,

I see. Well, we can probably live with two separate invocations, users who assign devices should be savvy or use libvirt.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#29 lore raw
Quoted 32 lines · Avi Kivity
Quoted 16 lines · Alex Williamson
Quoted 14 lines · Avi Kivity
Quoted 9 lines · Alex Williamson

The following series implements QEMU device assignment using the proposed VFIO/UIOMMU kernel interfaces. See the last patch for further vfio description. I've tested this on the v2 VFIO patch, with a number of fixes hacked in along the way. I'll update when Tom releases a new version of VFIO. Hopefully this will provide some support for the usefulness of such an interfaces. Thanks,

What's the plan for supporting this alongside the existing kvm device assignment code?

Quoted 8 lines
Quoted 3 lines

vfio will only exist in very new kernels, so we have to support the old code for a while to give people chance to adjust (say 12-18 months).

I was thinking that vfio device assignment might be the qemu acceptable version of device assignment, and we can let kvm style device assignment live out it's remaining time in the qemu-kvm tree, before it gets deprecated.

Definitely, the effort to make qemu-kvm device assignment mergable probably isn't worth it.

Quoted 3 lines
Quoted 3 lines

Ideally we'd have compatible command line syntax with qemu choosing vfio if available and falling back to kvm device assignment if not.

Quoted 8 lines
Quoted 5 lines

Ideally, yes, but I'm not sure how how feasible that is. For the command line root user, the syntax is nearly same (s/pci-assign/vfio/), but once we start trying to do libvirt based assignment, passing vfiofd & uiommufd, it will need to know the difference anyway. Thanks,

I see. Well, we can probably live with two separate invocations, users who assign devices should be savvy or use libvirt.

One other thing to be aware of is that vfio requires devices to be PCI-2.3 compliant in order to support DisINTx. This allows vfio to support devices making use of shared INTx interrupts, but excludes older devices that users maybe managed to get assigned to an exclusive interrupt for kvm style assignment.

I suppose we might be able to make vfio work with either pci 2.3 devices or older devices with exclusive interrupts if that ends up affecting many users.

Alex

#30 lore raw
Quoted 11 lines · Alex Williamson

One other thing to be aware of is that vfio requires devices to be PCI-2.3 compliant in order to support DisINTx. This allows vfio to support devices making use of shared INTx interrupts, but excludes older devices that users maybe managed to get assigned to an exclusive interrupt for kvm style assignment.

I suppose we might be able to make vfio work with either pci 2.3 devices or older devices with exclusive interrupts if that ends up affecting many users.

PCI 2.3 is already old enough (6-7 years?) that I believe we can require it.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#31 lore raw
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Alex Williamson

One other thing to be aware of is that vfio requires devices to be PCI-2.3 compliant in order to support DisINTx. This allows vfio to support devices making use of shared INTx interrupts, but excludes older devices that users maybe managed to get assigned to an exclusive interrupt for kvm style assignment.

Quoted 5 lines
Quoted 3 lines

I suppose we might be able to make vfio work with either pci 2.3 devices or older devices with exclusive interrupts if that ends up affecting many users.

PCI 2.3 is already old enough (6-7 years?)

I believe it was made a standard in 2002.

Quoted 5 lines

that I believe we can require it.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.