Skip to contentSkip to conversation

Fix multiple-grant mapping logic

PATCH New Derek Murray 1 participant 1 message Jan 23, 2008 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix multiple-grant mapping logic

This patch addresses a problem that occurs when multiple grants are mapped, leading to unpredictable behaviour. It should be applied to linux-2.6.18-xen.hg, and to the sparse tree in xen-3.1-testing.hg.

# HG changeset patch
# User [email protected]
# Date 1201130148 0
# Node ID fff68c1acc8c89c42cf294924fc48d30dbb10454 # Parent 947e0701cf7aecce9e1b391f5dadbb5024e48e12 Fixed error in compress_free_list.

drivers/xen/gntdev/gntdev.c +11 -4
diff -r 947e0701cf7a -r fff68c1acc8c drivers/xen/gntdev/gntdev.c
@@ -215,6 +215,8 @@ static int add_grant_reference(struct fi
 	}
 
 	slot_index = private_data->free_list[--private_data->free_list_size];
+	private_data->free_list[private_data->free_list_size]
+		= GNTDEV_FREE_LIST_INVALID;
 
 	/* Copy the grant information into file's private data. */
 	private_data->grants[slot_index].state = GNTDEV_SLOT_NOT_YET_MAPPED;
@@ -271,13 +273,19 @@ static void compress_free_list(struct fi
 {
 	gntdev_file_private_data_t *private_data 
 		= (gntdev_file_private_data_t *) flip->private_data;
-	int i, j = 0, old_size;
+	int i, j = 0, old_size, slot_index;
 	
 	old_size = private_data->free_list_size;
 	for (i = 0; i < old_size; ++i) {
 		if (private_data->free_list[i] != GNTDEV_FREE_LIST_INVALID) {
-			private_data->free_list[j] = 
-				private_data->free_list[i];
+			if (i > j) {
+				slot_index = private_data->free_list[i];
+				private_data->free_list[j] = slot_index;
+				private_data->grants[slot_index].u
+					.free_list_index = j;
+				private_data->free_list[i] 
+					= GNTDEV_FREE_LIST_INVALID;
+			}
 			++j;
 		} else {
 			--private_data->free_list_size;
@@ -908,7 +916,6 @@ static long gntdev_ioctl(struct file *fl
 				start_index + i;
 			++private_data->free_list_size;
 		}
-		compress_free_list(flip);
 
 	unmap_out:
 		up_write(&private_data->grants_sem);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel