Skip to contentSkip to conversation

linux: Add more consistency checking to balloon code

PATCH New Jan Beulich 1 participant 1 message Mar 12, 2007 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: Add more consistency checking to balloon code

.. to catch possible problems earlier. This is only a suggested patch, not one strictly required.

drivers/xen/balloon/balloon.c +10 -0
Index: head-2007-02-27/drivers/xen/balloon/balloon.c
===================================================================
@@ -106,6 +106,8 @@ static struct timer_list balloon_timer;
 /* balloon_append: add the given page to the balloon. */
 static void balloon_append(struct page *page)
 {
+	BUG_ON(!PageReserved(page));
+
 	/* Lowmem is re-populated first, so highmem pages go at list tail. */
 	if (PageHighMem(page)) {
 		list_add_tail(PAGE_TO_LIST(page), &ballooned_pages);
@@ -132,6 +134,8 @@ static struct page *balloon_retrieve(voi
 	else
 		bs.balloon_low--;
 
+	BUG_ON(!PageReserved(page));
+
 	return page;
 }
 
@@ -293,6 +297,7 @@ static int decrease_reservation(unsigned
 	for (i = 0; i < nr_pages; i++) {
 		pfn = mfn_to_pfn(frame_list[i]);
 		set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
+		SetPageReserved(pfn_to_page(pfn));
 		balloon_append(pfn_to_page(pfn));
 	}
 
@@ -483,6 +488,7 @@ static int __init balloon_init(void)
 	for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
 		page = pfn_to_page(pfn);
 		if (!PageReserved(page))
+			SetPageReserved(page),
 			balloon_append(page);
 	}
 #endif
@@ -560,6 +566,8 @@ struct page **alloc_empty_pages_and_page
 		} else {
 			ret = apply_to_page_range(&init_mm, vaddr, PAGE_SIZE,
 						  dealloc_pte_fn, NULL);
+			if (ret == 0)
+				SetPageReserved(page);
 		}
 
 		if (ret != 0) {
@@ -599,6 +607,7 @@ static void free_empty_pages_and_pageve
 	balloon_lock(flags);
 	for (i = 0; i < nr_pages; i++) {
 		BUG_ON(page_count(pagevec[i]) != 1);
+		set_phys_to_machine(page_to_pfn(pagevec[i]), INVALID_P2M_ENTRY);
 		balloon_append(pagevec[i]);
 	}
 	balloon_unlock(flags);
@@ -613,6 +622,7 @@ void balloon_release_driver_page(struct 
 	unsigned long flags;
 
 	balloon_lock(flags);
+	set_phys_to_machine(page_to_pfn(page), INVALID_P2M_ENTRY);
 	balloon_append(page);
 	bs.driver_pages--;
 	balloon_unlock(flags);