All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management
@ 2018-07-02 16:58 Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability Roman Kagan
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

This series modifies the management of HvSintRoute, which is an
important building block in Hyper-V emulation infrastructure, to make it
easier to maintain and enhance, and paves the way to the more complete
Synthetic Interrupt Controller (SynIC) emulation.

This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
to QEMU cpu_index" series (message-id:
<20180702134156.13404-1-rkagan@virtuozzo.com>).

Roman Kagan (6):
  hyperv_testdev: refactor for better maintainability
  hyperv: cosmetic: g_malloc -> g_new
  hyperv: synic: only setup ack notifier if there's a callback
  hyperv: allow passing arbitrary data to sint ack callback
  hyperv: address HvSintRoute by X86CPU pointer
  hyperv: make HvSintRoute reference-counted

---
For the reference, all of the Hyper-V / VMBus stuff can be found at
https://src.openvz.org/scm/up/qemu

 target/i386/hyperv.h     |  20 ++-----
 hw/misc/hyperv_testdev.c | 116 +++++++++++++++++++--------------------
 target/i386/hyperv.c     |  78 +++++++++++++++++++-------
 3 files changed, 120 insertions(+), 94 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 2/6] hyperv: cosmetic: g_malloc -> g_new Roman Kagan
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

Make hyperv_testdev slightly easier to follow and enhance in future.
For that, put the hyperv sint routes (wrapped in a helper structure) on
a linked list rather than a fixed-size array.  Besides, this way
HvSintRoute can be treated as an opaque structure, allowing for easier
refactoring of the core Hyper-V SynIC code in followup pathches.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 hw/misc/hyperv_testdev.c | 116 +++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 61 deletions(-)

diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c
index bf6bbfa8cf..de07d7e8c3 100644
--- a/hw/misc/hyperv_testdev.c
+++ b/hw/misc/hyperv_testdev.c
@@ -12,6 +12,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/queue.h"
 #include <linux/kvm.h>
 #include "hw/hw.h"
 #include "hw/qdev.h"
@@ -20,12 +21,17 @@
 #include "target/i386/hyperv.h"
 #include "kvm_i386.h"
 
-#define HV_TEST_DEV_MAX_SINT_ROUTES 64
+typedef struct TestSintRoute {
+    QLIST_ENTRY(TestSintRoute) le;
+    uint8_t vp_index;
+    uint8_t sint;
+    HvSintRoute *sint_route;
+} TestSintRoute;
 
 struct HypervTestDev {
     ISADevice parent_obj;
     MemoryRegion sint_control;
-    HvSintRoute *sint_route[HV_TEST_DEV_MAX_SINT_ROUTES];
+    QLIST_HEAD(, TestSintRoute) sint_routes;
 };
 typedef struct HypervTestDev HypervTestDev;
 
@@ -39,88 +45,76 @@ enum {
     HV_TEST_DEV_SINT_ROUTE_SET_SINT
 };
 
-static int alloc_sint_route_index(HypervTestDev *dev)
+static void sint_route_create(HypervTestDev *dev,
+                              uint8_t vp_index, uint8_t sint)
 {
-    int i;
+    TestSintRoute *sint_route;
 
-    for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) {
-        if (dev->sint_route[i] == NULL) {
-            return i;
-        }
-    }
-    return -1;
-}
+    sint_route = g_new0(TestSintRoute, 1);
+    assert(sint_route);
 
-static void free_sint_route_index(HypervTestDev *dev, int i)
-{
-    assert(i >= 0 && i < ARRAY_SIZE(dev->sint_route));
-    dev->sint_route[i] = NULL;
+    sint_route->vp_index = vp_index;
+    sint_route->sint = sint;
+
+    sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL);
+    assert(sint_route->sint_route);
+
+    QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le);
 }
 
