ia64/xen-unstable

changeset 11910:068aed15496d

[BLKTAP]: 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.

There is still a potential leak if create_lookup_pte_addr fails
in fast_flush_area. This leak is not affected by this patch.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
author kfraser@localhost.localdomain
date Fri Oct 20 09:28:31 2006 +0100 (2006-10-20)
parents bb76521fdcb3
children 49d16162a585
files linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Fri Oct 20 09:24:26 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Fri Oct 20 09:28:31 2006 +0100
     1.3 @@ -845,28 +845,29 @@ static void fast_flush_area(pending_req_
     1.4  		uvaddr = MMAP_VADDR(info->user_vstart, u_idx, i);
     1.5  
     1.6  		khandle = &pending_handle(mmap_idx, k_idx, i);
     1.7 -		if (BLKTAP_INVALID_HANDLE(khandle)) {
     1.8 -			WPRINTK("BLKTAP_INVALID_HANDLE\n");
     1.9 -			continue;
    1.10 -		}
    1.11 -		gnttab_set_unmap_op(&unmap[invcount], 
    1.12 -				    idx_to_kaddr(mmap_idx, k_idx, i), 
    1.13 -				    GNTMAP_host_map, khandle->kernel);
    1.14 -		invcount++;
    1.15  
    1.16 -		if (create_lookup_pte_addr(
    1.17 -		    info->vma->vm_mm,
    1.18 -		    MMAP_VADDR(info->user_vstart, u_idx, i), 
    1.19 -		    &ptep) !=0) {
    1.20 -			WPRINTK("Couldn't get a pte addr!\n");
    1.21 -			return;
    1.22 +		if (khandle->kernel != 0xFFFF) {
    1.23 +			gnttab_set_unmap_op(&unmap[invcount],
    1.24 +					    idx_to_kaddr(mmap_idx, k_idx, i),
    1.25 +					    GNTMAP_host_map, khandle->kernel);
    1.26 +			invcount++;
    1.27  		}
    1.28  
    1.29 -		gnttab_set_unmap_op(&unmap[invcount], 
    1.30 -			ptep, GNTMAP_host_map,
    1.31 -			khandle->user);
    1.32 -		invcount++;
    1.33 -            
    1.34 +		if (khandle->user != 0xFFFF) {
    1.35 +			if (create_lookup_pte_addr(
    1.36 +				info->vma->vm_mm,
    1.37 +				MMAP_VADDR(info->user_vstart, u_idx, i),
    1.38 +				&ptep) !=0) {
    1.39 +				WPRINTK("Couldn't get a pte addr!\n");
    1.40 +				return;
    1.41 +			}
    1.42 +
    1.43 +			gnttab_set_unmap_op(&unmap[invcount],
    1.44 +					    ptep, GNTMAP_host_map,
    1.45 +					    khandle->user);
    1.46 +			invcount++;
    1.47 +		}
    1.48 +
    1.49  		BLKTAP_INVALIDATE_HANDLE(khandle);
    1.50  	}
    1.51  	ret = HYPERVISOR_grant_table_op(
    1.52 @@ -1223,19 +1224,25 @@ static void dispatch_rw_block_io(blkif_t
    1.53  		if (unlikely(map[i].status != 0)) {
    1.54  			WPRINTK("invalid kernel buffer -- "
    1.55  				"could not remap it\n");
    1.56 -			goto fail_flush;
    1.57 +			ret |= 1;
    1.58 +			map[i].handle = 0xFFFF;
    1.59  		}
    1.60  
    1.61  		if (unlikely(map[i+1].status != 0)) {
    1.62  			WPRINTK("invalid user buffer -- "
    1.63  				"could not remap it\n");
    1.64 -			goto fail_flush;
    1.65 +			ret |= 1;
    1.66 +			map[i+1].handle = 0xFFFF;
    1.67  		}
    1.68  
    1.69  		pending_handle(mmap_idx, pending_idx, i/2).kernel 
    1.70  			= map[i].handle;
    1.71  		pending_handle(mmap_idx, pending_idx, i/2).user   
    1.72  			= map[i+1].handle;
    1.73 +
    1.74 +		if (ret)
    1.75 +			continue;
    1.76 +
    1.77  		set_phys_to_machine(__pa(kvaddr) >> PAGE_SHIFT,
    1.78  			FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT));
    1.79  		offset = (uvaddr - info->vma->vm_start) >> PAGE_SHIFT;
    1.80 @@ -1243,6 +1250,10 @@ static void dispatch_rw_block_io(blkif_t
    1.81  		((struct page **)info->vma->vm_private_data)[offset] =
    1.82  			pg;
    1.83  	}
    1.84 +
    1.85 +	if (ret)
    1.86 +		goto fail_flush;
    1.87 +
    1.88  	/* Mark mapped pages as reserved: */
    1.89  	for (i = 0; i < req->nr_segments; i++) {
    1.90  		unsigned long kvaddr;