Skip to contentSkip to conversation

linux/balloon: Fix hugepage-related bugs

PATCH In review Dave McCracken 2 participants 2 messages Dec 21, 2009 – Dec 22, 2009 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux/balloon: Fix hugepage-related bugs

Fix a couple of bugs in the hugepage changes to the Xen balloon driver.

--------

 balloon.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
/drivers/xen/balloon.c renamed from drivers/xen/balloon.c +11 -6
@@ -283,7 +283,7 @@ static int increase_reservation(unsigned
 		/* Relinquish the page back to the allocator. */
 		ClearPageReserved(page);
 		init_page_count(page);
-		__free_page(page);
+		__free_pages(page, balloon_order);
 	}
 
 	balloon_stats.current_pages += rc;
@@ -531,12 +531,13 @@ struct page **alloc_empty_pages_and_page
 	/* Round up to next number of balloon_order pages */
 	npages = (nr_pages + (balloon_npages-1)) >> balloon_order;
 
-	pagevec = kmalloc(sizeof(page) * nr_pages << balloon_order, GFP_KERNEL);
+	pagevec = kmalloc(sizeof(page) * nr_pages, GFP_KERNEL);
 	if (pagevec == NULL)
 		return NULL;
 
-	for (i = 0; i < nr_pages; i++) {
+	for (i = 0; i < npages; i++) {
 		void *v;
+		int limit;
 
 		page = alloc_pages(GFP_KERNEL|__GFP_COLD, balloon_order);
 		if (page == NULL)
@@ -555,10 +556,14 @@ struct page **alloc_empty_pages_and_page
 		if (ret != 0) {
 			mutex_unlock(&balloon_mutex);
 			//balloon_free_page(page); /* tries to use free_cold_page */
-			__free_page(page);
+			__free_pages(page, balloon_order);
 			goto err;
 		}
-		for (j = 0; j < balloon_npages; j++)
+		if (i == (npages-1))
+			limit = nr_pages - (i << balloon_order);
+		else
+			limit = balloon_npages;
+		for (j = 0; j < limit; j++)
 			pagevec[(i<<balloon_order)+j] = page++;
 
 		totalram_pages = balloon_stats.current_pages -= balloon_npages;
@@ -595,7 +600,7 @@ void free_empty_pages_and_pagevec(struct
 	npages = (nr_pages + (balloon_npages-1)) >> balloon_order;
 
 	mutex_lock(&balloon_mutex);
-	for (i = 0; i < nr_pages; i++) {
+	for (i = 0; i < npages; i++) {
 		page = pagevec[i << balloon_order];
 		BUG_ON(page_count(page) != 1);
 		balloon_append(page);
Acked-by on v1 1/1
#1 lore raw

/drivers/xen/balloon.c void free_empty_pages_and_pagevec(struct · line 605

Quoted 9 lines
Quoted 1 line
Quoted 1 line

Dave McCracken <[email protected]> 21.12.09 20:50 >>>

/drivers/xen/balloon.c renamed from drivers/xen/balloon.c +1 -1
@@ -595,7 +600,7 @@ void free_empty_pages_and_pagevec(struct
 	npages = (nr_pages + (balloon_npages-1)) >> balloon_order;
 
 	mutex_lock(&balloon_mutex);
-	for (i = 0; i < nr_pages; i++) {
+	for (i = 0; i < npages; i++) {
 		page = pagevec[i << balloon_order];
 		BUG_ON(page_count(page) != 1);

Wouldn't it be reasonable to also extend this check to all constituent pages?

/drivers/xen/balloon.c void free_empty_pages_and_pagevec(struct · line 606

Quoted 1 line
/drivers/xen/balloon.c renamed from drivers/xen/balloon.c +0 -0
 		balloon_append(page);

Jan