Skip to contentSkip to conversation

ivshmem: remove msix_write_config

PATCH Superseded Liu Ping Fan 4 participants 16 messages Nov 25, 2012 – Dec 6, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ivshmem: remove msix_write_config

From: Liu Ping Fan <[email protected]>

This logic has been integrated into pci core, so remove it.

---
 hw/ivshmem.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/ivshmem.c +0 -1
index f6dbb21..7c8630c 100644
@@ -629,7 +629,6 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
 				 uint32_t val, int len)
 {
     pci_default_write_config(pci_dev, address, val, len);
-    msix_write_config(pci_dev, address, val, len);
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH v2 2/2 ivshmem: use irqfd to interrupt among VMs

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -1
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
 				 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
Signature · 1 line
1.7.4.4
#2 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 4 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in me being able to test this. I'll follow up as soon as I can.

Quoted 112 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -2
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--

1.7.4.4

#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 9 lines · Cam Macdonell
Quoted 4 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in me being able to test this. I'll follow up as soon as I can.

BTW where can I find the latest guest code for test?
I got the guest code from git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Regards,
Pingfan

Quoted 112 lines
Quoted 112 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -2
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--

1.7.4.4

#14 lore raw
In reply to Liu Ping Fan

ping?

Quoted 24 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

This logic has been integrated into pci core, so remove it.

---
 hw/ivshmem.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/ivshmem.c +0 -2
index f6dbb21..7c8630c 100644
@@ -629,7 +629,6 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
     pci_default_write_config(pci_dev, address, val, len);
-    msix_write_config(pci_dev, address, val, len);
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
--

1.7.4.4

#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

In reply to liu ping fan
Quoted 7 lines · liu ping fan
Quoted 6 lines · Cam Macdonell
Quoted 4 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Quoted 8 lines
Quoted 3 lines

Nice work. Due to a hardware failure, there will be a small delay in me being able to test this. I'll follow up as soon as I can.

BTW where can I find the latest guest code for test?
I got the guest code from git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Hello,

Which device driver are you using?

Cam

Quoted 117 lines

Regards,
Pingfan

Quoted 112 lines
Quoted 112 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -2
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--

1.7.4.4

#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 17 lines · Cam Macdonell
Quoted 7 lines · liu ping fan
Quoted 6 lines · Cam Macdonell
Quoted 4 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Quoted 8 lines
Quoted 3 lines

Nice work. Due to a hardware failure, there will be a small delay in me being able to test this. I'll follow up as soon as I can.

BTW where can I find the latest guest code for test?
I got the guest code from git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Quoted 4 lines

Hello,

Which device driver are you using?

guest-code/kernel_module/standard/kvm_ivshmem.c

Quoted 119 lines

Cam

Quoted 117 lines

Regards,
Pingfan

Quoted 112 lines
Quoted 112 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -2
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--

1.7.4.4

#6 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 18 lines · liu ping fan
Quoted 17 lines · Cam Macdonell
Quoted 15 lines · liu ping fan
Quoted 9 lines · Cam Macdonell
Quoted 4 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in me being able to test this. I'll follow up as soon as I can.

BTW where can I find the latest guest code for test?
I got the guest code from git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Quoted 5 lines
Quoted 4 lines

Hello,

Which device driver are you using?

guest-code/kernel_module/standard/kvm_ivshmem.c

The uio driver is the recommended one, however if you want to use the kvm_ivshmem one and have it working, then feel free to continue.

I had deleted it form the repo, but some users had based solutions off it, so I added it back.

btw, my hardware issue has been resolved, so I'll get to testing your patch soon.

Sincerely,
Cam

Quoted 121 lines
Quoted 120 lines

Cam

Quoted 117 lines

Regards,
Pingfan

Quoted 112 lines
Quoted 112 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -2
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--

1.7.4.4

#7 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

----- Original Message -----

Quoted 28 lines
Quoted 26 lines · liu ping fan
Quoted 24 lines · Cam Macdonell
Quoted 21 lines · liu ping fan
Quoted 4 lines · Cam Macdonell
Quoted 2 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Quoted 8 lines
Quoted 3 lines

Using irqfd, so we can avoid switch between kernel and user when
VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in
me being able to test this. I'll follow up as soon as I can.

BTW where can I find the latest guest code for test?
I got the guest code from
git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits
position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Hello,

Which device driver are you using?

guest-code/kernel_module/standard/kvm_ivshmem.c

The uio driver is the recommended one, however if you want to use the kvm_ivshmem one and have it working, then feel free to continue.

If the uio driver is the recommended one, then can you please post it to lkml? It should be integrated into drivers/virt with an appropriate Kconfig update.

Thanks,
Drew

Quoted 143 lines

I had deleted it form the repo, but some users had based solutions off
it, so I added it back.

btw, my hardware issue has been resolved, so I'll get to testing your patch soon.

Sincerely,
Cam

Quoted 130 lines
Quoted 129 lines

Cam

Quoted 126 lines

Regards,
Pingfan

Quoted 121 lines
Quoted 121 lines
---
 hw/ivshmem.c |   54
 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -1
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void
 *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state,
 n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL,
 NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup
 irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned
 vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t
 address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice
 *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice
 *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);

--
1.7.4.4

#8 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 35 lines · Andrew Jones

----- Original Message -----

Quoted 32 lines
Quoted 30 lines · liu ping fan
Quoted 28 lines · Cam Macdonell
Quoted 14 lines · liu ping fan
Quoted 4 lines · Cam Macdonell
Quoted 2 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Quoted 8 lines
Quoted 3 lines

Using irqfd, so we can avoid switch between kernel and user when
VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in
me being able to test this. I'll follow up as soon as I can.

Quoted 7 lines

BTW where can I find the latest guest code for test?
I got the guest code from
git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id bits
position (the codes conflict with ivshmem spec), it works (I have tested for V1).

Hello,

Which device driver are you using?

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

guest-code/kernel_module/standard/kvm_ivshmem.c

The uio driver is the recommended one, however if you want to use the kvm_ivshmem one and have it working, then feel free to continue.

If the uio driver is the recommended one, then can you please post it to lkml? It should be integrated into drivers/virt with an appropriate Kconfig update.

Sure. Should it go under drivers/virt or drivers/uio? It seems the uio drivers all get grouped together.

Thanks,
Cam

Quoted 147 lines

Thanks,
Drew

Quoted 143 lines

I had deleted it form the repo, but some users had based solutions off
it, so I added it back.

btw, my hardware issue has been resolved, so I'll get to testing your patch soon.

Sincerely,
Cam

Quoted 130 lines
Quoted 129 lines

Cam

Quoted 126 lines

Regards,
Pingfan

Quoted 121 lines
Quoted 121 lines
---
 hw/ivshmem.c |   54
 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +53 -1
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void
 *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state,
 n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL,
 NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup
 irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned
 vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t
 address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice
 *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice
 *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);

--
1.7.4.4

#10 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

In reply to Liu Ping Fan
Quoted 5 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Using irqfd, so we can avoid switch between kernel and user when VMs interrupts each other.

Hi Liu Ping,

With this patch applied I was still seeing transitions to user-level on the receipt of an msi interrupt.

uncomment DEBUG_IVSHMEM in hw/ivshmem.c (and fix one compile error in the debug statement :) )

IVSHMEM: msix initialized (1 vectors)
...
IVSHMEM: interrupt on vector 0x7f2971b1d8d0 0
IVSHMEM: interrupt on vector 0x7f2971b1d8d0 0

if we're using irqfd, this should be avoided. Here's my command-line:

-device ivshmem,chardev=nahanni,msi=on,ioeventfd=on,size=2048,use64=1,role=peer

There are two issues as I see it:
1) irqfd is not being enabled in my tests
2) the defaults handlers are still being added

One difference is that I'm using the UIO driver, which enables PCI using pci_enable_msix as follows

pci_enable_msix(ivs_info->dev, ivs_info->msix_entries,

                    ivs_info->nvectors);

and succeeds

[    2.651253] uio_ivshmem 0000:00:04.0: irq 43 for MSI/MSI-X
[    2.651326] MSI-X enabled

(continued below)

Quoted 62 lines
---
 hw/ivshmem.c |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +35 -0
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 && kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) >= 0) {
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL);
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup irqfd\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;

hw/ivshmem.c static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) · line 672

Quoted 10 lines
hw/ivshmem.c +6 -0
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);

Problem 1) in my tests is_enabled is always 0, so I don't think the irqfds are getting setup

