From patchwork Wed Oct 17 23:40:04 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: 10646603 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 E555913A4 for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8E2E28893 for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCC812881A; Wed, 17 Oct 2018 23:40:45 +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 45E782888A for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbeJRHit (ORCPT ); Thu, 18 Oct 2018 03:38:49 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:46427 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHis (ORCPT ); Thu, 18 Oct 2018 03:38:48 -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:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=xZWmhAfUjps7peTMTKkpwkFObl7lK0KRmkbAIIF3pUk=; b=mT9prlZ+0oLm u4myS5PDjb3vBm/qmPJEA63N6SaOYBVoXjwNJ9Dm8ZVrlOME/B0KrfahDCrBghUb4LUYCQklXkpBM ZRjhyW1XgO1l3nATc8ND339YqUVSA8EO4M6wK71CrqYYbWxPanH8jddoFTuS02umajMRzt/s2fIsX +ZruIWypU3m0iSBcFVbYSlEwK33eQ3aRCNqdUBvpkOabu1WiYcYsUMWOrqVCWnBtgBcUo61K2MzXj xcV0ah50RzwdfOZgMiKfgoCGeJ4n9WwRnH/L/gKPSefzig2niZi+Bh5FqIfM3I0QM6QKP7sLziXRy 2Eba1D9lJ619khLgIFTwDg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQT-000AgP-Qp; Thu, 18 Oct 2018 01:40:30 +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 4F721C06CF; Thu, 18 Oct 2018 01:40:26 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Dan Williams , stable@vger.kernel.org Subject: [PATCH v2 5/7] sd: Avoid that hibernation triggers a kernel warning Date: Wed, 17 Oct 2018 16:40:04 -0700 Message-Id: <20181017234006.124251-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-1-bvanassche@acm.org> 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.009594143917) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5qlBwnhWqtehzElJIgmyQQd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASXozZWvOq7/lzcIrFAbAq19Wrt/oF2 ofKYeezPZTW+uAalYWA4nnQMwa+/md1Jf+J9Ga9nqe5rr63xa7zQu0+0FfVCTEILqGVovccflXpx +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/aGqZWyMscINMhb84jtK0p6yWNiIzBz7pfNjJPKZ H7A6vJ2MFQnp5x1mGP48AZJt1rFvmbNr7pOhQUae8pUmcVBBoCcOJxc4HUUCX6spe1jbbSG/WuM8 PBsXtzm7aNjCud2so9sFlpfWkybNYmBNw2nvSnaifocwwtEyvDkN3AfUBddcu9g0UhyiCb2MlFyJ Dbr15votsPUsFggZi3EkWTlHrw/XeattdADm3IkHus1KJdLlVEWX697Kep4sbb/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 | 15 ++++++--------- include/scsi/scsi_device.h | 1 - 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 7db3c5fae469..6c18a61176e5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3052,11 +3052,12 @@ 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 here to check the device state without + * holding the SCSI device state mutex. */ - WARN_ON_ONCE(sdev->quiesced_by && sdev->quiesced_by != current); + if (sdev->sdev_state == SDEV_QUIESCE) + return 0; blk_set_preempt_only(q); @@ -3072,9 +3073,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_preempt_only(q); mutex_unlock(&sdev->state_mutex); @@ -3098,8 +3097,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_preempt_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))));