Skip to contentSkip to conversation

dm-table: check BLK_FEAT_ATOMIC_WRITES inside limits_lock

PATCH In review Benjamin Marzinski 2 participants 5 messages May 30, 2025 – Jun 3, 2025 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 dm-table: check BLK_FEAT_ATOMIC_WRITES inside limits_lock

dm_set_device_limits() should check q->limits.features for BLK_FEAT_ATOMIC_WRITES while holding q->limits_lock, like it does for the rest of the queue limits.

Fixes b7c18b17a173 ("dm-table: Set BLK_FEAT_ATOMIC_WRITES for target queue limits")
---
 drivers/md/dm-table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-table.c +1 -1
index 57573e8b5aa9..9f95f77687ef 100644
@@ -430,13 +430,13 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
 		return 0;
 	}
 
+	mutex_lock(&q->limits_lock);
 	/*
 	 * BLK_FEAT_ATOMIC_WRITES is not inherited from the bottom device in
 	 * blk_stack_limits(), so do it manually.
 	 */
 	limits->features |= (q->limits.features & BLK_FEAT_ATOMIC_WRITES);
 
-	mutex_lock(&q->limits_lock);
 	if (blk_stack_limits(limits, &q->limits,
 			get_start_sect(bdev) + start) < 0)
 		DMWARN("%s: adding target device %pg caused an alignment inconsistency: "
Signature · 1 line
2.48.1
#1 lore raw

On 30/05/2025 15:50, Benjamin Marzinski wrote:

+

Quoted 6 lines

dm_set_device_limits() should check q->limits.features for BLK_FEAT_ATOMIC_WRITES while holding q->limits_lock, like it does for the rest of the queue limits.

Fixes b7c18b17a173 ("dm-table: Set BLK_FEAT_ATOMIC_WRITES for target queue limits")

In itself, the change seems fine, but I have doubts whether it's preferred to even grab the q->limits_lock outside block layer / its helpers.

And, apart from this, if the bottom device limits change later, do we actually trigger a top device limits evaluation update?

Quoted 23 lines
---
  drivers/md/dm-table.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-table.c +1 -1
index 57573e8b5aa9..9f95f77687ef 100644
@@ -430,13 +430,13 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
  		return 0;
  	}
 
+	mutex_lock(&q->limits_lock);
  	/*
  	 * BLK_FEAT_ATOMIC_WRITES is not inherited from the bottom device in
  	 * blk_stack_limits(), so do it manually.
  	 */
  	limits->features |= (q->limits.features & BLK_FEAT_ATOMIC_WRITES);
 
-	mutex_lock(&q->limits_lock);
  	if (blk_stack_limits(limits, &q->limits,
  			get_start_sect(bdev) + start) < 0)
  		DMWARN("%s: adding target device %pg caused an alignment inconsistency: "
author maintainer
#2 lore raw
Quoted 8 lines · John Garry

On 30/05/2025 15:50, Benjamin Marzinski wrote:

+

Quoted 4 lines

dm_set_device_limits() should check q->limits.features for BLK_FEAT_ATOMIC_WRITES while holding q->limits_lock, like it does for the rest of the queue limits.

Quoted 5 lines
Quoted 2 lines
Fixes b7c18b17a173 ("dm-table: Set BLK_FEAT_ATOMIC_WRITES for target queue limits")

In itself, the change seems fine, but I have doubts whether it's preferred to even grab the q->limits_lock outside block layer / its helpers.

I'm pretty sure Mikulas added the q->limits_lock around DM's queue limits accesses as the result of a discussion with some block layer developers.

Quoted 3 lines

And, apart from this, if the bottom device limits change later, do we actually trigger a top device limits evaluation update?

DM will obviously re-evaluate the limits if you reload the table. In some cases, DM will also disable features if turns out that they aren't supported when it actually tries to use them. Dumb question: Is there much chance of a SCSI device's atomic write support changing while it's in-use?

-Ben

Quoted 21 lines
Quoted 21 lines
---
  drivers/md/dm-table.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-table.c +1 -1
index 57573e8b5aa9..9f95f77687ef 100644
@@ -430,13 +430,13 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
  		return 0;
  	}
+	mutex_lock(&q->limits_lock);
  	/*
  	 * BLK_FEAT_ATOMIC_WRITES is not inherited from the bottom device in
  	 * blk_stack_limits(), so do it manually.
  	 */
  	limits->features |= (q->limits.features & BLK_FEAT_ATOMIC_WRITES);
-	mutex_lock(&q->limits_lock);
  	if (blk_stack_limits(limits, &q->limits,
  			get_start_sect(bdev) + start) < 0)
  		DMWARN("%s: adding target device %pg caused an alignment inconsistency: "
#3 lore raw
Quoted 12 lines · Benjamin Marzinski
Quoted 11 lines · John Garry

On 30/05/2025 15:50, Benjamin Marzinski wrote:

+

Quoted 6 lines

dm_set_device_limits() should check q->limits.features for BLK_FEAT_ATOMIC_WRITES while holding q->limits_lock, like it does for the rest of the queue limits.

Fixes b7c18b17a173 ("dm-table: Set BLK_FEAT_ATOMIC_WRITES for target queue limits")
Quoted 6 lines
Quoted 2 lines

In itself, the change seems fine, but I have doubts whether it's preferred to even grab the q->limits_lock outside block layer / its helpers.

I'm pretty sure Mikulas added the q->limits_lock around DM's queue limits accesses as the result of a discussion with some block layer developers.

Do you have a pointer for that?

Quoted 10 lines
Quoted 4 lines

And, apart from this, if the bottom device limits change later, do we actually trigger a top device limits evaluation update?

DM will obviously re-evaluate the limits if you reload the table. In some cases, DM will also disable features if turns out that they aren't supported when it actually tries to use them. Dumb question: Is there much chance of a SCSI device's atomic write support changing while it's in-use?

No, I would not think so.

thanks,
John

author maintainer
#4 lore raw
Quoted 13 lines · John Garry
Quoted 12 lines · Benjamin Marzinski
Quoted 11 lines · John Garry

On 30/05/2025 15:50, Benjamin Marzinski wrote:

+

Quoted 6 lines

dm_set_device_limits() should check q->limits.features for BLK_FEAT_ATOMIC_WRITES while holding q->limits_lock, like it does for the rest of the queue limits.

Fixes b7c18b17a173 ("dm-table: Set BLK_FEAT_ATOMIC_WRITES for target queue limits")
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

In itself, the change seems fine, but I have doubts whether it's preferred to even grab the q->limits_lock outside block layer / its helpers.

I'm pretty sure Mikulas added the q->limits_lock around DM's queue limits accesses as the result of a discussion with some block layer developers.

Do you have a pointer for that?

https://lore.kernel.org/dm-devel/[email protected]/

Specifically, in that thread Ming Lei suggests it here:
https://lore.kernel.org/dm-devel/Z9t709DZs-Flq1qS@fedora/
and Jens agrees.

-Ben

Quoted 16 lines
Quoted 11 lines
Quoted 5 lines

And, apart from this, if the bottom device limits change later, do we actually trigger a top device limits evaluation update?

DM will obviously re-evaluate the limits if you reload the table. In some cases, DM will also disable features if turns out that they aren't supported when it actually tries to use them. Dumb question: Is there much chance of a SCSI device's atomic write support changing while it's in-use?

No, I would not think so.

thanks,
John