Skip to contentSkip to conversation

xen/balloon: check whether a page is pointed to scratch page MFN

RFC PATCH In review Wei Liu 3 participants 7 messages Sep 5, 2013 Xen hypervisor interface

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

RFC PATCH 1/1 xen/balloon: check whether a page is pointed to scratch page MFN

Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON.

---
 drivers/xen/balloon.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/xen/balloon.c +20 -1
index 3101cf6..63a7e5e 100644
@@ -305,6 +305,24 @@ static enum bp_state reserve_additional_memory(long credit)
 }
 #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
 
+static bool p2m_is_ballooned_scratch_page(unsigned long pfn)
+{
+	int cpu;
+	unsigned long bpfn;
+	struct page *bpage;
+
+	for_each_possible_cpu(cpu) {
+		bpage = per_cpu(balloon_scratch_page, cpu);
+		if (!bpage)
+			continue;
+		bpfn = page_to_pfn(bpage);
+		if (pfn_to_mfn(pfn) == pfn_to_mfn(bpfn))
+			return true;
+	}
+
+	return false;
+}
+
 static enum bp_state increase_reservation(unsigned long nr_pages)
 {
 	int rc;
@@ -350,7 +368,8 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
 
 		pfn = page_to_pfn(page);
 		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
-		       phys_to_machine_mapping_valid(pfn));
+		       phys_to_machine_mapping_valid(pfn) &&
+		       !p2m_is_ballooned_scratch_page(pfn));
 
 		set_phys_to_machine(pfn, frame_list[i]);
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 20 lines · Wei Liu

Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON.

---
 drivers/xen/balloon.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/xen/balloon.c +2 -0
index 3101cf6..63a7e5e 100644
@@ -305,6 +305,24 @@ static enum bp_state reserve_additional_memory(long credit)
 }
 #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
 
+static bool p2m_is_ballooned_scratch_page(unsigned long pfn)
+{

drivers/xen/balloon.c static enum bp_state reserve_additional_memory(long credit) · line 319

Quoted 10 lines
drivers/xen/balloon.c +10 -0
+	int cpu;
+	unsigned long bpfn;
+	struct page *bpage;
+
+	for_each_possible_cpu(cpu) {
+		bpage = per_cpu(balloon_scratch_page, cpu);
+		if (!bpage)
+			continue;
+		bpfn = page_to_pfn(bpage);
+		if (pfn_to_mfn(pfn) == pfn_to_mfn(bpfn))

Even though it is true that this function doesn't need to be very fast, we might as well try to write in an efficient way.
For example it might be worth calculating pfn_to_mfn(pfn) just once outside the loop?

Quoted 22 lines
drivers/xen/balloon.c +8 -1
+			return true;
+	}
+
+	return false;
+}
+
 static enum bp_state increase_reservation(unsigned long nr_pages)
 {
 	int rc;
@@ -350,7 +368,8 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
 
 		pfn = page_to_pfn(page);
 		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
-		       phys_to_machine_mapping_valid(pfn));
+		       phys_to_machine_mapping_valid(pfn) &&
+		       !p2m_is_ballooned_scratch_page(pfn));
 
 		set_phys_to_machine(pfn, frame_list[i]);
 
Signature · 1 line
1.7.10.4
author
#2 lore raw
Quoted 28 lines · Stefano Stabellini
Quoted 27 lines · Wei Liu

Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON.

---
 drivers/xen/balloon.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/xen/balloon.c +9 -0
index 3101cf6..63a7e5e 100644
@@ -305,6 +305,24 @@ static enum bp_state reserve_additional_memory(long credit)
 }
 #endif /* CONFIG_XEN_BALLOON_MEMORY_HOTPLUG */
 
+static bool p2m_is_ballooned_scratch_page(unsigned long pfn)
+{
+	int cpu;
+	unsigned long bpfn;
+	struct page *bpage;
+
+	for_each_possible_cpu(cpu) {
+		bpage = per_cpu(balloon_scratch_page, cpu);
+		if (!bpage)
Quoted 9 lines

drivers/xen/balloon.c static enum bp_state reserve_additional_memory(long credit) · line 319

Quoted 3 lines
drivers/xen/balloon.c +3 -0
+			continue;
+		bpfn = page_to_pfn(bpage);
+		if (pfn_to_mfn(pfn) == pfn_to_mfn(bpfn))

Even though it is true that this function doesn't need to be very fast, we might as well try to write in an efficient way.
For example it might be worth calculating pfn_to_mfn(pfn) just once outside the loop?

Good point.

#3 lore raw
In reply to Wei Liu
Quoted 4 lines · Wei Liu

Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON.

This BUG_ON() isn't useful, please just remove it.

David

author
#4 lore raw
Quoted 8 lines · David Vrabel
Quoted 4 lines · Wei Liu

Now that balloon pages might have two kind of P2M entries, a) INVALID_P2M_ENTRY when that page is never used, b) mfn of one of the many ballooned scratch pages. Refelct this in increase_reservation to avoid hitting BUG_ON.

This BUG_ON() isn't useful, please just remove it.

I'm fine with that. I'm just less confident to do so. :-)

Now that you and Stefano both voted for this option, haha.

Quoted 1 line

David

author
#5 lore raw

PATCH 1/1 xen/balloon: remove BUG_ON in increase_reservation

The BUG_ON in increase_reservation is wrong as we have P2M entry ballooned out page set to balloon scratch page, so it might have a valid P2M entry at that point.

---
 drivers/xen/balloon.c |    2 --
 1 file changed, 2 deletions(-)
drivers/xen/balloon.c +0 -2
index 3101cf6..b52df76 100644
@@ -349,8 +349,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
 		BUG_ON(page == NULL);
 
 		pfn = page_to_pfn(page);
-		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
-		       phys_to_machine_mapping_valid(pfn));
 
 		set_phys_to_machine(pfn, frame_list[i]);
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#6 lore raw

Re: [PATCH] xen/balloon: remove BUG_ON in increase_reservation

Quoted 5 lines · Wei Liu

The BUG_ON in increase_reservation is wrong as we have P2M entry ballooned out page set to balloon scratch page, so it might have a valid P2M entry at that point.

Quoted 25 lines
 drivers/xen/balloon.c |    2 --
 1 file changed, 2 deletions(-)
drivers/xen/balloon.c +0 -2
index 3101cf6..b52df76 100644
@@ -349,8 +349,6 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
 		BUG_ON(page == NULL);
 
 		pfn = page_to_pfn(page);
-		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
-		       phys_to_machine_mapping_valid(pfn));
 
 		set_phys_to_machine(pfn, frame_list[i]);
 
Signature · 7 lines
1.7.10.4


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