linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block:Remove extra condition in end of disk check
@ 2013-06-23 17:17 Raghavendra K T
  2013-06-24 13:50 ` Raghavendra K T
  0 siblings, 1 reply; 4+ messages in thread
From: Raghavendra K T @ 2013-06-23 17:17 UTC (permalink / raw)
  To: Jens Axboe, LKML; +Cc: raghavendra.kt

From: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>

Since #sector is always positive the reduced condition check
encompasses maxsector < nr_sectors check.

Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
---
An userspace program looping with:
maxsector - 0-9999
nr_sector - 0-999
sector - 0-999 gave 6.4% improvement with new condition though I agree that
it is not the best way to test it perhaps :)

diff --git a/block/blk-core.c b/block/blk-core.c
index 33c33bc..4a78583 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1656,7 +1656,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
 	if (maxsector) {
 		sector_t sector = bio->bi_sector;
 
-		if (maxsector < nr_sectors || maxsector - nr_sectors < sector) {
+		if (maxsector - nr_sectors < sector) {
 			/*
 			 * This may well happen - the kernel calls bread()
 			 * without checking the size of the device, e.g., when


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

* Re: [PATCH] block:Remove extra condition in end of disk check
  2013-06-23 17:17 [PATCH] block:Remove extra condition in end of disk check Raghavendra K T
@ 2013-06-24 13:50 ` Raghavendra K T
  2013-06-24 22:51   ` Tejun Heo
  0 siblings, 1 reply; 4+ messages in thread
From: Raghavendra K T @ 2013-06-24 13:50 UTC (permalink / raw)
  To: LKML, Tejun Heo, Andrew Morton
  Cc: Raghavendra K T, Jens Axboe, Kiyoshi Ueda, Lin Ming, Christoph Hellwig

CCing more relevant people (with the help of get_maintainer --git-blame)

On 06/23/2013 10:47 PM, Raghavendra K T wrote:
> From: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
>
> Since #sector is always positive the reduced condition check
> encompasses maxsector < nr_sectors check.
>
> Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
> ---
> An userspace program looping with:
> maxsector - 0-9999
> nr_sector - 0-999
> sector - 0-999 gave 6.4% improvement with new condition though I agree that
> it is not the best way to test it perhaps :)
>
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 33c33bc..4a78583 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -1656,7 +1656,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
>   	if (maxsector) {
>   		sector_t sector = bio->bi_sector;
>
> -		if (maxsector < nr_sectors || maxsector - nr_sectors < sector) {
> +		if (maxsector - nr_sectors < sector) {
>   			/*
>   			 * This may well happen - the kernel calls bread()
>   			 * without checking the size of the device, e.g., when
>
>


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

* Re: [PATCH] block:Remove extra condition in end of disk check
  2013-06-24 13:50 ` Raghavendra K T
@ 2013-06-24 22:51   ` Tejun Heo
  2013-06-25  5:10     ` Raghavendra K T
  0 siblings, 1 reply; 4+ messages in thread
From: Tejun Heo @ 2013-06-24 22:51 UTC (permalink / raw)
  To: Raghavendra K T
  Cc: LKML, Andrew Morton, Jens Axboe, Kiyoshi Ueda, Lin Ming,
	Christoph Hellwig

On Mon, Jun 24, 2013 at 07:20:12PM +0530, Raghavendra K T wrote:
> >@@ -1656,7 +1656,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
> >  	if (maxsector) {
> >  		sector_t sector = bio->bi_sector;
> >
> >-		if (maxsector < nr_sectors || maxsector - nr_sectors < sector) {
> >+		if (maxsector - nr_sectors < sector) {

If maxsector < nr_sectors, the subtraction will underflow making it a
very large number and fail to detect the invalid condition, no?

Thanks.

-- 
tejun

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

* Re: [PATCH] block:Remove extra condition in end of disk check
  2013-06-24 22:51   ` Tejun Heo
@ 2013-06-25  5:10     ` Raghavendra K T
  0 siblings, 0 replies; 4+ messages in thread
From: Raghavendra K T @ 2013-06-25  5:10 UTC (permalink / raw)
  To: Tejun Heo
  Cc: LKML, Andrew Morton, Jens Axboe, Kiyoshi Ueda, Lin Ming,
	Christoph Hellwig

On 06/25/2013 04:21 AM, Tejun Heo wrote:
> On Mon, Jun 24, 2013 at 07:20:12PM +0530, Raghavendra K T wrote:
>>> @@ -1656,7 +1656,7 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
>>>   	if (maxsector) {
>>>   		sector_t sector = bio->bi_sector;
>>>
>>> -		if (maxsector < nr_sectors || maxsector - nr_sectors < sector) {
>>> +		if (maxsector - nr_sectors < sector) {
>
> If maxsector < nr_sectors, the subtraction will underflow making it a
> very large number and fail to detect the invalid condition, no?
>

Hi Tejun,
Thanks for the reply and explanation. You are right. underflow results
in invalid condition.

Considering maxsector and sectors are unsigned long, and nr_sector is
unsigned int, probably safer bet is
(max_sector < sector + nr_sector), but still it would leave scope for 
overflow.

Thanks again,
Raghu.


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

end of thread, other threads:[~2013-06-25  5:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-23 17:17 [PATCH] block:Remove extra condition in end of disk check Raghavendra K T
2013-06-24 13:50 ` Raghavendra K T
2013-06-24 22:51   ` Tejun Heo
2013-06-25  5:10     ` Raghavendra K T

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).