Skip to contentSkip to conversation

Fix qemu traditional with PCI passthrough.

PATCH In review Konrad Rzeszutek Wilk 3 participants 14 messages Apr 8, 2014 – Aug 7, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix qemu traditional with PCI passthrough.

Hey Ian and Stefano,

This patch was posted way back last year in July
(see http://lists.xen.org/archives/html/xen-devel/2013-07/msg00004.html) and was mentioned to:

">From what I understand following the conversation, I think this is

Quoted 6 lines

probably the right way to solve the problem, but given that it's only really a problem when you load and unload drivers, which is the uncommon case, I think at this point we should probably hold off on this one until 4.3.1.

Stefano, thoughts?

I think that's OK. I'll wait to apply the qemu-xen patch until after the release."

I think this patch just got lost in the Xen 4.4 release. Dusting it off and reposting.

The issue at hand is simple - you boot an PVHVM guest with a PCI passthrough device and in a loop do:

#!/bin/bash

while (true)
do
rmmod igbvf
killall dhclient
modprobe igbvf
dhclient eth1
done

and you find yourself in distressed to see that after a while it cannot allocate any IRQs. I've tested it and it fixes the issue.

Now there was also an qemu-xen version of this patch posted:
http://lists.xen.org/archives/html/xen-devel/2013-07/msg00008.html

and I just reposted it, see:
http://mid.gmane.org/[email protected]
(or "[PATCH] Fix qemu-xen with PCI passthrough.")

 hw/pass-through.c | 8 +++++++-
 hw/pt-msi.c       | 5 +++--
 2 files changed, 10 insertions(+), 3 deletions(-)

Zhenzhong Duan (1):
qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Thanks!

#1 lore raw

PATCH 1/1 qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

From: Zhenzhong Duan <[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

There is also other way of fixing it such as reuse pirqs between driver reload, but this way is better.
Xen-devel: http://marc.info/?l=xen-devel&m=136800120304275&w=2

---
 hw/pass-through.c | 8 +++++++-
 hw/pt-msi.c       | 5 +++--
 2 files changed, 10 insertions(+), 3 deletions(-)
hw/pass-through.c +7 -1
index 304c438..4821182 100644
@@ -3866,7 +3866,11 @@ static int pt_msgctrl_reg_write(struct pt_dev *ptdev,
         ptdev->msi->flags |= PCI_MSI_FLAGS_ENABLE;
     }
     else
-        ptdev->msi->flags &= ~PCI_MSI_FLAGS_ENABLE;
+    {
+        if (ptdev->msi->flags & PT_MSI_MAPPED) {
+            pt_msi_disable(ptdev);
+        }
+    }
 
     /* pass through MSI_ENABLE bit when no MSI-INTx translation */
     if (!ptdev->msi_trans_en) {
@@ -4013,6 +4017,8 @@ static int pt_msixctrl_reg_write(struct pt_dev *ptdev,
             pt_disable_msi_translate(ptdev);
         }
         pt_msix_update(ptdev);
+    } else if (!(*value & PCI_MSIX_ENABLE) && ptdev->msix->enabled) {
+        pt_msix_disable(ptdev);
     }
 
     ptdev->msix->enabled = !!(*value & PCI_MSIX_ENABLE);
hw/pt-msi.c +3 -2
index b03b989..3f5f94b 100644
@@ -213,7 +213,8 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED | PCI_MSI_FLAGS_ENABLE);
+    dev->msi->flags &= ~(PT_MSI_MAPPED | PCI_MSI_FLAGS_ENABLE);
+    dev->msi->flags |= MSI_FLAG_UNINIT;
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;
 }
