All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target/iblock: use ilog2 to compute block size
@ 2016-06-22 12:55 Arnd Bergmann
  2016-06-22 13:38 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2016-06-22 12:55 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: Arnd Bergmann, Jens Axboe, Mike Christie, Andy Grover,
	Hannes Reinecke, linux-scsi, target-devel, linux-kernel

Enabling CONFIG_UBSAN_SANITIZE_ALL on ARM caused a link error:

drivers/target/built-in.o: In function `iblock_emulate_read_cap_with_block_size.constprop.1':
target_core_iblock.c:(.text+0xc2774): undefined reference to `____ilog2_NaN'
target_core_iblock.c:(.text+0xc27f8): undefined reference to `__aeabi_uldivmod'
target_core_iblock.c:(.text+0xc299c): undefined reference to `__aeabi_uldivmod'

This is caused by gcc not behaving in the expected ways with __builtin_constant_p(),
but it also points to somewhat inefficient code: As we know that the
block size is a power-of-two value, we can turn the expensive 64-bit
division into a simpler variable bit shift.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/target/target_core_iblock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 22af12f8b8eb..3ab4e2d1202c 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -201,9 +201,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
 	struct block_device *bd,
 	struct request_queue *q)
 {
-	unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode),
-					bdev_logical_block_size(bd)) - 1);
 	u32 block_size = bdev_logical_block_size(bd);
+	unsigned int block_shift = ilog2(block_size);
+	unsigned long long blocks_long = (i_size_read(bd->bd_inode) >> block_shift) - 1;
 
 	if (block_size == dev->dev_attrib.block_size)
 		return blocks_long;
-- 
2.9.0

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

* Re: [PATCH] target/iblock: use ilog2 to compute block size
  2016-06-22 12:55 [PATCH] target/iblock: use ilog2 to compute block size Arnd Bergmann
@ 2016-06-22 13:38 ` Christoph Hellwig
  2016-06-22 15:53   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2016-06-22 13:38 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Nicholas A. Bellinger, Jens Axboe, Mike Christie, Andy Grover,
	Hannes Reinecke, linux-scsi, target-devel, linux-kernel

This doesn't compute the block size, it computes the number of block
in a block device.  I think it would be useful to add a generic helper
(e.g. in blkdev.h) as this calculation seems to be open coded in various
places.

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

* Re: [PATCH] target/iblock: use ilog2 to compute block size
  2016-06-22 13:38 ` Christoph Hellwig
@ 2016-06-22 15:53   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2016-06-22 15:53 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Nicholas A. Bellinger, Jens Axboe, Mike Christie, Andy Grover,
	Hannes Reinecke, linux-scsi, target-devel, linux-kernel

On Wednesday, June 22, 2016 6:38:09 AM CEST Christoph Hellwig wrote:
> This doesn't compute the block size, it computes the number of block
> in a block device. 

Right, that's at least what I planned to put in the $subject ;-)

> I think it would be useful to add a generic helper
> (e.g. in blkdev.h) as this calculation seems to be open coded in various
> places.

Good idea, I'll try to come up with a patch for that.

	Arnd

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

end of thread, other threads:[~2016-06-22 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 12:55 [PATCH] target/iblock: use ilog2 to compute block size Arnd Bergmann
2016-06-22 13:38 ` Christoph Hellwig
2016-06-22 15:53   ` Arnd Bergmann

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.