Skip to content

Commit 8c0bacc

Browse files
Boaz Harroshjejb
authored andcommitted
[SCSI] libosd: fix blk_put_request called from within request_end_io
A fix for a very serious and stupid bug in osd_initiator. It used to call blk_put_request() regardless of if it was from the end_io callback or if called after a sync execution. It should call the unlocked version __blk_put_request() instead. Also fixed is the remove of _abort_unexecuted_bios hack, and use of blk_end_request(,-ERROR,) to deallocate half baked requests. I've audited the code and it should be safe. Reported and Tested-by: Xu Yang <onlyxuyang@qq.com> Signed-off-by: Boaz Harrosh <bharrosh@panasas.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent a9bddd7 commit 8c0bacc

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

‎drivers/scsi/osd/osd_initiator.c‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,6 @@ struct osd_request *osd_start_request(struct osd_dev *dev, gfp_t gfp)
338338
}
339339
EXPORT_SYMBOL(osd_start_request);
340340

341-
/*
342-
* If osd_finalize_request() was called but the request was not executed through
343-
* the block layer, then we must release BIOs.
344-
*/
345-
static void _abort_unexecuted_bios(struct request *rq)
346-
{
347-
struct bio *bio;
348-
349-
while ((bio = rq->bio) != NULL) {
350-
rq->bio = bio->bi_next;
351-
bio_endio(bio, 0);
352-
}
353-
}
354-
355341
static void _osd_free_seg(struct osd_request *or __unused,
356342
struct _osd_req_data_segment *seg)
357343
{
@@ -363,22 +349,42 @@ static void _osd_free_seg(struct osd_request *or __unused,
363349
seg->alloc_size = 0;
364350
}
365351

352+
static void _put_request(struct request *rq , bool is_async)
353+
{
354+
if (is_async) {
355+
WARN_ON(rq->bio);
356+
__blk_put_request(rq->q, rq);
357+
} else {
358+
/*
359+
* If osd_finalize_request() was called but the request was not
360+
* executed through the block layer, then we must release BIOs.
361+
* TODO: Keep error code in or->async_error. Need to audit all
362+
* code paths.
363+
*/
364+
if (unlikely(rq->bio))
365+
blk_end_request(rq, -ENOMEM, blk_rq_bytes(rq));
366+
else
367+
blk_put_request(rq);
368+
}
369+
}
370+
366371
void osd_end_request(struct osd_request *or)
367372
{
368373
struct request *rq = or->request;
374+
/* IMPORTANT: make sure this agrees with osd_execute_request_async */
375+
bool is_async = (or->request->end_io_data == or);
369376

370377
_osd_free_seg(or, &or->set_attr);
371378
_osd_free_seg(or, &or->enc_get_attr);
372379
_osd_free_seg(or, &or->get_attr);
373380

374381
if (rq) {
375382
if (rq->next_rq) {
376-
_abort_unexecuted_bios(rq->next_rq);
377-
blk_put_request(rq->next_rq);
383+
_put_request(rq->next_rq, is_async);
384+
rq->next_rq = NULL;
378385
}
379386

380-
_abort_unexecuted_bios(rq);
381-
blk_put_request(rq);
387+
_put_request(rq, is_async);
382388
}
383389
_osd_request_free(or);
384390
}

0 commit comments

Comments
 (0)