Quoted 37 lines
hw/ivshmem.c +12 -2
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
--
Quoted 2 lines

1.7.4.4

Problem 2)
We'll also have to not add the handlers as below if irqfd is present otherwise we'll get double interrupts, so we'll have to add a check here too.

    /* if MSI is supported we need multiple interrupts */
    if (!ivshmem_has_feature(s, IVSHMEM_MSI)) {
        s->eventfd_table[vector].pdev = &s->dev;
        s->eventfd_table[vector].vector = vector;

        qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
                      ivshmem_event, &s->eventfd_table[vector]);
    } else {
        qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
                      ivshmem_event, s);
    }

Sincerely,
Cam

#15 lore raw
In reply to Liu Ping Fan
Quoted 5 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

This logic has been integrated into pci core, so remove it.

Quoted 19 lines
---
 hw/ivshmem.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
hw/ivshmem.c +0 -2
index f6dbb21..7c8630c 100644
@@ -629,7 +629,6 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
                                 uint32_t val, int len)
 {
     pci_default_write_config(pci_dev, address, val, len);
-    msix_write_config(pci_dev, address, val, len);
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
--

1.7.4.4

#11 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

In reply to Cam Macdonell
Quoted 10 lines · Cam Macdonell

hw/ivshmem.c static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) · line 672

Quoted 7 lines

static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{

hw/ivshmem.c +3 -0
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);

Problem 1) in my tests is_enabled is always 0, so I don't think the irqfds are getting setup

You likely want to call msix_enabled here.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
#9 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

In reply to Cam Macdonell

----- Original Message -----

Quoted 53 lines
Quoted 44 lines · Andrew Jones

----- Original Message -----

Quoted 33 lines
Quoted 31 lines · liu ping fan
Quoted 29 lines · Cam Macdonell
Quoted 14 lines · liu ping fan
Quoted 4 lines · Cam Macdonell
Quoted 2 lines · Liu Ping Fan

From: Liu Ping Fan <[email protected]>

Quoted 8 lines
Quoted 3 lines

Using irqfd, so we can avoid switch between kernel and user when
VMs interrupts each other.

Nice work. Due to a hardware failure, there will be a small delay in
me being able to test this. I'll follow up as soon as I can.

Quoted 9 lines

BTW where can I find the latest guest code for test? I got the guest code from
git://gitorious.org/nahanni/guest-code.git.
But it seems outdated, after fixing the unlocked_ioctl, and vm-id
bits
position (the codes conflict with ivshmem spec), it works (I have
tested for V1).

Hello,

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Which device driver are you using?

guest-code/kernel_module/standard/kvm_ivshmem.c

The uio driver is the recommended one, however if you want to use the
kvm_ivshmem one and have it working, then feel free to continue.

Quoted 6 lines

If the uio driver is the recommended one, then can you please post it
to lkml? It should be integrated into drivers/virt with an appropriate
Kconfig update.

Quoted 2 lines

Sure. Should it go under drivers/virt or drivers/uio? It seems the uio drivers all get grouped together.

Good point. That is the current practice. As there's still only a handful of uio drivers, then I guess it doesn't make sense to try and change that at this point. It seems that it would make more sense to use drivers/uio just for generic uio drivers though, and then the other uio drivers would go under drivers/<type>/uio, e.g. drivers/virt/uio

Drew

Quoted 162 lines

Thanks,
Cam

Quoted 156 lines

Thanks,
Drew

Quoted 152 lines

I had deleted it form the repo, but some users had based solutions off
it, so I added it back.

btw, my hardware issue has been resolved, so I'll get to testing your
patch soon.

Sincerely,
Cam

Quoted 138 lines
Quoted 137 lines

Cam

Quoted 134 lines

Regards,
Pingfan

Quoted 129 lines
Quoted 129 lines
---
 hw/ivshmem.c |   54
 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)
hw/ivshmem.c +2 -0
index 7c8630c..5709e89 100644
@@ -19,6 +19,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "msi.h"
 #include "msix.h"
 #include "kvm.h"
 #include "migration.h"
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
     uint32_t vectors;
     uint32_t features;
     EventfdEntry *eventfd_table;
+    int *vector_virqs;
 
     Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f,

void
*opaque, int version_id)

     return 0;

}

+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,

