Skip to content

Commit

Permalink
qla2xxx: Prevent removal and board_disable race
Browse files Browse the repository at this point in the history
Introduce mutual exclusion between the qla2xxx_remove_one PCI driver
callback and qla2x00_disable_board_on_pci_error, which is scheduled as
board_disable work by qla2x00_check_reg{32,16}_for_disconnect:

* Leave the driver-specific data attached to the underlying PCI device
intact in qla2x00_disable_board_on_pci_error, so that qla2x00_remove_one
has enough breadcrumbs to determine that any board_disable work has been
completed.

* In qla2xxx_remove_one, set a bit to prevent any subsequent
board_disable work from scheduling, then cancel and wait until pending
work has completed.

* Reuse the PCI device enable count check in qla2x00_remove_one to
determine if board_disable has occured. The original purpose of this
check was unnecessary since the driver remove function wasn't called
when the probe fails.

Signed-off-by: Joe Lawrence <[email protected]>
Acked-by: Chad Dupuis <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
Joe Lawrence authored and Christoph Hellwig committed Sep 16, 2014
1 parent 232792b commit beb9e31
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions drivers/scsi/qla2xxx/qla_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,7 @@ typedef struct scsi_qla_host {

unsigned long pci_flags;
#define PFLG_DISCONNECTED 0 /* PCI device removed */
#define PFLG_DRIVER_REMOVING 1 /* PCI driver .remove */

uint32_t device_flags;
#define SWITCH_FOUND BIT_0
Expand Down
3 changes: 2 additions & 1 deletion drivers/scsi/qla2xxx/qla_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ qla2x00_check_reg32_for_disconnect(scsi_qla_host_t *vha, uint32_t reg)
{
/* Check for PCI disconnection */
if (reg == 0xffffffff) {
if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags)) {
if (!test_and_set_bit(PFLG_DISCONNECTED, &vha->pci_flags) &&
!test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags)) {
/*
* Schedule this (only once) on the default system
* workqueue so that all the adapter workqueues and the
Expand Down
31 changes: 19 additions & 12 deletions drivers/scsi/qla2xxx/qla_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -3131,15 +3131,25 @@ qla2x00_remove_one(struct pci_dev *pdev)
scsi_qla_host_t *base_vha;
struct qla_hw_data *ha;

base_vha = pci_get_drvdata(pdev);
ha = base_vha->hw;

/* Indicate device removal to prevent future board_disable and wait
* until any pending board_disable has completed. */
set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
cancel_work_sync(&ha->board_disable);

/*
* If the PCI device is disabled that means that probe failed and any
* resources should be have cleaned up on probe exit.
* If the PCI device is disabled then there was a PCI-disconnect and
* qla2x00_disable_board_on_pci_error has taken care of most of the
* resources.
*/
if (!atomic_read(&pdev->enable_cnt))
if (!atomic_read(&pdev->enable_cnt)) {
scsi_host_put(base_vha->host);
kfree(ha);
pci_set_drvdata(pdev, NULL);
return;

base_vha = pci_get_drvdata(pdev);
ha = base_vha->hw;
}

qla2x00_wait_for_hba_ready(base_vha);

Expand Down Expand Up @@ -4799,18 +4809,15 @@ qla2x00_disable_board_on_pci_error(struct work_struct *work)
qla82xx_md_free(base_vha);
qla2x00_free_queues(ha);

scsi_host_put(base_vha->host);

qla2x00_unmap_iobases(ha);

pci_release_selected_regions(ha->pdev, ha->bars);
kfree(ha);
ha = NULL;

pci_disable_pcie_error_reporting(pdev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);

/*
* Let qla2x00_remove_one cleanup qla_hw_data on device removal.
*/
}

/**************************************************************************
Expand Down

0 comments on commit beb9e31

Please sign in to comment.