-static int find_sint_route_index(HypervTestDev *dev, uint32_t vp_index,
-                                 uint32_t sint)
+static TestSintRoute *sint_route_find(HypervTestDev *dev,
+                                      uint8_t vp_index, uint8_t sint)
 {
-    HvSintRoute *sint_route;
-    int i;
+    TestSintRoute *sint_route;
 
-    for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) {
-        sint_route = dev->sint_route[i];
-        if (sint_route && sint_route->vp_index == vp_index &&
-            sint_route->sint == sint) {
-            return i;
+    QLIST_FOREACH(sint_route, &dev->sint_routes, le) {
+        if (sint_route->vp_index == vp_index && sint_route->sint == sint) {
+            return sint_route;
         }
     }
-    return -1;
+    assert(false);
+    return NULL;
 }
 
-static void hv_synic_test_dev_control(HypervTestDev *dev, uint32_t ctl,
-                                      uint32_t vp_index, uint32_t sint)
+static void sint_route_destroy(HypervTestDev *dev,
+                               uint8_t vp_index, uint8_t sint)
 {
-    int i;
-    HvSintRoute *sint_route;
+    TestSintRoute *sint_route;
 
-    switch (ctl) {
-    case HV_TEST_DEV_SINT_ROUTE_CREATE:
-        i = alloc_sint_route_index(dev);
-        assert(i >= 0);
-        sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL);
-        assert(sint_route);
-        dev->sint_route[i] = sint_route;
-        break;
-    case HV_TEST_DEV_SINT_ROUTE_DESTROY:
-        i = find_sint_route_index(dev, vp_index, sint);
-        assert(i >= 0);
-        sint_route = dev->sint_route[i];
-        kvm_hv_sint_route_destroy(sint_route);
-        free_sint_route_index(dev, i);
-        break;
-    case HV_TEST_DEV_SINT_ROUTE_SET_SINT:
-        i = find_sint_route_index(dev, vp_index, sint);
-        assert(i >= 0);
-        sint_route = dev->sint_route[i];
-        kvm_hv_sint_route_set_sint(sint_route);
-        break;
-    default:
-        break;
-    }
+    sint_route = sint_route_find(dev, vp_index, sint);
+    QLIST_REMOVE(sint_route, le);
+    kvm_hv_sint_route_destroy(sint_route->sint_route);
+    g_free(sint_route);
+}
+
+static void sint_route_set_sint(HypervTestDev *dev,
+                                uint8_t vp_index, uint8_t sint)
+{
+    TestSintRoute *sint_route;
+
+    sint_route = sint_route_find(dev, vp_index, sint);
+
+    kvm_hv_sint_route_set_sint(sint_route->sint_route);
 }
 
 static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data,
                                 uint32_t len)
 {
     HypervTestDev *dev = HYPERV_TEST_DEV(opaque);
-    uint8_t ctl;
+    uint8_t sint = data & 0xFF;
+    uint8_t vp_index = (data >> 8ULL) & 0xFF;
+    uint8_t ctl = (data >> 16ULL) & 0xFF;
 
-    ctl = (data >> 16ULL) & 0xFF;
     switch (ctl) {
     case HV_TEST_DEV_SINT_ROUTE_CREATE:
+        sint_route_create(dev, vp_index, sint);
+        break;
     case HV_TEST_DEV_SINT_ROUTE_DESTROY:
-    case HV_TEST_DEV_SINT_ROUTE_SET_SINT: {
-        uint8_t sint = data & 0xFF;
-        uint8_t vp_index = (data >> 8ULL) & 0xFF;
-        hv_synic_test_dev_control(dev, ctl, vp_index, sint);
+        sint_route_destroy(dev, vp_index, sint);
+        break;
+    case HV_TEST_DEV_SINT_ROUTE_SET_SINT:
+        sint_route_set_sint(dev, vp_index, sint);
         break;
-    }
     default:
         break;
     }
@@ -139,7 +133,7 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp)
     HypervTestDev *dev = HYPERV_TEST_DEV(d);
     MemoryRegion *io = isa_address_space_io(isa);
 
-    memset(dev->sint_route, 0, sizeof(dev->sint_route));
+    QLIST_INIT(&dev->sint_routes);
     memory_region_init_io(&dev->sint_control, OBJECT(dev),
                           &synic_test_sint_ops, dev,
                           "hyperv-testdev-ctl", 4);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 2/6] hyperv: cosmetic: g_malloc -> g_new
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 3/6] hyperv: synic: only setup ack notifier if there's a callback Roman Kagan
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 target/i386/hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index 3065d765ed..47368b77c0 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -88,7 +88,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
     HvSintRoute *sint_route;
     int r, gsi;
 
-    sint_route = g_malloc0(sizeof(*sint_route));
+    sint_route = g_new0(HvSintRoute, 1);
     r = event_notifier_init(&sint_route->sint_set_notifier, false);
     if (r) {
         goto err;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 3/6] hyperv: synic: only setup ack notifier if there's a callback
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 2/6] hyperv: cosmetic: g_malloc -> g_new Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 4/6] hyperv: allow passing arbitrary data to sint ack callback Roman Kagan
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

There's no point setting up an sint ack notifier if no callback is
specified.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 target/i386/hyperv.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index 47368b77c0..acdb0ca9df 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -77,15 +77,14 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier)
     HvSintRoute *sint_route = container_of(notifier, HvSintRoute,
                                            sint_ack_notifier);
     event_notifier_test_and_clear(notifier);
-    if (sint_route->sint_ack_clb) {
-        sint_route->sint_ack_clb(sint_route);
-    }
+    sint_route->sint_ack_clb(sint_route);
 }
 
 HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
                                       HvSintAckClb sint_ack_clb)
 {
     HvSintRoute *sint_route;
+    EventNotifier *ack_notifier;
     int r, gsi;
 
     sint_route = g_new0(HvSintRoute, 1);
@@ -94,13 +93,15 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
         goto err;
     }
 
-    r = event_notifier_init(&sint_route->sint_ack_notifier, false);
-    if (r) {
-        goto err_sint_set_notifier;
-    }
+    ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL;
+    if (ack_notifier) {
+        r = event_notifier_init(ack_notifier, false);
+        if (r) {
+            goto err_sint_set_notifier;
+        }
 
-    event_notifier_set_handler(&sint_route->sint_ack_notifier,
-                               kvm_hv_sint_ack_handler);
+        event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler);
+    }
 
     gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint);
     if (gsi < 0) {
@@ -109,7 +110,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
 
     r = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state,
                                            &sint_route->sint_set_notifier,
-                                           &sint_route->sint_ack_notifier, gsi);
+                                           ack_notifier, gsi);
     if (r) {
         goto err_irqfd;
     }
@@ -123,8 +124,10 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
 err_irqfd:
     kvm_irqchip_release_virq(kvm_state, gsi);
 err_gsi:
-    event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL);
-    event_notifier_cleanup(&sint_route->sint_ack_notifier);
+    if (ack_notifier) {
+        event_notifier_set_handler(ack_notifier, NULL);
+        event_notifier_cleanup(ack_notifier);
+    }
 err_sint_set_notifier:
     event_notifier_cleanup(&sint_route->sint_set_notifier);
 err:
@@ -139,8 +142,10 @@ void kvm_hv_sint_route_destroy(HvSintRoute *sint_route)
                                           &sint_route->sint_set_notifier,
                                           sint_route->gsi);
     kvm_irqchip_release_virq(kvm_state, sint_route->gsi);
