public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <jens.axboe@oracle.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Pete Wyckoff <pw@osc.edu>,
	FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH] bsg: bidi bio map failure fix
Date: Mon, 18 Feb 2008 13:55:08 +0100	[thread overview]
Message-ID: <20080218125508.GA23197@kernel.dk> (raw)
In-Reply-To: <1202850758.3137.135.camel@localhost.localdomain>

On Tue, Feb 12 2008, James Bottomley wrote:
> On Tue, 2008-02-12 at 15:40 -0500, Pete Wyckoff wrote:
> > If blk_rq_map_user requires more than one bio, and fails mapping
> > somewhere after the first bio, it will return with rq->bio set to
> > non-NULL, but it will have already unmapped the partial bio.  The
> > "out:" error exit section will see the non-null bio and try to unmap
> > it again, triggering a mapcount bug via bad_page().
> > 
> > Signed-off-by: Pete Wyckoff <pw@osc.edu>
> > ---
> >  block/bsg.c |    4 +++-
> >  1 files changed, 3 insertions(+), 1 deletions(-)
> > 
> > diff --git a/block/bsg.c b/block/bsg.c
> > index 3337125..bba7154 100644
> > --- a/block/bsg.c
> > +++ b/block/bsg.c
> > @@ -295,8 +295,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr)
> >  
> >  		dxferp = (void*)(unsigned long)hdr->din_xferp;
> >  		ret =  blk_rq_map_user(q, next_rq, dxferp, hdr->din_xfer_len);
> > -		if (ret)
> > +		if (ret) {
> > +			next_rq->bio = NULL;  /* do not unmap twice */
> 
> Nice ... that's a nasty asymmetry of the blk_rq_map_user API.  The map
> takes a request gets a ref and fills in the bio.  The unmap has to be
> called on the bio leaving you to clear the now removed bio reference
> manually.

It is nasty, how about fixing that instead?

diff --git a/block/blk-map.c b/block/blk-map.c
index 955d75c..bc5ce60 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -143,6 +143,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
 	return 0;
 unmap_rq:
 	blk_rq_unmap_user(bio);
+	rq->bio = NULL;
 	return ret;
 }
 EXPORT_SYMBOL(blk_rq_map_user);

-- 
Jens Axboe


  reply	other threads:[~2008-02-18 12:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-12 20:40 [PATCH] bsg: bidi bio map failure fix Pete Wyckoff
2008-02-12 21:12 ` James Bottomley
2008-02-18 12:55   ` Jens Axboe [this message]
2008-02-18 14:37     ` FUJITA Tomonori
2008-02-18 14:46       ` Jens Axboe
2008-02-18 15:09         ` James Bottomley
2008-02-18 15:24           ` FUJITA Tomonori
2008-02-18 17:25           ` Jens Axboe
2008-02-18 14:54       ` James Bottomley
2008-02-14 11:57 ` FUJITA Tomonori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080218125508.GA23197@kernel.dk \
    --to=jens.axboe@oracle.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-scsi@vger.kernel.org \
    --cc=pw@osc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox