Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3331487imu; Sun, 11 Nov 2018 12:32:42 -0800 (PST) X-Google-Smtp-Source: AJdET5e8nJdTctrEbmukZ8E3LoAxyfbL2uGXT11J/rapbWQF4T1UqXurypkiMJgl11+Lnfx/mGcV X-Received: by 2002:a63:d40a:: with SMTP id a10mr14791483pgh.394.1541968362387; Sun, 11 Nov 2018 12:32:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968362; cv=none; d=google.com; s=arc-20160816; b=xkwQnFM5/C0OYRFhRiRNlhZWHZeaxtLw7tjVFxm+FprQcKG3MlHxlewffBIUkIEnq3 SbN0RZVWPnXeJ9ls41tryecsR5Sx/6h14yAebl87uLFzqE4bPP3DrC/J4aB8GBkPyeCm Vr+oEr+9My6AbsSJ1/FCnpnngB0g5MY9TM8uRucuTXNLsw/lRvFKyDFR8GCpCuFuCC7H bF4qegmlPk5SV+lsoFYHOvCwWdi3yeYcaHfFCmK119gPkIUs5pnsoay2HUcCUkLjX4ov fMldgtv+qq7KGYWgGEyPG0ZAJv73jHIB6mrYlJyYGbdpbKyxY+kig3ziSVjzse92zFBO 67Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=wUXocBZVuB6DHKNXFInKb8wBVfrI3qqyJMIgETMhDsA=; b=v6BD2ZtoDtGVcu7Zp37hQLstQpZ4el6ikvkbk1lCPk+mwxRqGZ4LoJ68bdqAXQxBN8 gxnFG3azjFr8k5FFYFg43y5bepxeWjQSyt8D8CB3Ppy/NKMg00QQyz2zc+bMe4P3Sfxz qmdztk10aeHbvqFcVHD9iLehgx9Ncl6SePjiNibrvWZc7dVJ9m/VRJOMkNWvApvPpFLY rho2fPzd0ookcENxwD1BJsFbmtyAQHlE/8vh13z74kYeLbOBRlBzDhrk0maVLk/xu2EB ie1KZmC1YpssdcOppnO3aPcRKtL4lMGBErf0jzNFz7wknRtLmbqYB0aq+kL097Ff3Zj2 glaw== 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 y24-v6si15678382pfm.141.2018.11.11.12.32.27; Sun, 11 Nov 2018 12:32:42 -0800 (PST) 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 S1730374AbeKLFsS (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:18 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50182 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730285AbeKLFsQ (ORCPT ); Mon, 12 Nov 2018 00:48:16 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsc-0000oJ-EK; Sun, 11 Nov 2018 19:58:46 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsY-0001or-Ux; Sun, 11 Nov 2018 19:58:42 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Alan Stern" , "Bart Van Assche" , "Johannes Thumshirn" , "Martin K. Petersen" , "Maurizio Lombardi" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 308/366] scsi: sr: Avoid that opening a CD-ROM hangs with runtime power management enabled In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 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 Tested-by: Johannes Thumshirn Reviewed-by: Johannes Thumshirn Signed-off-by: Martin K. Petersen [bwh: Backported to 3.16: - Update one extra "goto out" in sr_block_ioctl() and delete the unused label - Adjust context] Signed-off-by: Ben Hutchings --- --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -521,16 +521,25 @@ 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; - 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); - } + if (!cd) + goto out; + + sdev = cd->device; + scsi_autopm_get_device(sdev); + + mutex_lock(&sr_mutex); + 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; } @@ -553,6 +562,8 @@ static int sr_block_ioctl(struct block_d mutex_lock(&sr_mutex); + scsi_autopm_get_device(sdev); + /* * Send SCSI addressing ioctls directly to mid level, send other * ioctls to cdrom/block level. @@ -561,12 +572,12 @@ 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; /* * ENODEV means that we didn't recognise the ioctl, or that we @@ -577,10 +588,12 @@ static int sr_block_ioctl(struct block_d ret = scsi_nonblockable_ioctl(sdev, cmd, argp, (mode & FMODE_NDELAY) != 0); if (ret != -ENODEV) - goto out; + goto put; ret = scsi_ioctl(sdev, cmd, argp); -out: +put: + scsi_autopm_put_device(sdev); + mutex_unlock(&sr_mutex); return ret; }