-    event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL);
-    event_notifier_cleanup(&sint_route->sint_ack_notifier);
+    if (sint_route->sint_ack_clb) {
+        event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL);
+        event_notifier_cleanup(&sint_route->sint_ack_notifier);
+    }
     event_notifier_cleanup(&sint_route->sint_set_notifier);
     g_free(sint_route);
 }
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 4/6] hyperv: allow passing arbitrary data to sint ack callback
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
                   ` (2 preceding siblings ...)
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 3/6] hyperv: synic: only setup ack notifier if there's a callback Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 5/6] hyperv: address HvSintRoute by X86CPU pointer Roman Kagan
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

Make sint ack callback accept an opaque pointer, that is stored on
sint_route at creation time.

This allows for more convenient interaction with the callback.

Besides, nothing outside hyperv.c should need to know the layout of
HvSintRoute fields any more so its declaration can be removed from the
header.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 target/i386/hyperv.h     | 14 +++-----------
 hw/misc/hyperv_testdev.c |  2 +-
 target/i386/hyperv.c     | 16 ++++++++++++++--
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h
index 00c9b454bb..93f7300dd6 100644
--- a/target/i386/hyperv.h
+++ b/target/i386/hyperv.h
@@ -19,21 +19,13 @@
 #include "qemu/event_notifier.h"
 
 typedef struct HvSintRoute HvSintRoute;
-typedef void (*HvSintAckClb)(HvSintRoute *sint_route);
-
-struct HvSintRoute {
-    uint32_t sint;
-    uint32_t vp_index;
-    int gsi;
-    EventNotifier sint_set_notifier;
-    EventNotifier sint_ack_notifier;
-    HvSintAckClb sint_ack_clb;
-};
+typedef void (*HvSintAckClb)(void *data);
 
 int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
 
 HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
-                                      HvSintAckClb sint_ack_clb);
+                                      HvSintAckClb sint_ack_clb,
+                                      void *sint_ack_clb_data);
 
 void kvm_hv_sint_route_destroy(HvSintRoute *sint_route);
 
diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c
index de07d7e8c3..50dfa6af64 100644
--- a/hw/misc/hyperv_testdev.c
+++ b/hw/misc/hyperv_testdev.c
@@ -56,7 +56,7 @@ static void sint_route_create(HypervTestDev *dev,
     sint_route->vp_index = vp_index;
     sint_route->sint = sint;
 
-    sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL);
+    sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL, NULL);
     assert(sint_route->sint_route);
 
     QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le);
diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index acdb0ca9df..11fd1add2c 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -16,6 +16,16 @@
 #include "hyperv.h"
 #include "hyperv-proto.h"
 
+struct HvSintRoute {
+    uint32_t sint;
+    uint32_t vp_index;
+    int gsi;
+    EventNotifier sint_set_notifier;
+    EventNotifier sint_ack_notifier;
+    HvSintAckClb sint_ack_clb;
+    void *sint_ack_clb_data;
+};
+
 uint32_t hyperv_vp_index(X86CPU *cpu)
 {
     return CPU(cpu)->cpu_index;
@@ -77,11 +87,12 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier)
     HvSintRoute *sint_route = container_of(notifier, HvSintRoute,
                                            sint_ack_notifier);
     event_notifier_test_and_clear(notifier);
-    sint_route->sint_ack_clb(sint_route);
+    sint_route->sint_ack_clb(sint_route->sint_ack_clb_data);
 }
 
 HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
-                                      HvSintAckClb sint_ack_clb)
+                                      HvSintAckClb sint_ack_clb,
+                                      void *sint_ack_clb_data)
 {
     HvSintRoute *sint_route;
     EventNotifier *ack_notifier;
@@ -116,6 +127,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
     }
     sint_route->gsi = gsi;
     sint_route->sint_ack_clb = sint_ack_clb;
+    sint_route->sint_ack_clb_data = sint_ack_clb_data;
     sint_route->vp_index = vp_index;
     sint_route->sint = sint;
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 5/6] hyperv: address HvSintRoute by X86CPU pointer
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
                   ` (3 preceding siblings ...)
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 4/6] hyperv: allow passing arbitrary data to sint ack callback Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 6/6] hyperv: make HvSintRoute reference-counted Roman Kagan
  2018-07-02 20:55 ` [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Eric Blake
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

Use X86CPU pointer to refer to the respective HvSintRoute instead of
vp_index.  This is more convenient and also paves the way for future
enhancements.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 target/i386/hyperv.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index 11fd1add2c..0ce8a7aa2f 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -18,7 +18,7 @@
 
 struct HvSintRoute {
     uint32_t sint;
-    uint32_t vp_index;
+    X86CPU *cpu;
     int gsi;
     EventNotifier sint_set_notifier;
     EventNotifier sint_ack_notifier;
@@ -97,6 +97,12 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
     HvSintRoute *sint_route;
     EventNotifier *ack_notifier;
     int r, gsi;
+    X86CPU *cpu;
+
+    cpu = hyperv_find_vcpu(vp_index);
+    if (!cpu) {
+        return NULL;
+    }
 
     sint_route = g_new0(HvSintRoute, 1);
     r = event_notifier_init(&sint_route->sint_set_notifier, false);
@@ -128,7 +134,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
     sint_route->gsi = gsi;
     sint_route->sint_ack_clb = sint_ack_clb;
     sint_route->sint_ack_clb_data = sint_ack_clb_data;
-    sint_route->vp_index = vp_index;
+    sint_route->cpu = cpu;
     sint_route->sint = sint;
 
     return sint_route;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [Qemu-devel] [PATCH 6/6] hyperv: make HvSintRoute reference-counted
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
                   ` (4 preceding siblings ...)
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 5/6] hyperv: address HvSintRoute by X86CPU pointer Roman Kagan
@ 2018-07-02 16:58 ` Roman Kagan
  2018-07-02 20:55 ` [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Eric Blake
  6 siblings, 0 replies; 12+ messages in thread
From: Roman Kagan @ 2018-07-02 16:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Richard Henderson, Eduardo Habkost, Igor Mammedov, Liran Alon,
	Si-Wei Liu, Karl Heubaum, Boris Ostrovsky, Konrad Rzeszutek Wilk,
	Vijayabhaskar Balakrishna, Liam Merwick, Venu Busireddy

Multiple entities (e.g. VMBus devices) can use the same SINT route.  To
make their lives easier in maintaining SINT route ownership, make it
reference-counted.  Adjust the respective API names accordingly.

Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 target/i386/hyperv.h     | 10 +++++-----
 hw/misc/hyperv_testdev.c |  4 ++--
 target/i386/hyperv.c     | 25 +++++++++++++++++++++----
 3 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h
index 93f7300dd6..af5fc05ea4 100644
--- a/target/i386/hyperv.h
+++ b/target/i386/hyperv.h
@@ -23,11 +23,11 @@ typedef void (*HvSintAckClb)(void *data);
 
 int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
 
-HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
-                                      HvSintAckClb sint_ack_clb,
-                                      void *sint_ack_clb_data);
-
-void kvm_hv_sint_route_destroy(HvSintRoute *sint_route);
+HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
+                                   HvSintAckClb sint_ack_clb,
+                                   void *sint_ack_clb_data);
+void hyperv_sint_route_ref(HvSintRoute *sint_route);
+void hyperv_sint_route_unref(HvSintRoute *sint_route);
 
 int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route);
 
diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c
index 50dfa6af64..d29201b5ee 100644
--- a/hw/misc/hyperv_testdev.c
+++ b/hw/misc/hyperv_testdev.c
@@ -56,7 +56,7 @@ static void sint_route_create(HypervTestDev *dev,
     sint_route->vp_index = vp_index;
     sint_route->sint = sint;
 
-    sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL, NULL);
+    sint_route->sint_route = hyperv_sint_route_new(vp_index, sint, NULL, NULL);
     assert(sint_route->sint_route);
 
     QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le);
@@ -83,7 +83,7 @@ static void sint_route_destroy(HypervTestDev *dev,
 
     sint_route = sint_route_find(dev, vp_index, sint);
     QLIST_REMOVE(sint_route, le);
-    kvm_hv_sint_route_destroy(sint_route->sint_route);
+    hyperv_sint_route_unref(sint_route->sint_route);
     g_free(sint_route);
 }
 
diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c
index 0ce8a7aa2f..4d8ef6f2da 100644
--- a/target/i386/hyperv.c
+++ b/target/i386/hyperv.c
@@ -24,6 +24,7 @@ struct HvSintRoute {
     EventNotifier sint_ack_notifier;
     HvSintAckClb sint_ack_clb;
     void *sint_ack_clb_data;
+    unsigned refcount;
 };
 
 uint32_t hyperv_vp_index(X86CPU *cpu)
@@ -90,9 +91,9 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier)
     sint_route->sint_ack_clb(sint_route->sint_ack_clb_data);
 }
 
-HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
-                                      HvSintAckClb sint_ack_clb,
-                                      void *sint_ack_clb_data)
+HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
+                                   HvSintAckClb sint_ack_clb,
+                                   void *sint_ack_clb_data)
 {
     HvSintRoute *sint_route;
     EventNotifier *ack_notifier;
@@ -136,6 +137,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint,
     sint_route->sint_ack_clb_data = sint_ack_clb_data;
     sint_route->cpu = cpu;
     sint_route->sint = sint;
+    sint_route->refcount = 1;
 
     return sint_route;
 
@@ -154,8 +156,23 @@ err:
     return NULL;
 }
 
-void kvm_hv_sint_route_destroy(HvSintRoute *sint_route)
+void hyperv_sint_route_ref(HvSintRoute *sint_route)
 {
+    sint_route->refcount++;
+}
+
+void hyperv_sint_route_unref(HvSintRoute *sint_route)
+{
+    if (!sint_route) {
+        return;
+    }
+
+    assert(sint_route->refcount > 0);
+
+    if (--sint_route->refcount) {
+        return;
+    }
+
     kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state,
                                           &sint_route->sint_set_notifier,
                                           sint_route->gsi);
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management
  2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
                   ` (5 preceding siblings ...)
  2018-07-02 16:58 ` [Qemu-devel] [PATCH 6/6] hyperv: make HvSintRoute reference-counted Roman Kagan
@ 2018-07-02 20:55 ` Eric Blake
  2018-07-03  7:47   ` [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management] Roman Kagan
  6 siblings, 1 reply; 12+ messages in thread
From: Eric Blake @ 2018-07-02 20:55 UTC (permalink / raw)
  To: Roman Kagan, qemu-devel
  Cc: Vijayabhaskar Balakrishna, Eduardo Habkost, Michael S. Tsirkin,
	Konrad Rzeszutek Wilk, Venu Busireddy, Liran Alon, Igor Mammedov,
	Si-Wei Liu, Paolo Bonzini, Boris Ostrovsky, Karl Heubaum,
	Richard Henderson

On 07/02/2018 11:58 AM, Roman Kagan wrote:
> This series modifies the management of HvSintRoute, which is an
> important building block in Hyper-V emulation infrastructure, to make it
> easier to maintain and enhance, and paves the way to the more complete
> Synthetic Interrupt Controller (SynIC) emulation.
> 
> This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
> to QEMU cpu_index" series (message-id:
> <20180702134156.13404-1-rkagan@virtuozzo.com>).

Rewriting that in a form that patchew can parse:

Based-on: 20180702134156.13404-1-rkagan@virtuozzo.com

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management]
  2018-07-02 20:55 ` [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Eric Blake
@ 2018-07-03  7:47   ` Roman Kagan
  2018-07-03  8:00     ` Fam Zheng
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Kagan @ 2018-07-03  7:47 UTC (permalink / raw)
  To: Eric Blake
  Cc: qemu-devel, Vijayabhaskar Balakrishna, Eduardo Habkost,
	Michael S. Tsirkin, Konrad Rzeszutek Wilk, Venu Busireddy,
	Liran Alon, Igor Mammedov, Si-Wei Liu, Paolo Bonzini,
	Boris Ostrovsky, Karl Heubaum, Richard Henderson

On Mon, Jul 02, 2018 at 03:55:33PM -0500, Eric Blake wrote:
> On 07/02/2018 11:58 AM, Roman Kagan wrote:
> > This series modifies the management of HvSintRoute, which is an
> > important building block in Hyper-V emulation infrastructure, to make it
> > easier to maintain and enhance, and paves the way to the more complete
> > Synthetic Interrupt Controller (SynIC) emulation.
> > 
> > This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
> > to QEMU cpu_index" series (message-id:
> > <20180702134156.13404-1-rkagan@virtuozzo.com>).
> 
> Rewriting that in a form that patchew can parse:
> 
> Based-on: 20180702134156.13404-1-rkagan@virtuozzo.com

Thanks!

Are patchew-recognized headers documented anywhere?

Roman.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management]
  2018-07-03  7:47   ` [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management] Roman Kagan
