diff mbox series

usb: hcd-pci: replace usb_hcd_irq() with generic_handle_irq_safe() to avoid calltrace

Message ID 20231113030041.3655742-1-Meng.Li@windriver.com
State New
Headers show
Series usb: hcd-pci: replace usb_hcd_irq() with generic_handle_irq_safe() to avoid calltrace | expand

Commit Message

Li, Meng Nov. 13, 2023, 3 a.m. UTC
When running below to command to remove a PCIe-USB device,
there is below caltrace reported in RT kernel.
Call trace:
 ......
 __might_resched+0x160/0x1c0
 rt_spin_lock+0x38/0xb0
 xhci_irq+0x44/0x16d0
 usb_hcd_irq+0x38/0x5c
 usb_hcd_pci_remove+0x84/0x14c
 xhci_pci_remove+0x78/0xc0
 pci_device_remove+0x44/0xcc
 device_remove+0x54/0x8c
 device_release_driver_internal+0x1ec/0x260
 device_release_driver+0x20/0x30
 pci_stop_bus_device+0x8c/0xcc
 pci_stop_and_remove_bus_device_locked+0x28/0x44
 ......
 el0t_64_sync_handler+0xf4/0x120
 el0t_64_sync+0x18c/0x190
This issue is introduced by commit c548795abe0d("USB: add
check to detect host controller hardware removal"). Because
in RT-kernel, spinlock that may cause sleep is invoked under irq
disabled status. Therefore, replace usb_hcd_irq() function with
generic_handle_irq_safe() to avoid calltrace

Fixes: c548795abe0d ("USB: add check to detect host controller hardware removal")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/usb/core/hcd-pci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

kernel test robot Nov. 14, 2023, 7:55 p.m. UTC | #1
Hi Meng,

kernel test robot noticed the following build errors:

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on usb/usb-next usb/usb-linus linus/master v6.7-rc1 next-20231114]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Meng-Li/usb-hcd-pci-replace-usb_hcd_irq-with-generic_handle_irq_safe-to-avoid-calltrace/20231113-110341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
patch link:    https://lore.kernel.org/r/20231113030041.3655742-1-Meng.Li%40windriver.com
patch subject: [PATCH] usb: hcd-pci: replace usb_hcd_irq() with generic_handle_irq_safe() to avoid calltrace
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20231115/202311150335.CARpQOQl-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231115/202311150335.CARpQOQl-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311150335.CARpQOQl-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/usb/core/hcd-pci.c:328:2: error: call to undeclared function 'generic_handle_irq_safe'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
           generic_handle_irq_safe(dev->irq);
           ^
   1 error generated.


vim +/generic_handle_irq_safe +328 drivers/usb/core/hcd-pci.c

   297	
   298	/**
   299	 * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
   300	 * @dev: USB Host Controller being removed
   301	 *
   302	 * Context: task context, might sleep
   303	 *
   304	 * Reverses the effect of usb_hcd_pci_probe(), first invoking
   305	 * the HCD's stop() method.  It is always called from a thread
   306	 * context, normally "rmmod", "apmd", or something similar.
   307	 *
   308	 * Store this function in the HCD's struct pci_driver as remove().
   309	 */
   310	void usb_hcd_pci_remove(struct pci_dev *dev)
   311	{
   312		struct usb_hcd		*hcd;
   313		int			hcd_driver_flags;
   314	
   315		hcd = pci_get_drvdata(dev);
   316		if (!hcd)
   317			return;
   318	
   319		hcd_driver_flags = hcd->driver->flags;
   320	
   321		if (pci_dev_run_wake(dev))
   322			pm_runtime_get_noresume(&dev->dev);
   323	
   324		/* Fake an interrupt request in order to give the driver a chance
   325		 * to test whether the controller hardware has been removed (e.g.,
   326		 * cardbus physical eject).
   327		 */
 > 328		generic_handle_irq_safe(dev->irq);
   329	
   330		/* Note: dev_set_drvdata must be called while holding the rwsem */
   331		if (dev->class == CL_EHCI) {
   332			down_write(&companions_rwsem);
   333			for_each_companion(dev, hcd, ehci_remove);
   334			usb_remove_hcd(hcd);
   335			dev_set_drvdata(&dev->dev, NULL);
   336			up_write(&companions_rwsem);
   337		} else {
   338			/* Not EHCI; just clear the companion pointer */
   339			down_read(&companions_rwsem);
   340			hcd->self.hs_companion = NULL;
   341			usb_remove_hcd(hcd);
   342			dev_set_drvdata(&dev->dev, NULL);
   343			up_read(&companions_rwsem);
   344		}
   345		usb_put_hcd(hcd);
   346		if ((hcd_driver_flags & HCD_MASK) < HCD_USB3)
   347			pci_free_irq_vectors(dev);
   348		pci_disable_device(dev);
   349	}
   350	EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
   351
diff mbox series

Patch

diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index ee3156f49533..3b5f7dccbe6a 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -325,9 +325,7 @@  void usb_hcd_pci_remove(struct pci_dev *dev)
 	 * to test whether the controller hardware has been removed (e.g.,
 	 * cardbus physical eject).
 	 */
-	local_irq_disable();
-	usb_hcd_irq(0, hcd);
-	local_irq_enable();
+	generic_handle_irq_safe(dev->irq);
 
 	/* Note: dev_set_drvdata must be called while holding the rwsem */
 	if (dev->class == CL_EHCI) {