qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support
@ 2013-05-13 20:20 Alex Williamson
  2013-05-19 14:00 ` Michael S. Tsirkin
  2013-05-22 22:59 ` Anthony Liguori
  0 siblings, 2 replies; 5+ messages in thread
From: Alex Williamson @ 2013-05-13 20:20 UTC (permalink / raw)
  To: jan.kiszka, mst; +Cc: qemu-devel

To support guest MSI affinity changes update the MSI message any time
the guest writes to the address or data fields.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

v2: Don't cache MSIMessage

 hw/i386/kvm/pci-assign.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index c1e08ec..ff85590 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1026,6 +1026,21 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
     }
 }
 
+static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
+{
+    AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
+    uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap +
+                                     PCI_MSI_FLAGS);
+
+    if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI ||
+        !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) {
+        return;
+    }
+
+    kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
+                                 msi_get_message(pci_dev, 0));
+}
+
 static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
 {
     return (entry->ctrl & cpu_to_le32(0x1)) != 0;
@@ -1201,6 +1216,9 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
         if (range_covers_byte(address, len,
                               pci_dev->msi_cap + PCI_MSI_FLAGS)) {
             assigned_dev_update_msi(pci_dev);
+        } else if (ranges_overlap(address, len, /* 32bit MSI only */
+                                  pci_dev->msi_cap + PCI_MSI_ADDRESS_LO, 6)) {
+            assigned_dev_update_msi_msg(pci_dev);
         }
     }
     if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {

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

* Re: [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support
  2013-05-13 20:20 [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support Alex Williamson
@ 2013-05-19 14:00 ` Michael S. Tsirkin
  2013-05-20 12:51   ` Anthony Liguori
  2013-05-22 22:59 ` Anthony Liguori
  1 sibling, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2013-05-19 14:00 UTC (permalink / raw)
  To: Alex Williamson; +Cc: jan.kiszka, qemu-devel

On Mon, May 13, 2013 at 02:20:02PM -0600, Alex Williamson wrote:
> To support guest MSI affinity changes update the MSI message any time
> the guest writes to the address or data fields.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Seems the only way we can fix this for 1.5.

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

> ---
> 
> v2: Don't cache MSIMessage
> 
>  hw/i386/kvm/pci-assign.c |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> index c1e08ec..ff85590 100644
> --- a/hw/i386/kvm/pci-assign.c
> +++ b/hw/i386/kvm/pci-assign.c
> @@ -1026,6 +1026,21 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
>      }
>  }
>  
> +static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
> +{
> +    AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
> +    uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap +
> +                                     PCI_MSI_FLAGS);
> +
> +    if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI ||
> +        !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) {
> +        return;
> +    }
> +
> +    kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
> +                                 msi_get_message(pci_dev, 0));
> +}
> +
>  static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
>  {
>      return (entry->ctrl & cpu_to_le32(0x1)) != 0;
> @@ -1201,6 +1216,9 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
>          if (range_covers_byte(address, len,
>                                pci_dev->msi_cap + PCI_MSI_FLAGS)) {
>              assigned_dev_update_msi(pci_dev);
> +        } else if (ranges_overlap(address, len, /* 32bit MSI only */
> +                                  pci_dev->msi_cap + PCI_MSI_ADDRESS_LO, 6)) {
> +            assigned_dev_update_msi_msg(pci_dev);
>          }
>      }
>      if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {

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

* Re: [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support
  2013-05-19 14:00 ` Michael S. Tsirkin
@ 2013-05-20 12:51   ` Anthony Liguori
  2013-05-20 13:15     ` Michael S. Tsirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2013-05-20 12:51 UTC (permalink / raw)
  To: Michael S. Tsirkin, Alex Williamson; +Cc: jan.kiszka, qemu-devel

"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Mon, May 13, 2013 at 02:20:02PM -0600, Alex Williamson wrote:
>> To support guest MSI affinity changes update the MSI message any time
>> the guest writes to the address or data fields.
>> 
>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>
> Seems the only way we can fix this for 1.5.
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>

Is this a bug or a feature?  Can someone describe the scenario in which
the bug occurs?

Regards,

Anthony Liguori

>
>> ---
>> 
>> v2: Don't cache MSIMessage
>> 
>>  hw/i386/kvm/pci-assign.c |   18 ++++++++++++++++++
>>  1 file changed, 18 insertions(+)
>> 
>> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
>> index c1e08ec..ff85590 100644
>> --- a/hw/i386/kvm/pci-assign.c
>> +++ b/hw/i386/kvm/pci-assign.c
>> @@ -1026,6 +1026,21 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
>>      }
>>  }
>>  
>> +static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
>> +{
>> +    AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
>> +    uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap +
>> +                                     PCI_MSI_FLAGS);
>> +
>> +    if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI ||
>> +        !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) {
>> +        return;
>> +    }
>> +
>> +    kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
>> +                                 msi_get_message(pci_dev, 0));
>> +}
>> +
>>  static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
>>  {
>>      return (entry->ctrl & cpu_to_le32(0x1)) != 0;
>> @@ -1201,6 +1216,9 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
>>          if (range_covers_byte(address, len,
>>                                pci_dev->msi_cap + PCI_MSI_FLAGS)) {
>>              assigned_dev_update_msi(pci_dev);
>> +        } else if (ranges_overlap(address, len, /* 32bit MSI only */
>> +                                  pci_dev->msi_cap + PCI_MSI_ADDRESS_LO, 6)) {
>> +            assigned_dev_update_msi_msg(pci_dev);
>>          }
>>      }
>>      if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {

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

* Re: [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support
  2013-05-20 12:51   ` Anthony Liguori
@ 2013-05-20 13:15     ` Michael S. Tsirkin
  0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2013-05-20 13:15 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: jan.kiszka, Alex Williamson, qemu-devel

On Mon, May 20, 2013 at 07:51:40AM -0500, Anthony Liguori wrote:
> "Michael S. Tsirkin" <mst@redhat.com> writes:
> 
> > On Mon, May 13, 2013 at 02:20:02PM -0600, Alex Williamson wrote:
> >> To support guest MSI affinity changes update the MSI message any time
> >> the guest writes to the address or data fields.
> >> 
> >> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> >
> > Seems the only way we can fix this for 1.5.
> >
> > Acked-by: Michael S. Tsirkin <mst@redhat.com>
> 
> Is this a bug or a feature?  Can someone describe the scenario in which
> the bug occurs?
> 
> Regards,
> 
> Anthony Liguori

It's a bug. Here's how it occurs w.g. with a linux guest:

- guest kernel enables MSI, interrupts are sent to CPU0
- irqbalance runs in guest and moves MSI to CPU1
- guest kernel updates MSI register with new data

without this patch interrupts keep getting sent to CPU0
in violation of the spec.

> >
> >> ---
> >> 
> >> v2: Don't cache MSIMessage
> >> 
> >>  hw/i386/kvm/pci-assign.c |   18 ++++++++++++++++++
> >>  1 file changed, 18 insertions(+)
> >> 
> >> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> >> index c1e08ec..ff85590 100644
> >> --- a/hw/i386/kvm/pci-assign.c
> >> +++ b/hw/i386/kvm/pci-assign.c
> >> @@ -1026,6 +1026,21 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev)
> >>      }
> >>  }
> >>  
> >> +static void assigned_dev_update_msi_msg(PCIDevice *pci_dev)
> >> +{
> >> +    AssignedDevice *assigned_dev = DO_UPCAST(AssignedDevice, dev, pci_dev);
> >> +    uint8_t ctrl_byte = pci_get_byte(pci_dev->config + pci_dev->msi_cap +
> >> +                                     PCI_MSI_FLAGS);
> >> +
> >> +    if (assigned_dev->assigned_irq_type != ASSIGNED_IRQ_MSI ||
> >> +        !(ctrl_byte & PCI_MSI_FLAGS_ENABLE)) {
> >> +        return;
> >> +    }
> >> +
> >> +    kvm_irqchip_update_msi_route(kvm_state, assigned_dev->msi_virq[0],
> >> +                                 msi_get_message(pci_dev, 0));
> >> +}
> >> +
> >>  static bool assigned_dev_msix_masked(MSIXTableEntry *entry)
> >>  {
> >>      return (entry->ctrl & cpu_to_le32(0x1)) != 0;
> >> @@ -1201,6 +1216,9 @@ static void assigned_dev_pci_write_config(PCIDevice *pci_dev, uint32_t address,
> >>          if (range_covers_byte(address, len,
> >>                                pci_dev->msi_cap + PCI_MSI_FLAGS)) {
> >>              assigned_dev_update_msi(pci_dev);
> >> +        } else if (ranges_overlap(address, len, /* 32bit MSI only */
> >> +                                  pci_dev->msi_cap + PCI_MSI_ADDRESS_LO, 6)) {
> >> +            assigned_dev_update_msi_msg(pci_dev);
> >>          }
> >>      }
> >>      if (assigned_dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) {

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

* Re: [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support
  2013-05-13 20:20 [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support Alex Williamson
  2013-05-19 14:00 ` Michael S. Tsirkin
@ 2013-05-22 22:59 ` Anthony Liguori
  1 sibling, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2013-05-22 22:59 UTC (permalink / raw)
  To: Alex Williamson, jan.kiszka, mst; +Cc: qemu-devel

Applied.  Thanks.

Regards,

Anthony Liguori

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

end of thread, other threads:[~2013-05-22 22:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-13 20:20 [Qemu-devel] [PATCH v2] pci-assign: Add MSI affinity support Alex Williamson
2013-05-19 14:00 ` Michael S. Tsirkin
2013-05-20 12:51   ` Anthony Liguori
2013-05-20 13:15     ` Michael S. Tsirkin
2013-05-22 22:59 ` Anthony Liguori

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).