IDE: Do not call bh_phys() on buffers with invalid b_page.
Hi, I just spotted this in the patch (but the code itself have been there since 2.4.20-pre2).
Review
Quoted 2 lines
(quoted diff) +1
-1- if (((unsigned long) bh->b_data) < PAGE_SIZE) + if ((unsigned long) bh->b_data < PAGE_SIZE)
Didn't you meant PAGE_OFFSET and not PAGE_SIZE here ? I fail to see why it would make any sense to compare a virtual address to PAGE_SIZE ;)
Ben.
Quoted 8 lines · Benjamin Herrenschmidt
Hi, I just spotted this in the patch (but the code itself have been there since 2.4.20-pre2).
Review
Quoted 2 lines
(quoted diff) +1
-1- if (((unsigned long) bh->b_data) < PAGE_SIZE) + if ((unsigned long) bh->b_data < PAGE_SIZE)Didn't you meant
PAGE_OFFSETand notPAGE_SIZEhere ? I fail to see why it would make any sense to compare a virtual address toPAGE_SIZE;)
For highmem buffer heads, b_data is the offset into the page. Does look confusing, I'll give you that :-)
The test should most likely just be removed, if anything.
Signature · 1 line
Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 8 lines · Benjamin Herrenschmidt
Hi, I just spotted this in the patch (but the code itself have been there since 2.4.20-pre2).
Review
Quoted 2 lines
(quoted diff) +1
-1- if (((unsigned long) bh->b_data) < PAGE_SIZE) + if ((unsigned long) bh->b_data < PAGE_SIZE)Didn't you meant
PAGE_OFFSETand notPAGE_SIZEhere ? I fail to see why it would make any sense to compare a virtual address toPAGE_SIZE;)
Quoted 4 lines
For highmem buffer heads,
b_datais the offset into the page. Does look confusing, I'll give you that :-)The test should most likely just be removed, if anything.
I would agree with you if you were actually testing that ;) Look closely, the test is in the non-b_page case, that is when b_data contains a kernel virtual address.
So the test should be either removed or moved to the first part of the if () statement.
In our case (virtual address, not page), though, it makes some sense to test that it's higher or equal than PAGE_OFFSET since virt_to_page() won't work on addresses not part of the lowmem linear mapping.
Ben.
Quoted 20 lines · Benjamin Herrenschmidt
Quoted 10 lines · Jens Axboe
Quoted 8 lines · Benjamin Herrenschmidt
Hi, I just spotted this in the patch (but the code itself have been there since 2.4.20-pre2).
Review
Quoted 2 lines
(quoted diff) +1
-1- if (((unsigned long) bh->b_data) < PAGE_SIZE) + if ((unsigned long) bh->b_data < PAGE_SIZE)Didn't you meant
PAGE_OFFSETand notPAGE_SIZEhere ? I fail to see why it would make any sense to compare a virtual address toPAGE_SIZE;)Quoted 4 lines
For highmem buffer heads,
b_datais the offset into the page. Does look confusing, I'll give you that :-)The test should most likely just be removed, if anything.
I would agree with you if you were actually testing that ;) Look closely, the test is in the non-b_page case, that is when
b_datacontains a kernel virtual address.
Quoted 6 lines
So the test should be either removed or moved to the first part of the if () statement.
In our case (virtual address, not page), though, it makes some sense to test that it's higher or equal than
PAGE_OFFSETsincevirt_to_page()won't work on addresses not part of the lowmem linear mapping.
Ehm no, if b_data is < PAGE_SIZE, it's probably an offset and not a valid address. So it should be exactly where it is -- for b_page, it's _not_ buggy for b_data to be < PAGE_SIZE. That's expected. Submitter would have to be buggy for it to trigger, though, so you can just remove it if you want.
Signature · 1 line
Jens Axboe
Quoted 5 lines · Jens Axboe
Ehm no, if
b_datais <PAGE_SIZE, it's probably an offset and not a valid address. So it should be exactly where it is -- forb_page, it's _not_ buggy forb_datato be <PAGE_SIZE. That's expected. Submitter would have to be buggy for it to trigger, though, so you can just remove it if you want.
Ah, I see what you wanted to check now :) Ok, I won't remove it, though it would still make sense to extend the test to PAGE_OFFSET I beleive, any b_data < PAGE_OFFSET is wrong.
Anyway, let's leave 2.4 as it is now.
Signature · 1 line
Benjamin Herrenschmidt <[email protected]>
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 5 lines · Jens Axboe
Ehm no, if
b_datais <PAGE_SIZE, it's probably an offset and not a valid address. So it should be exactly where it is -- forb_page, it's _not_ buggy forb_datato be <PAGE_SIZE. That's expected. Submitter would have to be buggy for it to trigger, though, so you can just remove it if you want.Ah, I see what you wanted to check now :) Ok, I won't remove it, though it would still make sense to extend the test to
PAGE_OFFSETI beleive, anyb_data<PAGE_OFFSETis wrong.
No, any b_data < PAGE_OFFSET is not wrong, that's the point. For highmem b_page, b_data will be the offset into the page. So it could be 2048, for instance.
The test is meant to catch an invalid buffer_head, where b_page is not set but b_data isn't valid either. So to make it complete, you could do:
if (bh->b_page) {
...
if (bh->b_data >= PAGE_SIZE)
BUG();
} else {
...
if (bh->b_data < PAGE_SIZE)
BUG();
if (bh->b_data < PAGE_OFFSET)
BUG();
}as they are two different bugs.
Quoted 1 line
Anyway, let's leave 2.4 as it is now.
:-)
Signature · 1 line
Jens Axboe
Quoted 3 lines · Jens Axboe
No, any
b_data<PAGE_OFFSETis not wrong, that's the point. For highmemb_page,b_datawill be the offset into the page. So it could be 2048, for instance.
In the other if() case, yes ;)
Quoted 2 lines
The test is meant to catch an invalid
buffer_head, whereb_pageis not set butb_dataisn't valid either. So to make it complete, you could do:
Yup, I undestood that.
Quoted 5 lines
if (bh->b_data < PAGE_SIZE) BUG(); if (bh->b_data < PAGE_OFFSET) BUG(); }
All I wanted to spot is that < PAGE_OFFSET would catch the PAGE_SIZE bug as well ;) But that's not a problem in real life anyway it seems.
Signature · 1 line
Benjamin Herrenschmidt <[email protected]>
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines · Jens Axboe
No, any
b_data<PAGE_OFFSETis not wrong, that's the point. For highmemb_page,b_datawill be the offset into the page. So it could be 2048, for instance.In the other
if()case, yes ;)
b_data < PAGE_SIZE would not be a bug in the other case, if PageHighmem(bh->b_page). If !PageHighmem(bh->b_page), then b_data < PAGE_OFFSET would be a bug, yes.
But lets drop this now, it's getting way silly! :)
Quoted 2 lines
All I wanted to spot is that <
PAGE_OFFSETwould catch thePAGE_SIZEbug as well ;) But that's not a problem in real life anyway it seems.
That is correct, but as I said it's nice to separate them because it's two bugs really. And the one I wanted to catch was number 1, and that's the one I put in. EOD?
Signature · 1 line
Jens Axboe