hw/ivshmem.c +5 -0
+                                     MSIMessage msg)
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    int virq;
+    EventNotifier *n =

&s->peers[s->vm_id].eventfds[vector];

hw/ivshmem.c +3 -0
+
+    virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+    if (virq >= 0 &&

kvm_irqchip_add_irqfd_notifier(kvm_state,
n, virq) >= 0) {

hw/ivshmem.c +2 -0
+        s->vector_virqs[vector] = virq;
+        qemu_chr_add_handlers(s->eventfd_chr[vector], NULL,

NULL, NULL, NULL);

hw/ivshmem.c +6 -0
+    } else if (virq >= 0) {
+        kvm_irqchip_release_virq(kvm_state, virq);
+        error_report("ivshmem, can not setup irqfd\n");
+        return -1;
+    } else {
+        error_report("ivshmem, no enough msi route to setup

irqfd\n");

hw/ivshmem.c +7 -0
+        return -1;
+    }
+
+    return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned

vector)

hw/ivshmem.c +3 -0
+{
+    IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+    EventNotifier *n =

&s->peers[s->vm_id].eventfds[vector];

hw/ivshmem.c +4 -0
+    int virq = s->vector_virqs[vector];
+
+    if (s->vector_virqs[vector] >= 0) {
+        kvm_irqchip_remove_irqfd_notifier(kvm_state, n,

virq);

hw/ivshmem.c +10 -0
+        kvm_irqchip_release_virq(kvm_state, virq);
+        s->vector_virqs[vector] = -1;
+    }
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev,
 uint32_t
 address,
                                 uint32_t val, int len)
 {
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
+    if (!was_enabled && is_enabled) {
+        msix_set_vector_notifiers(pci_dev,

ivshmem_vector_use,

hw/ivshmem.c +10 -1
+            ivshmem_vector_release);
+    } else if (was_enabled && !is_enabled) {
+        msix_unset_vector_notifiers(pci_dev);
+    }
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
     uint8_t *pci_conf;
+    int i;
 
     if (s->sizearg == NULL)
         s->ivshmem_size = 4 << 20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice
 *dev)
     }
 
     s->dev.config_write = ivshmem_write_config;
-
+    s->vector_virqs = g_new0(int, s->vectors);
+    for (i = 0; i < s->vectors; i++) {
+        s->vector_virqs[i] = -1;
+    }
     return 0;
 }
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice
 *dev)
         migrate_del_blocker(s->migration_blocker);
         error_free(s->migration_blocker);
     }
+    g_free(s->vector_virqs);
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);

--
1.7.4.4

#12 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Cam Macdonell
Quoted 7 lines

static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{

hw/ivshmem.c +3 -0
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
Quoted 4 lines
Quoted 2 lines

Problem 1) in my tests is_enabled is always 0, so I don't think the irqfds are getting setup

You likely want to call msix_enabled here.

Yup, that gets it working.

Liu Ping, can you update the patch to use msix_enabled()?

Also, it seems that with irqfd enabled the user-level handlers are not triggered, but it may still be a better idea to not add the user-level handlers to the char devices at all if irqfd is enabled.

Cam

Quoted 7 lines

Jan

--
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux

#13 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

Quoted 10 lines · Cam Macdonell
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Cam Macdonell
Quoted 7 lines

static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{

hw/ivshmem.c +3 -0
+    bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
     pci_default_write_config(pci_dev, address, val, len);
+    is_enabled = msi_enabled(pci_dev);
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Problem 1) in my tests is_enabled is always 0, so I don't think the irqfds are getting setup

You likely want to call msix_enabled here.

Yup, that gets it working.

Liu Ping, can you update the patch to use msix_enabled()?

:-) , I just finish my test on uio before reading this

Quoted 4 lines

Also, it seems that with irqfd enabled the user-level handlers are not triggered, but it may still be a better idea to not add the user-level handlers to the char devices at all if irqfd is enabled.

Here, in ivshmem_vector_use(), qemu_chr_add_handlers(s->eventfd_chr[vector], NULL, NULL, NULL, NULL) serves this purpose. When irqfd enabled, the fake_irqfd will be removed from eventfd's listeners.

I will fix the msix_enabled, and send out next version.

Regards,
Pingfan

Quoted 9 lines

Cam

Quoted 7 lines

Jan

--
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux