driver core: Fix bus_type.match() error handling
Subsystems (2)
PATCH v2 1/1 driver core: Fix bus_type.match() error handling
Both __device_attach_driver() and __driver_attach() check the return code of the bus_type.match() function to see if the device needs to be added to the deferred probe list. After adding the device to the list, the logic attempts to bind the device to the driver anyway, as if the device had matched with the driver, which is not correct.
If __device_attach_driver() detects that the device in question is not ready to match with a driver on the bus, then it doesn't make sense for the device to attempt to bind with the current driver or continue attempting to match with any of the other drivers on the bus. So, update the logic in __device_attach_driver() to reflect this.
If __driver_attach() detects that a driver tried to match with a device and that results in any error, then the driver should not attempt to bind with the device. However, the driver can still attempt to match and bind with other devices on the bus, as drivers can be bound to multiple devices. So, update the logic in __driver_attach() to reflect this.
--- drivers/base/dd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
v1 -> v2:
- Fixed the logic in __driver_attach() to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.
Guenter,
Can you please give test this patch to make sure it still works for you?
Thanks,
Isaac
drivers/base/dd.c +15 -1
@@ -881,6 +881,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)dev_dbg (dev,"Device match requests probe deferral\n" ); dev->can_match = true;driver_deferred_probe_add (dev); +/* +* Device can't match with a driver right now, so don't attempt +* to match or bind with other drivers on the bus. +*/ +return ret; }else if (ret <0 ) {dev_dbg (dev,"Bus failed to match device: %d\n" , ret);return ret;
@@ -1120,9 +1125,18 @@ static int __driver_attach(struct device *dev, void *data)dev_dbg (dev,"Device match requests probe deferral\n" ); dev->can_match = true;driver_deferred_probe_add (dev); +/* +* Driver could not match with device right now, but may match +* with another device on the bus. +*/ +return 0 ; }else if (ret <0 ) {dev_dbg (dev,"Bus failed to match device: %d\n" , ret); -return ret; +/* +* Driver could not match with device, but may match with +* another device on the bus. +*/ +return 0 ; }/* ret > 0 means positive match */ if (driver_allows_async_probing (drv)) {
Signature · 1 line
2.37.1.595.g718a3a8f04-goog
Quoted 27 lines · Isaac J. Manjarres
Both
__device_attach_driver()and__driver_attach()check the return code of thebus_type.match()function to see if the device needs to be added to the deferred probe list. After adding the device to the list, the logic attempts to bind the device to the driver anyway, as if the device had matched with the driver, which is not correct.If
__device_attach_driver()detects that the device in question is not ready to match with a driver on the bus, then it doesn't make sense for the device to attempt to bind with the current driver or continue attempting to match with any of the other drivers on the bus. So, update the logic in__device_attach_driver()to reflect this.If
__driver_attach()detects that a driver tried to match with a device and that results in any error, then the driver should not attempt to bind with the device. However, the driver can still attempt to match and bind with other devices on the bus, as drivers can be bound to multiple devices. So, update the logic in__driver_attach()to reflect this.Cc Saravana Kannan <[email protected]>Fixes 656b8035b0ee ("ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()")Reported-by Guenter Roeck <[email protected]>Signed-off-by Isaac J. Manjarres <[email protected]>--- drivers/base/dd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Quoted 9 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Guenter
Quoted 7 lines · Guenter Roeck
Quoted 7 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Quoted 7 lines
Quoted 2 lines
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Guenter
Thanks for trying the patch out. This patch isn't meant to fix the clk crash that you mentioned on another thread. I had made the following patch for
that: https://lore.kernel.org/lkml/[email protected]/. Have you been able to give that a shot yet? If not can you please test with the patch in this e-mail and that patch?
Please make sure you do not include this patch as it is known to cause
deadlocks: https://lore.kernel.org/lkml/[email protected]/.
Did you test imx25-pdk emulations with just v1 of this patch previously?
Thanks,
Isaac
Quoted 14 lines · Isaac Manjarres
Quoted 13 lines · Guenter Roeck
Quoted 9 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Quoted 7 lines
Quoted 1 line
Guenter
Thanks for trying the patch out. This patch isn't meant to fix the clk crash that you mentioned on another thread. I had made the following patch for
that: https://lore.kernel.org/lkml/[email protected]/. Have you been able to give that a shot yet? If not can you please test with the patch in this e-mail and that patch?
No, sorry, I missed that one. It does not apply, though - it is whitespace corrupted. I tried to fix it up, but that failed.
Quoted 3 lines
Please make sure you do not include this patch as it is known to cause
deadlocks: https://lore.kernel.org/lkml/[email protected]/.
No, I did not include that patch.
Quoted 2 lines
Did you test imx25-pdk emulations with just v1 of this patch previously?
I am quite sure I did because it is a single setup.
Thanks,
Guenter
Quoted 23 lines · Guenter Roeck
Quoted 14 lines · Isaac Manjarres
Quoted 13 lines · Guenter Roeck
Quoted 9 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Quoted 7 lines
Quoted 1 line
Guenter
Thanks for trying the patch out. This patch isn't meant to fix the clk crash that you mentioned on another thread. I had made the following patch for
that: https://lore.kernel.org/lkml/[email protected]/. Have you been able to give that a shot yet? If not can you please test with the patch in this e-mail and that patch?
Quoted 2 lines
No, sorry, I missed that one. It does not apply, though - it is whitespace corrupted. I tried to fix it up, but that failed.
When applying the patch, can you please try with git apply --ignore-whitespace ? That worked for me.
Quoted 6 lines
Quoted 3 lines
Did you test imx25-pdk emulations with just v1 of this patch previously?
I am quite sure I did because it is a single setup.
That's odd. Is this something that I can try out on qemu? If so, can you please share the qemu commandline so I can take a look?
Thanks,
Isaac
Quoted 24 lines · Isaac Manjarres
Quoted 23 lines · Guenter Roeck
Quoted 21 lines · Isaac Manjarres
Quoted 7 lines · Guenter Roeck
Quoted 7 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Quoted 7 lines
Quoted 2 lines
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Guenter
Thanks for trying the patch out. This patch isn't meant to fix the clk crash that you mentioned on another thread. I had made the following patch for
that: https://lore.kernel.org/lkml/[email protected]/. Have you been able to give that a shot yet? If not can you please test with the patch in this e-mail and that patch?
Quoted 5 lines
Quoted 2 lines
No, sorry, I missed that one. It does not apply, though - it is whitespace corrupted. I tried to fix it up, but that failed.
When applying the patch, can you please try with git apply --ignore-whitespace ? That worked for me.
Ok, that worked. With the above patch, the problems with sx1 and versatileab are gone. However, imx25-pdk fails to shut down when booting from usb drive. I cross checked that this does not happen without the above patch.
Guenter
Quoted 25 lines · Guenter Roeck
Quoted 24 lines · Isaac Manjarres
Quoted 23 lines · Guenter Roeck
Quoted 21 lines · Isaac Manjarres
Quoted 7 lines · Guenter Roeck
Quoted 7 lines
v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Quoted 7 lines
Quoted 2 lines
Can you please give test this patch to make sure it still works for you?
Not as well as v1. I still see the clk crash with versatileab, and imx25-pdk emulations now stall during boot when trying to boot from usb.
Guenter
Thanks for trying the patch out. This patch isn't meant to fix the clk crash that you mentioned on another thread. I had made the following patch for
that: https://lore.kernel.org/lkml/[email protected]/. Have you been able to give that a shot yet? If not can you please test with the patch in this e-mail and that patch?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
No, sorry, I missed that one. It does not apply, though - it is whitespace corrupted. I tried to fix it up, but that failed.
When applying the patch, can you please try with git apply --ignore-whitespace ? That worked for me.
Ok, that worked. With the above patch, the problems with sx1 and versatileab are gone.
Good to hear! Thanks for testing that patch out.
Quoted 4 lines
However, imx25-pdk fails to shut down when booting from usb drive. I cross checked that this does not happen without the above patch.
Guenter
Can you please share the following for your imx25-pdk environment? qemu commandline, defconfig, dtb, and baseline kernel commit you're using for testing.
Thanks,
Isaac
Quoted 9 lines · Isaac Manjarres
Quoted 4 lines
However, imx25-pdk fails to shut down when booting from usb drive. I cross checked that this does not happen without the above patch.
Guenter
Can you please share the following for your imx25-pdk environment? qemu commandline, defconfig, dtb, and baseline kernel commit you're using for testing.
It doesn't only affect imx25-pdk but also mcimx7d-sabre. Problem is the same for both: Reboot after booting from usb drive doesn't work; the system is stuck in shutdown. Typical tail of log sequence:
Requesting system reboot
sd 0:0:0:0: [sda] Synchronizing SCSI cacheci_hdrc ci_hdrc.1: remove, state 4
usb usb2: USB disconnect, device number 1ci_hdrc ci_hdrc.1: USB bus 2 deregisteredci_hdrc ci_hdrc.0: remove, state 1
usb usb1: USB disconnect, device number 1
usb 1-1: USB disconnect, device number 2
sd 0:0:0:0: [sda] Synchronizing SCSI cache
sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x01 driverbyte=DRIVER_OK
[ stuck here until qemu is killed ]
qemu command line:
qemu-system-arm -M imx25-pdk -m 128 \
-kernel arch/arm/boot/zImage -no-reboot -snapshot \
-usb -device usb-storage,drive=d0,bus=usb-bus.0 \
-drive file=rootfs-armv5.ext2,if=none,id=d0,format=raw \
--append "root=/dev/sda rootwait console=ttymxc0,115200" \
-dtb arch/arm/boot/dts/imx25-pdk.dtb \
-nographic -monitor null -serial stdioRoot file system is
https://github.com/groeck/linux-build-test/blob/master/rootfs/arm/rootfs-armv5.ext2.gz
defconfig is below.
Hope this helps,
Guenter
---CONFIG_SYSVIPC=yCONFIG_POSIX_MQUEUE=yCONFIG_NO_HZ=yCONFIG_HIGH_RES_TIMERS=yCONFIG_PREEMPT=yCONFIG_LOG_BUF_SHIFT=14CONFIG_CGROUPS=yCONFIG_BLK_DEV_INITRD=yCONFIG_EXPERT=yCONFIG_PROFILING=yCONFIG_ARCH_MULTI_V4T=yCONFIG_ARCH_MULTI_V5=y
# CONFIG_ARCH_MULTI_V7 is not setCONFIG_ARCH_MXC=yCONFIG_SOC_IMX1=yCONFIG_SOC_IMX25=yCONFIG_SOC_IMX27=yCONFIG_AEABI=yCONFIG_PM_DEBUG=yCONFIG_KPROBES=yCONFIG_MODULES=yCONFIG_MODULE_UNLOAD=y
# CONFIG_SWAP is not setCONFIG_SLAB=y
# CONFIG_COMPAT_BRK is not setCONFIG_NET=yCONFIG_PACKET=yCONFIG_UNIX=yCONFIG_INET=yCONFIG_IP_MULTICAST=yCONFIG_IP_PNP=y
# CONFIG_INET_DIAG is not set
# CONFIG_IPV6 is not setCONFIG_NETFILTER=y
# CONFIG_WIRELESS is not setCONFIG_DEVTMPFS=yCONFIG_DEVTMPFS_MOUNT=yCONFIG_PM_QOS_KUNIT_TEST=yCONFIG_IMX_WEIM=yCONFIG_MTD=yCONFIG_MTD_CMDLINE_PARTS=yCONFIG_MTD_BLOCK=yCONFIG_MTD_CFI=yCONFIG_MTD_CFI_ADV_OPTIONS=yCONFIG_MTD_CFI_GEOMETRY=y
# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
# CONFIG_MTD_CFI_I2 is not setCONFIG_MTD_CFI_INTELEXT=yCONFIG_MTD_PHYSMAP=yCONFIG_MTD_RAW_NAND=yCONFIG_MTD_UBI=yCONFIG_OF_UNITTEST=yCONFIG_VIRTIO_BLK=yCONFIG_EEPROM_AT25=yCONFIG_BLK_DEV_SD=yCONFIG_BLK_DEV_SR=y
# CONFIG_BLK_DEV_BSG is not setCONFIG_SCSI_VIRTIO=yCONFIG_ATA=yCONFIG_PATA_IMX=yCONFIG_NETDEVICES=yCONFIG_VIRTIO_NET=y
CONFIG_CS89x0_PLATFORM=yCONFIG_DM9000=yCONFIG_SMC91X=yCONFIG_SMC911X=yCONFIG_SMSC911X=yCONFIG_SMSC_PHY=yCONFIG_USB_USBNET=y
# CONFIG_WLAN is not setCONFIG_INPUT_EVDEV=yCONFIG_KEYBOARD_GPIO=yCONFIG_KEYBOARD_IMX=y
# CONFIG_INPUT_MOUSE is not setCONFIG_INPUT_TOUCHSCREEN=yCONFIG_TOUCHSCREEN_ADS7846=mCONFIG_TOUCHSCREEN_MX25=yCONFIG_TOUCHSCREEN_MC13783=y
# CONFIG_LEGACY_PTYS is not setCONFIG_SERIAL_8250=mCONFIG_SERIAL_IMX=yCONFIG_SERIAL_IMX_CONSOLE=y
# CONFIG_HW_RANDOM is not setCONFIG_SPI=yCONFIG_SPI_IMX=yCONFIG_SPI_SPIDEV=yCONFIG_GPIO_SYSFS=yCONFIG_GPIO_MXC=yCONFIG_W1=yCONFIG_W1_MASTER_MXC=yCONFIG_W1_SLAVE_THERM=yCONFIG_HWMON=mCONFIG_SENSORS_MC13783_ADC=mCONFIG_WATCHDOG=yCONFIG_IMX2_WDT=yCONFIG_MFD_MC13XXX_SPI=yCONFIG_MFD_MX25_TSADC=yCONFIG_REGULATOR=yCONFIG_REGULATOR_FIXED_VOLTAGE=yCONFIG_REGULATOR_GPIO=yCONFIG_REGULATOR_MC13783=yCONFIG_REGULATOR_MC13892=yCONFIG_MEDIA_SUPPORT=yCONFIG_V4L_PLATFORM_DRIVERS=yCONFIG_V4L_MEM2MEM_DRIVERS=yCONFIG_VIDEO_CODA=y
# CONFIG_DRM_DEBUG_MODESET_LOCK is not setCONFIG_FB=yCONFIG_FB_IMX=yCONFIG_LCD_L4F00242T03=yCONFIG_FRAMEBUFFER_CONSOLE=yCONFIG_LOGO=yCONFIG_SOUND=yCONFIG_SND=y
# CONFIG_SND_ARM is not set
# CONFIG_SND_SPI is not setCONFIG_SND_SOC=yCONFIG_SND_IMX_SOC=yCONFIG_USB_HID=mCONFIG_USB=yCONFIG_USB_XHCI_HCD=yCONFIG_USB_EHCI_HCD=yCONFIG_USB_OHCI_HCD=yCONFIG_USB_STORAGE=yCONFIG_USB_UAS=yCONFIG_USB_CHIPIDEA=yCONFIG_USB_CHIPIDEA_UDC=yCONFIG_USB_CHIPIDEA_HOST=yCONFIG_USB_TEST=yCONFIG_USB_EHSET_TEST_FIXTURE=yCONFIG_USB_LINK_LAYER_TEST=yCONFIG_NOP_USB_XCEIV=yCONFIG_USB_GADGET=yCONFIG_USB_ETH=mCONFIG_MMC=yCONFIG_MMC_SDHCI=yCONFIG_MMC_SDHCI_PLTFM=yCONFIG_MMC_SDHCI_ESDHC_IMX=yCONFIG_MMC_MXC=yCONFIG_NEW_LEDS=yCONFIG_LEDS_CLASS=yCONFIG_LEDS_GPIO=yCONFIG_LEDS_MC13783=yCONFIG_LEDS_TRIGGERS=yCONFIG_LEDS_TRIGGER_TIMER=yCONFIG_LEDS_TRIGGER_HEARTBEAT=yCONFIG_LEDS_TRIGGER_BACKLIGHT=yCONFIG_LEDS_TRIGGER_GPIO=yCONFIG_LEDS_TRIGGER_DEFAULT_ON=yCONFIG_RTC_CLASS=yCONFIG_RTC_DRV_IMXDI=yCONFIG_RTC_DRV_MC13XXX=yCONFIG_RTC_DRV_MXC=yCONFIG_DMADEVICES=yCONFIG_IMX_DMA=yCONFIG_IMX_SDMA=yCONFIG_DMATEST=yCONFIG_VIRTIO_BALLOON=yCONFIG_VIRTIO_MMIO=y
# CONFIG_IOMMU_SUPPORT is not setCONFIG_IIO=yCONFIG_FSL_MX25_ADC=yCONFIG_PWM=yCONFIG_PWM_IMX1=yCONFIG_PWM_IMX27=yCONFIG_EXT3_FS=yCONFIG_EXT4_KUNIT_TESTS=yCONFIG_BTRFS_FS=y
# CONFIG_DNOTIFY is not setCONFIG_ISO9660_FS=yCONFIG_VFAT_FS=y
# CONFIG_PROC_PAGE_MONITOR is not setCONFIG_TMPFS=yCONFIG_JFFS2_FS=yCONFIG_UBIFS_FS=yCONFIG_SQUASHFS=yCONFIG_SQUASHFS_XATTR=yCONFIG_SQUASHFS_4K_DEVBLK_SIZE=yCONFIG_NFS_FS=yCONFIG_ROOT_NFS=yCONFIG_NLS_CODEPAGE_437=mCONFIG_NLS_CODEPAGE_850=mCONFIG_NLS_ISO8859_1=yCONFIG_NLS_ISO8859_15=m
# CONFIG_CRYPTO_MANAGER_DISABLE_TESTS is not setCONFIG_CRC32_SELFTEST=yCONFIG_GLOB_SELFTEST=yCONFIG_FONTS=y
CONFIG_FONT_8x8=yCONFIG_DEBUG_INFO_DWARF5=yCONFIG_KFENCE=yCONFIG_PROVE_LOCKING=yCONFIG_DEBUG_LOCKDEP=yCONFIG_DEBUG_ATOMIC_SLEEP=yCONFIG_DEBUG_LOCKING_API_SELFTESTS=yCONFIG_WW_MUTEX_SELFTEST=yCONFIG_DEBUG_LIST=yCONFIG_RCU_EQS_DEBUG=yCONFIG_KUNIT=yCONFIG_KUNIT_TEST=yCONFIG_TEST_SORT=yCONFIG_RBTREE_TEST=yCONFIG_INTERVAL_TREE_TEST=yCONFIG_STRING_SELFTEST=yCONFIG_TEST_BITMAP=yCONFIG_TEST_UUID=yCONFIG_TEST_FIRMWARE=yCONFIG_TEST_SYSCTL=yCONFIG_RESOURCE_KUNIT_TEST=yCONFIG_SYSCTL_KUNIT_TEST=yCONFIG_LIST_KUNIT_TEST=yCONFIG_CMDLINE_KUNIT_TEST=yCONFIG_MEMCPY_KUNIT_TEST=y
Quoted 11 lines · Guenter Roeck
Requesting system reboot
sd 0:0:0:0: [sda] Synchronizing SCSI cacheci_hdrcci_hdrc.1: remove, state 4
usb usb2: USB disconnect, device number 1ci_hdrcci_hdrc.1: USB bus 2 deregisteredci_hdrcci_hdrc.0: remove, state 1
usb usb1: USB disconnect, device number 1
usb 1-1: USB disconnect, device number 2
sd 0:0:0:0: [sda] Synchronizing SCSI cache
sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x01 driverbyte=DRIVER_OK
Quoted 2 lines
[ stuck here until qemu is killed ]
Hi Guenter,
I'm actually observing the behavior described above even without my patch. The tip of my tree is currently at 573ae4f13f63 ("tee: add overflow check in register_shm_helper()"). I used git bisect to find what commit was causing the problem, and narrowed it down to this series[1].
I reverted all 4 patches in that series, and I no longer see this hang with my tree.
[1]: https://lore.kernel.org/all/[email protected]/
Are these patches part of the tree you're using for testing and observing this hang in?
Thanks,
Isaac
Quoted 21 lines · Isaac Manjarres
Quoted 11 lines · Guenter Roeck
Requesting system reboot
sd 0:0:0:0: [sda] Synchronizing SCSI cacheci_hdrcci_hdrc.1: remove, state 4
usb usb2: USB disconnect, device number 1ci_hdrcci_hdrc.1: USB bus 2 deregisteredci_hdrcci_hdrc.0: remove, state 1
usb usb1: USB disconnect, device number 1
usb 1-1: USB disconnect, device number 2
sd 0:0:0:0: [sda] Synchronizing SCSI cache
sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x01 driverbyte=DRIVER_OKQuoted 2 lines
[ stuck here until qemu is killed ]
Hi Guenter,
I'm actually observing the behavior described above even without my patch. The tip of my tree is currently at
573ae4f13f63("tee: add overflow check inregister_shm_helper()"). I used git bisect to find what commit was causing the problem, and narrowed it down to this series[1].
Quoted 8 lines
I reverted all 4 patches in that series, and I no longer see this hang with my tree.
[1]: https://lore.kernel.org/all/[email protected]/
Are these patches part of the tree you're using for testing and observing this hang in?
Yes, you are correct. I also see the problem in the mainline kernel, at SHA 3b06a2755758, and with a large number of boots from usb drive in various arm emulations. Sorry for the confusion. Too many crashes :-(.
Guenter
Quoted 31 lines · Guenter Roeck
Quoted 21 lines · Isaac Manjarres
Quoted 11 lines · Guenter Roeck
Requesting system reboot
sd 0:0:0:0: [sda] Synchronizing SCSI cacheci_hdrcci_hdrc.1: remove, state 4
usb usb2: USB disconnect, device number 1ci_hdrcci_hdrc.1: USB bus 2 deregisteredci_hdrcci_hdrc.0: remove, state 1
usb usb1: USB disconnect, device number 1
usb 1-1: USB disconnect, device number 2
sd 0:0:0:0: [sda] Synchronizing SCSI cache
sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x01 driverbyte=DRIVER_OKQuoted 2 lines
[ stuck here until qemu is killed ]
Hi Guenter,
I'm actually observing the behavior described above even without my patch. The tip of my tree is currently at
573ae4f13f63("tee: add overflow check inregister_shm_helper()"). I used git bisect to find what commit was causing the problem, and narrowed it down to this series[1].Quoted 8 lines
I reverted all 4 patches in that series, and I no longer see this hang with my tree.
[1]: https://lore.kernel.org/all/[email protected]/
Are these patches part of the tree you're using for testing and observing this hang in?
Quoted 5 lines
Yes, you are correct. I also see the problem in the mainline kernel, at SHA
3b06a2755758, and with a large number of boots from usb drive in various arm emulations. Sorry for the confusion. Too many crashes :-(.Guenter
No worries, thanks for confirming.
Hi Bart,
It seems that the patches mentioned in [1] are causing a hang during reboot for various ARM emulations when booting from USB. Can you please take a look? There's more information about what defconfig, rootfs, and qemu commandline to use at [2].
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/
Thanks,
Isaac
Quoted 4 lines · Isaac Manjarres
It seems that the patches mentioned in [1] are causing a hang during reboot for various ARM emulations when booting from USB. Can you please take a look? There's more information about what defconfig, rootfs, and qemu commandline to use at [2].
Unfortunately I can't reproduce this hang in an x86 VM with kernel v6.0-rc1 and a USB disk attached via virt-manager. The lsscsi -v output shows that a USB disk has been attached:
[9:0:0:0] disk QEMU QEMU HARDDISK 2.5+ /dev/sdd
dir: /sys/bus/scsi/devices/9:0:0:0
[/sys/devices/pci0000:00/0000:00:07.0/usb2/2-2/2-2:1.0/host9/target9:0:0/9:0:0:0]
Rebooting that VM happens in the expected time and without triggering any kernel warnings.
Since the issue has been observed in qemu, how about sharing the sysrq-t output? I recommend to collect that output as follows:
* Send the serial console output to a file. This involves adding console=ttyS0,115200n8 to the kernel command line and using the proper qemu options to save the serial console output into a file.
* Reproduce the hang and send the sysrq-t key sequence to qemu, e.g. as follows: virsh send-key ${vm_name} KEY_LEFTALT KEY_SYSRQ KEY_T
Thanks,
Bart.
Quoted 10 lines · Bart Van Assche
Quoted 4 lines · Isaac Manjarres
It seems that the patches mentioned in [1] are causing a hang during reboot for various ARM emulations when booting from USB. Can you please take a look? There's more information about what defconfig, rootfs, and qemu commandline to use at [2].
Unfortunately I can't reproduce this hang in an x86 VM with kernel v6.0-rc1 and a USB disk attached via virt-manager. The lsscsi -v output shows that a USB disk has been attached:
The problem only reproduces with various arm emulations. I may have missed it, but I have not noticed it on any other architecture.
Quoted 6 lines
[9:0:0:0] disk QEMU QEMU HARDDISK 2.5+
/dev/sdd
dir: /sys/bus/scsi/devices/9:0:0:0 [/sys/devices/pci0000:00/0000:00:07.0/usb2/2-2/2-2:1.0/host9/target9:0:0/9:0:0:0]Rebooting that VM happens in the expected time and without triggering any kernel warnings.
There are no warnings. The reboot just stalls. Also, the usb drive attaches just fine. The probem is seen in shutdown, not during boot.
Quoted 8 lines
Since the issue has been observed in qemu, how about sharing the sysrq-t output? I recommend to collect that output as follows:
* Send the serial console output to a file. This involves adding console=ttyS0,115200n8 to the kernel command line and using the proper qemu options to save the serial console output into a file.
* Reproduce the hang and send the sysrq-t key sequence to qemu, e.g. as
follows: virsh send-key ${vm_name}KEY_LEFTALTKEY_SYSRQKEY_T
Will try.
Thanks,
Guenter
Quoted 16 lines · Bart Van Assche
Quoted 4 lines · Isaac Manjarres
It seems that the patches mentioned in [1] are causing a hang during reboot for various ARM emulations when booting from USB. Can you please take a look? There's more information about what defconfig, rootfs, and qemu commandline to use at [2].
Unfortunately I can't reproduce this hang in an x86 VM with kernel v6.0-rc1 and a USB disk attached via virt-manager. The lsscsi -v output shows that a USB disk has been attached:
[9:0:0:0] disk QEMU QEMU HARDDISK 2.5+
/dev/sdd
dir: /sys/bus/scsi/devices/9:0:0:0 [/sys/devices/pci0000:00/0000:00:07.0/usb2/2-2/2-2:1.0/host9/target9:0:0/9:0:0:0]Rebooting that VM happens in the expected time and without triggering any kernel warnings.
Quoted 8 lines
Since the issue has been observed in qemu, how about sharing the sysrq-t output? I recommend to collect that output as follows:
* Send the serial console output to a file. This involves adding console=ttyS0,115200n8 to the kernel command line and using the proper qemu options to save the serial console output into a file.
* Reproduce the hang and send the sysrq-t key sequence to qemu, e.g. as
follows: virsh send-key ${vm_name}KEY_LEFTALTKEY_SYSRQKEY_T
Unless I am missing something, this requires a virtio keyboard. So far I have been unable to get this to work with qemu arm emulations.
Guenter
Quoted 11 lines · Guenter Roeck
Quoted 8 lines · Bart Van Assche
Since the issue has been observed in qemu, how about sharing the sysrq-t output? I recommend to collect that output as follows:
* Send the serial console output to a file. This involves adding console=ttyS0,115200n8 to the kernel command line and using the proper qemu options to save the serial console output into a file.
* Reproduce the hang and send the sysrq-t key sequence to qemu, e.g. as
follows: virsh send-key ${vm_name}KEY_LEFTALTKEY_SYSRQKEY_TUnless I am missing something, this requires a virtio keyboard. So far I have been unable to get this to work with qemu arm emulations.
That's unfortunate. Is there another way to collect call traces after the lockup has happened? Is it sufficient to enable the serial console and to monitor the serial console output? Is CONFIG_SOFTLOCKUP_DETECTOR=y sufficient? If not, how about converting the new wait calls in the SCSI code, e.g. as shown in the (totally untested) patch below?
Thanks,
Bart.
drivers/scsi/hosts.c +6 -1
@@ -35,6 +35,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/idr.h> +#include <linux/sched/debug.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #include <scsi/scsi_transport.h>
@@ -196,7 +197,11 @@ void scsi_remove_host(struct Scsi_Host *shost)* unloaded and/or the host resources can be released. Hence wait until * the dependent SCSI targets and devices are gone before returning. */ -wait_event (shost->targets_wq,atomic_read (&shost->target_count) ==0 ); +while (wait_event_timeout (shost->targets_wq, +atomic_read (&shost->target_count) ==0 ,60 *HZ ) <=0 ) { +show_state (); +show_all_workqueues (); + }scsi_mq_destroy_tags (shost); }
drivers/scsi/scsi_sysfs.c +6 -1
@@ -14,6 +14,7 @@#include <linux/device.h> #include <linux/pm_runtime.h> #include <linux/bsg.h> +#include <linux/sched/debug.h> #include <scsi/scsi.h> #include <scsi/scsi_device.h>
@@ -1536,7 +1537,11 @@ static void __scsi_remove_target(struct scsi_target *starget)* devices associated with @starget have been removed to prevent that * a SCSI error handling callback function triggers a use-after-free. */ -wait_event (starget->sdev_wq,atomic_read (&starget->sdev_count) ==0 ); +while (wait_event_timeout (starget->sdev_wq, +atomic_read (&starget->sdev_count) ==0 ,60 *HZ ) <=0 ) { +show_state (); +show_all_workqueues (); + } }/**
Quoted 10 lines · Bart Van Assche
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Bart Van Assche
Since the issue has been observed in qemu, how about sharing the sysrq-t output? I recommend to collect that output as follows:
* Send the serial console output to a file. This involves adding console=ttyS0,115200n8 to the kernel command line and using the proper qemu options to save the serial console output into a file.
* Reproduce the hang and send the sysrq-t key sequence to qemu, e.g. as
follows: virsh send-key ${vm_name}KEY_LEFTALTKEY_SYSRQKEY_T
Quoted 9 lines
Quoted 2 lines
Unless I am missing something, this requires a virtio keyboard. So far I have been unable to get this to work with qemu arm emulations.
That's unfortunate. Is there another way to collect call traces after the lockup has happened? Is it sufficient to enable the serial console and to monitor the serial console output? Is
CONFIG_SOFTLOCKUP_DETECTOR=ysufficient? If not, how about converting the new wait calls in the SCSI code, e.g. as shown in the (totally untested) patch below?
Enabling the lockup detector did the trick. Backtrace below.
Guenter
---
INFO: task init:283 blocked for more than 122 seconds.
Tainted: G N 6.0.0-rc1-00303-g963a70bee588 #3"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:init state:D stack: 0 pid: 283 ppid: 1 flags:0x00000000
__schedule from schedule+0x70/0x118
schedule from scsi_remove_host+0x178/0x1c4
scsi_remove_host from usb_stor_disconnect+0x40/0xe8 usb_stor_disconnect from usb_unbind_interface+0x78/0x274 usb_unbind_interface from device_release_driver_internal+0x1a4/0x230 device_release_driver_internal from bus_remove_device+0xd0/0x100 bus_remove_device from device_del+0x174/0x3ec
device_del from usb_disable_device+0xcc/0x178 usb_disable_device from usb_disconnect+0xcc/0x274 usb_disconnect from usb_disconnect+0x98/0x274
usb_disconnect from usb_remove_hcd+0xd0/0x16c
usb_remove_hcd from host_stop+0x38/0xa8
host_stop from ci_hdrc_remove+0x40/0x134
ci_hdrc_remove from platform_remove+0x24/0x54 platform_remove from device_release_driver_internal+0x1a4/0x230 device_release_driver_internal from bus_remove_device+0xd0/0x100 bus_remove_device from device_del+0x174/0x3ec
device_del from platform_device_del.part.0+0x10/0x78 platform_device_del.part.0 from platform_device_unregister+0x18/0x28 platform_device_unregister from ci_hdrc_remove_device+0xc/0x24 ci_hdrc_remove_device from ci_hdrc_imx_remove+0x28/0xfc ci_hdrc_imx_remove from device_shutdown+0x178/0x230 device_shutdown from __do_sys_reboot+0x168/0x258 __do_sys_reboot from ret_fast_syscall+0x0/0x1c
Exception stack(0xc8cb9fa8 to 0xc8cb9ff0)
9fa0: 01234567 0000000f fee1dead 28121969 01234567 00000000
9fc0: 01234567 0000000f 00000001 00000058 000e05c0 00000000 00000000 00000000 9fe0: 000e0298 beacede4 000994bc b6efc2c0
Showing all locks held in the system:
1 lock held by rcu_tasks_kthre/10:
#0: c0de0d6c (rcu_tasks.tasks_gp_mutex){+.+.}-{3:3}, at: rcu_tasks_one_gp+0x24/0x48c
1 lock held by khungtaskd/16:
#0: c0de0c98 (rcu_read_lock){....}-{1:2}, at: debug_show_all_locks+0x24/0x1a8
8 locks held by init/283:
#0: c0dc87e4 (system_transition_mutex){+.+.}-{3:3}, at: __do_sys_reboot+0x90/0x258
#1: c1985888 (&dev->mutex){....}-{3:3}, at: device_shutdown+0xd8/0x230
#2: c1998488 (&dev->mutex){....}-{3:3}, at: device_shutdown+0xe8/0x230
#3: c2596088 (&dev->mutex){....}-{3:3}, at: device_release_driver_internal+0x34/0x230
#4: c0e5a5ac (usb_bus_idr_lock){+.+.}-{3:3}, at: usb_remove_hcd+0xc4/0x16c
#5: c277c8f8 (&dev->mutex){....}-{3:3}, at: usb_disconnect+0x60/0x274
#6: c27880f8 (&dev->mutex){....}-{3:3}, at: usb_disconnect+0x60/0x274
#7: c27a9498 (&dev->mutex){....}-{3:3}, at: device_release_driver_internal+0x34/0x230=============================================
Kernel panic - not syncing: hung_task: blocked tasks CPU: 0 PID: 16 Comm: khungtaskd Tainted: G N 6.0.0-rc1-00303-g963a70bee588 #3 Hardware name: Freescale i.MX25 (Device Tree Support) unwind_backtrace from show_stack+0x10/0x18 show_stack from dump_stack_lvl+0x34/0x54 dump_stack_lvl from panic+0x114/0x32c panic from watchdog+0x3f4/0x7b4 watchdog from kthread+0xec/0x128 kthread from ret_from_fork+0x14/0x3c Exception stack(0xc88b5fb0 to 0xc88b5ff8)
5fa0: 00000000 00000000 00000000 00000000
5fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 5fe0: 00000000 00000000 00000000 00000000 00000013 00000000
Quoted 20 lines · Guenter Roeck
INFO: task init:283 blocked for more than 122 seconds. Tainted: G N 6.0.0-rc1-00303-g963a70bee588 #3"echo 0 >
/proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:init state:D stack: 0 pid: 283 ppid: 1 flags:0x00000000
__schedulefromschedule+0x70/0x118
schedule fromscsi_remove_host+0x178/0x1c4
scsi_remove_hostfromusb_stor_disconnect+0x40/0xe8usb_stor_disconnectfromusb_unbind_interface+0x78/0x274usb_unbind_interfacefromdevice_release_driver_internal+0x1a4/0x230device_release_driver_internalfrombus_remove_device+0xd0/0x100bus_remove_devicefromdevice_del+0x174/0x3ec
device_delfromusb_disable_device+0xcc/0x178usb_disable_devicefromusb_disconnect+0xcc/0x274usb_disconnectfromusb_disconnect+0x98/0x274usb_disconnectfromusb_remove_hcd+0xd0/0x16cusb_remove_hcdfromhost_stop+0x38/0xa8
host_stopfromci_hdrc_remove+0x40/0x134
ci_hdrc_removefromplatform_remove+0x24/0x54platform_removefromdevice_release_driver_internal+0x1a4/0x230device_release_driver_internalfrombus_remove_device+0xd0/0x100
Quoted 8 lines
bus_remove_devicefromdevice_del+0x174/0x3ec
device_delfrom platform_device_del.part.0+0x10/0x78 platform_device_del.part.0 fromplatform_device_unregister+0x18/0x28platform_device_unregisterfromci_hdrc_remove_device+0xc/0x24ci_hdrc_remove_devicefromci_hdrc_imx_remove+0x28/0xfcci_hdrc_imx_removefromdevice_shutdown+0x178/0x230device_shutdownfrom__do_sys_reboot+0x168/0x258__do_sys_rebootfromret_fast_syscall+0x0/0x1c
Hi Guenter,
Thank you for having shared this information. I think this deadlock is the result of holding a reference on /dev/sda (by the mount() system call) while calling scsi_remove_host().
It seems wrong to me that ci_hdrc_imx_shutdown() calls ci_hdrc_imx_remove() - I think that function should only do the minimum that is required to prepare for shutdown instead of calling scsi_remove_host() indirectly.
That being said, the patch series "scsi: core: Call blk_mq_free_tag_set() earlier" probably will have to be reverted because of the following deadlock reported by syzbot: https://lore.kernel.org/linux-scsi/[email protected]/
Thanks,
Bart.
Quoted 18 lines · Isaac J. Manjarres
Both
__device_attach_driver()and__driver_attach()check the return code of thebus_type.match()function to see if the device needs to be added to the deferred probe list. After adding the device to the list, the logic attempts to bind the device to the driver anyway, as if the device had matched with the driver, which is not correct.If
__device_attach_driver()detects that the device in question is not ready to match with a driver on the bus, then it doesn't make sense for the device to attempt to bind with the current driver or continue attempting to match with any of the other drivers on the bus. So, update the logic in__device_attach_driver()to reflect this.If
__driver_attach()detects that a driver tried to match with a device and that results in any error, then the driver should not attempt to bind with the device. However, the driver can still attempt to match and bind with other devices on the bus, as drivers can be bound to multiple devices. So, update the logic in__driver_attach()to reflect this.
Quoted 5 lines
Cc Saravana Kannan <[email protected]>Fixes 656b8035b0ee ("ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()")Reported-by Guenter Roeck <[email protected]>Signed-off-by Isaac J. Manjarres <[email protected]>
This fixes the boot issue observed on Qualcomm APQ8016 based DragonBoard 410c, which I've missed while testing the "amba: Remove deferred device addition" patch. Feel free to add:
Quoted 42 lines
--- drivers/base/dd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)v1 -> v2:
- Fixed the logic in__driver_attach()to allow a driver to continue attempting to match and bind with devices in case of any error, not just probe deferral.Guenter,
Can you please give test this patch to make sure it still works for you?
Thanks,
Isaacdrivers/base/dd.c +10
-0@@ -881,6 +881,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)dev_dbg (dev,"Device match requests probe deferral\n" ); dev->can_match = true;driver_deferred_probe_add (dev); +/* +* Device can't match with a driver right now, so don't attempt +* to match or bind with other drivers on the bus. +*/ +return ret; }else if (ret <0 ) {dev_dbg (dev,"Bus failed to match device: %d\n" , ret);return ret;@@ -1120,9 +1125,18 @@ static int __driver_attach(struct device *dev, void *data)dev_dbg (dev,"Device match requests probe deferral\n" ); dev->can_match = true;driver_deferred_probe_add (dev); +/* +* Driver could not match with device right now, but may match +* with another device on the bus. +*/ +return 0 ; }else if (ret <0 ) {
drivers/base/dd.c static int __driver_attach(struct device *dev, void *data) · line 1142
Quoted 10 lines
drivers/base/dd.c +5
-1dev_dbg (dev,"Bus failed to match device: %d\n" , ret); -return ret; +/* +* Driver could not match with device, but may match with +* another device on the bus. +*/ +return 0 ; }/* ret > 0 means positive match */ if (driver_allows_async_probing (drv)) {
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland