From patchwork Thu Jan 9 05:57:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13932075 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D11012147EA; Thu, 9 Jan 2025 06:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736402410; cv=none; b=kYgX1xhektA01snChSDMISdgihIxofRtpvr72UIaaJuMR+j8DA8nWqxO4iDNgdqLxhjBINN6K+o4RvseFNSmRyLXQTUqBywgpqxZyD8haLorOIs/O3jMz/TkbdC1mtYmMSI3TV0tHzvCUMyGlBzPABMOVj2l4GwTc/exSPHyW5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736402410; c=relaxed/simple; bh=fi/s+cBhAmLuIop2UBpkN71LlHYlHzy90jizfqIlh9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uModkgR5Fr0e1MrbMZbxWEu3QtXn4ZQNPcdXwfO9fkoUL78+pkIJF3Mt3YnDPPpWGbtcYw9kBqoLLCo0on0XrscOCM1P9BqCYKXDNCzZRrdKCXUExXUWuwn5xRXrZfCvDbJYdsUmKPaX4dIz0fTTZ//Sc2SlAZ//AmO2ChEpTN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=v00tT2VE; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="v00tT2VE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=QYjYnvJCCu85L8ZQwU17Zz1hszoqzw6yMycLiSn8ENM=; b=v00tT2VE3Ao8aSvkQWXTOcIoow HDTjHMjmYrEXJmVZ4aGOZth6886xv3R/Vul+yXz5491biKjSfGLrtl+7PSjTPHp3DuNi7uGA2VMP9 qCLucNeKmfFms6u4KUdCsIN8wo1y2mkesnpuwU36rd90y/KJqXQ+5+0I2cwAMj0eNg5LmxzstITSN S9VVEh+zQjmYHJ9DPcG2qlgEHcNf0wS6HwOCTZxdHe+AqjOv6Tj32UnMwbkPkOvhYHEOmFdTLMVLP 6mLp+ml8IDooGTWPDbreGDPA3amwpF0/pUnxUjV4Q11JEFV3Kvt1UqOr8FY3z+7YRQPJjlpcXcL7B 3BY3ndcg==; Received: from 2a02-8389-2341-5b80-ddeb-cdec-70b9-e2f0.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:ddeb:cdec:70b9:e2f0] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tVlZF-0000000ArfV-2ZaU; Thu, 09 Jan 2025 05:59:22 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Damien Le Moal , Ming Lei , Nilay Shroff , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, nbd@other.debian.org, linux-scsi@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, Johannes Thumshirn Subject: [PATCH 11/11] loop: fix queue freeze vs limits lock order Date: Thu, 9 Jan 2025 06:57:32 +0100 Message-ID: <20250109055810.1402918-12-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250109055810.1402918-1-hch@lst.de> References: <20250109055810.1402918-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Match the locking order used by the core block code by only freezing the queue after taking the limits lock using the queue_limits_commit_update_frozen helper and document the callers that do not freeze the queue at all. Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Reviewed-by: Damien Le Moal Reviewed-by: Nilay Shroff Reviewed-by: Johannes Thumshirn --- drivers/block/loop.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 560d6d5879d6..15e486baa223 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -311,6 +311,13 @@ static void loop_clear_limits(struct loop_device *lo, int mode) lim.discard_granularity = 0; } + /* + * XXX: this updates the queue limits without freezing the queue, which + * is against the locking protocol and dangerous. But we can't just + * freeze the queue as we're inside the ->queue_rq method here. So this + * should move out into a workqueue unless we get the file operations to + * advertise if they support specific fallocate operations. + */ queue_limits_commit_update(lo->lo_queue, &lim); } @@ -1091,6 +1098,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, lim = queue_limits_start_update(lo->lo_queue); loop_update_limits(lo, &lim, config->block_size); + /* No need to freeze the queue as the device isn't bound yet. */ error = queue_limits_commit_update(lo->lo_queue, &lim); if (error) goto out_unlock; @@ -1151,7 +1159,12 @@ static void __loop_clr_fd(struct loop_device *lo) lo->lo_sizelimit = 0; memset(lo->lo_file_name, 0, LO_NAME_SIZE); - /* reset the block size to the default */ + /* + * Reset the block size to the default. + * + * No queue freezing needed because this is called from the final + * ->release call only, so there can't be any outstanding I/O. + */ lim = queue_limits_start_update(lo->lo_queue); lim.logical_block_size = SECTOR_SIZE; lim.physical_block_size = SECTOR_SIZE; @@ -1471,9 +1484,10 @@ static int loop_set_block_size(struct loop_device *lo, unsigned long arg) sync_blockdev(lo->lo_device); invalidate_bdev(lo->lo_device); - blk_mq_freeze_queue(lo->lo_queue); lim = queue_limits_start_update(lo->lo_queue); loop_update_limits(lo, &lim, arg); + + blk_mq_freeze_queue(lo->lo_queue); err = queue_limits_commit_update(lo->lo_queue, &lim); loop_update_dio(lo); blk_mq_unfreeze_queue(lo->lo_queue);