From patchwork Thu Jun 23 13:30:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102107 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp434378qgy; Thu, 23 Jun 2016 06:30:17 -0700 (PDT) X-Received: by 10.67.15.72 with SMTP id fm8mr43700568pad.50.1466688616958; Thu, 23 Jun 2016 06:30:16 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si122837pfk.240.2016.06.23.06.30.16; Thu, 23 Jun 2016 06:30:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932118AbcFWN3K (ORCPT + 30 others); Thu, 23 Jun 2016 09:29:10 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:54946 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752166AbcFWN3G (ORCPT ); Thu, 23 Jun 2016 09:29:06 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0LxLzO-1bQJ1f44vy-016td7; Thu, 23 Jun 2016 15:28:10 +0200 From: Arnd Bergmann To: Jens Axboe Cc: "Nicholas A . Bellinger" , Mike Christie , Andy Grover , Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Davidlohr Bueso , linux-efi@vger.kernel.org, linux-block@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 1/3] block: provide helpers for reading block count Date: Thu, 23 Jun 2016 15:30:14 +0200 Message-Id: <20160623133016.3781907-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:c5hq6TeNWqjlfLOByYx1OcjE2lZSKFPqulpSp6Hevsk7+bjXO+2 vvlTXZQOeJf8yt9YfXQOL+EXM8euKmJ8DoiffqFIaCNNrAL4qUpyyFRECz7O7+sKU5BJ8yR snBj6pDqbtl4L/HMV9L9aq+wiX7NkeGL4qQsZkAYo1T9QZ57B8xeTs7hIzBFXrSiwtBgJk1 DO3Tun6vsOtENNg1NtKvw== X-UI-Out-Filterresults: notjunk:1; V01:K0:58plwRA2L2c=:uoWxcPjt0P4mvS6S8PmgSx GEFePiyRfEcV1dyfqmPNJQkmytYSLZYjfWTr6KY3wt2OHRy67EtjPAgXc+7uE6fkmA76aqyJT CJ7KxC0nEu+LMhFuDZivBD/16NclPAxEi8d24zAlNighhtZQaFz/UMLBYOHk3PSCWeZrsQ1NV SkI38U60xb9cOaPTJDHyesRFjR/IN6iVK6NGCXCZMbZh/yHX+BL73iHbZ75TDqnEzbR1H9wrF ujN81ThIdCWBsOyFxrDZ0aWdPRPlq/LdY0cTujaacOotU/P3LnHKr9to1KkxNAg66PKhFbmIx OH9smLwUJey1yIDVVKTvCCzztItDKk18Uj1qcaeMzzQLMQbPi0voV+cmZf9J7DUgub+zgAPdZ NplDnWXvNwcrotYhws+N3LDEJzMndZV+eEr1zk5QEwDKKiv2Oqh10/OjLSb9OJsu4Y3G4KL5i Bbw6JEiBMHLqMAwmSyl0hhR8h0GF/I/BNR0S8qCpsBLwZcinPe4ICQxf2Vh2p/s70bWYEml8N iCm120VOrH54qBklbDtlcDwzsMLb39mSU46COetSXK5O1GubZpd32cbpbtzmZco/OGGPhYGdF DedJOEZYcPlBvR0fprnZX9pmmHCVCAf3cuhg79ULR6pt2be02zJuxbZXJkFSDFEm2VKpHG1Wo czCh5XWuiKY8+hlcUSqSGOuaq2VoFmCKvZbo3pHpF1bg0b9RAT0jG/KNceGD1JzkQnt4= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann Suggested-by: Christoph Hellwig --- include/linux/blkdev.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.9.0 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9d1e0a4650dc..ae8c408f6c22 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -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) +{ + unsigned int block_shift = ilog2(bdev_logical_block_size(bdev)); + + return bdev->bd_inode->i_size >> block_shift; +} + static inline unsigned int queue_physical_block_size(struct request_queue *q) { return q->limits.physical_block_size; @@ -1236,6 +1243,13 @@ static inline unsigned int bdev_physical_block_size(struct block_device *bdev) return queue_physical_block_size(bdev_get_queue(bdev)); } +static inline sector_t bdev_physical_block_count(struct block_device *bdev) +{ + unsigned int block_shift = ilog2(bdev_physical_block_size(bdev)); + + return bdev->bd_inode->i_size >> block_shift; +} + static inline unsigned int queue_io_min(struct request_queue *q) { return q->limits.io_min; From patchwork Thu Jun 23 13:30:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102108 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp434100qgy; Thu, 23 Jun 2016 06:29:37 -0700 (PDT) X-Received: by 10.98.104.68 with SMTP id d65mr43181520pfc.34.1466688577287; Thu, 23 Jun 2016 06:29:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d185si170680pfa.76.2016.06.23.06.29.37; Thu, 23 Jun 2016 06:29:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752354AbcFWN3c (ORCPT + 30 others); Thu, 23 Jun 2016 09:29:32 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:61937 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268AbcFWN33 (ORCPT ); Thu, 23 Jun 2016 09:29:29 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0MeMIx-1b0uNJ1g35-00QALY; Thu, 23 Jun 2016 15:28:10 +0200 From: Arnd Bergmann To: Jens Axboe Cc: "Nicholas A . Bellinger" , Mike Christie , Andy Grover , Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Davidlohr Bueso , linux-efi@vger.kernel.org, linux-block@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 2/3] partition/efi: use bdev_logical_block_count() Date: Thu, 23 Jun 2016 15:30:15 +0200 Message-Id: <20160623133016.3781907-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160623133016.3781907-1-arnd@arndb.de> References: <20160623133016.3781907-1-arnd@arndb.de> X-Provags-ID: V03:K0:T8tsdDkpHXjp+ft+It1HdnqELWUC/L6jTUHxMLBkuxskNUiHyfU l0t05XZvPAbXI3a9/SiJTPByAMbP1AyX5os3MDjIb6SiY0nS1uhZwu/vGHZGWhOmdYmTCDY fvjWtZkODmwp11VCPMjfLnMuPTjwUR5Gy8NgDX/9VU/achULb+1LguUX3xhKM/nkfKl7BdO TrSGxq4d+SevsuZRr9qvw== X-UI-Out-Filterresults: notjunk:1; V01:K0:Kt03CZKSCMU=:5e8BAjnR4SmvYMWM9+JEeZ miwgOCa2pE4TuHjIl9w++X0PvPOd4yNr2eDELsSAJO+WzgQt2vIXKeCMCKkDIyQt2c2Gks+T1 GhXhxHtmablKIqaLeYNmAJDztyLxwibzl5O7VFJKnMM8yD77gkwo7H+oORtSVy0XXLXC4fYJR sESBKS9mHWzJ7+/Kouqq/Mv9NK1xuxGxtPiwtsPL29wQ+Xhi+3bePyX3Rg0vk4iKpFTctvtAK xSPM/hZEFkR8YL8A3eG7KoSVNofBE7qtvHA/GxcWe4wPumTeR/VFE0PdwjS5QK1j7485XlLc9 XJokREuXAxe1kfApD99yTbTOBop8UDnqmEAnQMCGCebKegeET4LC3WWqjRpI7c2Jf1G/gd+dN h43JZoB8YWCLJVpZwqL8T0EUpjfASIpAq+G3HZTepTqwUqViQEpaCuoxguUIGSL5lJRut+OD7 UoXRrTVaukvRH7vLzWrfq1Pl9HNg/OsxhisBYuNH0xwY6Z95GwEOnvnlfKVijd5UFkYrxfQwM 2h+8bQNGYLy08Q+AVTAKq5+RcVP0oj148Yvh9LgRAZmOP5a1CqjaShTDcP5Foq5nyGdF0/ODL QeVoNFkArSAFG9jYS9HI77YluG5Lbjjiejk3tZ7oPD/gVJO901e7OoNVdIzdZ3J6LzJ7wYTOL UrgtM0yDBSuZthXOVJuPmu98MX/QgmBps/rMfFWX/QxLkJZWOUpsf50z9QfI2QBb+Gpg= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- block/partitions/efi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.9.0 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) From patchwork Thu Jun 23 13:30:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102109 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp434022qgy; Thu, 23 Jun 2016 06:29:27 -0700 (PDT) X-Received: by 10.98.24.148 with SMTP id 142mr14959093pfy.52.1466688567158; Thu, 23 Jun 2016 06:29:27 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p65si173970pfd.57.2016.06.23.06.29.26; Thu, 23 Jun 2016 06:29:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752238AbcFWN3M (ORCPT + 30 others); Thu, 23 Jun 2016 09:29:12 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:60459 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751265AbcFWN3G (ORCPT ); Thu, 23 Jun 2016 09:29:06 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0M51UE-1baFC03Zh0-00zE7F; Thu, 23 Jun 2016 15:28:11 +0200 From: Arnd Bergmann To: Jens Axboe Cc: "Nicholas A . Bellinger" , Mike Christie , Andy Grover , Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Davidlohr Bueso , linux-efi@vger.kernel.org, linux-block@vger.kernel.org, Arnd Bergmann Subject: [PATCH v2 3/3] target/iblock: use bdev_logical_block_count() Date: Thu, 23 Jun 2016 15:30:16 +0200 Message-Id: <20160623133016.3781907-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160623133016.3781907-1-arnd@arndb.de> References: <20160623133016.3781907-1-arnd@arndb.de> X-Provags-ID: V03:K0:11c3Wy/iks015af/kameWtW0yk8UAKKZ1tkxAKt5nRtsCoNcW/j Kl/jMCN3kJuHntGJbiDbhmXLLdUBAJDx2qEMBW4xiKhDx9PzIdd3DZoQ4o9HoX8CPu2r8XK q/iijyfSmk9aAXIMN3codGdDCR9NLJxykq/ceDu0ykGwITh7PR+a0lnKZPfeHkdECueMBKx 1HwobQ3fiCz6AB9R7Tz9w== X-UI-Out-Filterresults: notjunk:1; V01:K0:7JgAqogzuPg=:pGnEB/aNj2uGK0mWnO2eCS LGMhVhd79mPI0Z5lG7nrWt4q6Rjkgqj062WLcam+fLmCnpmk0RX12S61ymDDjWkA8Gfjg3M7/ udnchAPh4yAOr2UUnbzIMUA4TFJmvYyyaG7AKVXfIf8FydAoMfNaQ2xp1iSto7hGfGMxu7d8c kOd5TuvNZXTstnwzpIsxgl/4iIZDQKrdv9d5NO4ESjgtTiRBc3k66TBN+jsS+fnvZlMZkWo4/ hIlFeo0NrO4haYJn/TUEMSXkfcQg+bF0F76JE138rtfDVpPSYxAO63V8OBwT1nAC0OQ+Pa5gX UPyrq7USdJF0Ms7yvgf98EOrnd4eGqdqEnVp75WfHbO2TPVNhuDe1q4YmsoVqDVc3b8R9+DCq DTcVVIX3RzfL4defaQ6AvB9wPto+6MVi5n4KBUeKKD8Pc12G1lq+TZXzA/kmQOh6XgukLaG0O Vr1DupBC17pRz6u5oHQ0dl5Mwv4zP+5lu/x2mlP0gqcYCJd/q/pPXI0o20A+c3hpnEOWXLMZd lA0inm10DOCrKpNLno0s83H5nPYoyJ3xb02aZrLWCGTMw2Rrac30W2ApYQbygF8BeT9DNN34Z o5Cf2gagNjdyyfXZUH8DBfUfZRJfYqshOd5jwAFu9k1/GvpezkN5xsSvTw0lfQBIX6AOAa2xs xFmqy9x322YUfpkeyLU54Ke+US89Ma1cEjQ9ancMYIUMOs70KHgSuZoLJcX7HD3lZJ/w= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/target/target_core_iblock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.9.0 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;