All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi_debug: Fix compilation error on 32bits arch
@ 2020-05-07  2:35 Damien Le Moal
  2020-05-07  7:55 ` Johannes Thumshirn
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Damien Le Moal @ 2020-05-07  2:35 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert

Allowing a non-power-of-2 zone size forces the use of direct division
operations of 64bits sector values to obtain a zone number or number of
zones. Doing so without using do_div() leads to compilation errors on
32bits architecture.

Devices with a zone size that is not a power of 2 do not exist today so
allowing their emulation is of limited interest, as the sd driver will
not support them anyway. So to fix this compilation error, instead of
using do_div() for sector values divisions, simply disallow zone size
values that are not a power of 2 value, allowing to use bitshift for
divisions in all cases.

Fixes: 98e0a689868c ("scsi: scsi_debug: Add zone_size_mb module parameter")
Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/scsi_debug.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index d3ea16f3c12e..105e563d87b4 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2657,13 +2657,7 @@ static inline bool sdebug_dev_is_zoned(struct sdebug_dev_info *devip)
 static struct sdeb_zone_state *zbc_zone(struct sdebug_dev_info *devip,
 					unsigned long long lba)
 {
-	unsigned int zno;
-
-	if (devip->zsize_shift)
-		zno = lba >> devip->zsize_shift;
-	else
-		zno = lba / devip->zsize;
-	return &devip->zstate[zno];
+	return &devip->zstate[lba >> devip->zsize_shift];
 }
 
 static inline bool zbc_zone_is_conv(struct sdeb_zone_state *zsp)
@@ -4306,7 +4300,7 @@ static int resp_report_zones(struct scsi_cmnd *scp,
 		return check_condition_result;
 	}
 
-	max_zones = devip->nr_zones - zs_lba / devip->zsize;
+	max_zones = devip->nr_zones - (zs_lba >> devip->zsize_shift);
 	rep_max_zones = min((alloc_len - 64) >> ilog2(RZONES_DESC_HD),
 			    max_zones);
 
@@ -4826,6 +4820,10 @@ static int sdebug_device_create_zones(struct sdebug_dev_info *devip)
 			return -EINVAL;
 		}
 	} else {
+		if (!is_power_of_2(sdeb_zbc_zone_size_mb)) {
+			pr_err("Zone size is not a power of 2\n");
+			return -EINVAL;
+		}
 		devip->zsize = (sdeb_zbc_zone_size_mb * SZ_1M)
 			>> ilog2(sdebug_sector_size);
 		if (devip->zsize >= capacity) {
@@ -4834,8 +4832,7 @@ static int sdebug_device_create_zones(struct sdebug_dev_info *devip)
 		}
 	}
 
-	if (is_power_of_2(devip->zsize))
-		devip->zsize_shift = ilog2(devip->zsize);
+	devip->zsize_shift = ilog2(devip->zsize);
 	devip->nr_zones = (capacity + devip->zsize - 1) >> devip->zsize_shift;
 
 	if (sdeb_zbc_nr_conv >= devip->nr_zones) {
-- 
2.25.4


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

* Re: [PATCH] scsi_debug: Fix compilation error on 32bits arch
  2020-05-07  2:35 [PATCH] scsi_debug: Fix compilation error on 32bits arch Damien Le Moal
@ 2020-05-07  7:55 ` Johannes Thumshirn
  2020-05-07 13:34 ` Geert Uytterhoeven
  2020-05-08  0:56 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2020-05-07  7:55 UTC (permalink / raw)
  To: Damien Le Moal, linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH] scsi_debug: Fix compilation error on 32bits arch
  2020-05-07  2:35 [PATCH] scsi_debug: Fix compilation error on 32bits arch Damien Le Moal
  2020-05-07  7:55 ` Johannes Thumshirn
@ 2020-05-07 13:34 ` Geert Uytterhoeven
  2020-05-08  0:56 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2020-05-07 13:34 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: linux-scsi, Martin K . Petersen, Douglas Gilbert

 	Hi Damien,


On Thu, 7 May 2020, Damien Le Moal wrote:
> Allowing a non-power-of-2 zone size forces the use of direct division
> operations of 64bits sector values to obtain a zone number or number of
> zones. Doing so without using do_div() leads to compilation errors on
> 32bits architecture.

As reported by noreply@ellerman.id.au for m68k-allmodconfig:

     ERROR: modpost: "__udivdi3" [drivers/scsi/scsi_debug.ko] undefined!

> Devices with a zone size that is not a power of 2 do not exist today so
> allowing their emulation is of limited interest, as the sd driver will
> not support them anyway. So to fix this compilation error, instead of
> using do_div() for sector values divisions, simply disallow zone size
> values that are not a power of 2 value, allowing to use bitshift for
> divisions in all cases.
>
> Fixes: 98e0a689868c ("scsi: scsi_debug: Add zone_size_mb module parameter")
> Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>

And your patch fixes that, so

Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

 						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
 							    -- Linus Torvalds

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

* Re: [PATCH] scsi_debug: Fix compilation error on 32bits arch
  2020-05-07  2:35 [PATCH] scsi_debug: Fix compilation error on 32bits arch Damien Le Moal
  2020-05-07  7:55 ` Johannes Thumshirn
  2020-05-07 13:34 ` Geert Uytterhoeven
@ 2020-05-08  0:56 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2020-05-08  0:56 UTC (permalink / raw)
  To: linux-scsi, Damien Le Moal; +Cc: Martin K . Petersen, Douglas Gilbert

On Thu, 7 May 2020 11:35:26 +0900, Damien Le Moal wrote:

> Allowing a non-power-of-2 zone size forces the use of direct division
> operations of 64bits sector values to obtain a zone number or number of
> zones. Doing so without using do_div() leads to compilation errors on
> 32bits architecture.
> 
> Devices with a zone size that is not a power of 2 do not exist today so
> allowing their emulation is of limited interest, as the sd driver will
> not support them anyway. So to fix this compilation error, instead of
> using do_div() for sector values divisions, simply disallow zone size
> values that are not a power of 2 value, allowing to use bitshift for
> divisions in all cases.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: scsi_debug: Disallow zone sizes that are not powers of 2
      https://git.kernel.org/mkp/scsi/c/108e36f0d8bf

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2020-05-08  0:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07  2:35 [PATCH] scsi_debug: Fix compilation error on 32bits arch Damien Le Moal
2020-05-07  7:55 ` Johannes Thumshirn
2020-05-07 13:34 ` Geert Uytterhoeven
2020-05-08  0:56 ` 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.