Patchwork [v6] kvm irqfd: support direct msimessage to irq translation

login
register
mail settings
Submitter Alexey Kardashevskiy
Date Sept. 3, 2013, 8:08 a.m.
Message ID <1378195705-5143-1-git-send-email-aik@ozlabs.ru>
Download mbox | patch
Permalink /patch/272162/
State New
Headers show

Comments

Alexey Kardashevskiy - Sept. 3, 2013, 8:08 a.m.
On PPC64 systems MSI Messages are translated to system IRQ in a PCI
host bridge. This is already supported for emulated MSI/MSIX but
not for irqfd where the current QEMU allocates IRQ numbers from
irqchip and maps MSIMessages to IRQ in the host kernel.

This adds a new direct mapping flag which tells
the kvm_irqchip_add_msi_route() function that a new VIRQ
should not be allocated, instead the value from MSIMessage::data
should be used. It is up to the platform code to make sure that
this contains a valid IRQ number as sPAPR does in spapr_pci.c.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

---

The patch does not enable this mapping for any platform in this patch
as it is going be done for spapr only on a separate patch which is not
ready to go as it depends on the in-kernel XICS-KVM patchset which is not
in upstream yet.

---
Changes:
v6:
* simplified to a single global flag and putting an IRQ number
in MSIMessage::data

2013/08/07 v5:
* pci_bus_map_msi now has default behaviour which is to call
kvm_irqchip_add_msi_route
* kvm_irqchip_release_virq fixed not crash when there is no routes
---
 include/sysemu/kvm.h |  9 +++++++++
 kvm-all.c            | 13 +++++++++++++
 kvm-stub.c           |  1 +
 3 files changed, 23 insertions(+)
Michael S. Tsirkin - Sept. 3, 2013, 8:17 a.m.
On Tue, Sep 03, 2013 at 06:08:25PM +1000, Alexey Kardashevskiy wrote:
> On PPC64 systems MSI Messages are translated to system IRQ in a PCI
> host bridge. This is already supported for emulated MSI/MSIX but
> not for irqfd where the current QEMU allocates IRQ numbers from
> irqchip and maps MSIMessages to IRQ in the host kernel.
> 
> This adds a new direct mapping flag which tells
> the kvm_irqchip_add_msi_route() function that a new VIRQ
> should not be allocated, instead the value from MSIMessage::data
> should be used. It is up to the platform code to make sure that
> this contains a valid IRQ number as sPAPR does in spapr_pci.c.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>

Fine with me

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> 
> The patch does not enable this mapping for any platform in this patch
> as it is going be done for spapr only on a separate patch which is not
> ready to go as it depends on the in-kernel XICS-KVM patchset which is not
> in upstream yet.
> 
> ---
> Changes:
> v6:
> * simplified to a single global flag and putting an IRQ number
> in MSIMessage::data
> 
> 2013/08/07 v5:
> * pci_bus_map_msi now has default behaviour which is to call
> kvm_irqchip_add_msi_route
> * kvm_irqchip_release_virq fixed not crash when there is no routes
> ---
>  include/sysemu/kvm.h |  9 +++++++++
>  kvm-all.c            | 13 +++++++++++++
>  kvm-stub.c           |  1 +
>  3 files changed, 23 insertions(+)
> 
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 8e76685..0e9ef38 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -46,6 +46,7 @@ extern bool kvm_halt_in_kernel_allowed;
>  extern bool kvm_irqfds_allowed;
>  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;
>  
>  #if defined CONFIG_KVM || !defined NEED_CPU_H
> @@ -108,6 +109,13 @@ extern bool kvm_readonly_mem_allowed;
>  #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
>  
>  /**
> + * kvm_gsi_direct_mapping:
> + *
> + * Returns: true if GSI direct mapping is enabled.
> + */
> +#define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping)
> +
> +/**
>   * kvm_readonly_mem_enabled:
>   *
>   * Returns: true if KVM readonly memory is enabled (ie the kernel
> @@ -123,6 +131,7 @@ extern bool kvm_readonly_mem_allowed;
>  #define kvm_irqfds_enabled() (false)
>  #define kvm_msi_via_irqfd_enabled() (false)
>  #define kvm_gsi_routing_allowed() (false)
> +#define kvm_gsi_direct_mapping() (false)
>  #define kvm_readonly_mem_enabled() (false)
>  #endif
>  
> diff --git a/kvm-all.c b/kvm-all.c
> index 875e32e..17fb865 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -111,6 +111,7 @@ bool kvm_halt_in_kernel_allowed;
>  bool kvm_irqfds_allowed;
>  bool kvm_msi_via_irqfd_allowed;
>  bool kvm_gsi_routing_allowed;
> +bool kvm_gsi_direct_mapping;
>  bool kvm_allowed;
>  bool kvm_readonly_mem_allowed;
>  
> @@ -1069,6 +1070,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
>      struct kvm_irq_routing_entry *e;
>      int i;
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return;
> +    }
> +
>      for (i = 0; i < s->irq_routes->nr; i++) {
>          e = &s->irq_routes->entries[i];
>          if (e->gsi == virq) {
> @@ -1190,6 +1195,10 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
>      struct kvm_irq_routing_entry kroute = {};
>      int virq;
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return msg.data & 0xffff;
> +    }
> +
>      if (!kvm_gsi_routing_enabled()) {
>          return -ENOSYS;
>      }
> @@ -1216,6 +1225,10 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
>  {
>      struct kvm_irq_routing_entry kroute = {};
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return 0;
> +    }
> +
>      if (!kvm_irqchip_in_kernel()) {
>          return -ENOSYS;
>      }
> diff --git a/kvm-stub.c b/kvm-stub.c
> index 548f471..e979f76 100644
> --- a/kvm-stub.c
> +++ b/kvm-stub.c
> @@ -25,6 +25,7 @@ bool kvm_async_interrupts_allowed;
>  bool kvm_irqfds_allowed;
>  bool kvm_msi_via_irqfd_allowed;
>  bool kvm_gsi_routing_allowed;
> +bool kvm_gsi_direct_mapping;
>  bool kvm_allowed;
>  bool kvm_readonly_mem_allowed;
>  
> -- 
> 1.8.4.rc4
Alexander Graf - Sept. 3, 2013, 3:36 p.m.
On 09/03/2013 10:17 AM, Michael S. Tsirkin wrote:
> On Tue, Sep 03, 2013 at 06:08:25PM +1000, Alexey Kardashevskiy wrote:
>> On PPC64 systems MSI Messages are translated to system IRQ in a PCI
>> host bridge. This is already supported for emulated MSI/MSIX but
>> not for irqfd where the current QEMU allocates IRQ numbers from
>> irqchip and maps MSIMessages to IRQ in the host kernel.
>>
>> This adds a new direct mapping flag which tells
>> the kvm_irqchip_add_msi_route() function that a new VIRQ
>> should not be allocated, instead the value from MSIMessage::data
>> should be used. It is up to the platform code to make sure that
>> this contains a valid IRQ number as sPAPR does in spapr_pci.c.
>>
>> Signed-off-by: Alexey Kardashevskiy<aik@ozlabs.ru>
> Fine with me
>
> Acked-by: Michael S. Tsirkin<mst@redhat.com>

Thanks, applied to ppc-next.


Alex
Paolo Bonzini - Sept. 5, 2013, 4:01 p.m.
Il 03/09/2013 10:17, Michael S. Tsirkin ha scritto:
>> On PPC64 systems MSI Messages are translated to system IRQ in a PCI
>> > host bridge. This is already supported for emulated MSI/MSIX but
>> > not for irqfd where the current QEMU allocates IRQ numbers from
>> > irqchip and maps MSIMessages to IRQ in the host kernel.
>> > 
>> > This adds a new direct mapping flag which tells
>> > the kvm_irqchip_add_msi_route() function that a new VIRQ
>> > should not be allocated, instead the value from MSIMessage::data
>> > should be used. It is up to the platform code to make sure that
>> > this contains a valid IRQ number as sPAPR does in spapr_pci.c.
>> > 
>> > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Fine with me
> 
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
> 

Alex, are you picking this one?

Paolo
Alexander Graf - Sept. 5, 2013, 4:03 p.m.
On 05.09.2013, at 18:01, Paolo Bonzini wrote:

> Il 03/09/2013 10:17, Michael S. Tsirkin ha scritto:
>>> On PPC64 systems MSI Messages are translated to system IRQ in a PCI
>>>> host bridge. This is already supported for emulated MSI/MSIX but
>>>> not for irqfd where the current QEMU allocates IRQ numbers from
>>>> irqchip and maps MSIMessages to IRQ in the host kernel.
>>>> 
>>>> This adds a new direct mapping flag which tells
>>>> the kvm_irqchip_add_msi_route() function that a new VIRQ
>>>> should not be allocated, instead the value from MSIMessage::data
>>>> should be used. It is up to the platform code to make sure that
>>>> this contains a valid IRQ number as sPAPR does in spapr_pci.c.
>>>> 
>>>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> Fine with me
>> 
>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>> 
> 
> Alex, are you picking this one?

I wouldn't mind if you pull it in. It mostly touches generic kvm code after all.


Alex
Paolo Bonzini - Sept. 12, 2013, 4:32 p.m.
Il 03/09/2013 10:08, Alexey Kardashevskiy ha scritto:
> On PPC64 systems MSI Messages are translated to system IRQ in a PCI
> host bridge. This is already supported for emulated MSI/MSIX but
> not for irqfd where the current QEMU allocates IRQ numbers from
> irqchip and maps MSIMessages to IRQ in the host kernel.
> 
> This adds a new direct mapping flag which tells
> the kvm_irqchip_add_msi_route() function that a new VIRQ
> should not be allocated, instead the value from MSIMessage::data
> should be used. It is up to the platform code to make sure that
> this contains a valid IRQ number as sPAPR does in spapr_pci.c.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> 
> ---
> 
> The patch does not enable this mapping for any platform in this patch
> as it is going be done for spapr only on a separate patch which is not
> ready to go as it depends on the in-kernel XICS-KVM patchset which is not
> in upstream yet.
> 
> ---
> Changes:
> v6:
> * simplified to a single global flag and putting an IRQ number
> in MSIMessage::data
> 
> 2013/08/07 v5:
> * pci_bus_map_msi now has default behaviour which is to call
> kvm_irqchip_add_msi_route
> * kvm_irqchip_release_virq fixed not crash when there is no routes
> ---
>  include/sysemu/kvm.h |  9 +++++++++
>  kvm-all.c            | 13 +++++++++++++
>  kvm-stub.c           |  1 +
>  3 files changed, 23 insertions(+)
> 
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index 8e76685..0e9ef38 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -46,6 +46,7 @@ extern bool kvm_halt_in_kernel_allowed;
>  extern bool kvm_irqfds_allowed;
>  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;
>  
>  #if defined CONFIG_KVM || !defined NEED_CPU_H
> @@ -108,6 +109,13 @@ extern bool kvm_readonly_mem_allowed;
>  #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
>  
>  /**
> + * kvm_gsi_direct_mapping:
> + *
> + * Returns: true if GSI direct mapping is enabled.
> + */
> +#define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping)
> +
> +/**
>   * kvm_readonly_mem_enabled:
>   *
>   * Returns: true if KVM readonly memory is enabled (ie the kernel
> @@ -123,6 +131,7 @@ extern bool kvm_readonly_mem_allowed;
>  #define kvm_irqfds_enabled() (false)
>  #define kvm_msi_via_irqfd_enabled() (false)
>  #define kvm_gsi_routing_allowed() (false)
> +#define kvm_gsi_direct_mapping() (false)
>  #define kvm_readonly_mem_enabled() (false)
>  #endif
>  
> diff --git a/kvm-all.c b/kvm-all.c
> index 875e32e..17fb865 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -111,6 +111,7 @@ bool kvm_halt_in_kernel_allowed;
>  bool kvm_irqfds_allowed;
>  bool kvm_msi_via_irqfd_allowed;
>  bool kvm_gsi_routing_allowed;
> +bool kvm_gsi_direct_mapping;
>  bool kvm_allowed;
>  bool kvm_readonly_mem_allowed;
>  
> @@ -1069,6 +1070,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
>      struct kvm_irq_routing_entry *e;
>      int i;
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return;
> +    }
> +
>      for (i = 0; i < s->irq_routes->nr; i++) {
>          e = &s->irq_routes->entries[i];
>          if (e->gsi == virq) {
> @@ -1190,6 +1195,10 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
>      struct kvm_irq_routing_entry kroute = {};
>      int virq;
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return msg.data & 0xffff;
> +    }
> +
>      if (!kvm_gsi_routing_enabled()) {
>          return -ENOSYS;
>      }
> @@ -1216,6 +1225,10 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
>  {
>      struct kvm_irq_routing_entry kroute = {};
>  
> +    if (kvm_gsi_direct_mapping()) {
> +        return 0;
> +    }
> +
>      if (!kvm_irqchip_in_kernel()) {
>          return -ENOSYS;
>      }
> diff --git a/kvm-stub.c b/kvm-stub.c
> index 548f471..e979f76 100644
> --- a/kvm-stub.c
> +++ b/kvm-stub.c
> @@ -25,6 +25,7 @@ bool kvm_async_interrupts_allowed;
>  bool kvm_irqfds_allowed;
>  bool kvm_msi_via_irqfd_allowed;
>  bool kvm_gsi_routing_allowed;
> +bool kvm_gsi_direct_mapping;
>  bool kvm_allowed;
>  bool kvm_readonly_mem_allowed;
>  
> 

Applied to uq/master, thanks.

Paolo

Patch

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 8e76685..0e9ef38 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -46,6 +46,7 @@  extern bool kvm_halt_in_kernel_allowed;
 extern bool kvm_irqfds_allowed;
 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;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
@@ -108,6 +109,13 @@  extern bool kvm_readonly_mem_allowed;
 #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
 
 /**
+ * kvm_gsi_direct_mapping:
+ *
+ * Returns: true if GSI direct mapping is enabled.
+ */
+#define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping)
+
+/**
  * kvm_readonly_mem_enabled:
  *
  * Returns: true if KVM readonly memory is enabled (ie the kernel
@@ -123,6 +131,7 @@  extern bool kvm_readonly_mem_allowed;
 #define kvm_irqfds_enabled() (false)
 #define kvm_msi_via_irqfd_enabled() (false)
 #define kvm_gsi_routing_allowed() (false)
+#define kvm_gsi_direct_mapping() (false)
 #define kvm_readonly_mem_enabled() (false)
 #endif
 
diff --git a/kvm-all.c b/kvm-all.c
index 875e32e..17fb865 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -111,6 +111,7 @@  bool kvm_halt_in_kernel_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
+bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 
@@ -1069,6 +1070,10 @@  void kvm_irqchip_release_virq(KVMState *s, int virq)
     struct kvm_irq_routing_entry *e;
     int i;
 
+    if (kvm_gsi_direct_mapping()) {
+        return;
+    }
+
     for (i = 0; i < s->irq_routes->nr; i++) {
         e = &s->irq_routes->entries[i];
         if (e->gsi == virq) {
@@ -1190,6 +1195,10 @@  int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)
     struct kvm_irq_routing_entry kroute = {};
     int virq;
 
+    if (kvm_gsi_direct_mapping()) {
+        return msg.data & 0xffff;
+    }
+
     if (!kvm_gsi_routing_enabled()) {
         return -ENOSYS;
     }
@@ -1216,6 +1225,10 @@  int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg)
 {
     struct kvm_irq_routing_entry kroute = {};
 
+    if (kvm_gsi_direct_mapping()) {
+        return 0;
+    }
+
     if (!kvm_irqchip_in_kernel()) {
         return -ENOSYS;
     }
diff --git a/kvm-stub.c b/kvm-stub.c
index 548f471..e979f76 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -25,6 +25,7 @@  bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
+bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;