@@ -447,7 +448,7 @@ static void pci_msix_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     {
         const volatile uint32_t *vec_ctrl;
 
-        if ( entry->io_mem[offset] == val )
+        if ( entry->io_mem[offset] == val && entry->pirq != -1)
             return;
 
         /*
Signature · 1 line
1.8.5.3
#2 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan <[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

Tested-by G.R.
#3 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

There is a patch dependency missed.

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED | PCI_MSI_FLAGS_ENABLE);
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;
 }
Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#4 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

Quoted 53 lines

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED |
 PCI_MSI_FLAGS_ENABLE);
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;

}

Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#5 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

Quoted 51 lines
Quoted 51 lines

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
  out:
      /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED |
 PCI_MSI_FLAGS_ENABLE);
      dev->msi->pirq = -1;
      dev->msi_trans_en = 0;
  }
Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#6 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 9 lines · Zhenzhong Duan
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

[konrad@build-external qemu-xen-dir]$ pwd /home/konrad/xtt-x86_64/xen/tools/qemu-xen-dir
[konrad@build-external qemu-xen-dir]$ git show adf74189dd58014744a4b8c9d64407d629da5e2f
fatal: bad object adf74189dd58014744a4b8c9d64407d629da5e2f [konrad@build-external qemu-xen-dir]$ git log --grep="clear all MSI" [konrad@build-external qemu-xen-dir]$

?

Quoted 52 lines
Quoted 51 lines
Quoted 51 lines

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED |
 PCI_MSI_FLAGS_ENABLE);
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;

}

Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#7 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 8 lines · Zhenzhong Duan
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

Quoted 8 lines

[konrad@build-external qemu-xen-dir]$ pwd /home/konrad/xtt-x86_64/xen/tools/qemu-xen-dir
[konrad@build-external qemu-xen-dir]$ git show adf74189dd58014744a4b8c9d64407d629da5e2f
fatal: bad object adf74189dd58014744a4b8c9d64407d629da5e2f [konrad@build-external qemu-xen-dir]$ git log --grep="clear all MSI" [konrad@build-external qemu-xen-dir]$

?

Sorry, I mean qemu-xen-traditional upstream git

zduan

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
  out:
      /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED |
 PCI_MSI_FLAGS_ENABLE);
      dev->msi->pirq = -1;
      dev->msi_trans_en = 0;
  }
Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#8 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 19 lines · Zhenzhong Duan
Quoted 17 lines · Konrad Rzeszutek Wilk
Quoted 8 lines · Zhenzhong Duan
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

[konrad@build-external qemu-xen-dir]$ pwd /home/konrad/xtt-x86_64/xen/tools/qemu-xen-dir
[konrad@build-external qemu-xen-dir]$ git show adf74189dd58014744a4b8c9d64407d629da5e2f
fatal: bad object adf74189dd58014744a4b8c9d64407d629da5e2f [konrad@build-external qemu-xen-dir]$ git log --grep="clear all MSI" [konrad@build-external qemu-xen-dir]$

Quoted 2 lines
Quoted 1 line

?

Sorry, I mean qemu-xen-traditional upstream git

Ok, is that patch upstream? Should it be upstream? If so, had it been posted in the past?

Thank you!

Quoted 54 lines

zduan

Quoted 51 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI flags as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED |
 PCI_MSI_FLAGS_ENABLE);
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;

}

Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#9 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Zhenzhong Duan
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 8 lines · Zhenzhong Duan
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

[konrad@build-external qemu-xen-dir]$ pwd /home/konrad/xtt-x86_64/xen/tools/qemu-xen-dir
[konrad@build-external qemu-xen-dir]$ git show adf74189dd58014744a4b8c9d64407d629da5e2f
fatal: bad object adf74189dd58014744a4b8c9d64407d629da5e2f [konrad@build-external qemu-xen-dir]$ git log --grep="clear all MSI" [konrad@build-external qemu-xen-dir]$

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

?

Sorry, I mean qemu-xen-traditional upstream git

Ok, is that patch upstream? Should it be upstream? If so, had it been posted in the past?

It's already in qemu-xen upstream, see below

void xen_pt_msi_disable(XenPCIPassthroughState *s) {
.......

    /* clear msi info */
    msi->flags &= ~PCI_MSI_FLAGS_ENABLE;
    msi->initialized = false;
    msi->mapped = false;
    msi->pirq = XEN_PT_UNASSIGNED_PIRQ;
}
author Acked-by Stefano Stabellini
#10 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

Quoted 29 lines · Zhenzhong Duan
Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Zhenzhong Duan
Quoted 16 lines · Konrad Rzeszutek Wilk
Quoted 8 lines · Zhenzhong Duan
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 1 line · Zhenzhong Duan

There is a patch dependency missed.

Is that one upstream as well? Or does it not need to be? If it is upstream, what is the title/commit id of that one?

Thank you!

It's upstream, see detail below

[konrad@build-external qemu-xen-dir]$ pwd /home/konrad/xtt-x86_64/xen/tools/qemu-xen-dir
[konrad@build-external qemu-xen-dir]$ git show adf74189dd58014744a4b8c9d64407d629da5e2f
fatal: bad object adf74189dd58014744a4b8c9d64407d629da5e2f [konrad@build-external qemu-xen-dir]$ git log --grep="clear all MSI" [konrad@build-external qemu-xen-dir]$

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

?

Sorry, I mean qemu-xen-traditional upstream git

Ok, is that patch upstream? Should it be upstream? If so, had it been posted in the past?

It's already in qemu-xen upstream, see below

void xen_pt_msi_disable(XenPCIPassthroughState *s) {
.......

Quoted 6 lines
    /* clear msi info */
    msi->flags &= ~PCI_MSI_FLAGS_ENABLE;
    msi->initialized = false;
    msi->mapped = false;
    msi->pirq = XEN_PT_UNASSIGNED_PIRQ;
}

OK, and that is part of the giant '3854ca57':

