[linux-azure:xenial] PCI: hv: Do not sleep in compose_msi_msg()

Message ID 1517919241-23983-1-git-send-email-marcelo.cerri@canonical.com
State New
Headers show
Series
  • [linux-azure:xenial] PCI: hv: Do not sleep in compose_msi_msg()
Related show

Commit Message

Marcelo Henrique Cerri Feb. 6, 2018, 12:14 p.m.
From: Stephen Hemminger <stephen@networkplumber.org>

BugLink: http://bugs.launchpad.net/bugs/1747543

The setup of MSI with Hyper-V host was sleeping with locks held.  This
error is reported when doing SR-IOV hotplug with kernel built with lockdep:

    BUG: sleeping function called from invalid context at kernel/sched/completion.c:93
    in_atomic(): 1, irqs_disabled(): 1, pid: 1405, name: ip
    3 locks held by ip/1405:
   #0:  (rtnl_mutex){+.+.+.}, at: [<ffffffff976b10bb>] rtnetlink_rcv+0x1b/0x40
   #1:  (&desc->request_mutex){+.+...}, at: [<ffffffff970ddd33>] __setup_irq+0xb3/0x720
   #2:  (&irq_desc_lock_class){-.-...}, at: [<ffffffff970ddd65>] __setup_irq+0xe5/0x720
   irq event stamp: 3476
   hardirqs last  enabled at (3475): [<ffffffff971b3005>] get_page_from_freelist+0x225/0xc90
   hardirqs last disabled at (3476): [<ffffffff978024e7>] _raw_spin_lock_irqsave+0x27/0x90
   softirqs last  enabled at (2446): [<ffffffffc05ef0b0>] ixgbevf_configure+0x380/0x7c0 [ixgbevf]
   softirqs last disabled at (2444): [<ffffffffc05ef08d>] ixgbevf_configure+0x35d/0x7c0 [ixgbevf]

The workaround is to poll for host response instead of blocking on
completion.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
(cherry picked from commit 80bfeeb9dd6b54ac108c884c792f0fc7d4912bee)
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
 drivers/pci/host/pci-hyperv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Kleber Souza Feb. 6, 2018, 1:19 p.m. | #1
