From patchwork Wed Mar 1 18:42:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9599125 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 16F2C60429 for ; Wed, 1 Mar 2017 21:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 076E9201BD for ; Wed, 1 Mar 2017 21:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F00E928564; Wed, 1 Mar 2017 21:35:11 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 729FA201BD for ; Wed, 1 Mar 2017 21:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753344AbdCAVet (ORCPT ); Wed, 1 Mar 2017 16:34:49 -0500 Received: from mail-pg0-f43.google.com ([74.125.83.43]:35647 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753299AbdCAVeq (ORCPT ); Wed, 1 Mar 2017 16:34:46 -0500 Received: by mail-pg0-f43.google.com with SMTP id b129so24286805pgc.2 for ; Wed, 01 Mar 2017 13:34:32 -0800 (PST) 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; bh=U3IKrbA8h/QEbfYboaDj6lMBKhQN7QDv8C1Hiy96V3k=; b=T/M6oabFinREH276mIc8xNeTunZthANkQ9N4kcnain+x17mRvAsC/floPa+lGSOp2I jtAzlxQBYxTkTfr8PXXPVRcslAo1WC0XeUPI9xMSfjZJS3A2MoG3kzQEBqvEK0xPwJIO ZCrL49v/78hORkRMOtXcaXpJQbxFE8Pl24Y+QxpbVqhKaL50H/eiN07fKPiG+2hiQa9o wBoFRXnCtYvBMUhglavhq4fTg2Bo3K2k6MeN/zuwgiMF/QCbXN9z3KTqhbY+MMikTYJs 6FXNcnmH7+aHs90ZpAdATMjfbDn3VBRQHqz+tCE5bvtw+t5Prt81BSnxJohJEAF9q3C5 HH+Q== 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; bh=U3IKrbA8h/QEbfYboaDj6lMBKhQN7QDv8C1Hiy96V3k=; b=oLDt3Z6j3Qi65Sq4wpLWuDJHB468ROYxyMtYfjappmBi400FbUNpWxarY++ruJ777r 5coiJUMTdl0hE4kFMQpwis8UEbeU3FwUD5RW0ejfiN9iRLmo7Fxh5GUHrCZ1fK0u8Rm/ NB6fCn93wROx3mUNRcT0ut88QvDcXbInmUpoINrwPMlFQ2IG+GaJCEgy1zoH05O1hifs x8tbBMnvDW36hjiH1tD5GyNvPMqOAlKNbUgGLcudBVnvbzJaQfHIa+vFErmFxzDD/6wD EO2iphWkYy+BriSWWCDbY7b72PRzfQFTemZ4Up6dwwxzHlolg0vXnMmQP/I1vAi8mwmg vwnQ== X-Gm-Message-State: AMke39nKLfZTUNloGSyKWulkSzg2fXfQCcxGg+//2Hifj/twsh0w7VUIiT/fnvZc9uQWUeE9 X-Received: by 10.99.135.73 with SMTP id i70mr10145776pge.157.1488393815259; Wed, 01 Mar 2017 10:43:35 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::e:9abf]) by smtp.gmail.com with ESMTPSA id y6sm12128242pgc.1.2017.03.01.10.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Mar 2017 10:43:34 -0800 (PST) From: Omar Sandoval To: Jens Axboe , linux-block@vger.kernel.org Cc: kernel-team@fb.com, Ming Lei , stable@vger.kernel.org Subject: [PATCH 1/2] loop: fix LO_FLAGS_PARTSCAN hang Date: Wed, 1 Mar 2017 10:42:38 -0800 Message-Id: <7e888cad9e6c35835559281d3ab9e05ea48836d0.1488393750.git.osandov@fb.com> X-Mailer: git-send-email 2.12.0 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 loop_reread_partitions() needs to do I/O, but we just froze the queue, so we end up waiting forever. This can easily be reproduced with losetup -P. Fix it by moving the reread to after we unfreeze the queue. Fixes: ecdd09597a57 ("block/loop: fix race between I/O and set_status") Reported-by: Tejun Heo Cc: Ming Lei Cc: stable@vger.kernel.org Signed-off-by: Omar Sandoval Reviewed-by: Ming Lei --- drivers/block/loop.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 4b52a1690329..132c9f371dce 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1142,13 +1142,6 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) (info->lo_flags & LO_FLAGS_AUTOCLEAR)) lo->lo_flags ^= LO_FLAGS_AUTOCLEAR; - if ((info->lo_flags & LO_FLAGS_PARTSCAN) && - !(lo->lo_flags & LO_FLAGS_PARTSCAN)) { - lo->lo_flags |= LO_FLAGS_PARTSCAN; - lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; - loop_reread_partitions(lo, lo->lo_device); - } - lo->lo_encrypt_key_size = info->lo_encrypt_key_size; lo->lo_init[0] = info->lo_init[0]; lo->lo_init[1] = info->lo_init[1]; @@ -1163,6 +1156,14 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) exit: blk_mq_unfreeze_queue(lo->lo_queue); + + if (!err && (info->lo_flags & LO_FLAGS_PARTSCAN) && + !(lo->lo_flags & LO_FLAGS_PARTSCAN)) { + lo->lo_flags |= LO_FLAGS_PARTSCAN; + lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; + loop_reread_partitions(lo, lo->lo_device); + } + return err; }