Return-Path: Received: from mail-sn1nam02on0112.outbound.protection.outlook.com ([104.47.36.112]:31168 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755132AbeARVFl (ORCPT ); Thu, 18 Jan 2018 16:05:41 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Don Brace , "Martin K . Petersen" , Sasha Levin Subject: [added to the 4.1 stable tree] scsi: hpsa: limit outstanding rescans Date: Thu, 18 Jan 2018 21:01:29 +0000 Message-ID: <20180118205908.3220-236-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Don Brace This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 87b9e6aa87d9411f1059aa245c0c79976bc557ac ] Avoid rescan storms. No need to queue another if one is pending. Reviewed-by: Scott Benesh Reviewed-by: Scott Teel Reviewed-by: Tomas Henzl Signed-off-by: Don Brace Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/hpsa.c | 16 +++++++++++++++- drivers/scsi/hpsa.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 8eab107b53fb..0ef5d9286e0a 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -4158,7 +4158,7 @@ static void hpsa_scan_complete(struct ctlr_info *h) =20 spin_lock_irqsave(&h->scan_lock, flags); h->scan_finished =3D 1; - wake_up_all(&h->scan_wait_queue); + wake_up(&h->scan_wait_queue); spin_unlock_irqrestore(&h->scan_lock, flags); } =20 @@ -4176,11 +4176,23 @@ static void hpsa_scan_start(struct Scsi_Host *sh) if (unlikely(lockup_detected(h))) return hpsa_scan_complete(h); =20 + /* + * If a scan is already waiting to run, no need to add another + */ + spin_lock_irqsave(&h->scan_lock, flags); + if (h->scan_waiting) { + spin_unlock_irqrestore(&h->scan_lock, flags); + return; + } + + spin_unlock_irqrestore(&h->scan_lock, flags); + /* wait until any scan already in progress is finished. */ while (1) { spin_lock_irqsave(&h->scan_lock, flags); if (h->scan_finished) break; + h->scan_waiting =3D 1; spin_unlock_irqrestore(&h->scan_lock, flags); wait_event(h->scan_wait_queue, h->scan_finished); /* Note: We don't need to worry about a race between this @@ -4190,6 +4202,7 @@ static void hpsa_scan_start(struct Scsi_Host *sh) */ } h->scan_finished =3D 0; /* mark scan as in progress */ + h->scan_waiting =3D 0; spin_unlock_irqrestore(&h->scan_lock, flags); =20 if (unlikely(lockup_detected(h))) @@ -6936,6 +6949,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const = struct pci_device_id *ent) goto clean4; init_waitqueue_head(&h->scan_wait_queue); h->scan_finished =3D 1; /* no scan currently in progress */ + h->scan_waiting =3D 0; =20 pci_set_drvdata(pdev, h); h->ndevices =3D 0; diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h index 657713050349..cbaf416d5456 100644 --- a/drivers/scsi/hpsa.h +++ b/drivers/scsi/hpsa.h @@ -166,6 +166,7 @@ struct ctlr_info { dma_addr_t errinfo_pool_dhandle; unsigned long *cmd_pool_bits; int scan_finished; + u8 scan_waiting : 1; spinlock_t scan_lock; wait_queue_head_t scan_wait_queue; =20 --=20 2.11.0