linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
@ 2017-01-26 19:07 Prarit Bhargava
  2017-03-09 21:57 ` Bjorn Helgaas
  0 siblings, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2017-01-26 19:07 UTC (permalink / raw)
  To: linux-pci
  Cc: Prarit Bhargava, alex.williamson, darcari, mstowe, bhelgaas,
	lukas, keith.busch, mika.westerberg

Bjorn, I read your comment on the earlier patch and decided to answer it
with this explanation.  I hope this explains the behavior, why the code
was introduced, what the problem is, and why it no longer is an issue for
kdump.

The following unhandled IRQ warning is seen during shutdown:

    irq 16: nobody cared (try booting with the "irqpoll" option)
    CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
    Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/
     0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
     ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
     0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
    Call Trace:
     <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
     [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
     [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
     [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
     [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
     [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
     [<ffffffff8102edfb>] handle_irq+0xab/0x130
     [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
     [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
     [<ffffffff81704502>] common_interrupt+0x82/0x82
     <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
     [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
     [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
     [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
     [<ffffffff816f6da7>] rest_init+0x77/0x80
     [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
     [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
     [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
     [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
     [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c

When a system boots the Linux PCI devices are initialized by BIOS in
legacy interrupt mode.  In the Linux PCI model, as part of the driver
initialization of a device, the driver decides the type of interrupt handler to
register.  If the device supports MSI/X then an MSI/X handler will be
registered for all MSI/X interrupts through a call to pci_enable_msix_range()
which will also put the PCI device into MSI/X mode; if the device doesn't
support MSI/X then the legacy handler will be registered for the legacy
interrupt and the device will remain in legacy mode.  A good example of a
driver doing this is e1000e_set_interrupt_capability().

The stack trace occurs on a system that has a MSI/X capable device with a MSI/X
capable driver, but the driver does not have a pci shutdown function.  The PCI
subsystem (not the driver!!) calls pci_device_shutdown() which disables MSI/X
on the device during system shutdown by calling pci_msi_shutdown() and
pci_msix_shutdown() asynchronously of the driver.  Disabling MSI/X will result
in the active device being switched into legacy mode with a driver that is
configured for MSI/X.  If the PCI device generates an interrupt during
shutdown, the resulting legacy interrupt will not be handled by any driver and
will be reported as being unhandled.

[Aside: This does not mean that there is a problem with the driver.  If the
driver had a proper shutdown function and this happened, then yes, there's a
problem with the driver because the shutdown should have stopped HW interrupts
being generated.  However, that isn't the case here because there isn't a
shutdown function for this device.  (There is no requirement for a shutdown
function.)  We want some drivers to remain active, for example the serial
driver and on those devices the problem really lies with the PCI shutdown
disabling MSI/X and switching to legacy mode when the HW and driver haven't
stopped.]

The pci_device_shutdown() MSI disable code was introduced in commit
d52877c7b1af ("pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2").
This commit was for a kdump failure with the mptscsih storage driver on 2.6.18.
The change should have been made directly to that driver's shutdown function,
not for every PCI driver [1].  Additionally, pci_device_shutdown() is no
longer called during the panic path so this code does not reset devices
for kdump.

I have tested this patch in kdump with both nr_cpus=1 and nr_cpus=4 on various
systems.  In cases where bugs have been reported on shutdown
(https://bugzilla.kernel.org/show_bug.cgi?id=187351#c1) test kernels have
resolved the unhandled IRQ stack trace.  In order to test for driver
regressions (ie, "whack-a-mole" bugs) I have tested this patch on ~200 systems
with different cpu counts (many drivers that support MSI/X initialize IRQs for
each cpu) and various network and storage devices and drivers, without any
issues. [2]

This patch also has a positive effect with the PCI-based serial devices.
On many systems during reboot/shutdown the the serial driver stops
outputting messages.  I have tracked this to PCI serial devices that are
as described above asynchronously switched from MSI/X to legacy.  After
applying this patch serial console messages are output for the entire
reboot/shutdown.

[1] I cannot reproduce the mptscsih failure on a recent kernel on older or
newer hardware.  Again, I think the patch has no effect on kdump because
pci_device_shutdown() is not called during the panic path.

[2] I have also tested a kernel that completely removes pci_msix_shutdown() and
pci_msi_shutdown() without any issues.

P.
---------8<---------

On some systems an unhandled IRQ stack trace is output during shutdown.

This occurs because pci_device_shutdown() disables MSI/X on all devices
during shutdown by calling pci_msi_shutdown() and pci_msix_shutdown()
asynchronously of the devices' drivers.  If a driver does not have a
shutdown method and is configured for MSI/X interrupts, disabling MSI/X
will result in the device being configured for legacy interrupts with a
driver that is configured for MSI/X.  If the hardware generates an
interrupt during shutdown, the interrupt will be a legacy interrupt and
will be reported as being unhandled by any driver.

Do not disable MSI/X interrupts during shutdown.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: alex.williamson@redhat.com
Cc: darcari@redhat.com
Cc: mstowe@redhat.com
Cc: bhelgaas@google.com
Cc: lukas@wunner.de
Cc: keith.busch@intel.com
Cc: mika.westerberg@linux.intel.com
---
 drivers/pci/pci-driver.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 1ccce1cd6aca..87c35db5a564 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
 
 	pm_runtime_resume(dev);
 
-	if (drv && drv->shutdown)
+	if (drv && drv->shutdown) {
 		drv->shutdown(pci_dev);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_shutdown(pci_dev);
+		pci_msi_shutdown(pci_dev);
+		pci_msix_shutdown(pci_dev);
+	}
 
 	/*
 	 * If this is a kexec reboot, turn off Bus Master bit on the
-- 
1.7.9.3


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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2017-01-26 19:07 [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called Prarit Bhargava
@ 2017-03-09 21:57 ` Bjorn Helgaas
  2017-03-10 12:30   ` Prarit Bhargava
  0 siblings, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2017-03-09 21:57 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

Hi Prarit,

My abject apologies for taking so long to deal with this.

On Thu, Jan 26, 2017 at 02:07:47PM -0500, Prarit Bhargava wrote:
> Bjorn, I read your comment on the earlier patch and decided to answer it
> with this explanation.  I hope this explains the behavior, why the code
> was introduced, what the problem is, and why it no longer is an issue for
> kdump.
> 
> The following unhandled IRQ warning is seen during shutdown:
> 
>     irq 16: nobody cared (try booting with the "irqpoll" option)
>     CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
>     Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/
>      0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
>      ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
>      0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
>     Call Trace:
>      <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
>      [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
>      [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
>      [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
>      [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
>      [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
>      [<ffffffff8102edfb>] handle_irq+0xab/0x130
>      [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
>      [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
>      [<ffffffff81704502>] common_interrupt+0x82/0x82
>      <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
>      [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
>      [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
>      [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
>      [<ffffffff816f6da7>] rest_init+0x77/0x80
>      [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
>      [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
>      [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
>      [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
>      [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c
> 
> When a system boots the Linux PCI devices are initialized by BIOS in
> legacy interrupt mode.  In the Linux PCI model, as part of the driver
> initialization of a device, the driver decides the type of interrupt handler to
> register.  If the device supports MSI/X then an MSI/X handler will be
> registered for all MSI/X interrupts through a call to pci_enable_msix_range()
> which will also put the PCI device into MSI/X mode; if the device doesn't
> support MSI/X then the legacy handler will be registered for the legacy
> interrupt and the device will remain in legacy mode.  A good example of a
> driver doing this is e1000e_set_interrupt_capability().
> 
> The stack trace occurs on a system that has a MSI/X capable device with a MSI/X
> capable driver, but the driver does not have a pci shutdown function.  The PCI
> subsystem (not the driver!!) calls pci_device_shutdown() which disables MSI/X
> on the device during system shutdown by calling pci_msi_shutdown() and
> pci_msix_shutdown() asynchronously of the driver.  Disabling MSI/X will result
> in the active device being switched into legacy mode with a driver that is
> configured for MSI/X.  If the PCI device generates an interrupt during
> shutdown, the resulting legacy interrupt will not be handled by any driver and
> will be reported as being unhandled.
> 
> [Aside: This does not mean that there is a problem with the driver.  If the
> driver had a proper shutdown function and this happened, then yes, there's a
> problem with the driver because the shutdown should have stopped HW interrupts
> being generated.  However, that isn't the case here because there isn't a
> shutdown function for this device.  (There is no requirement for a shutdown
> function.)  We want some drivers to remain active, for example the serial
> driver and on those devices the problem really lies with the PCI shutdown
> disabling MSI/X and switching to legacy mode when the HW and driver haven't
> stopped.]
> 
> The pci_device_shutdown() MSI disable code was introduced in commit
> d52877c7b1af ("pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2").
> This commit was for a kdump failure with the mptscsih storage driver on 2.6.18.
> The change should have been made directly to that driver's shutdown function,
> not for every PCI driver [1].  Additionally, pci_device_shutdown() is no
> longer called during the panic path so this code does not reset devices
> for kdump.
> 
> I have tested this patch in kdump with both nr_cpus=1 and nr_cpus=4 on various
> systems.  In cases where bugs have been reported on shutdown
> (https://bugzilla.kernel.org/show_bug.cgi?id=187351#c1) test kernels have
> resolved the unhandled IRQ stack trace.  In order to test for driver
> regressions (ie, "whack-a-mole" bugs) I have tested this patch on ~200 systems
> with different cpu counts (many drivers that support MSI/X initialize IRQs for
> each cpu) and various network and storage devices and drivers, without any
> issues. [2]
> 
> This patch also has a positive effect with the PCI-based serial devices.
> On many systems during reboot/shutdown the the serial driver stops
> outputting messages.  I have tracked this to PCI serial devices that are
> as described above asynchronously switched from MSI/X to legacy.  After
> applying this patch serial console messages are output for the entire
> reboot/shutdown.
> 
> [1] I cannot reproduce the mptscsih failure on a recent kernel on older or
> newer hardware.  Again, I think the patch has no effect on kdump because
> pci_device_shutdown() is not called during the panic path.
> 
> [2] I have also tested a kernel that completely removes pci_msix_shutdown() and
> pci_msi_shutdown() without any issues.
> 
> P.
> ---------8<---------
> 
> On some systems an unhandled IRQ stack trace is output during shutdown.
> 
> This occurs because pci_device_shutdown() disables MSI/X on all devices
> during shutdown by calling pci_msi_shutdown() and pci_msix_shutdown()
> asynchronously of the devices' drivers.  If a driver does not have a
> shutdown method and is configured for MSI/X interrupts, disabling MSI/X
> will result in the device being configured for legacy interrupts with a
> driver that is configured for MSI/X.  If the hardware generates an
> interrupt during shutdown, the interrupt will be a legacy interrupt and
> will be reported as being unhandled by any driver.
> 
> Do not disable MSI/X interrupts during shutdown.
> 
> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> Cc: alex.williamson@redhat.com
> Cc: darcari@redhat.com
> Cc: mstowe@redhat.com
> Cc: bhelgaas@google.com
> Cc: lukas@wunner.de
> Cc: keith.busch@intel.com
> Cc: mika.westerberg@linux.intel.com
> ---
>  drivers/pci/pci-driver.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 1ccce1cd6aca..87c35db5a564 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
>  
>  	pm_runtime_resume(dev);
>  
> -	if (drv && drv->shutdown)
> +	if (drv && drv->shutdown) {
>  		drv->shutdown(pci_dev);
> -	pci_msi_shutdown(pci_dev);
> -	pci_msix_shutdown(pci_dev);
> +		pci_msi_shutdown(pci_dev);
> +		pci_msix_shutdown(pci_dev);
> +	}

I love this patch because it cleans up pci_device_shutdown().  You
mentioned that you've also tested a patch that just removes the calls
to pci_msi_shutdown() and pci_msix_shutdown() completely.  I like that
even more.

As Keith pointed out, the driver remains bound to the device even
after we call pci_device_shutdown(), and the PCI core should not
change the configuration of the device behind the back of the driver.

I think these commits are important pieces:

  1851617cd2da ("PCI/MSI: Disable MSI at enumeration even if kernel
    doesn't support MSI")
  e80e7edc55ba ("PCI/MSI: Initialize MSI capability for all
    architectures")

because they ensure that a kexeced kernel can deal with MSIs being
left enabled.

What do you think of the following two patches?  Thanks for all the
details in your changelog -- I think they finally helped me gel all
the pieces in my mind, and it all seems obvious now.  I tried to
distill it down to just the critical pieces.

Bjorn


commit fda78d7a0ead144f4b2cdb582dcba47911f4952c
Author: Prarit Bhargava <prarit@redhat.com>
Date:   Thu Jan 26 14:07:47 2017 -0500

    PCI/MSI: Stop disabling MSI/MSI-X in pci_device_shutdown()
    
    The pci_bus_type .shutdown method, pci_device_shutdown(), is called from
    device_shutdown() in the kernel restart and shutdown paths.
    
    Previously, pci_device_shutdown() called pci_msi_shutdown() and
    pci_msix_shutdown().  This disables MSI and MSI-X, which causes the device
    to fall back to raising interrupts via INTx.  But the driver is still bound
    to the device, it doesn't know about this change, and it likely doesn't
    have an INTx handler, so these INTx interrupts cause "nobody cared"
    warnings like this:
    
      irq 16: nobody cared (try booting with the "irqpoll" option)
      CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
      Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/
      ...
    
    The MSI disabling code was added by d52877c7b1af ("pci/irq: let
    pci_device_shutdown to call pci_msi_shutdown v2") because a driver left MSI
    enabled and kdump failed because the kexeced kernel wasn't prepared to
    receive the MSI interrupts.
    
    Subsequent commits 1851617cd2da ("PCI/MSI: Disable MSI at enumeration even
    if kernel doesn't support MSI") and  e80e7edc55ba ("PCI/MSI: Initialize MSI
    capability for all architectures") changed the kexeced kernel to disable
    all MSIs itself so it no longer depends on the crashed kernel to clean up
    after itself.
    
    Stop disabling MSI/MSI-X in pci_device_shutdown().  This resolves the
    "nobody cared" unhandled IRQ issue above.  It also allows PCI serial
    devices, which may rely on the MSI interrupts, to continue outputting
    messages during reboot/shutdown.
    
    [bhelgaas: changelog, drop pci_msi_shutdown() and pci_msix_shutdown() calls
    altogether]
    Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=187351
    Signed-off-by: Prarit Bhargava <prarit@redhat.com>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    CC: Alex Williamson <alex.williamson@redhat.com>
    CC: David Arcari <darcari@redhat.com>
    CC: Myron Stowe <mstowe@redhat.com>
    CC: Lukas Wunner <lukas@wunner.de>
    CC: Keith Busch <keith.busch@intel.com>
    CC: Mika Westerberg <mika.westerberg@linux.intel.com>

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index afa72717a979..8ec136164e93 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -461,8 +461,6 @@ static void pci_device_shutdown(struct device *dev)
 
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_shutdown(pci_dev);
 
 	/*
 	 * If this is a kexec reboot, turn off Bus Master bit on the

commit 688769f643bfce894f14dc7141bfc6c010f52750
Author: Bjorn Helgaas <bhelgaas@google.com>
Date:   Thu Mar 9 15:45:14 2017 -0600

    PCI/MSI: Make pci_msi_shutdown() and pci_msix_shutdown() static
    
    pci_msi_shutdown() and pci_msix_shutdown() are used only in
    drivers/pci/msi.c, so make them static.
    
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index d571bc330686..4d062c3bf5f0 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -882,7 +882,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
 }
 EXPORT_SYMBOL(pci_msi_vec_count);
 
-void pci_msi_shutdown(struct pci_dev *dev)
+static void pci_msi_shutdown(struct pci_dev *dev)
 {
 	struct msi_desc *desc;
 	u32 mask;
@@ -994,7 +994,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
 }
 EXPORT_SYMBOL(pci_enable_msix);
 
-void pci_msix_shutdown(struct pci_dev *dev)
+static void pci_msix_shutdown(struct pci_dev *dev)
 {
 	struct msi_desc *entry;
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index eb3da1a04e6c..10917c122974 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1297,11 +1297,9 @@ struct msix_entry {
 
 #ifdef CONFIG_PCI_MSI
 int pci_msi_vec_count(struct pci_dev *dev);
-void pci_msi_shutdown(struct pci_dev *dev);
 void pci_disable_msi(struct pci_dev *dev);
 int pci_msix_vec_count(struct pci_dev *dev);
 int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
-void pci_msix_shutdown(struct pci_dev *dev);
 void pci_disable_msix(struct pci_dev *dev);
 void pci_restore_msi_state(struct pci_dev *dev);
 int pci_msi_enabled(void);
@@ -1327,13 +1325,11 @@ int pci_irq_get_node(struct pci_dev *pdev, int vec);
 
 #else
 static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
-static inline void pci_msi_shutdown(struct pci_dev *dev) { }
 static inline void pci_disable_msi(struct pci_dev *dev) { }
 static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
 static inline int pci_enable_msix(struct pci_dev *dev,
 				  struct msix_entry *entries, int nvec)
 { return -ENOSYS; }
-static inline void pci_msix_shutdown(struct pci_dev *dev) { }
 static inline void pci_disable_msix(struct pci_dev *dev) { }
 static inline void pci_restore_msi_state(struct pci_dev *dev) { }
 static inline int pci_msi_enabled(void) { return 0; }

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2017-03-09 21:57 ` Bjorn Helgaas
@ 2017-03-10 12:30   ` Prarit Bhargava
  2017-03-30 11:59     ` Prarit Bhargava
  0 siblings, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2017-03-10 12:30 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg



On 03/09/2017 04:57 PM, Bjorn Helgaas wrote:
> Hi Prarit,
> 
> My abject apologies for taking so long to deal with this.

np.  It's only two lines but it is also complex code and I know you're busy.

>>  drivers/pci/pci-driver.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index 1ccce1cd6aca..87c35db5a564 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
>>  
>>  	pm_runtime_resume(dev);
>>  
>> -	if (drv && drv->shutdown)
>> +	if (drv && drv->shutdown) {
>>  		drv->shutdown(pci_dev);
>> -	pci_msi_shutdown(pci_dev);
>> -	pci_msix_shutdown(pci_dev);
>> +		pci_msi_shutdown(pci_dev);
>> +		pci_msix_shutdown(pci_dev);
>> +	}
> 
> I love this patch because it cleans up pci_device_shutdown().  You
> mentioned that you've also tested a patch that just removes the calls
> to pci_msi_shutdown() and pci_msix_shutdown() completely.  I like that
> even more.
> 
> As Keith pointed out, the driver remains bound to the device even
> after we call pci_device_shutdown(), and the PCI core should not
> change the configuration of the device behind the back of the driver.
> 
> I think these commits are important pieces:
> 
>   1851617cd2da ("PCI/MSI: Disable MSI at enumeration even if kernel
>     doesn't support MSI")
>   e80e7edc55ba ("PCI/MSI: Initialize MSI capability for all
>     architectures")
> 
> because they ensure that a kexeced kernel can deal with MSIs being
> left enabled.
> 
> What do you think of the following two patches?  Thanks for all the
> details in your changelog -- I think they finally helped me gel all
> the pieces in my mind, and it all seems obvious now.  I tried to
> distill it down to just the critical pieces.
> 

I'm good with these two patches.

P.

> Bjorn
> 
> 
> commit fda78d7a0ead144f4b2cdb582dcba47911f4952c
> Author: Prarit Bhargava <prarit@redhat.com>
> Date:   Thu Jan 26 14:07:47 2017 -0500
> 
>     PCI/MSI: Stop disabling MSI/MSI-X in pci_device_shutdown()
>     
>     The pci_bus_type .shutdown method, pci_device_shutdown(), is called from
>     device_shutdown() in the kernel restart and shutdown paths.
>     
>     Previously, pci_device_shutdown() called pci_msi_shutdown() and
>     pci_msix_shutdown().  This disables MSI and MSI-X, which causes the device
>     to fall back to raising interrupts via INTx.  But the driver is still bound
>     to the device, it doesn't know about this change, and it likely doesn't
>     have an INTx handler, so these INTx interrupts cause "nobody cared"
>     warnings like this:
>     
>       irq 16: nobody cared (try booting with the "irqpoll" option)
>       CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
>       Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/
>       ...
>     
>     The MSI disabling code was added by d52877c7b1af ("pci/irq: let
>     pci_device_shutdown to call pci_msi_shutdown v2") because a driver left MSI
>     enabled and kdump failed because the kexeced kernel wasn't prepared to
>     receive the MSI interrupts.
>     
>     Subsequent commits 1851617cd2da ("PCI/MSI: Disable MSI at enumeration even
>     if kernel doesn't support MSI") and  e80e7edc55ba ("PCI/MSI: Initialize MSI
>     capability for all architectures") changed the kexeced kernel to disable
>     all MSIs itself so it no longer depends on the crashed kernel to clean up
>     after itself.
>     
>     Stop disabling MSI/MSI-X in pci_device_shutdown().  This resolves the
>     "nobody cared" unhandled IRQ issue above.  It also allows PCI serial
>     devices, which may rely on the MSI interrupts, to continue outputting
>     messages during reboot/shutdown.
>     
>     [bhelgaas: changelog, drop pci_msi_shutdown() and pci_msix_shutdown() calls
>     altogether]
>     Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=187351
>     Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>     Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>     CC: Alex Williamson <alex.williamson@redhat.com>
>     CC: David Arcari <darcari@redhat.com>
>     CC: Myron Stowe <mstowe@redhat.com>
>     CC: Lukas Wunner <lukas@wunner.de>
>     CC: Keith Busch <keith.busch@intel.com>
>     CC: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index afa72717a979..8ec136164e93 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -461,8 +461,6 @@ static void pci_device_shutdown(struct device *dev)
>  
>  	if (drv && drv->shutdown)
>  		drv->shutdown(pci_dev);
> -	pci_msi_shutdown(pci_dev);
> -	pci_msix_shutdown(pci_dev);
>  
>  	/*
>  	 * If this is a kexec reboot, turn off Bus Master bit on the
> 
> commit 688769f643bfce894f14dc7141bfc6c010f52750
> Author: Bjorn Helgaas <bhelgaas@google.com>
> Date:   Thu Mar 9 15:45:14 2017 -0600
> 
>     PCI/MSI: Make pci_msi_shutdown() and pci_msix_shutdown() static
>     
>     pci_msi_shutdown() and pci_msix_shutdown() are used only in
>     drivers/pci/msi.c, so make them static.
>     
>     Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> 
> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
> index d571bc330686..4d062c3bf5f0 100644
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -882,7 +882,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
>  }
>  EXPORT_SYMBOL(pci_msi_vec_count);
>  
> -void pci_msi_shutdown(struct pci_dev *dev)
> +static void pci_msi_shutdown(struct pci_dev *dev)
>  {
>  	struct msi_desc *desc;
>  	u32 mask;
> @@ -994,7 +994,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
>  }
>  EXPORT_SYMBOL(pci_enable_msix);
>  
> -void pci_msix_shutdown(struct pci_dev *dev)
> +static void pci_msix_shutdown(struct pci_dev *dev)
>  {
>  	struct msi_desc *entry;
>  
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index eb3da1a04e6c..10917c122974 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1297,11 +1297,9 @@ struct msix_entry {
>  
>  #ifdef CONFIG_PCI_MSI
>  int pci_msi_vec_count(struct pci_dev *dev);
> -void pci_msi_shutdown(struct pci_dev *dev);
>  void pci_disable_msi(struct pci_dev *dev);
>  int pci_msix_vec_count(struct pci_dev *dev);
>  int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
> -void pci_msix_shutdown(struct pci_dev *dev);
>  void pci_disable_msix(struct pci_dev *dev);
>  void pci_restore_msi_state(struct pci_dev *dev);
>  int pci_msi_enabled(void);
> @@ -1327,13 +1325,11 @@ int pci_irq_get_node(struct pci_dev *pdev, int vec);
>  
>  #else
>  static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
> -static inline void pci_msi_shutdown(struct pci_dev *dev) { }
>  static inline void pci_disable_msi(struct pci_dev *dev) { }
>  static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
>  static inline int pci_enable_msix(struct pci_dev *dev,
>  				  struct msix_entry *entries, int nvec)
>  { return -ENOSYS; }
> -static inline void pci_msix_shutdown(struct pci_dev *dev) { }
>  static inline void pci_disable_msix(struct pci_dev *dev) { }
>  static inline void pci_restore_msi_state(struct pci_dev *dev) { }
>  static inline int pci_msi_enabled(void) { return 0; }
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2017-03-10 12:30   ` Prarit Bhargava
@ 2017-03-30 11:59     ` Prarit Bhargava
  2017-03-30 21:52       ` Bjorn Helgaas
  0 siblings, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2017-03-30 11:59 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

On 03/10/2017 07:30 AM, Prarit Bhargava wrote:
> 
> 
> On 03/09/2017 04:57 PM, Bjorn Helgaas wrote:
>> Hi Prarit,
>>
>> My abject apologies for taking so long to deal with this.
> 
> np.  It's only two lines but it is also complex code and I know you're busy.
> 

<snip>

>>
>> What do you think of the following two patches?  Thanks for all the
>> details in your changelog -- I think they finally helped me gel all
>> the pieces in my mind, and it all seems obvious now.  I tried to
>> distill it down to just the critical pieces.
>>
> 
> I'm good with these two patches.

Bjorn, I just am making sure that these don't get left on the floor (so to speak).

P.

> 
> P.
> 
>> Bjorn
>>
>>
>> commit fda78d7a0ead144f4b2cdb582dcba47911f4952c
>> Author: Prarit Bhargava <prarit@redhat.com>
>> Date:   Thu Jan 26 14:07:47 2017 -0500
>>
>>     PCI/MSI: Stop disabling MSI/MSI-X in pci_device_shutdown()
>>     
>>     The pci_bus_type .shutdown method, pci_device_shutdown(), is called from
>>     device_shutdown() in the kernel restart and shutdown paths.
>>     
>>     Previously, pci_device_shutdown() called pci_msi_shutdown() and
>>     pci_msix_shutdown().  This disables MSI and MSI-X, which causes the device
>>     to fall back to raising interrupts via INTx.  But the driver is still bound
>>     to the device, it doesn't know about this change, and it likely doesn't
>>     have an INTx handler, so these INTx interrupts cause "nobody cared"
>>     warnings like this:
>>     
>>       irq 16: nobody cared (try booting with the "irqpoll" option)
>>       CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
>>       Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/
>>       ...
>>     
>>     The MSI disabling code was added by d52877c7b1af ("pci/irq: let
>>     pci_device_shutdown to call pci_msi_shutdown v2") because a driver left MSI
>>     enabled and kdump failed because the kexeced kernel wasn't prepared to
>>     receive the MSI interrupts.
>>     
>>     Subsequent commits 1851617cd2da ("PCI/MSI: Disable MSI at enumeration even
>>     if kernel doesn't support MSI") and  e80e7edc55ba ("PCI/MSI: Initialize MSI
>>     capability for all architectures") changed the kexeced kernel to disable
>>     all MSIs itself so it no longer depends on the crashed kernel to clean up
>>     after itself.
>>     
>>     Stop disabling MSI/MSI-X in pci_device_shutdown().  This resolves the
>>     "nobody cared" unhandled IRQ issue above.  It also allows PCI serial
>>     devices, which may rely on the MSI interrupts, to continue outputting
>>     messages during reboot/shutdown.
>>     
>>     [bhelgaas: changelog, drop pci_msi_shutdown() and pci_msix_shutdown() calls
>>     altogether]
>>     Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=187351
>>     Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>>     Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>>     CC: Alex Williamson <alex.williamson@redhat.com>
>>     CC: David Arcari <darcari@redhat.com>
>>     CC: Myron Stowe <mstowe@redhat.com>
>>     CC: Lukas Wunner <lukas@wunner.de>
>>     CC: Keith Busch <keith.busch@intel.com>
>>     CC: Mika Westerberg <mika.westerberg@linux.intel.com>
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index afa72717a979..8ec136164e93 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -461,8 +461,6 @@ static void pci_device_shutdown(struct device *dev)
>>  
>>  	if (drv && drv->shutdown)
>>  		drv->shutdown(pci_dev);
>> -	pci_msi_shutdown(pci_dev);
>> -	pci_msix_shutdown(pci_dev);
>>  
>>  	/*
>>  	 * If this is a kexec reboot, turn off Bus Master bit on the
>>
>> commit 688769f643bfce894f14dc7141bfc6c010f52750
>> Author: Bjorn Helgaas <bhelgaas@google.com>
>> Date:   Thu Mar 9 15:45:14 2017 -0600
>>
>>     PCI/MSI: Make pci_msi_shutdown() and pci_msix_shutdown() static
>>     
>>     pci_msi_shutdown() and pci_msix_shutdown() are used only in
>>     drivers/pci/msi.c, so make them static.
>>     
>>     Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>>
>> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
>> index d571bc330686..4d062c3bf5f0 100644
>> --- a/drivers/pci/msi.c
>> +++ b/drivers/pci/msi.c
>> @@ -882,7 +882,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
>>  }
>>  EXPORT_SYMBOL(pci_msi_vec_count);
>>  
>> -void pci_msi_shutdown(struct pci_dev *dev)
>> +static void pci_msi_shutdown(struct pci_dev *dev)
>>  {
>>  	struct msi_desc *desc;
>>  	u32 mask;
>> @@ -994,7 +994,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
>>  }
>>  EXPORT_SYMBOL(pci_enable_msix);
>>  
>> -void pci_msix_shutdown(struct pci_dev *dev)
>> +static void pci_msix_shutdown(struct pci_dev *dev)
>>  {
>>  	struct msi_desc *entry;
>>  
>> diff --git a/include/linux/pci.h b/include/linux/pci.h
>> index eb3da1a04e6c..10917c122974 100644
>> --- a/include/linux/pci.h
>> +++ b/include/linux/pci.h
>> @@ -1297,11 +1297,9 @@ struct msix_entry {
>>  
>>  #ifdef CONFIG_PCI_MSI
>>  int pci_msi_vec_count(struct pci_dev *dev);
>> -void pci_msi_shutdown(struct pci_dev *dev);
>>  void pci_disable_msi(struct pci_dev *dev);
>>  int pci_msix_vec_count(struct pci_dev *dev);
>>  int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
>> -void pci_msix_shutdown(struct pci_dev *dev);
>>  void pci_disable_msix(struct pci_dev *dev);
>>  void pci_restore_msi_state(struct pci_dev *dev);
>>  int pci_msi_enabled(void);
>> @@ -1327,13 +1325,11 @@ int pci_irq_get_node(struct pci_dev *pdev, int vec);
>>  
>>  #else
>>  static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
>> -static inline void pci_msi_shutdown(struct pci_dev *dev) { }
>>  static inline void pci_disable_msi(struct pci_dev *dev) { }
>>  static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
>>  static inline int pci_enable_msix(struct pci_dev *dev,
>>  				  struct msix_entry *entries, int nvec)
>>  { return -ENOSYS; }
>> -static inline void pci_msix_shutdown(struct pci_dev *dev) { }
>>  static inline void pci_disable_msix(struct pci_dev *dev) { }
>>  static inline void pci_restore_msi_state(struct pci_dev *dev) { }
>>  static inline int pci_msi_enabled(void) { return 0; }
>>
> 
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2017-03-30 11:59     ` Prarit Bhargava
@ 2017-03-30 21:52       ` Bjorn Helgaas
  0 siblings, 0 replies; 13+ messages in thread
From: Bjorn Helgaas @ 2017-03-30 21:52 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

On Thu, Mar 30, 2017 at 07:59:12AM -0400, Prarit Bhargava wrote:
> On 03/10/2017 07:30 AM, Prarit Bhargava wrote:
> > 
> > 
> > On 03/09/2017 04:57 PM, Bjorn Helgaas wrote:
> >> Hi Prarit,
> >>
> >> My abject apologies for taking so long to deal with this.
> > 
> > np.  It's only two lines but it is also complex code and I know you're busy.
> > 
> 
> <snip>
> 
> >>
> >> What do you think of the following two patches?  Thanks for all the
> >> details in your changelog -- I think they finally helped me gel all
> >> the pieces in my mind, and it all seems obvious now.  I tried to
> >> distill it down to just the critical pieces.
> >>
> > 
> > I'm good with these two patches.
> 
> Bjorn, I just am making sure that these don't get left on the floor (so to speak).

Yep, sorry, they're on my pci/msi branch; I just hadn't merged that
into "next".  I did that now, so you should see it in linux-next
tomorrow.

Bjorn

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2017-01-19 14:38     ` Bjorn Helgaas
@ 2017-01-25 13:23       ` Prarit Bhargava
  0 siblings, 0 replies; 13+ messages in thread
From: Prarit Bhargava @ 2017-01-25 13:23 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg



On 01/19/2017 09:38 AM, Bjorn Helgaas wrote:
> On Fri, Dec 16, 2016 at 11:48:06AM -0500, Prarit Bhargava wrote:
>> On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
>>> Hi Prarit,
>>>
>>> Is there a bugzilla or other archive of configuration/dmesg/other info
>>> related to this problem?  I'd really like to connect this fix to a
>>> problem report, and it would help me review the patch as well.
>>
>> Bjorn, have you had a chance to look at this?
>>
>> I had opened
>>
>> https://bugzilla.kernel.org/show_bug.cgi?id=187351
> 
> Hi Prarit,
> 
> Sorry, I've not had a chance to dig into this yet.  What I'd *like* to do
> is figure out what the kexec/kdump/shutdown strategy really is and make
> sure this is all coherent.  It seems like we've gone back and forth on this
> a couple times because this or that is broken, but I don't really
> understand why.
> 

Bjorn,

Let me start from the beginning with a new patch and explanation.  I think
that as time went on, some of the details and explanation were lost ...

I'll post a v2 shortly.

P.

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-12-16 16:48   ` Prarit Bhargava
@ 2017-01-19 14:38     ` Bjorn Helgaas
  2017-01-25 13:23       ` Prarit Bhargava
  0 siblings, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2017-01-19 14:38 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

On Fri, Dec 16, 2016 at 11:48:06AM -0500, Prarit Bhargava wrote:
> On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
> > Hi Prarit,
> > 
> > Is there a bugzilla or other archive of configuration/dmesg/other info
> > related to this problem?  I'd really like to connect this fix to a
> > problem report, and it would help me review the patch as well.
> 
> Bjorn, have you had a chance to look at this?
> 
> I had opened
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=187351

Hi Prarit,

Sorry, I've not had a chance to dig into this yet.  What I'd *like* to do
is figure out what the kexec/kdump/shutdown strategy really is and make
sure this is all coherent.  It seems like we've gone back and forth on this
a couple times because this or that is broken, but I don't really
understand why.

> > On Tue, Nov 08, 2016 at 12:57:47PM -0500, Prarit Bhargava wrote:
> >> Bjorn,
> >>
> >> We have seen this at Red Hat on various drivers: nouveau, ahci, mei_me, and
> >> pcieport (so far).  Google search for "unhandled irq 16" yields many results
> >> reporting similar behavior during shutdown indicating that this problem is
> >> widespread.  I can cause this to happen on a "stable" system by adding a 3
> >> second delay in pci_device_shutdown() which causes the number of spurious
> >> interrupts to exceed the 100000 limit and display the warning below for the
> >> primarily the nouveau driver, and occasionally for the other mentioned drivers.
> >>
> >> A patch for this was proposed and rejected here for being too risky:
> >>
> >> https://patchwork.kernel.org/patch/5990701/
> >>
> >> I also originally posted a patch to resolve this here:
> >>
> >> http://marc.info/?l=linux-pci&m=147705209308588&w=2
> >>
> >> and several other patch suggestions were made.  The problem with all of these
> >> solutions is that there is some risk associated with them (kdump, kvm, etc.)
> >> and they are papering over the real issue that the PCI shutdown should not
> >> blindly switch to INTx for all devices.
> >>
> >> I am reproposing the original suggested patch.  There is some risk associated
> >> with this but I don't think it is any more or any less than the other patches,
> >> and it seems like the other patches are only applying band-aids to the problem.
> >>
> >> [Aside: Lukas Wunner asked why does this always happen on IRQ 16 (even when the
> >> legacy device says IRQ 32 in lspci)?
> >>
> >> The PCI irq pins A, B, C, and D are routed according to the ACPI _PRT table for
> >> the device.  _In general_, I have noted a consistent pattern for PCI irq pins
> >> such that
> >>
> >> 	irq pin A is IRQ 0x10 (16)
> >> 	irq pin B is IRQ 0x11 (17)
> >> 	irq pin C is IRQ 0x12 (18)
> >> 	irq pin D is IRQ 0x13 (19)
> >>
> >> Since the device's IRQ is hooked up to pin A we're seeing the unhandled
> >> interrupt on IRQ 16.]
> >>
> >> I have tested this on various systems with KVM and kdump (and kdump on
> >> KVM) and didn't see any issues.
> >>
> >> NOTE: In my testing this resolves the problem with PCI based serial ports
> >> cutting off their output during shutdown.  Again, this can be tracked to the
> >> PCI shutdown path switching between MSI & INTx independently of the driver.
> >>
> >> ----8<----
> >>
> >> The following unhandled IRQ warning is seen during shutdown:
> >>
> >> irq 16: nobody cared (try booting with the "irqpoll" option)
> >> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
> >> Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/01/2016
> >>  0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
> >>  ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
> >>  0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
> >> Call Trace:
> >>  <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
> >>  [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
> >>  [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
> >>  [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
> >>  [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
> >>  [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
> >>  [<ffffffff8102edfb>] handle_irq+0xab/0x130
> >>  [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
> >>  [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
> >>  [<ffffffff81704502>] common_interrupt+0x82/0x82
> >>  <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
> >>  [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
> >>  [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
> >>  [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
> >>  [<ffffffff816f6da7>] rest_init+0x77/0x80
> >>  [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
> >>  [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
> >>  [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
> >>  [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
> >>  [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c
> >>
> >> pci_device_shutdown() is called on each PCI device, and does
> >>
> >>         if (drv && drv->shutdown)
> >>                 drv->shutdown(pci_dev);
> >>         pci_msi_shutdown(pci_dev);
> >>         pci_msix_shutdown(pci_dev);
> >>
> >> The pci_msi_shutdown() and pci_msix_shutdown() functions both call
> >> pci_intx_for_msi() which enables the INTx interrupt asynchronously of the
> >> driver.
> >>
> >> The problem is that the driver may not have a shutdown function and the
> >> device remains active.  The driver continues to operate the PCI device and the
> >> device interrupts to generate INTx.  The driver, however, has not registered a
> >> handler for INTx and the interrupt line remains set which leads to an unhandled
> >> IRQ warning.
> >>
> >> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> >> Cc: alex.williamson@redhat.com
> >> Cc: darcari@redhat.com
> >> Cc: mstowe@redhat.com
> >> Cc: bhelgaas@google.com
> >> Cc: lukas@wunner.de
> >> Cc: keith.busch@intel.com
> >> Cc: mika.westerberg@linux.intel.com
> >> ---
> >>  drivers/pci/pci-driver.c |    7 ++++---
> >>  1 file changed, 4 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> >> index 1ccce1cd6aca..87c35db5a564 100644
> >> --- a/drivers/pci/pci-driver.c
> >> +++ b/drivers/pci/pci-driver.c
> >> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
> >>  
> >>  	pm_runtime_resume(dev);
> >>  
> >> -	if (drv && drv->shutdown)
> >> +	if (drv && drv->shutdown) {
> >>  		drv->shutdown(pci_dev);
> >> -	pci_msi_shutdown(pci_dev);
> >> -	pci_msix_shutdown(pci_dev);
> >> +		pci_msi_shutdown(pci_dev);
> >> +		pci_msix_shutdown(pci_dev);
> >> +	}
> >>  
> >>  	/*
> >>  	 * If this is a kexec reboot, turn off Bus Master bit on the
> >> -- 
> >> 1.7.9.3
> >>
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> >> the body of a message to majordomo@vger.kernel.org
> >> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> > 
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-11-09 17:05 ` Bjorn Helgaas
  2016-11-09 19:36   ` Prarit Bhargava
@ 2016-12-16 16:48   ` Prarit Bhargava
  2017-01-19 14:38     ` Bjorn Helgaas
  1 sibling, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2016-12-16 16:48 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
> Hi Prarit,
> 
> Is there a bugzilla or other archive of configuration/dmesg/other info
> related to this problem?  I'd really like to connect this fix to a
> problem report, and it would help me review the patch as well.

Bjorn, have you had a chance to look at this?

I had opened

https://bugzilla.kernel.org/show_bug.cgi?id=187351

P.

> 
> On Tue, Nov 08, 2016 at 12:57:47PM -0500, Prarit Bhargava wrote:
>> Bjorn,
>>
>> We have seen this at Red Hat on various drivers: nouveau, ahci, mei_me, and
>> pcieport (so far).  Google search for "unhandled irq 16" yields many results
>> reporting similar behavior during shutdown indicating that this problem is
>> widespread.  I can cause this to happen on a "stable" system by adding a 3
>> second delay in pci_device_shutdown() which causes the number of spurious
>> interrupts to exceed the 100000 limit and display the warning below for the
>> primarily the nouveau driver, and occasionally for the other mentioned drivers.
>>
>> A patch for this was proposed and rejected here for being too risky:
>>
>> https://patchwork.kernel.org/patch/5990701/
>>
>> I also originally posted a patch to resolve this here:
>>
>> http://marc.info/?l=linux-pci&m=147705209308588&w=2
>>
>> and several other patch suggestions were made.  The problem with all of these
>> solutions is that there is some risk associated with them (kdump, kvm, etc.)
>> and they are papering over the real issue that the PCI shutdown should not
>> blindly switch to INTx for all devices.
>>
>> I am reproposing the original suggested patch.  There is some risk associated
>> with this but I don't think it is any more or any less than the other patches,
>> and it seems like the other patches are only applying band-aids to the problem.
>>
>> [Aside: Lukas Wunner asked why does this always happen on IRQ 16 (even when the
>> legacy device says IRQ 32 in lspci)?
>>
>> The PCI irq pins A, B, C, and D are routed according to the ACPI _PRT table for
>> the device.  _In general_, I have noted a consistent pattern for PCI irq pins
>> such that
>>
>> 	irq pin A is IRQ 0x10 (16)
>> 	irq pin B is IRQ 0x11 (17)
>> 	irq pin C is IRQ 0x12 (18)
>> 	irq pin D is IRQ 0x13 (19)
>>
>> Since the device's IRQ is hooked up to pin A we're seeing the unhandled
>> interrupt on IRQ 16.]
>>
>> I have tested this on various systems with KVM and kdump (and kdump on
>> KVM) and didn't see any issues.
>>
>> NOTE: In my testing this resolves the problem with PCI based serial ports
>> cutting off their output during shutdown.  Again, this can be tracked to the
>> PCI shutdown path switching between MSI & INTx independently of the driver.
>>
>> ----8<----
>>
>> The following unhandled IRQ warning is seen during shutdown:
>>
>> irq 16: nobody cared (try booting with the "irqpoll" option)
>> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
>> Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/01/2016
>>  0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
>>  ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
>>  0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
>> Call Trace:
>>  <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
>>  [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
>>  [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
>>  [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
>>  [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
>>  [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
>>  [<ffffffff8102edfb>] handle_irq+0xab/0x130
>>  [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
>>  [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
>>  [<ffffffff81704502>] common_interrupt+0x82/0x82
>>  <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
>>  [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
>>  [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
>>  [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
>>  [<ffffffff816f6da7>] rest_init+0x77/0x80
>>  [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
>>  [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
>>  [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
>>  [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
>>  [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c
>>
>> pci_device_shutdown() is called on each PCI device, and does
>>
>>         if (drv && drv->shutdown)
>>                 drv->shutdown(pci_dev);
>>         pci_msi_shutdown(pci_dev);
>>         pci_msix_shutdown(pci_dev);
>>
>> The pci_msi_shutdown() and pci_msix_shutdown() functions both call
>> pci_intx_for_msi() which enables the INTx interrupt asynchronously of the
>> driver.
>>
>> The problem is that the driver may not have a shutdown function and the
>> device remains active.  The driver continues to operate the PCI device and the
>> device interrupts to generate INTx.  The driver, however, has not registered a
>> handler for INTx and the interrupt line remains set which leads to an unhandled
>> IRQ warning.
>>
>> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>> Cc: alex.williamson@redhat.com
>> Cc: darcari@redhat.com
>> Cc: mstowe@redhat.com
>> Cc: bhelgaas@google.com
>> Cc: lukas@wunner.de
>> Cc: keith.busch@intel.com
>> Cc: mika.westerberg@linux.intel.com
>> ---
>>  drivers/pci/pci-driver.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index 1ccce1cd6aca..87c35db5a564 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
>>  
>>  	pm_runtime_resume(dev);
>>  
>> -	if (drv && drv->shutdown)
>> +	if (drv && drv->shutdown) {
>>  		drv->shutdown(pci_dev);
>> -	pci_msi_shutdown(pci_dev);
>> -	pci_msix_shutdown(pci_dev);
>> +		pci_msi_shutdown(pci_dev);
>> +		pci_msix_shutdown(pci_dev);
>> +	}
>>  
>>  	/*
>>  	 * If this is a kexec reboot, turn off Bus Master bit on the
>> -- 
>> 1.7.9.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-11-09 19:36   ` Prarit Bhargava
@ 2016-11-09 19:54     ` Keith Busch
  2016-11-09 19:49       ` Prarit Bhargava
  0 siblings, 1 reply; 13+ messages in thread
From: Keith Busch @ 2016-11-09 19:54 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: Bjorn Helgaas, linux-pci, alex.williamson, darcari, mstowe,
	bhelgaas, lukas, mika.westerberg

On Wed, Nov 09, 2016 at 02:36:23PM -0500, Prarit Bhargava wrote:
> 
> 
> On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
> > Hi Prarit,
> > 
> > Is there a bugzilla or other archive of configuration/dmesg/other info
> 
> [I have only added Bjorn and myself to the BZ below.  Please feel free to add
> yourself.]
> 
> Bjorn, unfortunately this won't be caught in a dmesg log because the filesystem
> is unmounted by the time we shutdown the PCI devices in the halt/reboot path.
> 
> The trace is only available from serial console, and I have opened up
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=187351
> 
> to track this.
> 
> I have added some additional links to other bugzillas which seem to show the
> same behavior, and included a full serial console capture of the boot to the BZ.
>  The end of the log shows the unhandled irq stack trace for irq 16.

Just researching where this came from, the behavior to shutdown msi/msix
and enable intx was done in commit d52877c7b1 for some kexec issue,
and I think that was wrong in the first place. We shouldn't be changing
interrupt configuration out from under the drivers.

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-11-09 19:54     ` Keith Busch
@ 2016-11-09 19:49       ` Prarit Bhargava
  0 siblings, 0 replies; 13+ messages in thread
From: Prarit Bhargava @ 2016-11-09 19:49 UTC (permalink / raw)
  To: Keith Busch
  Cc: Bjorn Helgaas, linux-pci, alex.williamson, darcari, mstowe,
	bhelgaas, lukas, mika.westerberg



On 11/09/2016 02:54 PM, Keith Busch wrote:
> On Wed, Nov 09, 2016 at 02:36:23PM -0500, Prarit Bhargava wrote:
>>
>>
>> On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
>>> Hi Prarit,
>>>
>>> Is there a bugzilla or other archive of configuration/dmesg/other info
>>
>> [I have only added Bjorn and myself to the BZ below.  Please feel free to add
>> yourself.]
>>
>> Bjorn, unfortunately this won't be caught in a dmesg log because the filesystem
>> is unmounted by the time we shutdown the PCI devices in the halt/reboot path.
>>
>> The trace is only available from serial console, and I have opened up
>>
>> https://bugzilla.kernel.org/show_bug.cgi?id=187351
>>
>> to track this.
>>
>> I have added some additional links to other bugzillas which seem to show the
>> same behavior, and included a full serial console capture of the boot to the BZ.
>>  The end of the log shows the unhandled irq stack trace for irq 16.
> 
> Just researching where this came from, the behavior to shutdown msi/msix
> and enable intx was done in commit d52877c7b1 for some kexec issue,
> and I think that was wrong in the first place. We shouldn't be changing
> interrupt configuration out from under the drivers.

Yeah .. and it was RHEL specific?  Or at least it seems that way.

P.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-11-09 17:05 ` Bjorn Helgaas
@ 2016-11-09 19:36   ` Prarit Bhargava
  2016-11-09 19:54     ` Keith Busch
  2016-12-16 16:48   ` Prarit Bhargava
  1 sibling, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2016-11-09 19:36 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg



On 11/09/2016 12:05 PM, Bjorn Helgaas wrote:
> Hi Prarit,
> 
> Is there a bugzilla or other archive of configuration/dmesg/other info

[I have only added Bjorn and myself to the BZ below.  Please feel free to add
yourself.]

Bjorn, unfortunately this won't be caught in a dmesg log because the filesystem
is unmounted by the time we shutdown the PCI devices in the halt/reboot path.

The trace is only available from serial console, and I have opened up

https://bugzilla.kernel.org/show_bug.cgi?id=187351

to track this.

I have added some additional links to other bugzillas which seem to show the
same behavior, and included a full serial console capture of the boot to the BZ.
 The end of the log shows the unhandled irq stack trace for irq 16.

HTH,

P.

> related to this problem?  I'd really like to connect this fix to a
> problem report, and it would help me review the patch as well.
> 
> On Tue, Nov 08, 2016 at 12:57:47PM -0500, Prarit Bhargava wrote:
>> Bjorn,
>>
>> We have seen this at Red Hat on various drivers: nouveau, ahci, mei_me, and
>> pcieport (so far).  Google search for "unhandled irq 16" yields many results
>> reporting similar behavior during shutdown indicating that this problem is
>> widespread.  I can cause this to happen on a "stable" system by adding a 3
>> second delay in pci_device_shutdown() which causes the number of spurious
>> interrupts to exceed the 100000 limit and display the warning below for the
>> primarily the nouveau driver, and occasionally for the other mentioned drivers.
>>
>> A patch for this was proposed and rejected here for being too risky:
>>
>> https://patchwork.kernel.org/patch/5990701/
>>
>> I also originally posted a patch to resolve this here:
>>
>> http://marc.info/?l=linux-pci&m=147705209308588&w=2
>>
>> and several other patch suggestions were made.  The problem with all of these
>> solutions is that there is some risk associated with them (kdump, kvm, etc.)
>> and they are papering over the real issue that the PCI shutdown should not
>> blindly switch to INTx for all devices.
>>
>> I am reproposing the original suggested patch.  There is some risk associated
>> with this but I don't think it is any more or any less than the other patches,
>> and it seems like the other patches are only applying band-aids to the problem.
>>
>> [Aside: Lukas Wunner asked why does this always happen on IRQ 16 (even when the
>> legacy device says IRQ 32 in lspci)?
>>
>> The PCI irq pins A, B, C, and D are routed according to the ACPI _PRT table for
>> the device.  _In general_, I have noted a consistent pattern for PCI irq pins
>> such that
>>
>> 	irq pin A is IRQ 0x10 (16)
>> 	irq pin B is IRQ 0x11 (17)
>> 	irq pin C is IRQ 0x12 (18)
>> 	irq pin D is IRQ 0x13 (19)
>>
>> Since the device's IRQ is hooked up to pin A we're seeing the unhandled
>> interrupt on IRQ 16.]
>>
>> I have tested this on various systems with KVM and kdump (and kdump on
>> KVM) and didn't see any issues.
>>
>> NOTE: In my testing this resolves the problem with PCI based serial ports
>> cutting off their output during shutdown.  Again, this can be tracked to the
>> PCI shutdown path switching between MSI & INTx independently of the driver.
>>
>> ----8<----
>>
>> The following unhandled IRQ warning is seen during shutdown:
>>
>> irq 16: nobody cared (try booting with the "irqpoll" option)
>> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
>> Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/01/2016
>>  0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
>>  ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
>>  0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
>> Call Trace:
>>  <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
>>  [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
>>  [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
>>  [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
>>  [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
>>  [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
>>  [<ffffffff8102edfb>] handle_irq+0xab/0x130
>>  [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
>>  [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
>>  [<ffffffff81704502>] common_interrupt+0x82/0x82
>>  <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
>>  [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
>>  [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
>>  [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
>>  [<ffffffff816f6da7>] rest_init+0x77/0x80
>>  [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
>>  [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
>>  [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
>>  [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
>>  [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c
>>
>> pci_device_shutdown() is called on each PCI device, and does
>>
>>         if (drv && drv->shutdown)
>>                 drv->shutdown(pci_dev);
>>         pci_msi_shutdown(pci_dev);
>>         pci_msix_shutdown(pci_dev);
>>
>> The pci_msi_shutdown() and pci_msix_shutdown() functions both call
>> pci_intx_for_msi() which enables the INTx interrupt asynchronously of the
>> driver.
>>
>> The problem is that the driver may not have a shutdown function and the
>> device remains active.  The driver continues to operate the PCI device and the
>> device interrupts to generate INTx.  The driver, however, has not registered a
>> handler for INTx and the interrupt line remains set which leads to an unhandled
>> IRQ warning.
>>
>> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>> Cc: alex.williamson@redhat.com
>> Cc: darcari@redhat.com
>> Cc: mstowe@redhat.com
>> Cc: bhelgaas@google.com
>> Cc: lukas@wunner.de
>> Cc: keith.busch@intel.com
>> Cc: mika.westerberg@linux.intel.com
>> ---
>>  drivers/pci/pci-driver.c |    7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index 1ccce1cd6aca..87c35db5a564 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
>>  
>>  	pm_runtime_resume(dev);
>>  
>> -	if (drv && drv->shutdown)
>> +	if (drv && drv->shutdown) {
>>  		drv->shutdown(pci_dev);
>> -	pci_msi_shutdown(pci_dev);
>> -	pci_msix_shutdown(pci_dev);
>> +		pci_msi_shutdown(pci_dev);
>> +		pci_msix_shutdown(pci_dev);
>> +	}
>>  
>>  	/*
>>  	 * If this is a kexec reboot, turn off Bus Master bit on the
>> -- 
>> 1.7.9.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
  2016-11-08 17:57 Prarit Bhargava
@ 2016-11-09 17:05 ` Bjorn Helgaas
  2016-11-09 19:36   ` Prarit Bhargava
  2016-12-16 16:48   ` Prarit Bhargava
  0 siblings, 2 replies; 13+ messages in thread
From: Bjorn Helgaas @ 2016-11-09 17:05 UTC (permalink / raw)
  To: Prarit Bhargava
  Cc: linux-pci, alex.williamson, darcari, mstowe, bhelgaas, lukas,
	keith.busch, mika.westerberg

Hi Prarit,

Is there a bugzilla or other archive of configuration/dmesg/other info
related to this problem?  I'd really like to connect this fix to a
problem report, and it would help me review the patch as well.

On Tue, Nov 08, 2016 at 12:57:47PM -0500, Prarit Bhargava wrote:
> Bjorn,
> 
> We have seen this at Red Hat on various drivers: nouveau, ahci, mei_me, and
> pcieport (so far).  Google search for "unhandled irq 16" yields many results
> reporting similar behavior during shutdown indicating that this problem is
> widespread.  I can cause this to happen on a "stable" system by adding a 3
> second delay in pci_device_shutdown() which causes the number of spurious
> interrupts to exceed the 100000 limit and display the warning below for the
> primarily the nouveau driver, and occasionally for the other mentioned drivers.
> 
> A patch for this was proposed and rejected here for being too risky:
> 
> https://patchwork.kernel.org/patch/5990701/
> 
> I also originally posted a patch to resolve this here:
> 
> http://marc.info/?l=linux-pci&m=147705209308588&w=2
> 
> and several other patch suggestions were made.  The problem with all of these
> solutions is that there is some risk associated with them (kdump, kvm, etc.)
> and they are papering over the real issue that the PCI shutdown should not
> blindly switch to INTx for all devices.
> 
> I am reproposing the original suggested patch.  There is some risk associated
> with this but I don't think it is any more or any less than the other patches,
> and it seems like the other patches are only applying band-aids to the problem.
> 
> [Aside: Lukas Wunner asked why does this always happen on IRQ 16 (even when the
> legacy device says IRQ 32 in lspci)?
> 
> The PCI irq pins A, B, C, and D are routed according to the ACPI _PRT table for
> the device.  _In general_, I have noted a consistent pattern for PCI irq pins
> such that
> 
> 	irq pin A is IRQ 0x10 (16)
> 	irq pin B is IRQ 0x11 (17)
> 	irq pin C is IRQ 0x12 (18)
> 	irq pin D is IRQ 0x13 (19)
> 
> Since the device's IRQ is hooked up to pin A we're seeing the unhandled
> interrupt on IRQ 16.]
> 
> I have tested this on various systems with KVM and kdump (and kdump on
> KVM) and didn't see any issues.
> 
> NOTE: In my testing this resolves the problem with PCI based serial ports
> cutting off their output during shutdown.  Again, this can be tracked to the
> PCI shutdown path switching between MSI & INTx independently of the driver.
> 
> ----8<----
> 
> The following unhandled IRQ warning is seen during shutdown:
> 
> irq 16: nobody cared (try booting with the "irqpoll" option)
> CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
> Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/01/2016
>  0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
>  ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
>  0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
> Call Trace:
>  <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
>  [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
>  [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
>  [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
>  [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
>  [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
>  [<ffffffff8102edfb>] handle_irq+0xab/0x130
>  [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
>  [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
>  [<ffffffff81704502>] common_interrupt+0x82/0x82
>  <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
>  [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
>  [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
>  [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
>  [<ffffffff816f6da7>] rest_init+0x77/0x80
>  [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
>  [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
>  [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
>  [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
>  [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c
> 
> pci_device_shutdown() is called on each PCI device, and does
> 
>         if (drv && drv->shutdown)
>                 drv->shutdown(pci_dev);
>         pci_msi_shutdown(pci_dev);
>         pci_msix_shutdown(pci_dev);
> 
> The pci_msi_shutdown() and pci_msix_shutdown() functions both call
> pci_intx_for_msi() which enables the INTx interrupt asynchronously of the
> driver.
> 
> The problem is that the driver may not have a shutdown function and the
> device remains active.  The driver continues to operate the PCI device and the
> device interrupts to generate INTx.  The driver, however, has not registered a
> handler for INTx and the interrupt line remains set which leads to an unhandled
> IRQ warning.
> 
> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
> Cc: alex.williamson@redhat.com
> Cc: darcari@redhat.com
> Cc: mstowe@redhat.com
> Cc: bhelgaas@google.com
> Cc: lukas@wunner.de
> Cc: keith.busch@intel.com
> Cc: mika.westerberg@linux.intel.com
> ---
>  drivers/pci/pci-driver.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 1ccce1cd6aca..87c35db5a564 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
>  
>  	pm_runtime_resume(dev);
>  
> -	if (drv && drv->shutdown)
> +	if (drv && drv->shutdown) {
>  		drv->shutdown(pci_dev);
> -	pci_msi_shutdown(pci_dev);
> -	pci_msix_shutdown(pci_dev);
> +		pci_msi_shutdown(pci_dev);
> +		pci_msix_shutdown(pci_dev);
> +	}
>  
>  	/*
>  	 * If this is a kexec reboot, turn off Bus Master bit on the
> -- 
> 1.7.9.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called
@ 2016-11-08 17:57 Prarit Bhargava
  2016-11-09 17:05 ` Bjorn Helgaas
  0 siblings, 1 reply; 13+ messages in thread
From: Prarit Bhargava @ 2016-11-08 17:57 UTC (permalink / raw)
  To: linux-pci
  Cc: Prarit Bhargava, alex.williamson, darcari, mstowe, bhelgaas,
	lukas, keith.busch, mika.westerberg

Bjorn,

We have seen this at Red Hat on various drivers: nouveau, ahci, mei_me, and
pcieport (so far).  Google search for "unhandled irq 16" yields many results
reporting similar behavior during shutdown indicating that this problem is
widespread.  I can cause this to happen on a "stable" system by adding a 3
second delay in pci_device_shutdown() which causes the number of spurious
interrupts to exceed the 100000 limit and display the warning below for the
primarily the nouveau driver, and occasionally for the other mentioned drivers.

A patch for this was proposed and rejected here for being too risky:

https://patchwork.kernel.org/patch/5990701/

I also originally posted a patch to resolve this here:

http://marc.info/?l=linux-pci&m=147705209308588&w=2

and several other patch suggestions were made.  The problem with all of these
solutions is that there is some risk associated with them (kdump, kvm, etc.)
and they are papering over the real issue that the PCI shutdown should not
blindly switch to INTx for all devices.

I am reproposing the original suggested patch.  There is some risk associated
with this but I don't think it is any more or any less than the other patches,
and it seems like the other patches are only applying band-aids to the problem.

[Aside: Lukas Wunner asked why does this always happen on IRQ 16 (even when the
legacy device says IRQ 32 in lspci)?

The PCI irq pins A, B, C, and D are routed according to the ACPI _PRT table for
the device.  _In general_, I have noted a consistent pattern for PCI irq pins
such that

	irq pin A is IRQ 0x10 (16)
	irq pin B is IRQ 0x11 (17)
	irq pin C is IRQ 0x12 (18)
	irq pin D is IRQ 0x13 (19)

Since the device's IRQ is hooked up to pin A we're seeing the unhandled
interrupt on IRQ 16.]

I have tested this on various systems with KVM and kdump (and kdump on
KVM) and didn't see any issues.

NOTE: In my testing this resolves the problem with PCI based serial ports
cutting off their output during shutdown.  Again, this can be tracked to the
PCI shutdown path switching between MSI & INTx independently of the driver.

----8<----

The following unhandled IRQ warning is seen during shutdown:

irq 16: nobody cared (try booting with the "irqpoll" option)
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.8.2-1.el7_UNSUPPORTED.x86_64 #1
Hardware name: Hewlett-Packard HP Z820 Workstation/158B, BIOS J63 v03.90 06/01/2016
 0000000000000000 ffff88041f803e70 ffffffff81333bd5 ffff88041cb78200
 ffff88041cb7829c ffff88041f803e98 ffffffff810d9465 ffff88041cb78200
 0000000000000000 0000000000000028 ffff88041f803ed0 ffffffff810d97bf
Call Trace:
 <IRQ>  [<ffffffff81333bd5>] dump_stack+0x63/0x8e
 [<ffffffff810d9465>] __report_bad_irq+0x35/0xd0
 [<ffffffff810d97bf>] note_interrupt+0x20f/0x260
 [<ffffffff810d6b35>] handle_irq_event_percpu+0x45/0x60
 [<ffffffff810d6b7c>] handle_irq_event+0x2c/0x50
 [<ffffffff810da31a>] handle_fasteoi_irq+0x8a/0x150
 [<ffffffff8102edfb>] handle_irq+0xab/0x130
 [<ffffffff81082391>] ? _local_bh_enable+0x21/0x50
 [<ffffffff817064ad>] do_IRQ+0x4d/0xd0
 [<ffffffff81704502>] common_interrupt+0x82/0x82
 <EOI>  [<ffffffff815d0181>] ? cpuidle_enter_state+0xc1/0x280
 [<ffffffff815d0174>] ? cpuidle_enter_state+0xb4/0x280
 [<ffffffff815d0377>] cpuidle_enter+0x17/0x20
 [<ffffffff810bf660>] cpu_startup_entry+0x220/0x3a0
 [<ffffffff816f6da7>] rest_init+0x77/0x80
 [<ffffffff81d8e147>] start_kernel+0x495/0x4a2
 [<ffffffff81d8daa0>] ? set_init_arg+0x55/0x55
 [<ffffffff81d8d120>] ? early_idt_handler_array+0x120/0x120
 [<ffffffff81d8d5d6>] x86_64_start_reservations+0x2a/0x2c
 [<ffffffff81d8d715>] x86_64_start_kernel+0x13d/0x14c

pci_device_shutdown() is called on each PCI device, and does

        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);
        pci_msix_shutdown(pci_dev);

The pci_msi_shutdown() and pci_msix_shutdown() functions both call
pci_intx_for_msi() which enables the INTx interrupt asynchronously of the
driver.

The problem is that the driver may not have a shutdown function and the
device remains active.  The driver continues to operate the PCI device and the
device interrupts to generate INTx.  The driver, however, has not registered a
handler for INTx and the interrupt line remains set which leads to an unhandled
IRQ warning.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: alex.williamson@redhat.com
Cc: darcari@redhat.com
Cc: mstowe@redhat.com
Cc: bhelgaas@google.com
Cc: lukas@wunner.de
Cc: keith.busch@intel.com
Cc: mika.westerberg@linux.intel.com
---
 drivers/pci/pci-driver.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 1ccce1cd6aca..87c35db5a564 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -461,10 +461,11 @@ static void pci_device_shutdown(struct device *dev)
 
 	pm_runtime_resume(dev);
 
-	if (drv && drv->shutdown)
+	if (drv && drv->shutdown) {
 		drv->shutdown(pci_dev);
-	pci_msi_shutdown(pci_dev);
-	pci_msix_shutdown(pci_dev);
+		pci_msi_shutdown(pci_dev);
+		pci_msix_shutdown(pci_dev);
+	}
 
 	/*
 	 * If this is a kexec reboot, turn off Bus Master bit on the
-- 
1.7.9.3


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

end of thread, other threads:[~2017-03-30 21:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 19:07 [PATCH] pci: Only disable MSI/X and enable INTx if shutdown function has been called Prarit Bhargava
2017-03-09 21:57 ` Bjorn Helgaas
2017-03-10 12:30   ` Prarit Bhargava
2017-03-30 11:59     ` Prarit Bhargava
2017-03-30 21:52       ` Bjorn Helgaas
  -- strict thread matches above, loose matches on Subject: below --
2016-11-08 17:57 Prarit Bhargava
2016-11-09 17:05 ` Bjorn Helgaas
2016-11-09 19:36   ` Prarit Bhargava
2016-11-09 19:54     ` Keith Busch
2016-11-09 19:49       ` Prarit Bhargava
2016-12-16 16:48   ` Prarit Bhargava
2017-01-19 14:38     ` Bjorn Helgaas
2017-01-25 13:23       ` Prarit Bhargava

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