1
0
Fork 0
alistair23-linux/drivers/ata
John Garry f545fda258 libata: Ensure ata_port probe has completed before detach
[ Upstream commit 130f4caf14 ]

With CONFIG_DEBUG_TEST_DRIVER_REMOVE set, we may find the following WARN:

[   23.452574] ------------[ cut here ]------------
[   23.457190] WARNING: CPU: 59 PID: 1 at drivers/ata/libata-core.c:6676 ata_host_detach+0x15c/0x168
[   23.466047] Modules linked in:
[   23.469092] CPU: 59 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc1-00010-g5b83fd27752b-dirty #296
[   23.477776] Hardware name: Huawei D06 /D06, BIOS Hisilicon D06 UEFI RC0 - V1.16.01 03/15/2019
[   23.486286] pstate: a0c00009 (NzCv daif +PAN +UAO)
[   23.491065] pc : ata_host_detach+0x15c/0x168
[   23.495322] lr : ata_host_detach+0x88/0x168
[   23.499491] sp : ffff800011cabb50
[   23.502792] x29: ffff800011cabb50 x28: 0000000000000007
[   23.508091] x27: ffff80001137f068 x26: ffff8000112c0c28
[   23.513390] x25: 0000000000003848 x24: ffff0023ea185300
[   23.518689] x23: 0000000000000001 x22: 00000000000014c0
[   23.523987] x21: 0000000000013740 x20: ffff0023bdc20000
[   23.529286] x19: 0000000000000000 x18: 0000000000000004
[   23.534584] x17: 0000000000000001 x16: 00000000000000f0
[   23.539883] x15: ffff0023eac13790 x14: ffff0023eb76c408
[   23.545181] x13: 0000000000000000 x12: ffff0023eac13790
[   23.550480] x11: ffff0023eb76c228 x10: 0000000000000000
[   23.555779] x9 : ffff0023eac13798 x8 : 0000000040000000
[   23.561077] x7 : 0000000000000002 x6 : 0000000000000001
[   23.566376] x5 : 0000000000000002 x4 : 0000000000000000
[   23.571674] x3 : ffff0023bf08a0bc x2 : 0000000000000000
[   23.576972] x1 : 3099674201f72700 x0 : 0000000000400284
[   23.582272] Call trace:
[   23.584706]  ata_host_detach+0x15c/0x168
[   23.588616]  ata_pci_remove_one+0x10/0x18
[   23.592615]  ahci_remove_one+0x20/0x40
[   23.596356]  pci_device_remove+0x3c/0xe0
[   23.600267]  really_probe+0xdc/0x3e0
[   23.603830]  driver_probe_device+0x58/0x100
[   23.608000]  device_driver_attach+0x6c/0x90
[   23.612169]  __driver_attach+0x84/0xc8
[   23.615908]  bus_for_each_dev+0x74/0xc8
[   23.619730]  driver_attach+0x20/0x28
[   23.623292]  bus_add_driver+0x148/0x1f0
[   23.627115]  driver_register+0x60/0x110
[   23.630938]  __pci_register_driver+0x40/0x48
[   23.635199]  ahci_pci_driver_init+0x20/0x28
[   23.639372]  do_one_initcall+0x5c/0x1b0
[   23.643199]  kernel_init_freeable+0x1a4/0x24c
[   23.647546]  kernel_init+0x10/0x108
[   23.651023]  ret_from_fork+0x10/0x18
[   23.654590] ---[ end trace 634a14b675b71c13 ]---

With KASAN also enabled, we may also get many use-after-free reports.

The issue is that when CONFIG_DEBUG_TEST_DRIVER_REMOVE is set, we may
attempt to detach the ata_port before it has been probed.

This is because the ata_ports are async probed, meaning that there is no
guarantee that the ata_port has probed prior to detach. When the ata_port
does probe in this scenario, we get all sorts of issues as the detach may
have already happened.