@ 2018-07-03  8:00     ` Fam Zheng
  2018-07-03 12:48       ` Eric Blake
  0 siblings, 1 reply; 12+ messages in thread
From: Fam Zheng @ 2018-07-03  8:00 UTC (permalink / raw)
  To: Roman Kagan, Eric Blake, qemu-devel, Vijayabhaskar Balakrishna,
	Eduardo Habkost, Michael S. Tsirkin, Konrad Rzeszutek Wilk,
	Venu Busireddy, Liran Alon, Igor Mammedov, Si-Wei Liu,
	Paolo Bonzini, Boris Ostrovsky, Karl Heubaum, Richard Henderson

On Tue, 07/03 10:47, Roman Kagan wrote:
> On Mon, Jul 02, 2018 at 03:55:33PM -0500, Eric Blake wrote:
> > On 07/02/2018 11:58 AM, Roman Kagan wrote:
> > > This series modifies the management of HvSintRoute, which is an
> > > important building block in Hyper-V emulation infrastructure, to make it
> > > easier to maintain and enhance, and paves the way to the more complete
> > > Synthetic Interrupt Controller (SynIC) emulation.
> > > 
> > > This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
> > > to QEMU cpu_index" series (message-id:
> > > <20180702134156.13404-1-rkagan@virtuozzo.com>).
> > 
> > Rewriting that in a form that patchew can parse:
> > 
> > Based-on: 20180702134156.13404-1-rkagan@virtuozzo.com
> 
> Thanks!
> 
> Are patchew-recognized headers documented anywhere?

No dedicated documentation so far becasue the only recognized syntax is this
"^Based-on: $MESSAGE_ID$" line, which is mentioned in

https://wiki.qemu.org/Contribute/SubmitAPatch

There are requests to support more, such as the git base tree information:

https://github.com/patchew-project/patchew/issues/79

and once we get there, we'll find a better place to document these features so
that people can read about it more easily.

Fam

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management]
  2018-07-03  8:00     ` Fam Zheng
@ 2018-07-03 12:48       ` Eric Blake
  2018-07-03 13:36         ` Fam Zheng
  0 siblings, 1 reply; 12+ messages in thread
From: Eric Blake @ 2018-07-03 12:48 UTC (permalink / raw)
  To: Fam Zheng, Roman Kagan, qemu-devel, Vijayabhaskar Balakrishna,
	Eduardo Habkost, Michael S. Tsirkin, Konrad Rzeszutek Wilk,
	Venu Busireddy, Liran Alon, Igor Mammedov, Si-Wei Liu,
	Paolo Bonzini, Boris Ostrovsky, Karl Heubaum

On 07/03/2018 03:00 AM, Fam Zheng wrote:
> On Tue, 07/03 10:47, Roman Kagan wrote:
>> On Mon, Jul 02, 2018 at 03:55:33PM -0500, Eric Blake wrote:
>>> On 07/02/2018 11:58 AM, Roman Kagan wrote:
>>>> This series modifies the management of HvSintRoute, which is an
>>>> important building block in Hyper-V emulation infrastructure, to make it
>>>> easier to maintain and enhance, and paves the way to the more complete
>>>> Synthetic Interrupt Controller (SynIC) emulation.
>>>>
>>>> This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
>>>> to QEMU cpu_index" series (message-id:
>>>> <20180702134156.13404-1-rkagan@virtuozzo.com>).
>>>
>>> Rewriting that in a form that patchew can parse:
>>>
>>> Based-on: 20180702134156.13404-1-rkagan@virtuozzo.com
>>
>> Thanks!
>>
>> Are patchew-recognized headers documented anywhere?
> 
> No dedicated documentation so far becasue the only recognized syntax is this
> "^Based-on: $MESSAGE_ID$" line, which is mentioned in

I seem to recall that "^Based-on: $URL$" also works, when $URL points to 
a message within https://lists.gnu.org/archive/html/qemu-devel/ (at 
least, I've used it in a few cases, rather than further looking up the 
translation from $URL to $MESSAGE_ID myself).

> 
> https://wiki.qemu.org/Contribute/SubmitAPatch
> 
> There are requests to support more, such as the git base tree information:
> 
> https://github.com/patchew-project/patchew/issues/79

And if my recollection was wrong, adding $URL support would be one of 
those requests, and perhaps ought to be given an issue so we don't 
forget it.

> 
> and once we get there, we'll find a better place to document these features so
> that people can read about it more easily.
> 
> Fam
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management]
  2018-07-03 12:48       ` Eric Blake