commit 3854ca577dad92c4fe97b4a6ebce360e25407af7

Author: Jiang Yunhong <[email protected]>
Date:   Thu Jun 21 15:42:35 2012 +0000

Introduce Xen PCI Passthrough, MSI

A more complete history can be found here:
git://xenbits.xensource.com/qemu-xen-unstable.git

And the git tree it points to has tons of tags but nothing really saying 'pci'. <sigh>

Seems like the only option is to spin out a tiny patch that has the fix and document where it was (aka point to the giant commit).

Duan, I can do it in two-three weeks time-frame. If you want to take a stab at it before then, don't hesitate!

#11 lore raw

Re: [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads

In reply to Zhenzhong Duan

Hi Ian,

Could you cherry-pick commit adf74189dd58014744a4b8c9d64407d629da5e2f before backport my patch? It seems 4.3 and 4.4 branch already has commit adf74189dd but 4.2 not.

thanks
zduan

Quoted 55 lines · Zhenzhong Duan

There is a patch dependency missed.

commit adf74189dd58014744a4b8c9d64407d629da5e2f

Author: Stefano Stabellini <[email protected]>
Date:   Mon Dec 10 12:43:33 2012 +0000

qemu-xen-trad/pt_msi_disable: do not clear all MSI flags

"qemu-xen-trad: fix msi_translate with PV event delivery" added a pt_msi_disable() call into pt_msgctrl_reg_write, clearing the MSI
flags
as a consequence. MSIs get enabled again soon after by calling pt_msi_setup.

However the MSI flags are only setup once in the pt_msgctrl_reg_init function, so from the QEMU point of view the device has lost some important properties, like for example PCI_MSI_FLAGS_64BIT.

This patch fixes the bug by clearing only the MSI enabled/mapped/initialized flags in pt_msi_disable.

Xen-devel: http://marc.info/?l=xen-devel&m=135489879503075

hw/pt-msi.c +1 -1
index 73f737d..b03b989 100644
@@ -213,7 +213,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
 out:
     /* clear msi info */
-    dev->msi->flags = 0;
+    dev->msi->flags &= ~(MSI_FLAG_UNINIT | PT_MSI_MAPPED | 
 PCI_MSI_FLAGS_ENABLE);
     dev->msi->pirq = -1;
     dev->msi_trans_en = 0;

}

Quoted 13 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("[Xen-devel] [PATCH] qemu-xen-trad: free all the pirqs for msi/msix when driver unloads"):

Quoted 7 lines

From: Zhenzhong Duan<[email protected]>

Pirqs are not freed when driver unloads, then new pirqs are allocated when driver reloads. This could exhaust pirqs if do it in a loop.

This patch fixes the bug by freeing pirqs when ENABLE bit is cleared in msi/msix control reg.

I have backported this to 4.4 and 4.3. It did not apply cleanly to 4.2 (and I have not investgated why).

Thanks,
Ian.

#12 lore raw
In reply to Konrad Rzeszutek Wilk

Konrad Rzeszutek Wilk writes ("[PATCH] Fix qemu traditional with PCI passthrough."):

Quoted 12 lines

Hey Ian and Stefano,

This patch was posted way back last year in July
(see http://lists.xen.org/archives/html/xen-devel/2013-07/msg00004.html) and was mentioned to:

">From what I understand following the conversation, I think this is

Quoted 5 lines

probably the right way to solve the problem, but given that it's only really a problem when you load and unload drivers, which is the uncommon case, I think at this point we should probably hold off on this one until 4.3.1.

Quoted 7 lines
Quoted 1 line

Stefano, thoughts?

I think that's OK. I'll wait to apply the qemu-xen patch until after the release."

I think this patch just got lost in the Xen 4.4 release. Dusting it off and reposting.

Quite likely.

I'll wait for Stefano to comment on the qemu-xen patch but I don't see a problem with applying this to staging, and it should probably go on my backport list.

Thanks,
Ian.

#13 lore raw

Re: [PATCH] Fix qemu traditional with PCI passthrough. [and 2 more messages]

In reply to Konrad Rzeszutek Wilk

Ian Jackson writes ("Re: [PATCH] Fix qemu traditional with PCI passthrough."):

Quoted 9 lines

Konrad Rzeszutek Wilk writes ("[PATCH] Fix qemu traditional with PCI passthrough."):

Quoted 2 lines

I think this patch just got lost in the Xen 4.4 release. Dusting it off and reposting.

Quite likely.

I'll wait for Stefano to comment on the qemu-xen patch but I don't see a problem with applying this to staging, and it should probably go on my backport list.

I see this is in our qemu-upstream tree (as d0395cc49b2ec6d1723c01f1daf2394b9264ca29). I have applied it to qemu-xen-traditional and added it to my backport list.

Thanks,
Ian.