qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/3] Make KVM/MSI code device-ID-aware
@ 2015-10-14 15:06 Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 1/3] kvm: Make KVM_CAP_SIGNAL_MSI globally available Pavel Fedin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Pavel Fedin @ 2015-10-14 15:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Paolo Bonzini, Michael S. Tsirkin

On ARM architecture ITS (Interrupt Translation Service), additionally to
normal MSI data, uses also side-band device IDs. This series prepares the
infrastructure to handling them.

This small series is actually an extraction from vITS support RFC
(https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg07074.html).
Nobody reviewed it so far, however some bits of it could actually be
applied early. This series consists only of those parts, which do not
depend on any new unreleased kernel APIs.

v3 => v4:
- Rename msi_requester_id() to pci_requester_id() and move from MSI to PCI
  code

v2 => v3:
- Use official "requester ID" denotion everywhere. Renamed getter function
  and MemTxAttrs field.

v1 => v2:
- Improved commit messages, more explanations
- msi_device_id() function made architecture-specific

Pavel Fedin (3):
  kvm: Make KVM_CAP_SIGNAL_MSI globally available
  hw/pci: Introduce pci_requester_id()
  kvm: Pass PCI device pointer to MSI routing functions

 hw/i386/kvm/pci-assign.c |  9 +++++----
 hw/pci/msi.c             |  2 +-
 hw/vfio/pci.c            | 11 ++++++-----
 hw/virtio/virtio-pci.c   |  5 +++--
 include/exec/memattrs.h  |  4 ++--
 include/hw/pci/pci.h     |  1 +
 include/sysemu/kvm.h     | 14 ++++++++++++--
 kvm-all.c                | 15 ++++++++-------
 kvm-stub.c               |  5 +++--
 stubs/Makefile.objs      |  1 +
 stubs/pci.c              | 16 ++++++++++++++++
 target-arm/Makefile.objs |  1 +
 target-arm/pci.c         | 16 ++++++++++++++++
 13 files changed, 75 insertions(+), 25 deletions(-)
 create mode 100644 stubs/pci.c
 create mode 100644 target-arm/pci.c

-- 
2.4.4

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

* [Qemu-devel] [PATCH v4 1/3] kvm: Make KVM_CAP_SIGNAL_MSI globally available
  2015-10-14 15:06 [Qemu-devel] [PATCH v4 0/3] Make KVM/MSI code device-ID-aware Pavel Fedin