@ 2018-07-03 13:36         ` Fam Zheng
  0 siblings, 0 replies; 12+ messages in thread
From: Fam Zheng @ 2018-07-03 13:36 UTC (permalink / raw)
  To: Eric Blake
  Cc: Roman Kagan, qemu-devel, Vijayabhaskar Balakrishna,
	Eduardo Habkost, Michael S. Tsirkin, Konrad Rzeszutek Wilk,
	Venu Busireddy, Liran Alon, Igor Mammedov, Si-Wei Liu,
	Paolo Bonzini, Boris Ostrovsky, Karl Heubaum

On Tue, 07/03 07:48, Eric Blake wrote:
> On 07/03/2018 03:00 AM, Fam Zheng wrote:
> > On Tue, 07/03 10:47, Roman Kagan wrote:
> > > On Mon, Jul 02, 2018 at 03:55:33PM -0500, Eric Blake wrote:
> > > > On 07/02/2018 11:58 AM, Roman Kagan wrote:
> > > > > This series modifies the management of HvSintRoute, which is an
> > > > > important building block in Hyper-V emulation infrastructure, to make it
> > > > > easier to maintain and enhance, and paves the way to the more complete
> > > > > Synthetic Interrupt Controller (SynIC) emulation.
> > > > > 
> > > > > This series applies on top of "[PATCH 0/2] hyperv: ensure VP index equal
> > > > > to QEMU cpu_index" series (message-id:
> > > > > <20180702134156.13404-1-rkagan@virtuozzo.com>).
> > > > 
> > > > Rewriting that in a form that patchew can parse:
> > > > 
> > > > Based-on: 20180702134156.13404-1-rkagan@virtuozzo.com
> > > 
> > > Thanks!
> > > 
> > > Are patchew-recognized headers documented anywhere?
> > 
> > No dedicated documentation so far becasue the only recognized syntax is this
> > "^Based-on: $MESSAGE_ID$" line, which is mentioned in
> 
> I seem to recall that "^Based-on: $URL$" also works, when $URL points to a
> message within https://lists.gnu.org/archive/html/qemu-devel/ (at least,
> I've used it in a few cases, rather than further looking up the translation
> from $URL to $MESSAGE_ID myself).
> 
> > 
> > https://wiki.qemu.org/Contribute/SubmitAPatch
> > 
> > There are requests to support more, such as the git base tree information:
> > 
> > https://github.com/patchew-project/patchew/issues/79
> 
> And if my recollection was wrong, adding $URL support would be one of those
> requests, and perhaps ought to be given an issue so we don't forget it.

I've created one now:

https://github.com/patchew-project/patchew/issues/84

Thanks,
Fam

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-07-03 13:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 16:58 [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 2/6] hyperv: cosmetic: g_malloc -> g_new Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 3/6] hyperv: synic: only setup ack notifier if there's a callback Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 4/6] hyperv: allow passing arbitrary data to sint ack callback Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 5/6] hyperv: address HvSintRoute by X86CPU pointer Roman Kagan
2018-07-02 16:58 ` [Qemu-devel] [PATCH 6/6] hyperv: make HvSintRoute reference-counted Roman Kagan
2018-07-02 20:55 ` [Qemu-devel] [PATCH 0/6] hyperv: refactor HvSintRoute management Eric Blake
2018-07-03  7:47   ` [Qemu-devel] patchew header docs [was: Re: [PATCH 0/6] hyperv: refactor HvSintRoute management] Roman Kagan
2018-07-03  8:00     ` Fam Zheng
2018-07-03 12:48       ` Eric Blake
2018-07-03 13:36         ` Fam Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.