All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc
@ 2021-02-17 13:52 Johannes Thumshirn
  2021-02-17 22:58 ` Damien Le Moal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2021-02-17 13:52 UTC (permalink / raw)
  To: martin . petersen @ oracle . com
  Cc: linux-scsi, Johannes Thumshirn, Dan Carpenter, Damien Le Moal

Dan reported we're passing in GFP_NOIO to kvmalloc() which will then
fallback to doing kmalloc() instead of an optional vmalloc() if the size
exceeds kmalloc()s limits. This will break with drives that have zone
numbers exceeding PAGE_SIZE/sizeof(u32).

Instead of passing in GFP_NOIO, enter an implicit GFP_NOIO allocation
scope.

Link: https://lore.kernel.org/r/YCuvSfKw4qEQBr/t@mwanda
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Damien Le Moal <Damien.LeMoal@wdc.com>
Fixes: 5795eb443060: ("scsi: sd_zbc: emulate ZONE_APPEND commands")
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/scsi/sd_zbc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index cf07b7f93579..87a7274e4632 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -688,6 +688,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
 	unsigned int nr_zones = sdkp->rev_nr_zones;
 	u32 max_append;
 	int ret = 0;
+	unsigned int flags;
 
 	/*
 	 * For all zoned disks, initialize zone append emulation data if not
@@ -720,16 +721,19 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
 	    disk->queue->nr_zones == nr_zones)
 		goto unlock;
 
+	flags = memalloc_noio_save();
 	sdkp->zone_blocks = zone_blocks;
 	sdkp->nr_zones = nr_zones;
-	sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_NOIO);
+	sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_KERNEL);
 	if (!sdkp->rev_wp_offset) {
 		ret = -ENOMEM;
+		memalloc_noio_restore(flags);
 		goto unlock;
 	}
 
 	ret = blk_revalidate_disk_zones(disk, sd_zbc_revalidate_zones_cb);
 
+	memalloc_noio_restore(flags);
 	kvfree(sdkp->rev_wp_offset);
 	sdkp->rev_wp_offset = NULL;
 
-- 
2.30.0


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

* Re: [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc
  2021-02-17 13:52 [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc Johannes Thumshirn
@ 2021-02-17 22:58 ` Damien Le Moal
  2021-02-23  3:30 ` Martin K. Petersen
  2021-02-26  2:22 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2021-02-17 22:58 UTC (permalink / raw)
  To: Johannes Thumshirn, martin . petersen @ oracle . com
  Cc: linux-scsi, Dan Carpenter

On 2021/02/17 22:52, Johannes Thumshirn wrote:
> Dan reported we're passing in GFP_NOIO to kvmalloc() which will then
> fallback to doing kmalloc() instead of an optional vmalloc() if the size
> exceeds kmalloc()s limits. This will break with drives that have zone
> numbers exceeding PAGE_SIZE/sizeof(u32).
> 
> Instead of passing in GFP_NOIO, enter an implicit GFP_NOIO allocation
> scope.
> 
> Link: https://lore.kernel.org/r/YCuvSfKw4qEQBr/t@mwanda
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Cc: Damien Le Moal <Damien.LeMoal@wdc.com>
> Fixes: 5795eb443060: ("scsi: sd_zbc: emulate ZONE_APPEND commands")
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  drivers/scsi/sd_zbc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index cf07b7f93579..87a7274e4632 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -688,6 +688,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
>  	unsigned int nr_zones = sdkp->rev_nr_zones;
>  	u32 max_append;
>  	int ret = 0;
> +	unsigned int flags;
>  
>  	/*
>  	 * For all zoned disks, initialize zone append emulation data if not
> @@ -720,16 +721,19 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
>  	    disk->queue->nr_zones == nr_zones)
>  		goto unlock;
>  
> +	flags = memalloc_noio_save();
>  	sdkp->zone_blocks = zone_blocks;
>  	sdkp->nr_zones = nr_zones;
> -	sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_NOIO);
> +	sdkp->rev_wp_offset = kvcalloc(nr_zones, sizeof(u32), GFP_KERNEL);
>  	if (!sdkp->rev_wp_offset) {
>  		ret = -ENOMEM;
> +		memalloc_noio_restore(flags);
>  		goto unlock;
>  	}
>  
>  	ret = blk_revalidate_disk_zones(disk, sd_zbc_revalidate_zones_cb);
>  
> +	memalloc_noio_restore(flags);
>  	kvfree(sdkp->rev_wp_offset);
>  	sdkp->rev_wp_offset = NULL;
>  
> 

Looks good to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>

-- 
Damien Le Moal
Western Digital Research

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

* Re: [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc
  2021-02-17 13:52 [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc Johannes Thumshirn
  2021-02-17 22:58 ` Damien Le Moal
@ 2021-02-23  3:30 ` Martin K. Petersen
  2021-02-26  2:22 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-02-23  3:30 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: martin . petersen @ oracle . com, linux-scsi, Dan Carpenter,
	Damien Le Moal


Johannes,

> Dan reported we're passing in GFP_NOIO to kvmalloc() which will then
> fallback to doing kmalloc() instead of an optional vmalloc() if the
> size exceeds kmalloc()s limits. This will break with drives that have
> zone numbers exceeding PAGE_SIZE/sizeof(u32).
>
> Instead of passing in GFP_NOIO, enter an implicit GFP_NOIO allocation
> scope.

Applied to 5.12/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc
  2021-02-17 13:52 [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc Johannes Thumshirn
  2021-02-17 22:58 ` Damien Le Moal
  2021-02-23  3:30 ` Martin K. Petersen
@ 2021-02-26  2:22 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2021-02-26  2:22 UTC (permalink / raw)
  To: Johannes Thumshirn
  Cc: Martin K . Petersen, Damien Le Moal, linux-scsi, Dan Carpenter

On Wed, 17 Feb 2021 22:52:45 +0900, Johannes Thumshirn wrote:

> Dan reported we're passing in GFP_NOIO to kvmalloc() which will then
> fallback to doing kmalloc() instead of an optional vmalloc() if the size
> exceeds kmalloc()s limits. This will break with drives that have zone
> numbers exceeding PAGE_SIZE/sizeof(u32).
> 
> Instead of passing in GFP_NOIO, enter an implicit GFP_NOIO allocation
> scope.

Applied to 5.12/scsi-queue, thanks!

[1/1] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc
      https://git.kernel.org/mkp/scsi/c/9acced3f58ad

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2021-02-26  2:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17 13:52 [PATCH] sd: sd_zbc: don't pass GFP_NOIO to kvcalloc Johannes Thumshirn
2021-02-17 22:58 ` Damien Le Moal
2021-02-23  3:30 ` Martin K. Petersen
2021-02-26  2:22 ` Martin K. Petersen

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.