@ 2015-10-14 15:06 ` Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id() Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 3/3] kvm: Pass PCI device pointer to MSI routing functions Pavel Fedin
  2 siblings, 0 replies; 9+ messages in thread
From: Pavel Fedin @ 2015-10-14 15:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Paolo Bonzini, Michael S. Tsirkin

This capability is useful to determine whether we can use KVM ITS
emulation on ARM

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 include/sysemu/kvm.h |  9 +++++++++
 kvm-all.c            | 10 +++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 2a58b4d..d42c464 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -52,6 +52,7 @@ extern bool kvm_msi_via_irqfd_allowed;
 extern bool kvm_gsi_routing_allowed;
 extern bool kvm_gsi_direct_mapping;
 extern bool kvm_readonly_mem_allowed;
+extern bool kvm_direct_msi_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()           (kvm_allowed)
@@ -145,6 +146,13 @@ extern bool kvm_readonly_mem_allowed;
  */
 #define kvm_readonly_mem_enabled() (kvm_readonly_mem_allowed)
 
+/**
+ * kvm_direct_msi_enabled:
+ *
+ * Returns: true if KVM allows direct MSI injection.
+ */
+#define kvm_direct_msi_enabled() (kvm_direct_msi_allowed)
+
 #else
 #define kvm_enabled()           (0)
 #define kvm_irqchip_in_kernel() (false)
@@ -157,6 +165,7 @@ extern bool kvm_readonly_mem_allowed;
 #define kvm_gsi_routing_allowed() (false)
 #define kvm_gsi_direct_mapping() (false)
 #define kvm_readonly_mem_enabled() (false)
+#define kvm_direct_msi_enabled() (false)
 #endif
 
 struct kvm_run;
diff --git a/kvm-all.c b/kvm-all.c
index 0be4615..4931b27 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -93,7 +93,6 @@ struct KVMState
     uint32_t *used_gsi_bitmap;
     unsigned int gsi_count;
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
-    bool direct_msi;
 #endif
     KVMMemoryListener memory_listener;
 };
@@ -111,6 +110,7 @@ bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 bool kvm_vm_attributes_allowed;
+bool kvm_direct_msi_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
     KVM_CAP_INFO(USER_MEMORY),
@@ -979,7 +979,7 @@ void kvm_init_irq_routing(KVMState *s)
     s->irq_routes = g_malloc0(sizeof(*s->irq_routes));
     s->nr_allocated_irq_routes = 0;
 
-    if (!s->direct_msi) {
+    if (!kvm_direct_msi_allowed) {
         for (i = 0; i < KVM_MSI_HASHTAB_SIZE; i++) {
             QTAILQ_INIT(&s->msi_hashtab[i]);
         }
@@ -1113,7 +1113,7 @@ static int kvm_irqchip_get_virq(KVMState *s)
      * number can succeed even though a new route entry cannot be added.
      * When this happens, flush dynamic MSI entries to free IRQ route entries.
      */
-    if (!s->direct_msi && s->irq_routes->nr == s->gsi_count) {
+    if (!kvm_direct_msi_allowed && s->irq_routes->nr == s->gsi_count) {
         kvm_flush_dynamic_msi_routes(s);
     }
 
@@ -1150,7 +1150,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
     struct kvm_msi msi;
     KVMMSIRoute *route;
 
-    if (s->direct_msi) {
+    if (kvm_direct_msi_allowed) {
         msi.address_lo = (uint32_t)msg.address;
         msi.address_hi = msg.address >> 32;
         msi.data = le32_to_cpu(msg.data);
@@ -1598,7 +1598,7 @@ static int kvm_init(MachineState *ms)
 #endif
 
 #ifdef KVM_CAP_IRQ_ROUTING
-    s->direct_msi = (kvm_check_extension(s, KVM_CAP_SIGNAL_MSI) > 0);
+    kvm_direct_msi_allowed = (kvm_check_extension(s, KVM_CAP_SIGNAL_MSI) > 0);
 #endif
 
     s->intx_set_mask = kvm_check_extension(s, KVM_CAP_PCI_2_3);
-- 
2.4.4

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

* [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-14 15:06 [Qemu-devel] [PATCH v4 0/3] Make KVM/MSI code device-ID-aware Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 1/3] kvm: Make KVM_CAP_SIGNAL_MSI globally available Pavel Fedin
@ 2015-10-14 15:06 ` Pavel Fedin
  2015-10-14 16:09   ` Michael S. Tsirkin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 3/3] kvm: Pass PCI device pointer to MSI routing functions Pavel Fedin
  2 siblings, 1 reply; 9+ messages in thread
From: Pavel Fedin @ 2015-10-14 15:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Paolo Bonzini, Michael S. Tsirkin

For GICv3 ITS implementation we are going to use requester IDs in KVM IRQ
routing code. This patch introduces reusable convenient way to obtain this
ID from the device pointer.

Since requester ID is an architecture-specific thing, the function can be
overridden on per-architecture basis. Default stub just returns 0.

MemTxAttrs.stream_id also renamed to requester_id in order to better
reflect semantics of the field.

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 hw/pci/msi.c             |  2 +-
 include/exec/memattrs.h  |  4 ++--
 include/hw/pci/pci.h     |  1 +
 stubs/Makefile.objs      |  1 +
 stubs/pci.c              | 16 ++++++++++++++++
 target-arm/Makefile.objs |  1 +
 target-arm/pci.c         | 16 ++++++++++++++++
 7 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 stubs/pci.c
 create mode 100644 target-arm/pci.c

diff --git a/hw/pci/msi.c b/hw/pci/msi.c
index f9c0484..c1dd531 100644
--- a/hw/pci/msi.c
+++ b/hw/pci/msi.c
@@ -294,7 +294,7 @@ void msi_send_message(PCIDevice *dev, MSIMessage msg)
 {
     MemTxAttrs attrs = {};
 
-    attrs.stream_id = (pci_bus_num(dev->bus) << 8) | dev->devfn;
+    attrs.requester_id = pci_requester_id(dev);
     address_space_stl_le(&dev->bus_master_as, msg.address, msg.data,
                          attrs, NULL);
 }
diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h
index f8537a8..e601061 100644
--- a/include/exec/memattrs.h
+++ b/include/exec/memattrs.h
@@ -35,8 +35,8 @@ typedef struct MemTxAttrs {
     unsigned int secure:1;
     /* Memory access is usermode (unprivileged) */
     unsigned int user:1;
-    /* Stream ID (for MSI for example) */
-    unsigned int stream_id:16;
+    /* Requester ID (for MSI for example) */
+    unsigned int requester_id:16;
 } MemTxAttrs;
 
 /* Bus masters which don't specify any attributes will get this,
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 551cb3d..708dc3a 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -381,6 +381,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);
 void pci_device_set_intx_routing_notifier(PCIDevice *dev,
                                           PCIINTxRoutingNotifier notifier);
 void pci_device_reset(PCIDevice *dev);
+uint16_t pci_requester_id(PCIDevice *dev);
 
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
                                const char *default_model,
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 85e4e81..dbd69a9 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -22,6 +22,7 @@ stub-obj-y += migr-blocker.o
 stub-obj-y += mon-is-qmp.o
 stub-obj-y += mon-printf.o
 stub-obj-y += monitor-init.o
+stub-obj-$(CONFIG_PCI) += pci.o
 stub-obj-y += notify-event.o
 stub-obj-$(CONFIG_SPICE) += qemu-chr-open-spice.o
 stub-obj-y += qtest.o
diff --git a/stubs/pci.c b/stubs/pci.c
new file mode 100644
index 0000000..3b13000
--- /dev/null
+++ b/stubs/pci.c
@@ -0,0 +1,16 @@
+/*
+ * QEMU architecture-specific PCI functions
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Written by Pavel Fedin
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include "hw/pci/pci.h"
+
+uint16_t pci_requester_id(PCIDevice *dev)
+{
+    return 0;
+}
diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs
index 9460b40..7b47434 100644
--- a/target-arm/Makefile.objs
+++ b/target-arm/Makefile.objs
@@ -1,5 +1,6 @@
 obj-y += arm-semi.o
 obj-$(CONFIG_SOFTMMU) += machine.o
+obj-$(CONFIG_PCI) += pci.o
 obj-$(CONFIG_KVM) += kvm.o
 obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
 obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
diff --git a/target-arm/pci.c b/target-arm/pci.c
new file mode 100644
index 0000000..9bd5964
--- /dev/null
+++ b/target-arm/pci.c
@@ -0,0 +1,16 @@
+/*
+ * QEMU ARM specific PCI functions
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Written by Pavel Fedin
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include "hw/pci/pci.h"
+
+uint16_t pci_requester_id(PCIDevice *dev)
+{
+    return (pci_bus_num(dev->bus) << 8) | dev->devfn;
+}
-- 
2.4.4

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

* [Qemu-devel] [PATCH v4 3/3] kvm: Pass PCI device pointer to MSI routing functions
  2015-10-14 15:06 [Qemu-devel] [PATCH v4 0/3] Make KVM/MSI code device-ID-aware Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 1/3] kvm: Make KVM_CAP_SIGNAL_MSI globally available Pavel Fedin
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id() Pavel Fedin
@ 2015-10-14 15:06 ` Pavel Fedin
  2 siblings, 0 replies; 9+ messages in thread
From: Pavel Fedin @ 2015-10-14 15:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Paolo Bonzini, Michael S. Tsirkin

In-kernel ITS emulation on ARM64 will require to supply requester IDs.
These IDs can now be retrieved from the device pointer using new
pci_requester_id() function.

This patch adds pci_dev pointer to KVM GSI routing functions and makes
callers passing it.

x86 architecture does not use requester IDs, but hw/i386/kvm/pci-assign.c
also made passing PCI device pointer instead of NULL for consistency with
the rest of the code.

Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
---
 hw/i386/kvm/pci-assign.c |  9 +++++----
 hw/vfio/pci.c            | 11 ++++++-----
 hw/virtio/virtio-pci.c   |  5 +++--
 include/sysemu/kvm.h     |  5 +++--
 kvm-all.c                |  5 +++--
 kvm-stub.c               |  5 +++--
 6 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 44beee3..f9db250 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -979,7 +979,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
         MSIMessage msg = msi_get_message(pci_dev, 0);
         int virq;
 
-        virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+        virq = kvm_irqchip_add_msi_route(kvm_state, msg, pci_dev);
         if (virq < 0) {
             perror("assigned_dev_update_msi: kvm_irqchip_add_msi_route");
             return;
@@ -1017,7 +1017,7 @@ static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
     }
 
     kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
-                                 msi_get_message(pci_dev, 0));
+                                 msi_get_message(pci_dev, 0), pci_dev);
 }
 
 static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
@@ -1083,7 +1083,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
 
         msg.address = entry->addr_lo | ((uint64_t)entry->addr_hi << 32);
         msg.data = entry->data;
-        r = kvm_irqchip_add_msi_route(kvm_state, msg);
+        r = kvm_irqchip_add_msi_route(kvm_state, msg, pci_dev);
         if (r < 0) {
             return r;
         }
@@ -1602,7 +1602,8 @@ static void assigned_dev_msix_mmio_write(void *opaque, hwaddr addr,
                 msg.data = entry->data;
 
                 ret = kvm_irqchip_update_msi_route(kvm_state,
-                                                   adev->msi_virq[i], msg);
+                                                   adev->msi_virq[i], msg,
+                                                   pci_dev);
                 if (ret) {
                     error_report("Error updating irq routing entry (%d)", ret);
                 }
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index dcabb6d..8fadbcf 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -424,7 +424,7 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
         return;
     }
 
-    virq = kvm_irqchip_add_msi_route(kvm_state, *msg);
+    virq = kvm_irqchip_add_msi_route(kvm_state, *msg, &vdev->pdev);
     if (virq < 0) {
         event_notifier_cleanup(&vector->kvm_interrupt);
         return;
@@ -449,9 +449,10 @@ static void vfio_remove_kvm_msi_virq(VFIOMSIVector *vector)
     event_notifier_cleanup(&vector->kvm_interrupt);
 }
 
-static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg)
+static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg,
+                                     PCIDevice *pdev)
 {
-    kvm_irqchip_update_msi_route(kvm_state, vector->virq, msg);
+    kvm_irqchip_update_msi_route(kvm_state, vector->virq, msg, pdev);
 }
 
 static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
@@ -486,7 +487,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
         if (!msg) {
             vfio_remove_kvm_msi_virq(vector);
         } else {
-            vfio_update_kvm_msi_virq(vector, *msg);
+            vfio_update_kvm_msi_virq(vector, *msg, pdev);
         }
     } else {
         vfio_add_kvm_msi_virq(vdev, vector, msg, true);
@@ -760,7 +761,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
         }
 
         msg = msi_get_message(&vdev->pdev, i);
-        vfio_update_kvm_msi_virq(vector, msg);
+        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
     }
 }
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index e5c406d..f55dd2b 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -590,7 +590,7 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
     int ret;
 
     if (irqfd->users == 0) {
-        ret = kvm_irqchip_add_msi_route(kvm_state, msg);
+        ret = kvm_irqchip_add_msi_route(kvm_state, msg, &proxy->pci_dev);
         if (ret < 0) {
             return ret;
         }
@@ -726,7 +726,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
     if (proxy->vector_irqfd) {
         irqfd = &proxy->vector_irqfd[vector];
         if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) {
-            ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg);
+            ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg,
+                                               &proxy->pci_dev);
             if (ret < 0) {
                 return ret;
             }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index d42c464..4d26571 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -447,8 +447,9 @@ static inline void cpu_clean_state(CPUState *cpu)
     }
 }
 
-int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg);
-int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg);
+int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev);
+int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
+                                 PCIDevice *dev);
 void kvm_irqchip_release_virq(KVMState *s, int virq);
 
 int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter);
diff --git a/kvm-all.c b/kvm-all.c
index 4931b27..4632138 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1189,7 +1189,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
     return kvm_set_irq(s, route->kroute.gsi, 1);
 }
 
-int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
+int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev)
 {
     struct kvm_irq_routing_entry kroute = {};
     int virq;
@@ -1224,7 +1224,8 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
     return virq;
 }
 
-int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
+int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
+                                 PCIDevice *dev)
 {
     struct kvm_irq_routing_entry kroute = {};
 
diff --git a/kvm-stub.c b/kvm-stub.c
index d9ad624..08bcc32 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -115,7 +115,7 @@ int kvm_on_sigbus(int code, void *addr)
 }
 
 #ifndef CONFIG_USER_ONLY
-int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
+int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg, PCIDevice *dev)
 {
     return -ENOSYS;
 }
@@ -128,7 +128,8 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
 {
 }
 
-int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
+int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
+                                 PCIDevice *dev)
 {
     return -ENOSYS;
 }
-- 
2.4.4

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

* Re: [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id() Pavel Fedin
@ 2015-10-14 16:09   ` Michael S. Tsirkin
  2015-10-15  8:54     ` Pavel Fedin
  0 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2015-10-14 16:09 UTC (permalink / raw)
  To: Pavel Fedin; +Cc: Paolo Bonzini, qemu-devel, Peter Maydell

On Wed, Oct 14, 2015 at 06:06:37PM +0300, Pavel Fedin wrote:
> For GICv3 ITS implementation we are going to use requester IDs in KVM IRQ
> routing code. This patch introduces reusable convenient way to obtain this
> ID from the device pointer.
> 
> Since requester ID is an architecture-specific thing, the function can be
> overridden on per-architecture basis. Default stub just returns 0.
> 
> MemTxAttrs.stream_id also renamed to requester_id in order to better
> reflect semantics of the field.
> 
> Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
> ---
>  hw/pci/msi.c             |  2 +-
>  include/exec/memattrs.h  |  4 ++--
>  include/hw/pci/pci.h     |  1 +
>  stubs/Makefile.objs      |  1 +
>  stubs/pci.c              | 16 ++++++++++++++++
>  target-arm/Makefile.objs |  1 +
>  target-arm/pci.c         | 16 ++++++++++++++++
>  7 files changed, 38 insertions(+), 3 deletions(-)
>  create mode 100644 stubs/pci.c
>  create mode 100644 target-arm/pci.c
> 
> diff --git a/hw/pci/msi.c b/hw/pci/msi.c
> index f9c0484..c1dd531 100644
> --- a/hw/pci/msi.c
> +++ b/hw/pci/msi.c
> @@ -294,7 +294,7 @@ void msi_send_message(PCIDevice *dev, MSIMessage msg)
>  {
>      MemTxAttrs attrs = {};
>  
> -    attrs.stream_id = (pci_bus_num(dev->bus) << 8) | dev->devfn;
> +    attrs.requester_id = pci_requester_id(dev);
>      address_space_stl_le(&dev->bus_master_as, msg.address, msg.data,
>                           attrs, NULL);
>  }
> diff --git a/include/exec/memattrs.h b/include/exec/memattrs.h
> index f8537a8..e601061 100644
> --- a/include/exec/memattrs.h
> +++ b/include/exec/memattrs.h
> @@ -35,8 +35,8 @@ typedef struct MemTxAttrs {
>      unsigned int secure:1;
>      /* Memory access is usermode (unprivileged) */
>      unsigned int user:1;
> -    /* Stream ID (for MSI for example) */
> -    unsigned int stream_id:16;
> +    /* Requester ID (for MSI for example) */
> +    unsigned int requester_id:16;
>  } MemTxAttrs;
>  
>  /* Bus masters which don't specify any attributes will get this,
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index 551cb3d..708dc3a 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -381,6 +381,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);
>  void pci_device_set_intx_routing_notifier(PCIDevice *dev,
>                                            PCIINTxRoutingNotifier notifier);
>  void pci_device_reset(PCIDevice *dev);
> +uint16_t pci_requester_id(PCIDevice *dev);
>  
>  PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
>                                 const char *default_model,
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 85e4e81..dbd69a9 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -22,6 +22,7 @@ stub-obj-y += migr-blocker.o
>  stub-obj-y += mon-is-qmp.o
>  stub-obj-y += mon-printf.o
>  stub-obj-y += monitor-init.o
> +stub-obj-$(CONFIG_PCI) += pci.o
>  stub-obj-y += notify-event.o
>  stub-obj-$(CONFIG_SPICE) += qemu-chr-open-spice.o
>  stub-obj-y += qtest.o
> diff --git a/stubs/pci.c b/stubs/pci.c
> new file mode 100644
> index 0000000..3b13000
> --- /dev/null
> +++ b/stubs/pci.c
> @@ -0,0 +1,16 @@
> +/*
> + * QEMU architecture-specific PCI functions
> + *
> + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
> + * Written by Pavel Fedin
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +#include "hw/pci/pci.h"
> +
> +uint16_t pci_requester_id(PCIDevice *dev)
> +{
> +    return 0;
> +}

OK this is now wrong. You should move the logic back here
from target-arm.

> diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs
> index 9460b40..7b47434 100644
> --- a/target-arm/Makefile.objs
> +++ b/target-arm/Makefile.objs
> @@ -1,5 +1,6 @@
>  obj-y += arm-semi.o
>  obj-$(CONFIG_SOFTMMU) += machine.o
> +obj-$(CONFIG_PCI) += pci.o
>  obj-$(CONFIG_KVM) += kvm.o
>  obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
>  obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
> diff --git a/target-arm/pci.c b/target-arm/pci.c
> new file mode 100644
> index 0000000..9bd5964
> --- /dev/null
> +++ b/target-arm/pci.c
> @@ -0,0 +1,16 @@
> +/*
> + * QEMU ARM specific PCI functions
> + *
> + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
> + * Written by Pavel Fedin
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + */
> +#include "hw/pci/pci.h"
> +
> +uint16_t pci_requester_id(PCIDevice *dev)
> +{
> +    return (pci_bus_num(dev->bus) << 8) | dev->devfn;
> +}
> -- 
> 2.4.4

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

* Re: [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-14 16:09   ` Michael S. Tsirkin
@ 2015-10-15  8:54     ` Pavel Fedin
  2015-10-15  9:36       ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Fedin @ 2015-10-15  8:54 UTC (permalink / raw)
  To: 'Michael S. Tsirkin'
  Cc: 'Paolo Bonzini', qemu-devel, 'Peter Maydell'

 Hello!

> > diff --git a/stubs/pci.c b/stubs/pci.c
> > new file mode 100644
> > index 0000000..3b13000
> > --- /dev/null
> > +++ b/stubs/pci.c
> > @@ -0,0 +1,16 @@
> > +/*
> > + * QEMU architecture-specific PCI functions
> > + *
> > + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
> > + * Written by Pavel Fedin
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> > + * See the COPYING file in the top-level directory.
> > + *
> > + */
> > +#include "hw/pci/pci.h"
> > +
> > +uint16_t pci_requester_id(PCIDevice *dev)
> > +{
> > +    return 0;
> > +}
> 
> OK this is now wrong. You should move the logic back here
> from target-arm.

 Thank you very much for quick responses and cooperation, but... Could we discuss a little bit, what you actually want as a result?
This starts to be very inefficient and time-consuming. Every time i redo the whole thing only to hear that "this single line is now
wrong".
 So far, previously you told me that since requester ID is architecture-specific, if should be moved to arch code. Now you tell me
that you want it in stubs... Why? Stubs are something to be replaced. And we won't have the replacement anywhere, because nowadays
no architecture except ARM uses it. And probably it will stay this way forever. The function is very small, and even if we add more
bits for root complex ID, it will stay very small. Why not to have it as inline in include/hw/pci.h? If we ever need to replace it
in future, then we'll move it to stubs and override in target-XXX.
 And, what with other two patches? Actually, all three are independent, i combined them into one series only because they are part
of original bigger series. You didn't have any comments on them, could you ACK them finally in order to simplify things down?

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia

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

* Re: [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-15  8:54     ` Pavel Fedin
@ 2015-10-15  9:36       ` Michael S. Tsirkin
  2015-10-15  9:42         ` Pavel Fedin
  0 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2015-10-15  9:36 UTC (permalink / raw)
  To: Pavel Fedin; +Cc: 'Paolo Bonzini', qemu-devel, 'Peter Maydell'

On Thu, Oct 15, 2015 at 11:54:57AM +0300, Pavel Fedin wrote:
>  Hello!
> 
> > > diff --git a/stubs/pci.c b/stubs/pci.c
> > > new file mode 100644
> > > index 0000000..3b13000
> > > --- /dev/null
> > > +++ b/stubs/pci.c
> > > @@ -0,0 +1,16 @@
> > > +/*
> > > + * QEMU architecture-specific PCI functions
> > > + *
> > > + * Copyright (c) 2015 Samsung Electronics Co., Ltd.
> > > + * Written by Pavel Fedin
> > > + *
> > > + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> > > + * See the COPYING file in the top-level directory.
> > > + *
> > > + */
> > > +#include "hw/pci/pci.h"
> > > +
> > > +uint16_t pci_requester_id(PCIDevice *dev)
> > > +{
> > > +    return 0;
> > > +}
> > 
> > OK this is now wrong. You should move the logic back here
> > from target-arm.
> 
>  Thank you very much for quick responses and cooperation, but... Could we discuss a little bit, what you actually want as a result?
> This starts to be very inefficient and time-consuming. Every time i redo the whole thing only to hear that "this single line is now
> wrong".
>  So far, previously you told me that since requester ID is architecture-specific, if should be moved to arch code.

Sorry about that, it does sometimes take a while and some back and forth
to arrive at the correct approach.

So originally you had an msi_requester_id thing. That didn't mean
anything (maybe outside ARM). So I said put it in ARM then.

But you still had a stub in pci code, and I didn't like that.
Then I went back and actually looked at what it is, to see
whether we can get rid of it completely.

Then I realized it's actually the PCI requester ID.
That, in turn, means it can just be a generic PCI API,
e.g. it's also used for assigning pci-x devices.

> Now you tell me
> that you want it in stubs... Why? Stubs are something to be replaced. And we won't have the replacement anywhere, because nowadays
> no architecture except ARM uses it. And probably it will stay this way forever. The function is very small, and even if we add more
> bits for root complex ID, it will stay very small. Why not to have it as inline in include/hw/pci.h? If we ever need to replace it
> in future, then we'll move it to stubs and override in target-XXX.
>  And, what with other two patches? Actually, all three are independent, i combined them into one series only because they are part
> of original bigger series. You didn't have any comments on them, could you ACK them finally in order to simplify things down?
> 
> Kind regards,
> Pavel Fedin
> Expert Engineer
> Samsung Electronics Research center Russia
> 

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

* Re: [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-15  9:36       ` Michael S. Tsirkin
@ 2015-10-15  9:42         ` Pavel Fedin
  2015-10-15  9:58           ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Pavel Fedin @ 2015-10-15  9:42 UTC (permalink / raw)
  To: 'Michael S. Tsirkin'
  Cc: 'Paolo Bonzini', qemu-devel, 'Peter Maydell'

 Hello!

> Then I realized it's actually the PCI requester ID.
> That, in turn, means it can just be a generic PCI API,
> e.g. it's also used for assigning pci-x devices.

 Ok. So, will it be good if i place it in includes/hw/pci.h as static inline, similar to how it was done in v1?

Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia

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

* Re: [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id()
  2015-10-15  9:42         ` Pavel Fedin
@ 2015-10-15  9:58           ` Michael S. Tsirkin
  0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2015-10-15  9:58 UTC (permalink / raw)
  To: Pavel Fedin; +Cc: 'Paolo Bonzini', qemu-devel, 'Peter Maydell'

On Thu, Oct 15, 2015 at 12:42:06PM +0300, Pavel Fedin wrote:
>  Hello!
> 
> > Then I realized it's actually the PCI requester ID.
> > That, in turn, means it can just be a generic PCI API,
> > e.g. it's also used for assigning pci-x devices.
> 
>  Ok. So, will it be good if i place it in includes/hw/pci.h as static inline, similar to how it was done in v1?
> 
> Kind regards,
> Pavel Fedin
> Expert Engineer
> Samsung Electronics Research center Russia

I think so, yes.

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

end of thread, other threads:[~2015-10-15  9:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-14 15:06 [Qemu-devel] [PATCH v4 0/3] Make KVM/MSI code device-ID-aware Pavel Fedin
2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 1/3] kvm: Make KVM_CAP_SIGNAL_MSI globally available Pavel Fedin
2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 2/3] hw/pci: Introduce pci_requester_id() Pavel Fedin
2015-10-14 16:09   ` Michael S. Tsirkin
2015-10-15  8:54     ` Pavel Fedin
2015-10-15  9:36       ` Michael S. Tsirkin
2015-10-15  9:42         ` Pavel Fedin
2015-10-15  9:58           ` Michael S. Tsirkin
2015-10-14 15:06 ` [Qemu-devel] [PATCH v4 3/3] kvm: Pass PCI device pointer to MSI routing functions Pavel Fedin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).