From patchwork Tue Mar 27 04:39:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10309187 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 C1BA260325 for ; Tue, 27 Mar 2018 04:40:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3C8429AAD for ; Tue, 27 Mar 2018 04:40:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8D2A29AB2; Tue, 27 Mar 2018 04:40:28 +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 4FB3329AAD for ; Tue, 27 Mar 2018 04:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751292AbeC0Ek1 (ORCPT ); Tue, 27 Mar 2018 00:40:27 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:36298 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751219AbeC0EkX (ORCPT ); Tue, 27 Mar 2018 00:40:23 -0400 Received: by mail-pl0-f65.google.com with SMTP id 91-v6so5594497pld.3 for ; Mon, 26 Mar 2018 21:40:23 -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=Ju4c4v0ZbpE16pXvMX3omkfLP592cwMcMvE2Hh112xo=; b=SyzrM3p6kk/R9DicYAwPtBBA7yyZ6mBKvUVsoa4gFYrcyrQmHQ7990+aWpztvGAPE7 l1MNm6WSik5F9ZuNuOqyBr7R4ehGhpmj9T9kULl9kuywoeEZ14QnuBqk8pOf3HMgphJO 98EwN2PXAz7udekpsAhUm+qBSjvvfKtZRLg+yYc8Vq3DU24zbZlrz9GPWHyHjbPKhOAy jzOpJ6MRVLLAwO8vYxT0TNCM20/t4iVUNQDWvSmcNTUWgZn2DDh3J2P+6NlRn4Le4q6R FeXoSS1PqRJ4vPNzUOXwIFbV6d7gTQAS4Ga3F/V5pp36WHmB5ewB//YgQY5heWybn0UA 12TQ== 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=Ju4c4v0ZbpE16pXvMX3omkfLP592cwMcMvE2Hh112xo=; b=UGooNjpGyYwgK6ZBKTb4pOFKz5hLbr8b2ZKR8gRKTKX6DBpG4cRTtDDM7LqkYgsGLU 7zsQfgs+NyqW/SahLfuCcMdUzwIf4K0Qq4zTS8JpeHkvJlHXkqIBfKODnMHGottFgsr4 x/bDFg1WsrxGOeLedkIaHhQsNzjKBzR1AVkkFNAQRrZJNfhz6JBM8PIS6LFFzJ8QuZfJ 1bkF+CaSvZYLAbl84W7pJpuPXrfUSM9+hCs4Eg8IY/QLaSXJTkSiaflpHOJj+39WgW6c D70Sn5DOQj5LFx2iWu1TETPrhR3jcyiFNndXL+eCRhpgsl75xkhwpY+VKB8Z38nqtZvE 28cA== X-Gm-Message-State: AElRT7FhvTL0igO4NZDnOtPx3m82Qf1rTATQp2plRYMdcMFivUhESQKr fatcdOgc5UU/5ZSIf5JREwPT6W2PfHw= X-Google-Smtp-Source: AIpwx4/SWvNgHlKu2wZluLzQuT1KhAcrXDIaU5U0nJjnt2gb1QZum6XEpD3L/NKLw2kJ0NjU8efVvg== X-Received: by 2002:a17:902:3001:: with SMTP id u1-v6mr68565plb.164.1522125623116; Mon, 26 Mar 2018 21:40:23 -0700 (PDT) Received: from localhost.localdomain ([2601:602:8801:8110:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id e21sm587892pfi.68.2018.03.26.21.40.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 21:40:22 -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 v2 2/2] loop: use killable lock in ioctls Date: Mon, 26 Mar 2018 21:39:12 -0700 Message-Id: <5637ab0b470930bd180ed7e2436b0f487f27cb9f.1522125370.git.osandov@fb.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@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..264abaaff662 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_killable_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_killable(&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_killable(&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_killable(&lo->lo_ctl_mutex); + if (ret) + break; if (lo->lo_state != Lo_unbound) { ret = -EBUSY; mutex_unlock(&lo->lo_ctl_mutex);