From patchwork Mon Mar 26 23:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10308961 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 EFB5360212 for ; Mon, 26 Mar 2018 23:16:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E70E729878 for ; Mon, 26 Mar 2018 23:16:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB1EA298F8; Mon, 26 Mar 2018 23:16:42 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 6F09529878 for ; Mon, 26 Mar 2018 23:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752525AbeCZXQk (ORCPT ); Mon, 26 Mar 2018 19:16:40 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:37844 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752484AbeCZXQh (ORCPT ); Mon, 26 Mar 2018 19:16:37 -0400 Received: by mail-pg0-f65.google.com with SMTP id n11so7863326pgp.4 for ; Mon, 26 Mar 2018 16:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FTyQJf+kZ01M57/jqfmgfkGr+Mi2t+/ZWiSxD5xQIPg=; b=cpGCeVAqmfjhdqQBMKCxPanslXYpUbvpe9UzZ8bnxVxUCDv2MHUVmI7w9zg1HYJyek aVJnX+ARk1q+ML4h3eI8jKasIa5AgnhnZYqPdrB/4uv23Zm+VjTc8uOVw6DjAmp9gAa2 ss4A2xYKmBo60hH47zNP2BVnuGxf0w8Fyq6l6s88BY4HKomJPghVvHDw0BKAk5GvQnFN zyANo5khbjc8Q+fctvKAkcpPgEjGD54fNZwvX+N/qqzZEk9Y3tAUlvUNPawBquFC/0hk PW7b/Jc4hhtzsXA3AffIeonZYAAcoPZ40FCc9B2wcFX7ewsddNNuKIoFmgJqPW9Hyf0V z/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FTyQJf+kZ01M57/jqfmgfkGr+Mi2t+/ZWiSxD5xQIPg=; b=doiac0WKw+eoh8IR5BQpYjnGSrLwYCae20cwqOhGuQBxJ4ZQv4Qgq6RWB5j/3QcIWR xiT7PICVF2hKA6dsC41o9vJdAOCTPn30NbfVX5t1qqEEVAbs7ZVplMVtuhZuuf8ENWyE eqXfNnKKOsUmQaEi7rHuS2Q1OO4jUmMjveovnVFfDGWv7IxP3NHIiJgW28tuSBF2V7Gp hYQSLctmVqb8qJar2NTB2y3QnBBtS1RBI5ilLCMlBk7dEi2d7P1B5hPI6rtvYJco6a4r awb1+nHePPeoNhDMScPZBv6YbzOs2pH11TuUfY/HjZndax2dndEapVl8t+PgwS5DtQoV N69Q== X-Gm-Message-State: AElRT7HBhEsnbsWGdnxkHBRKEiQIhfz+FvSv6KdC7Nt2RDEU7pLzYZVC 2LGc7p9V7rK+ZAywqU1aOPdm3Q6Oi7Q= X-Google-Smtp-Source: AIpwx484Ie3l8t5Uxfx50iKJOE6L6RNr0QyHabqrkgzqGNvkM97ftMAphkgIsewlprzYtiSqB9SKYw== X-Received: by 10.167.128.204 with SMTP id a12mr2955816pfn.177.1522106196690; Mon, 26 Mar 2018 16:16:36 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:324b]) by smtp.gmail.com with ESMTPSA id y18sm30701567pfe.67.2018.03.26.16.16.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 16:16:35 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/2] loop: use interruptible lock in ioctls Date: Mon, 26 Mar 2018 16:16:26 -0700 Message-Id: <7ec1489d2ca54e886713efe5beb6dd379c2279b6.1522106130.git.osandov@fb.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Even after the previous patch to drop lo_ctl_mutex while calling vfs_getattr(), there are other cases where we can end up sleeping for a long time while holding lo_ctl_mutex. Let's avoid the uninterruptible sleep from the ioctls. Signed-off-by: Omar Sandoval --- drivers/block/loop.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 93a60bda7608..28673cfdd3a3 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1360,7 +1360,10 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, struct loop_device *lo = bdev->bd_disk->private_data; int err; - mutex_lock_nested(&lo->lo_ctl_mutex, 1); + err = mutex_lock_interruptible_nested(&lo->lo_ctl_mutex, 1); + if (err) + goto out_unlocked; + switch (cmd) { case LOOP_SET_FD: err = loop_set_fd(lo, mode, bdev, arg); @@ -1545,16 +1548,20 @@ static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode, switch(cmd) { case LOOP_SET_STATUS: - mutex_lock(&lo->lo_ctl_mutex); - err = loop_set_status_compat( - lo, (const struct compat_loop_info __user *) arg); - mutex_unlock(&lo->lo_ctl_mutex); + err = mutex_lock_interruptible(&lo->lo_ctl_mutex); + if (!err) { + err = loop_set_status_compat(lo, + (const struct compat_loop_info __user *)arg); + mutex_unlock(&lo->lo_ctl_mutex); + } break; case LOOP_GET_STATUS: - mutex_lock(&lo->lo_ctl_mutex); - err = loop_get_status_compat( - lo, (struct compat_loop_info __user *) arg); - /* loop_get_status() unlocks lo_ctl_mutex */ + err = mutex_lock_interruptible(&lo->lo_ctl_mutex); + if (!err) { + err = loop_get_status_compat(lo, + (struct compat_loop_info __user *)arg); + /* loop_get_status() unlocks lo_ctl_mutex */ + } break; case LOOP_SET_CAPACITY: case LOOP_CLR_FD: @@ -1959,7 +1966,9 @@ static long loop_control_ioctl(struct file *file, unsigned int cmd, ret = loop_lookup(&lo, parm); if (ret < 0) break; - mutex_lock(&lo->lo_ctl_mutex); + ret = mutex_lock_interruptible(&lo->lo_ctl_mutex); + if (ret) + break; if (lo->lo_state != Lo_unbound) { ret = -EBUSY; mutex_unlock(&lo->lo_ctl_mutex);