Skip to contentSkip to conversation

for-2.6.32/bug-fixes

GIT PULL Konrad Rzeszutek Wilk 2 participants 8 messages May 16, 2011 – May 17, 2011 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

Hey Jeremy,

Please pull from:

git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git for-2.6.32/bug-fixes

It has two bug-fixes in it. The first one is quite specific and it only handles the case if you run v2.6.32 on an IBM Summit machine. The other fixes an issue with xen-blkback wherein a barrier request would have been discarded (and an error returned) b/c the sector provided via the request was -1. The -1 sector made vbd_translate return an error (it checked the sector number against the size of the disk) and it would never go through trying to do a barrier. The second bug-fix is also in my devel/xen-blkback-v3.2 upstream tree.

Konrad Rzeszutek Wilk (2):
xen/apic: Provide an 'apic_xen' to set the override the apic->[read|write] for all cases. xen/blkback: When writting barriers set the sector number to zero...

 arch/x86/kernel/apic/probe_32.c |    4 ++++
 arch/x86/kernel/apic/probe_64.c |    4 ++++
 arch/x86/xen/enlighten.c        |   26 ++++++++++++++++++++++++++
 drivers/xen/blkback/blkback.c   |    2 ++
 4 files changed, 36 insertions(+)
#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk

with xen-blkback wherein a barrier request would have been discarded (and an error returned) b/c the sector provided via the request was -1. The -1 sector made vbd_translate return an error (it checked the sector number against the size of the disk) and it would never go through trying to do a barrier. The second bug-fix is also in my devel/xen-blkback-v3.2 upstream tree.

Is this really correct? You appear to assume that BLKIF_OP_WRITE_BARRIER always has no data, but the rest of the code in the driver (and the frontend) doesn't seem to imply that (see e.g. the check immediately following the switch statement your patch modifies). Hence shouldn't you clear the sector number only when req->nr_segments is zero? Or alternatively, shouldn't vbd_translate() simply not fail when req->nr_sects is zero?

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Jan

#2 lore raw
Quoted 19 lines
Quoted 3 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line · Konrad Rzeszutek Wilk

with xen-blkback wherein a barrier request would have been discarded (and an

error

Quoted 2 lines

returned) b/c the sector provided via the request was -1. The -1 sector made vbd_translate return an error (it checked the sector number against the size

of

Quoted 1 line

the disk) and it would never go through trying to do a barrier. The second

bug-fix

Quoted 1 line

is also in my devel/xen-blkback-v3.2 upstream tree.

Is this really correct? You appear to assume that BLKIF_OP_WRITE_BARRIER always has no data, but the rest of the code in the driver (and the frontend) doesn't seem to imply that (see e.g. the check immediately following the switch statement your patch modifies). Hence shouldn't you clear the sector number only when req->nr_segments is zero? Or alternatively, shouldn't vbd_translate() simply not fail when req->nr_sects is zero?

Quoted 2 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Altogether e.g.

Subject: xen/blkback: don't fail empty barrier requests

The sector number on empty barrier requests may (will?) be -1, which, given that it's being treated as unsigned 64-bit quantity, will almost always exceed the actual (virtual) disk's size.

Inspired by Konrad's "When writting barriers set the sector number to zero...".

While at it also add overflow checking to the math in vbd_translate().

