From patchwork Fri Jan 5 17:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10146847 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 8D3B8604D3 for ; Fri, 5 Jan 2018 17:19:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DEC02871F for ; Fri, 5 Jan 2018 17:19:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62F2128736; Fri, 5 Jan 2018 17:19:17 +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=unavailable 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 16AD128779 for ; Fri, 5 Jan 2018 17:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752139AbeAERTN (ORCPT ); Fri, 5 Jan 2018 12:19:13 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:24390 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752136AbeAERTL (ORCPT ); Fri, 5 Jan 2018 12:19:11 -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=1515172751; x=1546708751; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=NIrgFRBaUxAGfuwlZDDleVJwLI9PxN9PDPBuL/KQqFA=; b=TENoE9kx4TYzd6qoomiUgYhUexdsKKB68ELhL4Du6BAXGDqDBe0PKB8P egnN3Wxha1kpkWVCgPhATGCktJASwVYZz6hLxrgh/MRGd+ulOafBT1djW FYc9MCwKWbR/reOkjaMKntGKBMGANUg40MoI+XRPGtZ2YWdO6yzxv3m4z W0W5bUMv/3/+diQPagmTbiVW2Vb/PwnnxItVMj+6mor9XFqR9iD2uKYCU FUNLc42GizUtP/VbNlKbaq3Et/pctWPR8itD8cEsDMM1XsmcV5DZj5F4t y+qc9l87tXGk5VRHkJrMrnNpjAeo8h3qS/OYzBa5SiyYRJdY2kZtNT/71 Q==; X-IronPort-AV: E=Sophos;i="5.46,319,1511798400"; d="scan'208";a="67969655" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 06 Jan 2018 01:19:11 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 05 Jan 2018 09:14:55 -0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.171.236]) by uls-op-cesaip02.wdc.com with ESMTP; 05 Jan 2018 09:19:11 -0800 From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J . Wysocki" , Woody Suwalski , Alan Stern , Bart Van Assche Subject: [PATCH 2/2] Fix a race condition between SPI domain validation and system suspend Date: Fri, 5 Jan 2018 09:19:09 -0800 Message-Id: <20180105171909.11839-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180105171909.11839-1-bart.vanassche@wdc.com> References: <20180105171909.11839-1-bart.vanassche@wdc.com> 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 Avoid that the following warning is reported when suspending a system that is using the mptspi driver: WARNING: CPU: 0 PID: 4187 at drivers/scsi/scsi_lib.c:2960 scsi_device_quiesce+0x20/0xb0 EIP: scsi_device_quiesce+0x20/0xb0 Call Trace: spi_dv_device+0x65/0x5f0 [scsi_transport_spi] mptspi_dv_device+0x4d/0x170 [mptspi] mptspi_dv_renegotiate_work+0x49/0xc0 [mptspi] process_one_work+0x190/0x2e0 worker_thread+0x37/0x3f0 kthread+0xcb/0x100 ret_from_fork+0x19/0x24 Fixes: 3a0a529971ec ("block, scsi: Make SCSI quiesce and resume work reliably") Reported-by: Woody Suwalski Signed-off-by: Bart Van Assche Cc: Alan Stern Cc: Rafael J. Wysocki Cc: linux-pm@vger.kernel.org Acked-by: Martin K. Petersen --- drivers/scsi/scsi_transport_spi.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c index 10ebb213ddb3..871ea582029e 100644 --- a/drivers/scsi/scsi_transport_spi.c +++ b/drivers/scsi/scsi_transport_spi.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "scsi_priv.h" #include @@ -1009,11 +1010,20 @@ spi_dv_device(struct scsi_device *sdev) u8 *buffer; const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; + /* + * Because this function and the power management code both call + * scsi_device_quiesce(), it is not safe to perform domain validation + * while suspend or resume is in progress. Hence the + * lock/unlock_system_sleep() calls. + */ + lock_system_sleep(); + if (unlikely(spi_dv_in_progress(starget))) - return; + goto unlock; if (unlikely(scsi_device_get(sdev))) - return; + goto unlock; + spi_dv_in_progress(starget) = 1; buffer = kzalloc(len, GFP_KERNEL); @@ -1049,6 +1059,8 @@ spi_dv_device(struct scsi_device *sdev) out_put: spi_dv_in_progress(starget) = 0; scsi_device_put(sdev); +unlock: + unlock_system_sleep(); } EXPORT_SYMBOL(spi_dv_device);