Fix by ensuring synchronisation with async_synchronize_full(). We could
alternatively use the cookie returned from the ata_port probe
async_schedule() call, but that means managing the cookie, so more
complicated.

Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-12-31 16:44:31 +01:00
..
Kconfig ata: add Buddha PATA controller driver 2019-02-08 06:32:01 -07:00
Makefile ata: add Buddha PATA controller driver 2019-02-08 06:32:01 -07:00
acard-ahci.c acard_ahci: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
ahci.c libata/ahci: Fix PCS quirk application 2019-10-15 14:10:19 -06:00
ahci.h libata/ahci: Drop PCS quirk for Denverton and beyond 2019-08-30 20:53:42 -06:00
ahci_brcm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 118 2019-05-24 17:39:02 +02:00
ahci_ceva.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 201 2019-05-30 11:29:52 -07:00
ahci_da850.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 45 2019-05-24 17:27:12 +02:00
ahci_dm816.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 45 2019-05-24 17:27:12 +02:00
ahci_imx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 201 2019-05-30 11:29:52 -07:00
ahci_mtk.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
ahci_mvebu.c ata: ahci: mvebu: request PHY suspend/resume for Armada 3700 2019-01-11 14:47:51 -07:00
ahci_octeon.c Delete redundant return value check of platform_get_resource() 2017-03-06 15:40:59 -05:00
ahci_platform.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 45 2019-05-24 17:27:12 +02:00
ahci_qoriq.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 45 2019-05-24 17:27:12 +02:00
ahci_seattle.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 235 2019-06-19 17:09:07 +02:00
ahci_st.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ahci_sunxi.c drivers: ata: ahci_sunxi: Increased SATA/AHCI DMA TX/RX FIFOs 2019-07-05 10:17:18 -06:00
ahci_tegra.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 282 2019-06-05 17:36:37 +02:00
ahci_xgene.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
ata_generic.c ata: use CONFIG_PM_SLEEP instead of CONFIG_PM where applicable in host drivers 2014-05-09 22:37:49 -04:00
ata_piix.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
libahci.c ahci: Do not export local variable ahci_em_messages 2019-08-30 14:25:57 -06:00
libahci_platform.c ata: libahci_platform: Fix regulator_get_optional() misuse 2019-10-25 14:22:20 -06:00
libata-acpi.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
libata-core.c libata: Ensure ata_port probe has completed before detach 2019-12-31 16:44:31 +01:00
libata-eh.c libata: don't request sense data on !ZAC ATA devices 2019-06-25 09:22:45 -06:00
libata-pmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 428 2019-06-05 17:37:16 +02:00
libata-scsi.c Revert "libata, freezer: avoid block device removal while system is frozen" 2019-10-06 09:11:37 -06:00
libata-sff.c for-5.4/libata-2019-09-15 2019-09-17 16:54:40 -07:00
libata-trace.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
libata-transport.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 209 2019-05-30 11:29:53 -07:00
libata-transport.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
libata-zpodd.c libata: zpodd: Fix small read overflow in zpodd_get_mech_type() 2019-07-29 16:00:14 -06:00
libata.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_acpi.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_ali.c ata: Deprecate pci_get_bus_and_slot() 2018-01-11 17:23:23 -06:00
pata_amd.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_arasan_cf.c pata_arasan_cf: Delete an unnecessary variable initialisation in arasan_cf_probe() 2018-02-18 05:16:35 -08:00
pata_artop.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_atiixp.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_atp867x.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_bk3710.c pata_bk3710: clarify license version and use SPDX header 2018-03-01 13:59:03 -08:00
pata_buddha.c ata/pata_buddha: Probe via modalias instead of initcall 2019-08-23 06:58:50 -06:00
pata_cmd64x.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_cmd640.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_cs5520.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_cs5530.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pata_cs5535.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pata_cs5536.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pata_cypress.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_efar.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_ep93xx.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_falcon.c pata_falcon: clarify license version and use SPDX header 2018-03-01 13:58:17 -08:00
pata_ftide010.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_gayle.c ata: add Amiga Gayle PATA controller driver 2018-03-19 07:41:36 -07:00
pata_hpt3x2n.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_hpt3x3.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_hpt37x.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_hpt366.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_icside.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_imx.c Merge branch 'for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata 2018-08-24 13:20:33 -07:00
pata_isapnp.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_it821x.c pata_it821x: Delete an error message for a failed memory allocation in it821x_firmware_command() 2018-02-18 05:26:07 -08:00
pata_it8213.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_ixp4xx_cf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pata_jmicron.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_legacy.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_macio.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_marvell.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_mpc52xx.c pata_mpc52xx: Delete an error message for a failed memory allocation in mpc52xx_ata_probe() 2018-02-18 05:23:25 -08:00
pata_mpiix.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_netcell.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_ninja32.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_ns87410.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_ns87415.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_octeon_cf.c pata_octeon_cf: use of_property_read_{bool|u32}() 2017-08-28 10:44:24 -07:00
pata_of_platform.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pata_oldpiix.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_opti.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_optidma.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_palmld.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pata_pcmcia.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_pdc202xx_old.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_pdc2027x.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_piccolo.c ata: use CONFIG_PM_SLEEP instead of CONFIG_PM where applicable in host drivers 2014-05-09 22:37:49 -04:00
pata_platform.c ata: pata_platform: Add IRQF_SHARED to IRQ flags 2019-02-08 06:42:55 -07:00
pata_pxa.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_radisys.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_rb532_cf.c ata: rb532_cf: Fix unused variable warning in rb532_pata_driver_probe 2019-08-06 07:44:59 -06:00
pata_rdc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
pata_rz1000.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_samsung_cf.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pata_sc1200.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pata_sch.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 300 2019-06-05 17:37:00 +02:00
pata_serverworks.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_sil680.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
pata_sis.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_sl82c105.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pata_triflex.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pata_via.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
pdc_adma.c pdc_adma: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
sata_dwc_460ex.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sata_fsl.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
sata_gemini.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
sata_gemini.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sata_highbank.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 201 2019-05-30 11:29:52 -07:00
sata_inic162x.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_mv.c sata_mv: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
sata_nv.c sata_nv: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
sata_promise.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_promise.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
sata_qstor.c sata_qstor: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
sata_rcar.c sata_rcar: Remove ata_host_alloc() error printing 2019-05-09 11:19:32 -06:00
sata_sil.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_sil24.c sata_sil24: use dma_set_mask_and_coherent 2019-08-26 13:58:58 -06:00
sata_sis.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
sata_svw.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_sx4.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_uli.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 18 2019-05-21 11:28:46 +02:00
sata_via.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sata_vsc.c libata: switch remaining drivers to use dma_set_mask_and_coherent 2019-08-26 13:58:59 -06:00
sis.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00