Cc Konrad Rzeszutek Wilk <[email protected]>
drivers/xen/blkback/vbd.c +8 -2
@@ -114,8 +114,14 @@ int vbd_translate(struct phys_req *req, 
 	if (vbd->bdev == NULL)
 		goto out;
 
-	if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
-		goto out;
+	if (likely(req->nr_sects)) {
+		blkif_sector_t end = req->sector_number + req->nr_sects;
+
+		if (unlikely(end < req->sector_number))
+			goto out;
+		if (unlikely(end > vbd_sz(vbd)))
+			goto out;
+	}
 
 	req->dev  = vbd->pdevice;
 	req->bdev = vbd->bdev;
#3 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk

with xen-blkback wherein a barrier request would have been discarded (and an error returned) b/c the sector provided via the request was -1. The -1 sector made vbd_translate return an error (it checked the sector number against the size of the disk) and it would never go through trying to do a barrier. The second bug-fix is also in my devel/xen-blkback-v3.2 upstream tree.

Is this really correct? You appear to assume that BLKIF_OP_WRITE_BARRIER always has no data, but the rest of the code in the driver (and the frontend) doesn't seem to imply that (see e.g. the check immediately following the switch statement your patch modifies).

That is correct. Look at the end of the code logic (this is from the 2.6.18 hg tree):

528 if (!bio) {

529                 BUG_ON(operation != WRITE_BARRIER);
530                 bio = bio_alloc(GFP_KERNEL, 0);
531                 if (unlikely(bio == NULL))
532                         goto fail_put_bio;
533 
534                 bio->bi_bdev    = preq.bdev;
535                 bio->bi_private = pending_req;
536                 bio->bi_end_io  = end_block_io_op;
537                 bio->bi_sector  = -1;

538 }

No attaching of data to the barrier.

Quoted 2 lines

Hence shouldn't you clear the sector number only when req->nr_segments is zero? Or alternatively, shouldn't

We could do that too.

Quoted 1 line

vbd_translate() simply not fail when req->nr_sects is zero?

It does not fail when req->nr_sects is zero. It fails when it is -1.

Quoted 3 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Sure, could add that in. Albeit it seems incorrect to do it in that function. It checks to see if the sector is correct, and -1 is definitly wrong.

Quoted 2 lines

Jan

#4 lore raw
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk

with xen-blkback wherein a barrier request would have been discarded (and an

error

Quoted 2 lines
Quoted 2 lines

returned) b/c the sector provided via the request was -1. The -1 sector made vbd_translate return an error (it checked the sector number against the

size of

Quoted 1 line
Quoted 1 line

the disk) and it would never go through trying to do a barrier. The second

bug-fix

Quoted 6 lines
Quoted 1 line

is also in my devel/xen-blkback-v3.2 upstream tree.

Is this really correct? You appear to assume that BLKIF_OP_WRITE_BARRIER always has no data, but the rest of the code in the driver (and the frontend) doesn't seem to imply that (see e.g. the check immediately following the switch statement your patch modifies).

That is correct. Look at the end of the code logic (this is from the 2.6.18 hg tree):

528 if (!bio) {

529                 BUG_ON(operation != WRITE_BARRIER);
530                 bio = bio_alloc(GFP_KERNEL, 0);
531                 if (unlikely(bio == NULL))
532                         goto fail_put_bio;
533 
534                 bio->bi_bdev    = preq.bdev;
535                 bio->bi_private = pending_req;
536                 bio->bi_end_io  = end_block_io_op;
537                 bio->bi_sector  = -1;
Quoted 3 lines

538 }

No attaching of data to the barrier.

Sure, this direction we agree about. But your change is enforcing it the other way around (if barrier then no data), which wasn't the case so far.

Quoted 10 lines
Quoted 2 lines

Hence shouldn't you clear the sector number only when req->nr_segments is zero? Or alternatively, shouldn't

We could do that too.

Quoted 1 line

vbd_translate() simply not fail when req->nr_sects is zero?

It does not fail when req->nr_sects is zero. It fails when it is -1.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Sure, could add that in. Albeit it seems incorrect to do it in that function. It checks to see if the sector is correct, and -1 is definitly wrong.

Hmm, depends on your perspective - I'd say that any sector_number is valid when nr_sects is zero.

Jan

#5 lore raw
Quoted 5 lines
Quoted 1 line

No attaching of data to the barrier.

Sure, this direction we agree about. But your change is enforcing it the other way around (if barrier then no data), which wasn't the case so far.

OK, even if the code that actually does the bio submission does not attach any data to the bio? The end result is the same - no data with barriers.

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

Hence shouldn't you clear the sector number only when req->nr_segments is zero? Or alternatively, shouldn't

We could do that too.

Quoted 1 line

vbd_translate() simply not fail when req->nr_sects is zero?

It does not fail when req->nr_sects is zero. It fails when it is -1.

Quoted 3 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Quoted 6 lines
Quoted 3 lines

Sure, could add that in. Albeit it seems incorrect to do it in that function. It checks to see if the sector is correct, and -1 is definitly wrong.

Hmm, depends on your perspective - I'd say that any sector_number is valid when nr_sects is zero.

I concur. The value that is passed by the frontend is not zero. It is -1.

#6 lore raw
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines · Konrad Rzeszutek Wilk

No attaching of data to the barrier.

Sure, this direction we agree about. But your change is enforcing it the other way around (if barrier then no data), which wasn't the case so far.

OK, even if the code that actually does the bio submission does not attach any data to the bio? The end result is the same - no data with barriers.

My problem is that I can't see where attaching data would be skipped. The only thing I see is the BUG_ON() you pointed at earlier, checking that if there is no data, then this must be a barrier request.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Sure, could add that in. Albeit it seems incorrect to do it in that function. It checks to see if the sector is correct, and -1 is definitly wrong.

Hmm, depends on your perspective - I'd say that any sector_number is valid when nr_sects is zero.

I concur. The value that is passed by the frontend is not zero. It is -1.

Oh, you say both sector_number and nr_sects are -1? Looking again... No, that can't be the case, the value starts out at zero in dispatch_rw_block_io().

Jan

#7 lore raw
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines · Konrad Rzeszutek Wilk

No attaching of data to the barrier.

Sure, this direction we agree about. But your change is enforcing it the other way around (if barrier then no data), which wasn't the case so far.

Quoted 6 lines
Quoted 3 lines

OK, even if the code that actually does the bio submission does not attach any data to the bio? The end result is the same - no data with barriers.

My problem is that I can't see where attaching data would be skipped. The only thing I see is the BUG_ON() you pointed at

Well, req->ns_segments = 0, so nseg is zero, which means all of those for loops never get executed.

Quoted 10 lines

earlier, checking that if there is no data, then this must be a barrier request.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Additionally, looking at the check in vbd_translate(), wouldn't you think there ought to be overflow checking for the addition, too?

Sure, could add that in. Albeit it seems incorrect to do it in that function. It checks to see if the sector is correct, and -1 is definitly wrong.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Hmm, depends on your perspective - I'd say that any sector_number is valid when nr_sects is zero.

I concur. The value that is passed by the frontend is not zero. It is -1.

Oh, you say both sector_number and nr_sects are -1? Looking again... No, that can't be the case, the value starts out at zero in dispatch_rw_block_io().

No, wait. Argh.

The req->nr_sects is 0 and req->sector_number is -1.

This is what I got before the fix:

access denied: write of [18446744073709551615,18446744073709551615] on dev=ca0

And req->nr_segments is 0.