* [PATCH v2 2/3] partition/efi: use bdev_logical_block_count()
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
@ 2016-06-23 13:30 ` Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 3/3] target/iblock: " Arnd Bergmann
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2016-06-23 13:30 UTC (permalink / raw)
To: Jens Axboe
Cc: Nicholas A . Bellinger, Mike Christie, Andy Grover,
Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
Christoph Hellwig, Davidlohr Bueso, linux-efi, linux-block,
Arnd Bergmann
Enabling CONFIG_UBSAN_SANITIZE_ALL on ARM caused a link error:
last_lba.part.0':
:(.text+0xc3440): undefined reference to `____ilog2_NaN'
:(.text+0xc3538): undefined reference to `__aeabi_uldivmod'
:(.text+0xc38e8): 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 based on a 64-bit
division.
I have introduced a better bdev_logical_block_count() now, so we
can use that here.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
block/partitions/efi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index bcd86e5cd546..7b1a62073d34 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -149,8 +149,8 @@ static u64 last_lba(struct block_device *bdev)
{
if (!bdev || !bdev->bd_inode)
return 0;
- return div_u64(bdev->bd_inode->i_size,
- bdev_logical_block_size(bdev)) - 1ULL;
+
+ return bdev_logical_block_count(bdev) - 1;
}
static inline int pmbr_part_valid(gpt_mbr_record *part)
--
2.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] target/iblock: use bdev_logical_block_count()
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 2/3] partition/efi: use bdev_logical_block_count() Arnd Bergmann
@ 2016-06-23 13:30 ` Arnd Bergmann
2016-06-23 14:22 ` [PATCH v2 1/3] block: provide helpers for reading block count Christoph Hellwig
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2016-06-23 13:30 UTC (permalink / raw)
To: Jens Axboe
Cc: Nicholas A . Bellinger, Mike Christie, Andy Grover,
Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
Christoph Hellwig, Davidlohr Bueso, linux-efi, linux-block,
Arnd Bergmann
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 based on an expensive 64-bit
division.
I have introduced a better bdev_logical_block_count() now, so we can use that here.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/target/target_core_iblock.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 22af12f8b8eb..2dc0129553e1 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -201,9 +201,8 @@ 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 long long blocks_long = bdev_logical_block_count(bd) - 1;
if (block_size == dev->dev_attrib.block_size)
return blocks_long;
--
2.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] block: provide helpers for reading block count
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 2/3] partition/efi: use bdev_logical_block_count() Arnd Bergmann
2016-06-23 13:30 ` [PATCH v2 3/3] target/iblock: " Arnd Bergmann
@ 2016-06-23 14:22 ` Christoph Hellwig
2016-06-23 15:52 ` Sagi Grimberg
2016-06-27 16:30 ` Davidlohr Bueso
4 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2016-06-23 14:22 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jens Axboe, Nicholas A . Bellinger, Mike Christie, Andy Grover,
Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
Christoph Hellwig, Davidlohr Bueso, linux-efi, linux-block
Thanks Arnd,
the series looks fine to me:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] block: provide helpers for reading block count
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
` (2 preceding siblings ...)
2016-06-23 14:22 ` [PATCH v2 1/3] block: provide helpers for reading block count Christoph Hellwig
@ 2016-06-23 15:52 ` Sagi Grimberg
2016-06-27 16:30 ` Davidlohr Bueso
4 siblings, 0 replies; 6+ messages in thread
From: Sagi Grimberg @ 2016-06-23 15:52 UTC (permalink / raw)
To: Arnd Bergmann, Jens Axboe
Cc: Nicholas A . Bellinger, Mike Christie, Andy Grover,
Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
Christoph Hellwig, Davidlohr Bueso, linux-efi, linux-block
Looks good, for the series:
Reviewed-by: Sagi Grimbeg <sagi@grimbeg.me>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/3] block: provide helpers for reading block count
2016-06-23 13:30 [PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann
` (3 preceding siblings ...)
2016-06-23 15:52 ` Sagi Grimberg
@ 2016-06-27 16:30 ` Davidlohr Bueso
4 siblings, 0 replies; 6+ messages in thread
From: Davidlohr Bueso @ 2016-06-27 16:30 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jens Axboe, Nicholas A . Bellinger, Mike Christie, Andy Grover,
Hannes Reinecke, linux-scsi, target-devel, linux-kernel,
Christoph Hellwig, linux-efi, linux-block
On Thu, 23 Jun 2016, Arnd Bergmann wrote:
>Several drivers use an expensive do_div() to compute the number
>of logical or physical blocks in a blockdev, which can be done
>more efficiently using a shift, since the blocksize is always
>a power of two number.
>
>Let's introduce bdev_logical_block_count() and bdev_physical_block_count()
>helper functions mirroring the bdev_logical_block_size() and
>bdev_physical_block_size() interfaces for the block size.
>@@ -1226,6 +1226,13 @@ static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
> return queue_logical_block_size(bdev_get_queue(bdev));
> }
>
>+static inline sector_t bdev_logical_block_count(struct block_device *bdev)
Curious, why not just return u64 instead for all these instead of sector_t (ie
dealing with lba, it reads weird)?
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 6+ messages in thread