summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Hagberg <ehagberg@janestreet.com>2025-09-22 13:17:04 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-09-25 11:00:10 +0200
commit42a6aeb4b23890a4d2323b51841690be7ea49f8d (patch)
tree6bf3c066dbad685a05e5588120f6d7c2dc3f0f4a
parent06146c26f5cfbb4cb0d14c78dc44c7e122c82b80 (diff)
Revert "loop: Avoid updating block size under exclusive owner"
Revert commit ce8da5d13d8c2a7b30b2fb376a22e8eb1a70b8bb which is commit 7e49538288e523427beedd26993d446afef1a6fb upstream. This reverts commit ce8da5d13d8c ("loop: Avoid updating block size under exclusive owner") for the 6.6 kernel, because if the LTP ioctl_loop06 test is run with this patch in place, the test will fail, it leaves the host unable to kexec into the kernel again (hangs forever) and "losetup -a" will hang on attempting to access the /dev/loopN device that the test has set up. The patch doesn't need to be reverted from 6.12, as it works fine there. Cc: stable@vger.kernel.org # 6.6.x Signed-off-by: Eric Hagberg <ehagberg@janestreet.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/block/loop.c38
1 files changed, 8 insertions, 30 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ed004e1610dd..455e2a2b149f 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1472,36 +1472,19 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg)
return error;
}
-static int loop_set_block_size(struct loop_device *lo, blk_mode_t mode,
- struct block_device *bdev, unsigned long arg)
+static int loop_set_block_size(struct loop_device *lo, unsigned long arg)
{
int err = 0;
- /*
- * If we don't hold exclusive handle for the device, upgrade to it
- * here to avoid changing device under exclusive owner.
- */
- if (!(mode & BLK_OPEN_EXCL)) {
- err = bd_prepare_to_claim(bdev, loop_set_block_size, NULL);
- if (err)
- return err;
- }
-
- err = mutex_lock_killable(&lo->lo_mutex);
- if (err)
- goto abort_claim;
-
- if (lo->lo_state != Lo_bound) {
- err = -ENXIO;
- goto unlock;
- }
+ if (lo->lo_state != Lo_bound)
+ return -ENXIO;
err = blk_validate_block_size(arg);
if (err)
return err;
if (lo->lo_queue->limits.logical_block_size == arg)
- goto unlock;
+ return 0;
sync_blockdev(lo->lo_device);
invalidate_bdev(lo->lo_device);
@@ -1513,11 +1496,6 @@ static int loop_set_block_size(struct loop_device *lo, blk_mode_t mode,
loop_update_dio(lo);
blk_mq_unfreeze_queue(lo->lo_queue);
-unlock:
- mutex_unlock(&lo->lo_mutex);
-abort_claim:
- if (!(mode & BLK_OPEN_EXCL))
- bd_abort_claiming(bdev, loop_set_block_size);
return err;
}
@@ -1536,6 +1514,9 @@ static int lo_simple_ioctl(struct loop_device *lo, unsigned int cmd,
case LOOP_SET_DIRECT_IO:
err = loop_set_dio(lo, arg);
break;
+ case LOOP_SET_BLOCK_SIZE:
+ err = loop_set_block_size(lo, arg);
+ break;
default:
err = -EINVAL;
}
@@ -1590,12 +1571,9 @@ static int lo_ioctl(struct block_device *bdev, blk_mode_t mode,
break;
case LOOP_GET_STATUS64:
return loop_get_status64(lo, argp);
- case LOOP_SET_BLOCK_SIZE:
- if (!(mode & BLK_OPEN_WRITE) && !capable(CAP_SYS_ADMIN))
- return -EPERM;
- return loop_set_block_size(lo, mode, bdev, arg);
case LOOP_SET_CAPACITY:
case LOOP_SET_DIRECT_IO:
+ case LOOP_SET_BLOCK_SIZE:
if (!(mode & BLK_OPEN_WRITE) && !capable(CAP_SYS_ADMIN))
return -EPERM;
fallthrough;