On 02/06/18 13:14, Marcelo Henrique Cerri wrote:
> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> BugLink: http://bugs.launchpad.net/bugs/1747543
> 
> The setup of MSI with Hyper-V host was sleeping with locks held.  This
> error is reported when doing SR-IOV hotplug with kernel built with lockdep:
> 
>     BUG: sleeping function called from invalid context at kernel/sched/completion.c:93
>     in_atomic(): 1, irqs_disabled(): 1, pid: 1405, name: ip
>     3 locks held by ip/1405:
>    #0:  (rtnl_mutex){+.+.+.}, at: [<ffffffff976b10bb>] rtnetlink_rcv+0x1b/0x40
>    #1:  (&desc->request_mutex){+.+...}, at: [<ffffffff970ddd33>] __setup_irq+0xb3/0x720
>    #2:  (&irq_desc_lock_class){-.-...}, at: [<ffffffff970ddd65>] __setup_irq+0xe5/0x720
>    irq event stamp: 3476
>    hardirqs last  enabled at (3475): [<ffffffff971b3005>] get_page_from_freelist+0x225/0xc90
>    hardirqs last disabled at (3476): [<ffffffff978024e7>] _raw_spin_lock_irqsave+0x27/0x90
>    softirqs last  enabled at (2446): [<ffffffffc05ef0b0>] ixgbevf_configure+0x380/0x7c0 [ixgbevf]
>    softirqs last disabled at (2444): [<ffffffffc05ef08d>] ixgbevf_configure+0x35d/0x7c0 [ixgbevf]
> 
> The workaround is to poll for host response instead of blocking on
> completion.
> 
> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> (cherry picked from commit 80bfeeb9dd6b54ac108c884c792f0fc7d4912bee)
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
> ---
>  drivers/pci/host/pci-hyperv.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
> index 9ade00572399..8b5f66d3c4f2 100644
> --- a/drivers/pci/host/pci-hyperv.c
> +++ b/drivers/pci/host/pci-hyperv.c
> @@ -50,6 +50,7 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/pci.h>
> +#include <linux/delay.h>
>  #include <linux/semaphore.h>
>  #include <linux/irqdomain.h>
>  #include <asm/irqdomain.h>
> @@ -1115,7 +1116,12 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
>  		goto free_int_desc;
>  	}
>  
> -	wait_for_completion(&comp.comp_pkt.host_event);
> +	/*
> +	 * Since this function is called with IRQ locks held, can't
> +	 * do normal wait for completion; instead poll.
> +	 */
> +	while (!try_wait_for_completion(&comp.comp_pkt.host_event))
> +		udelay(100);
>  
>  	if (comp.comp_pkt.completion_status < 0) {
>  		dev_err(&hbus->hdev->device,
> 

Clean cherry-pick, the change makes sense to me.

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Seth Forshee Feb. 6, 2018, 1:34 p.m. | #2
On Tue, Feb 06, 2018 at 10:14:01AM -0200, Marcelo Henrique Cerri wrote:
> From: Stephen Hemminger <stephen@networkplumber.org>
> 
> BugLink: http://bugs.launchpad.net/bugs/1747543
> 
> The setup of MSI with Hyper-V host was sleeping with locks held.  This
> error is reported when doing SR-IOV hotplug with kernel built with lockdep:
> 
>     BUG: sleeping function called from invalid context at kernel/sched/completion.c:93
>     in_atomic(): 1, irqs_disabled(): 1, pid: 1405, name: ip
>     3 locks held by ip/1405:
>    #0:  (rtnl_mutex){+.+.+.}, at: [<ffffffff976b10bb>] rtnetlink_rcv+0x1b/0x40
>    #1:  (&desc->request_mutex){+.+...}, at: [<ffffffff970ddd33>] __setup_irq+0xb3/0x720
>    #2:  (&irq_desc_lock_class){-.-...}, at: [<ffffffff970ddd65>] __setup_irq+0xe5/0x720
>    irq event stamp: 3476
>    hardirqs last  enabled at (3475): [<ffffffff971b3005>] get_page_from_freelist+0x225/0xc90
>    hardirqs last disabled at (3476): [<ffffffff978024e7>] _raw_spin_lock_irqsave+0x27/0x90
>    softirqs last  enabled at (2446): [<ffffffffc05ef0b0>] ixgbevf_configure+0x380/0x7c0 [ixgbevf]
>    softirqs last disabled at (2444): [<ffffffffc05ef08d>] ixgbevf_configure+0x35d/0x7c0 [ixgbevf]
> 
> The workaround is to poll for host response instead of blocking on
> completion.
> 
> Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> (cherry picked from commit 80bfeeb9dd6b54ac108c884c792f0fc7d4912bee)
> Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>

Acked-by: Seth Forshee <seth.forshee@canonical.com>

Patch

diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
index 9ade00572399..8b5f66d3c4f2 100644
--- a/drivers/pci/host/pci-hyperv.c
+++ b/drivers/pci/host/pci-hyperv.c
@@ -50,6 +50,7 @@ 
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/delay.h>
 #include <linux/semaphore.h>
 #include <linux/irqdomain.h>
 #include <asm/irqdomain.h>
@@ -1115,7 +1116,12 @@  static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		goto free_int_desc;
 	}
 
-	wait_for_completion(&comp.comp_pkt.host_event);
+	/*
+	 * Since this function is called with IRQ locks held, can't
+	 * do normal wait for completion; instead poll.
+	 */
+	while (!try_wait_for_completion(&comp.comp_pkt.host_event))
+		udelay(100);
 
 	if (comp.comp_pkt.completion_status < 0) {
 		dev_err(&hbus->hdev->device,