From patchwork Thu Nov 23 01:05:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10072233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8E99F60353 for ; Thu, 23 Nov 2017 01:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7579729C1A for ; Thu, 23 Nov 2017 01:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6767829D7C; Thu, 23 Nov 2017 01:06:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8308F29C1A for ; Thu, 23 Nov 2017 01:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751861AbdKWBGg (ORCPT ); Wed, 22 Nov 2017 20:06:36 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:13286 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751549AbdKWBGf (ORCPT ); Wed, 22 Nov 2017 20:06:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1511399195; x=1542935195; h=from:to:cc:subject:date:message-id:mime-version; bh=//tLBkwTJDO4Z2vTakXaVbtcQYBymeIY2ieVUMYbWuw=; b=qI1p8KfxE8c0Cm8ffEEGlgu1rDDDZ6yuRYdrjl/FNyoawhwXCoWyUDl3 QhwHV32wRB6NGe+r+IFhO7XnioqXbkC/uctgykvcyeuHRyfhPm2WCIdbZ vNx9/+BV8vvpuUupUDPI3Ewr/2ASoF6S9ZPhlrKoLeW+CvLNULNKDKpE6 KEhO6E8qMwdkecLxi1+W2oSCD0HbQ8LzqVMecL2uLlaCAuwjkMqQF182m BfVAaEhf0R70mazgVNpu3yuzDcOVp6JIBeL8Zj+qRmLKYjvhVL9yjOxEA gNLH63DfIln8R3Ug1bxmqJIfCOb9eBqEARETorqTA4i863aIjd1w0NKgY w==; X-IronPort-AV: E=Sophos;i="5.44,438,1505750400"; d="scan'208";a="63044380" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 23 Nov 2017 09:06:35 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 22 Nov 2017 17:03:34 -0800 Received: from unknown (HELO MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Nov 2017 17:06:35 -0800 Received: from milsmgip11.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Wed, 22 Nov 2017 17:05:08 -0800 X-AuditID: 0ab10959-0abff70000002c97-93-5a161ec16a4b Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id A2.61.11415.1CE161A5; Wed, 22 Nov 2017 17:05:08 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" CC: , Bart Van Assche , Konstantin Khorenko , Stuart Hayes , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Subject: [PATCH] Ensure that the SCSI error handler gets woken up Date: Wed, 22 Nov 2017 17:05:05 -0800 Message-ID: <20171123010505.9603-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFJMWRmVeSWpSXmKPExsXCtZEjRfeInFiUwZbzwhaX/nxhtFjwZi+b xcrVR5ksVk3Ms3jcNYPV4vHOl6wW3dd3sFksP/6PyWLBxkeMFkdWrWN24PLYOesuu8eDQ5tZ PHbfbGDz+Pj0FovH+i1XWTw2n672+LxJzuP1/kOMHu0HupkCOKO4bFJSczLLUov07RK4Mtoa HjIV3JGsuHd4DnsD4xfRLkZODgkBE4n1R7+ydjFycQgJrGaU2LXxMyNIgk1AT+LUvH1MILaI QK7EqYc3mECKmAXWM0l8eP+aBSQhLOAo8Xv9PlYQm0VAVeLkjNvsIDavgJXEj28X2SA2yEss /r6TbQIj5wJGhlWMYrmZOcW56ZkFhoZ6xYl5KZnF2XrJ+bmbGMGhwxm5g/HpRPNDjEwcnFIN jBNidsjdLP3MFqZedDRwdsrsZdNqr3VPiTJ5vDl2jv1ptz9apsULVgY180Ub+gjaGN8J+Jyi 9tSx/qNO88z3NpdFDwcv39H/zzvBZZnehTdvV4a63MlmYWyUiP9jsZLL/OVGU54PyZvPPXhS tzYo2481wytdd4bnw1pZlk37tOT6kh1spcMPKLEUZyQaajEXFScCAD2geW/NAQAA MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If scsi_eh_scmd_add() is called concurrently with scsi_host_queue_ready() while shost->host_blocked > 0 then it can happen that neither function wakes up the SCSI error handler. Fix this by making every function that decreases the host_busy counter to wake up the error handler if necessary. Reported-by: Pavel Tikhomirov Fixes: commit 746650160866 ("scsi: convert host_busy to atomic_t") Signed-off-by: Bart Van Assche Cc: Konstantin Khorenko Cc: Stuart Hayes Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Signed-off-by: Pavel Tikhomirov --- drivers/scsi/scsi_error.c | 3 ++- drivers/scsi/scsi_lib.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 5e89049e9b4e..f7f014c755d7 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -61,9 +61,10 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd); static int scsi_try_to_abort_cmd(struct scsi_host_template *, struct scsi_cmnd *); -/* called with shost->host_lock held */ void scsi_eh_wakeup(struct Scsi_Host *shost) { + lockdep_assert_held(shost->host_lock); + if (atomic_read(&shost->host_busy) == shost->host_failed) { trace_scsi_eh_wakeup(shost); wake_up_process(shost->ehandler); diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1e05e1885ac8..abd37d77af2d 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -318,22 +318,28 @@ static void scsi_init_cmd_errh(struct scsi_cmnd *cmd) cmd->cmd_len = scsi_command_size(cmd->cmnd); } -void scsi_device_unbusy(struct scsi_device *sdev) +static void scsi_dec_host_busy(struct Scsi_Host *shost) { - struct Scsi_Host *shost = sdev->host; - struct scsi_target *starget = scsi_target(sdev); unsigned long flags; atomic_dec(&shost->host_busy); - if (starget->can_queue > 0) - atomic_dec(&starget->target_busy); - if (unlikely(scsi_host_in_recovery(shost) && (shost->host_failed || shost->host_eh_scheduled))) { spin_lock_irqsave(shost->host_lock, flags); scsi_eh_wakeup(shost); spin_unlock_irqrestore(shost->host_lock, flags); } +} + +void scsi_device_unbusy(struct scsi_device *sdev) +{ + struct Scsi_Host *shost = sdev->host; + struct scsi_target *starget = scsi_target(sdev); + + scsi_dec_host_busy(shost); + + if (starget->can_queue > 0) + atomic_dec(&starget->target_busy); atomic_dec(&sdev->device_busy); } @@ -1532,7 +1538,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q, list_add_tail(&sdev->starved_entry, &shost->starved_list); spin_unlock_irq(shost->host_lock); out_dec: - atomic_dec(&shost->host_busy); + scsi_dec_host_busy(shost); return 0; } @@ -2020,7 +2026,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, return BLK_STS_OK; out_dec_host_busy: - atomic_dec(&shost->host_busy); + scsi_dec_host_busy(shost); out_dec_target_busy: if (scsi_target(sdev)->can_queue > 0) atomic_dec(&scsi_target(sdev)->target_busy);