From patchwork Wed Oct 17 20:27:19 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: 10646053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C33F1508 for ; Wed, 17 Oct 2018 20:28:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F910252D5 for ; Wed, 17 Oct 2018 20:28:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50F84287A4; Wed, 17 Oct 2018 20:28:07 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 57DF1252D5 for ; Wed, 17 Oct 2018 20:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726673AbeJREZ1 (ORCPT ); Thu, 18 Oct 2018 00:25:27 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:49023 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbeJREZ0 (ORCPT ); Thu, 18 Oct 2018 00:25:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:Message-Id :Date:Subject:Cc:To:From:reply-to:sender:bcc:in-reply-to:references: content-type; bh=MWn6Rnse07zjThyrJBNbWpRqcdl/5ALpgLnd9lP3xq0=; b=aHcLuT3Wj7vq RpUiZ8OiWcWl9DPUC1/ODTya4ZhG+e/+vdJTUBhlGsmemjmK4eaD0dPQd0Q0rYLPbStfmbeINmClm SqeXodcY+BOKJBTMzS2u91ll+KevBl5TON8NWIJrpx0z/e7gVOsZ7ijET0ihrNDnSAKuukFDscrRV 2eTuRN1AAlXVCmTMFduOJ8IsDXwCKgpG+ryOhNBuDqM7FXFaEBuFixRqzlCqP0e/L9wF1lKhke8Ly GIiod3p0YA63IKdG1ToQ5tXueKcQHmaqg7eRK4xXRzn8iZlD4PUKSn9Lkcj2rnD+G4i6oHuBWDjrl 1g2PlASbx+Bkmd4rQJrmWQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCsQ4-0007V0-Rx; Wed, 17 Oct 2018 22:27:53 +0200 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 1D009C0555; Wed, 17 Oct 2018 22:27:47 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Greg Kroah-Hartman , Dan Williams , stable@vger.kernel.org Subject: [PATCH] scsi/sd: Avoid that hibernation triggers a kernel warning Date: Wed, 17 Oct 2018 13:27:19 -0700 Message-Id: <20181017202719.137168-1-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00579761024761) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ui1o4ubE/6B7Mu3nRYAHeJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASXozZWvOq7/lzcIrFAbAq19Wrt/oF2 ofKYeezPZTW+uAalYWA4nnQMwa+/md1Jf+IyuV+FKWeGEdXHh+AgsGHHFfVCTEILqGVovccflXpx +fg3CKX09/MzS0rEiVixyzHa6yqyQF+H2As0G8RVWSCOiTaS+9n8WE1Y7K/JLhDDsDYzgnMJz/9H pbKfTERrj+BspFS7A/1PFTncn77/+ZqDoMChHB0S+sP4TQZXFi/lRByWwivjTmT6P1lHM+NIsbhf tOZqtI9cgrR+tgS+RRF4FrkiZ1f0lzZs/vSNj0hOyuhdevnTtDLp/PjSQR66Oi3gTjj2FUsrgVdG LSrx7oPt3FtekKBuIoGwD4N2LqZrB6nqKatjQpXXJ4kbVmWQW1DriHckHGu9Lyf5e/woa/nVTvns qJRjOJfK5cbhn4VPt1DBqSq2/YL3vElg8bQzvJffqjJtNmkHha/oSXJNlTxzxMlHBG/DYARUPbpb cZAOJc7u6MZ0JA+gBrTb8cbNipHb6WeYomLR/aGqZWyMscINMhb84jtK0p6yWNiIzBz7pfHjnii/ hkgx190Y6VwzHL1mGP48AZJt1rFvmbNr7pOhQUae8pUmcVBBoCcOJxc4HUUCX6spe1jbbSG/WuM8 PBsXtzm7aNjCud2so9sFlpfWkybNYmBNw2nvSnaifocwwtEyvDkN3AfUBddcu9g0UhyiCb2MlFyJ Dbr15votsPUsGl8Q6d6bxSpCo3szwp+4egDm3IkHus1KJdLlVEWX697Kep4sbb/eH7sIHDPI7Vhn 4PCr7z8ShfHSk7QkzdXEFjPHPxbEXVO0XLmZkIMU99HKATDDBZ7fFc0FDw0l2bg+uy5d/sAhazOy rD7BKivmVB9+oFMMhiNhviIa1CUp5UOkASe0zzIoSVH5jzhBWWlj91p/N1gxMbxdAh/YOdmDwsA3 9QrhLkqREK5PnlEc5EfmWLNVRopVQ2QSjOQ8Ng3p X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 Although the power management code never calls the system-wide and runtime suspend callbacks concurrently, runtime power state changes can happen while the system is being suspended or resumed. See also the dpm_suspend() and dpm_resume() calls in hibernation_snapshot(). Make sure the sd driver supports this. This patch avoids that the following call trace is reported during system-wide suspend: WARNING: CPU: 0 PID: 701 at drivers/scsi/scsi_lib.c:3047 scsi_device_quiesce+0x4b/0xd0 Workqueue: events_unbound async_run_entry_fn RIP: 0010:scsi_device_quiesce+0x4b/0xd0 Call Trace: scsi_bus_suspend_common+0x71/0xe0 scsi_bus_freeze+0x15/0x20 dpm_run_callback+0x88/0x360 __device_suspend+0x1c4/0x840 async_suspend+0x1f/0xb0 async_run_entry_fn+0x6e/0x2c0 process_one_work+0x4ae/0xa20 worker_thread+0x63/0x5a0 kthread+0x1cf/0x1f0 ret_from_fork+0x24/0x30 Fixes: cd84a62e0078 ("block, scsi: Change the preempt-only flag into a counter") Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Dan Williams Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 16 +++++----------- include/scsi/scsi_device.h | 1 - 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 62348412ed1b..3106e910e766 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3040,13 +3040,11 @@ scsi_device_quiesce(struct scsi_device *sdev) int err; /* - * It is allowed to call scsi_device_quiesce() multiple times from - * the same context but concurrent scsi_device_quiesce() calls are - * not allowed. + * Since all scsi_device_quiesce() and scsi_device_resume() calls + * are serialized it is safe to check the device state without holding + * the SCSI device state mutex. */ - WARN_ON_ONCE(sdev->quiesced_by && sdev->quiesced_by != current); - - if (sdev->quiesced_by == current) + if (sdev->sdev_state == SDEV_QUIESCE) return 0; blk_set_pm_only(q); @@ -3063,9 +3061,7 @@ scsi_device_quiesce(struct scsi_device *sdev) mutex_lock(&sdev->state_mutex); err = scsi_device_set_state(sdev, SDEV_QUIESCE); - if (err == 0) - sdev->quiesced_by = current; - else + if (err) blk_clear_pm_only(q); mutex_unlock(&sdev->state_mutex); @@ -3089,8 +3085,6 @@ void scsi_device_resume(struct scsi_device *sdev) * device deleted during suspend) */ mutex_lock(&sdev->state_mutex); - WARN_ON_ONCE(!sdev->quiesced_by); - sdev->quiesced_by = NULL; blk_clear_pm_only(sdev->request_queue); if (sdev->sdev_state == SDEV_QUIESCE) scsi_device_set_state(sdev, SDEV_RUNNING); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 202f4d6a4342..ef86c8adc5d5 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -226,7 +226,6 @@ struct scsi_device { unsigned char access_state; struct mutex state_mutex; enum scsi_device_state sdev_state; - struct task_struct *quiesced_by; unsigned long sdev_data[0]; } __attribute__((aligned(sizeof(unsigned long))));