All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm-table: fix checking for rq stackable devices
@ 2025-06-13 23:08 Benjamin Marzinski
  2025-06-17 23:00 ` Mike Snitzer
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Marzinski @ 2025-06-13 23:08 UTC (permalink / raw)
  To: Mikulas Patocka, Mike Snitzer; +Cc: dm-devel

Due to the semantics of iterate_devices(), the current code allows a
request-based dm table as long as it includes one request-stackable
device. It is supposed to only allow tables where there are no
non-request-stackable devices.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 drivers/md/dm-table.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 9f95f77687ef..d91207b2d77f 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -898,17 +898,17 @@ static bool dm_table_supports_dax(struct dm_table *t,
 	return true;
 }
 
-static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
-				  sector_t start, sector_t len, void *data)
+static int device_is_not_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
+				      sector_t start, sector_t len, void *data)
 {
 	struct block_device *bdev = dev->bdev;
 	struct request_queue *q = bdev_get_queue(bdev);
 
 	/* request-based cannot stack on partitions! */
 	if (bdev_is_partition(bdev))
-		return false;
+		return true;
 
-	return queue_is_mq(q);
+	return !queue_is_mq(q);
 }
 
 static int dm_table_determine_type(struct dm_table *t)
@@ -1004,7 +1004,7 @@ static int dm_table_determine_type(struct dm_table *t)
 
 	/* Non-request-stackable devices can't be used for request-based dm */
 	if (!ti->type->iterate_devices ||
-	    !ti->type->iterate_devices(ti, device_is_rq_stackable, NULL)) {
+	    ti->type->iterate_devices(ti, device_is_not_rq_stackable, NULL)) {
 		DMERR("table load rejected: including non-request-stackable devices");
 		return -EINVAL;
 	}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: dm-table: fix checking for rq stackable devices
  2025-06-13 23:08 [PATCH] dm-table: fix checking for rq stackable devices Benjamin Marzinski
@ 2025-06-17 23:00 ` Mike Snitzer
  2025-06-23  9:59   ` Mikulas Patocka
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Snitzer @ 2025-06-17 23:00 UTC (permalink / raw)
  To: Benjamin Marzinski; +Cc: Mikulas Patocka, Mike Snitzer, dm-devel

On Fri, Jun 13, 2025 at 07:08:52PM -0400, Benjamin Marzinski wrote:
> Due to the semantics of iterate_devices(), the current code allows a
> request-based dm table as long as it includes one request-stackable
> device. It is supposed to only allow tables where there are no
> non-request-stackable devices.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Amazing this type of bug is still lurking, thought I audited all of
the iterate_devices callout functions.. anyway, thanks for fixing it!

Reviewed-by: Mike Snitzer <snitzer@kernel.org>

> ---
>  drivers/md/dm-table.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
> index 9f95f77687ef..d91207b2d77f 100644
> --- a/drivers/md/dm-table.c
> +++ b/drivers/md/dm-table.c
> @@ -898,17 +898,17 @@ static bool dm_table_supports_dax(struct dm_table *t,
>  	return true;
>  }
>  
> -static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
> -				  sector_t start, sector_t len, void *data)
> +static int device_is_not_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
> +				      sector_t start, sector_t len, void *data)
>  {
>  	struct block_device *bdev = dev->bdev;
>  	struct request_queue *q = bdev_get_queue(bdev);
>  
>  	/* request-based cannot stack on partitions! */
>  	if (bdev_is_partition(bdev))
> -		return false;
> +		return true;
>  
> -	return queue_is_mq(q);
> +	return !queue_is_mq(q);
>  }
>  
>  static int dm_table_determine_type(struct dm_table *t)
> @@ -1004,7 +1004,7 @@ static int dm_table_determine_type(struct dm_table *t)
>  
>  	/* Non-request-stackable devices can't be used for request-based dm */
>  	if (!ti->type->iterate_devices ||
> -	    !ti->type->iterate_devices(ti, device_is_rq_stackable, NULL)) {
> +	    ti->type->iterate_devices(ti, device_is_not_rq_stackable, NULL)) {
>  		DMERR("table load rejected: including non-request-stackable devices");
>  		return -EINVAL;
>  	}
> -- 
> 2.48.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dm-table: fix checking for rq stackable devices
  2025-06-17 23:00 ` Mike Snitzer
@ 2025-06-23  9:59   ` Mikulas Patocka
  0 siblings, 0 replies; 3+ messages in thread
From: Mikulas Patocka @ 2025-06-23  9:59 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: Benjamin Marzinski, Mike Snitzer, dm-devel



On Tue, 17 Jun 2025, Mike Snitzer wrote:

> On Fri, Jun 13, 2025 at 07:08:52PM -0400, Benjamin Marzinski wrote:
> > Due to the semantics of iterate_devices(), the current code allows a
> > request-based dm table as long as it includes one request-stackable
> > device. It is supposed to only allow tables where there are no
> > non-request-stackable devices.
> > 
> > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> 
> Amazing this type of bug is still lurking, thought I audited all of
> the iterate_devices callout functions.. anyway, thanks for fixing it!
> 
> Reviewed-by: Mike Snitzer <snitzer@kernel.org>

I've applied the patch, thanks.

Mikulas


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-23  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-13 23:08 [PATCH] dm-table: fix checking for rq stackable devices Benjamin Marzinski
2025-06-17 23:00 ` Mike Snitzer
2025-06-23  9:59   ` Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.