Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4807091ooa; Tue, 14 Aug 2018 10:49:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwJpPu14eRNUZo4X4dtr4vZvKOQ3NwheqlHb0C6PyZnaiHB2Q88OsJ/QafOhHO0bn4FPMdy X-Received: by 2002:a63:d309:: with SMTP id b9-v6mr21992430pgg.163.1534268961442; Tue, 14 Aug 2018 10:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268961; cv=none; d=google.com; s=arc-20160816; b=N1JP7YIBoBHs6uYWq4E/fMPzuTPyFG5l5L1sLG/YAQIWlbmFPbTlazTAq9MrpLvjsk EhNi3s12Nw8e3jVmsUqDrP8d0Zy2yT7YxsWLxOrsni6ojHMfk1edlfihwr5lcrxT8/XF yObkvXGrtQGVwg5Y0A1fXntJXPFNgkZfAr3Ba/VXPZ7pqgnGEyMOFSmCcRGjiHntvtcu wzppUiriW1M9wg28mP+I0hpY7P2XWb3NWw5zNxqvdrMlOFFeN4q3euEofpvG2v9oA/I5 my7MpJboIozg2saYUqn7ufDppgol80/WfthcHixW2hS3OYbnkM3hmXyE8r0u4zF6Tgm8 0avA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=sX9WJncRDBgcQv3LN7WuE0dC5N2P0SNfNf5IOpQqwYo=; b=lUtRzODfkSuuEd5vetZT/5yPFfnWUoEe1/52DU4DTs2czF0Y3csfi/KR3K1LRE7HZb KX40J+kGKDm0gUhG8y+gQ8QzMLFCLs/RvpZcxa7I+vT6jd6vpHaBDO3lnp7HVUTuSU9i 91tIhHtXQqeHa4zU9u9gU+DCN/+9nug1Or5tXZTUVGOoHvKBkgkZmbC7+HTSOZMkGnNK RAmtwkm2FtGYKgxZM8yp56TQbYoC/2qdh8KTo+o3gKk4eS1d8n7KV5GFBwjEdtYCGcDD b6nLtKs/FUe2BGHmyZolR0HOsxavsqwmOkpfaB0NgcavKmUNY2baqoJVPes2RfnbqrZ5 JFFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si983338plb.197.2018.08.14.10.49.06; Tue, 14 Aug 2018 10:49:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391225AbeHNUgD (ORCPT + 99 others); Tue, 14 Aug 2018 16:36:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:32856 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390875AbeHNUgC (ORCPT ); Tue, 14 Aug 2018 16:36:02 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BDC2CC74; Tue, 14 Aug 2018 17:47:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Maurizio Lombardi , Johannes Thumshirn , Alan Stern , "Martin K. Petersen" Subject: [PATCH 4.4 09/43] scsi: sr: Avoid that opening a CD-ROM hangs with runtime power management enabled Date: Tue, 14 Aug 2018 19:17:45 +0200 Message-Id: <20180814171517.705499658@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171517.014285600@linuxfoundation.org> References: <20180814171517.014285600@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 1214fd7b497400d200e3f4e64e2338b303a20949 upstream. Surround scsi_execute() calls with scsi_autopm_get_device() and scsi_autopm_put_device(). Note: removing sr_mutex protection from the scsi_cd_get() and scsi_cd_put() calls is safe because the purpose of sr_mutex is to serialize cdrom_*() calls. This patch avoids that complaints similar to the following appear in the kernel log if runtime power management is enabled: INFO: task systemd-udevd:650 blocked for more than 120 seconds. Not tainted 4.18.0-rc7-dbg+ #1 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. systemd-udevd D28176 650 513 0x00000104 Call Trace: __schedule+0x444/0xfe0 schedule+0x4e/0xe0 schedule_preempt_disabled+0x18/0x30 __mutex_lock+0x41c/0xc70 mutex_lock_nested+0x1b/0x20 __blkdev_get+0x106/0x970 blkdev_get+0x22c/0x5a0 blkdev_open+0xe9/0x100 do_dentry_open.isra.19+0x33e/0x570 vfs_open+0x7c/0xd0 path_openat+0x6e3/0x1120 do_filp_open+0x11c/0x1c0 do_sys_open+0x208/0x2d0 __x64_sys_openat+0x59/0x70 do_syscall_64+0x77/0x230 entry_SYSCALL_64_after_hwframe+0x49/0xbe Signed-off-by: Bart Van Assche Cc: Maurizio Lombardi Cc: Johannes Thumshirn Cc: Alan Stern Cc: Tested-by: Johannes Thumshirn Reviewed-by: Johannes Thumshirn Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sr.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -520,18 +520,26 @@ static int sr_init_command(struct scsi_c static int sr_block_open(struct block_device *bdev, fmode_t mode) { struct scsi_cd *cd; + struct scsi_device *sdev; int ret = -ENXIO; + cd = scsi_cd_get(bdev->bd_disk); + if (!cd) + goto out; + + sdev = cd->device; + scsi_autopm_get_device(sdev); check_disk_change(bdev); mutex_lock(&sr_mutex); - cd = scsi_cd_get(bdev->bd_disk); - if (cd) { - ret = cdrom_open(&cd->cdi, bdev, mode); - if (ret) - scsi_cd_put(cd); - } + ret = cdrom_open(&cd->cdi, bdev, mode); mutex_unlock(&sr_mutex); + + scsi_autopm_put_device(sdev); + if (ret) + scsi_cd_put(cd); + +out: return ret; } @@ -559,6 +567,8 @@ static int sr_block_ioctl(struct block_d if (ret) goto out; + scsi_autopm_get_device(sdev); + /* * Send SCSI addressing ioctls directly to mid level, send other * ioctls to cdrom/block level. @@ -567,15 +577,18 @@ static int sr_block_ioctl(struct block_d case SCSI_IOCTL_GET_IDLUN: case SCSI_IOCTL_GET_BUS_NUMBER: ret = scsi_ioctl(sdev, cmd, argp); - goto out; + goto put; } ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg); if (ret != -ENOSYS) - goto out; + goto put; ret = scsi_ioctl(sdev, cmd, argp); +put: + scsi_autopm_put_device(sdev); + out: mutex_unlock(&sr_mutex); return ret;