• Tejun Heo's avatar
    libata, freezer: avoid block device removal while system is frozen · 4e7255f3
    Tejun Heo authored
    commit 85fbd722ad0f5d64d1ad15888cd1eb2188bfb557 upstream.
    
    Freezable kthreads and workqueues are fundamentally problematic in
    that they effectively introduce a big kernel lock widely used in the
    kernel and have already been the culprit of several deadlock
    scenarios.  This is the latest occurrence.
    
    During resume, libata rescans all the ports and revalidates all
    pre-existing devices.  If it determines that a device has gone
    missing, the device is removed from the system which involves
    invalidating block device and flushing bdi while holding driver core
    layer locks.  Unfortunately, this can race with the rest of device
    resume.  Because freezable kthreads and workqueues are thawed after
    device resume is complete and block device removal depends on
    freezable workqueues and kthreads (e.g. bdi_wq, jbd2) to make
    progress, this can lead to deadlock - block device removal can't
    proceed because kthreads are frozen and kthreads can't be thawed
    because device resume is blocked behind block device removal.
    
    839a8e86 ("writeback: replace custom worker pool implementation
    with unbound workqueue") made this particular deadlock scenario more
    visible but the underlying problem has always been there - the
    original forker task and jbd2 are freezable too.  In fact, this is
    highly likely just one of many possible deadlock scenarios given that
    freezer behaves as a big kernel lock and we don't have any debug
    mechanism around it.
    
    I believe the right thing to do is getting rid of freezable kthreads
    and workqueues.  This is something fundamentally broken.  For now,
    implement a funny workaround in libata - just avoid doing block device
    hot[un]plug while the system is frozen.  Kernel engineering at its
    finest.  :(
    
    v2: Add EXPORT_SYMBOL_GPL(pm_freezing) for cases where libata is built
        as a module.
    
    v3: Comment updated and polling interval changed to 10ms as suggested
        by Rafael.
    
    v4: Add #ifdef CONFIG_FREEZER around the hack as pm_freezing is not
        defined when FREEZER is not configured thus breaking build.
        Reported by kbuild test robot.
    Signed-off-by: 's avatarTejun Heo <tj@kernel.org>
    Reported-by: 's avatarTomaž Šolc <tomaz.solc@tablix.org>
    Reviewed-by: 's avatar"Rafael J. Wysocki" <rjw@rjwysocki.net>
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=62801
    Link: http://lkml.kernel.org/r/20131213174932.GA27070@htj.dyndns.org
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Len Brown <len.brown@intel.com>
    Cc: Oleg Nesterov <oleg@redhat.com>
    Cc: kbuild test robot <fengguang.wu@intel.com>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    4e7255f3
Name
Last commit
Last update
..
Kconfig Loading commit data...
Makefile Loading commit data...
acard-ahci.c Loading commit data...
ahci.c Loading commit data...
ahci.h Loading commit data...
ahci_platform.c Loading commit data...
ata_generic.c Loading commit data...
ata_piix.c Loading commit data...
libahci.c Loading commit data...
libata-acpi.c Loading commit data...
libata-core.c Loading commit data...
libata-eh.c Loading commit data...
libata-pmp.c Loading commit data...
libata-scsi.c Loading commit data...
libata-sff.c Loading commit data...
libata-transport.c Loading commit data...
libata-transport.h Loading commit data...
libata-zpodd.c Loading commit data...
libata.h Loading commit data...
pata_acpi.c Loading commit data...
pata_ali.c Loading commit data...
pata_amd.c Loading commit data...
pata_arasan_cf.c Loading commit data...
pata_artop.c Loading commit data...
pata_at32.c Loading commit data...
pata_at91.c Loading commit data...
pata_atiixp.c Loading commit data...
pata_atp867x.c Loading commit data...
pata_bf54x.c Loading commit data...
pata_cmd640.c Loading commit data...
pata_cmd64x.c Loading commit data...
pata_cs5520.c Loading commit data...
pata_cs5530.c Loading commit data...
pata_cs5535.c Loading commit data...
pata_cs5536.c Loading commit data...
pata_cypress.c Loading commit data...
pata_efar.c Loading commit data...
pata_ep93xx.c Loading commit data...
pata_hpt366.c Loading commit data...
pata_hpt37x.c Loading commit data...
pata_hpt3x2n.c Loading commit data...
pata_hpt3x3.c Loading commit data...
pata_icside.c Loading commit data...
pata_imx.c Loading commit data...
pata_isapnp.c Loading commit data...
pata_it8213.c Loading commit data...
pata_it821x.c Loading commit data...
pata_ixp4xx_cf.c Loading commit data...
pata_jmicron.c Loading commit data...
pata_legacy.c Loading commit data...
pata_macio.c Loading commit data...
pata_marvell.c Loading commit data...
pata_mpc52xx.c Loading commit data...
pata_mpiix.c Loading commit data...
pata_netcell.c Loading commit data...
pata_ninja32.c Loading commit data...
pata_ns87410.c Loading commit data...
pata_ns87415.c Loading commit data...
pata_octeon_cf.c Loading commit data...
pata_of_platform.c Loading commit data...
pata_oldpiix.c Loading commit data...
pata_opti.c Loading commit data...
pata_optidma.c Loading commit data...
pata_palmld.c Loading commit data...
pata_pcmcia.c Loading commit data...
pata_pdc2027x.c Loading commit data...
pata_pdc202xx_old.c Loading commit data...
pata_piccolo.c Loading commit data...
pata_platform.c Loading commit data...
pata_pxa.c Loading commit data...
pata_radisys.c Loading commit data...
pata_rb532_cf.c Loading commit data...
pata_rdc.c Loading commit data...
pata_rz1000.c Loading commit data...
pata_samsung_cf.c Loading commit data...
pata_sc1200.c Loading commit data...
pata_scc.c Loading commit data...
pata_sch.c Loading commit data...
pata_serverworks.c Loading commit data...
pata_sil680.c Loading commit data...
pata_sis.c Loading commit data...
pata_sl82c105.c Loading commit data...
pata_triflex.c Loading commit data...
pata_via.c Loading commit data...
pdc_adma.c Loading commit data...
sata_dwc_460ex.c Loading commit data...
sata_fsl.c Loading commit data...
sata_highbank.c Loading commit data...
sata_inic162x.c Loading commit data...
sata_mv.c Loading commit data...
sata_nv.c Loading commit data...
sata_promise.c Loading commit data...
sata_promise.h Loading commit data...
sata_qstor.c Loading commit data...
sata_rcar.c Loading commit data...
sata_sil.c Loading commit data...
sata_sil24.c Loading commit data...
sata_sis.c Loading commit data...
sata_svw.c Loading commit data...
sata_sx4.c Loading commit data...
sata_uli.c Loading commit data...
sata_via.c Loading commit data...
sata_vsc.c Loading commit data...
sis.h Loading commit data...