From: Herbert Xu Subject: [BLOCK] blkback: Fix potential grant entry leaks on error Date: Tue, 24 Oct 2006 16:34:32 +1000 Message-ID: <20061024063432.GA11077@gondor.apana.org.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser , Xen Development Mailing List List-Id: xen-devel@lists.xenproject.org Hi Keir: This patch is similar to the corresponding patch for blktap. [BLOCK] blkback: Fix potential grant entry leaks on error As it stands grant entries for the actual data are mapped in bulk. If one of the earlier entries fail to be mapped, it can cause all subsequent entries to be leaked if they were successfully mapped. This patch changes it so that we will continue to reap grant entries even when an error is detected. Signed-off-by: Herbert Xu Cheers, -- Visit Openswan at http://www.openswan.org/ Email: Herbert Xu ~{PmV>HI~} Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- diff -r 29b02d929b7e linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Mon Oct 23 14:42:52 2006 +0100 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Tue Oct 24 16:31:07 2006 +1000 @@ -392,16 +392,24 @@ static void dispatch_rw_block_io(blkif_t for (i = 0; i < nseg; i++) { if (unlikely(map[i].status != 0)) { DPRINTK("invalid buffer -- could not remap it\n"); - goto fail_flush; + map[i].handle = BLKBACK_INVALID_HANDLE; + ret |= 1; } pending_handle(pending_req, i) = map[i].handle; + + if (ret) + continue; + set_phys_to_machine(__pa(vaddr( pending_req, i)) >> PAGE_SHIFT, FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT)); seg[i].buf = map[i].dev_bus_addr | (req->seg[i].first_sect << 9); } + + if (ret) + goto fail_flush; if (vbd_translate(&preq, blkif, operation) != 0) { DPRINTK("access denied: %s of [%llu,%llu] on dev=%04x\n",