Skip to contentSkip to conversation

xen/balloon: set ballooned out pages as invalid in p2m

PATCH In review David Vrabel 3 participants 5 messages Jul 1, 2014 – Jul 4, 2014 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/balloon: set ballooned out pages as invalid in p2m

Since cd9151e26d31048b2b5e00fd02e110e07d2200c9 (xen/balloon: set a mapping for ballooned out pages), a ballooned out page had its entry in the p2m set to the MFN of one of the scratch pages. This means that the p2m will contain many entries pointing to the same MFN.

During a domain save, these many-to-one entries are not identified as such and the scratch page is saved multiple times. On restore the ballooned pages are populated with new frames and the domain may use up its allocation before all pages can be restored.

Set ballooned out pages as INVALID_P2M_ENTRY in the p2m (as they were before), preventing them from being saved and re-populated on restore.

---
 drivers/xen/balloon.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/xen/balloon.c +5 -7
index b7a506f..5c660c7 100644
@@ -426,20 +426,18 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 		 * p2m are consistent.
 		 */
 		if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-			unsigned long p;
-			struct page   *scratch_page = get_balloon_scratch_page();
-
 			if (!PageHighMem(page)) {
+				struct page *scratch_page = get_balloon_scratch_page();
+
 				ret = HYPERVISOR_update_va_mapping(
 						(unsigned long)__va(pfn << PAGE_SHIFT),
 						pfn_pte(page_to_pfn(scratch_page),
 							PAGE_KERNEL_RO), 0);
 				BUG_ON(ret);
-			}
-			p = page_to_pfn(scratch_page);
-			__set_phys_to_machine(pfn, pfn_to_mfn(p));
 
-			put_balloon_scratch_page();
+				put_balloon_scratch_page();
+			}
+			__set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
 		}
 #endif
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · David Vrabel

Since cd9151e26d31048b2b5e00fd02e110e07d2200c9 (xen/balloon: set a mapping for ballooned out pages), a ballooned out page had its entry in the p2m set to the MFN of one of the scratch pages. This means that the p2m will contain many entries pointing to the same MFN.

Quoted 8 lines

During a domain save, these many-to-one entries are not identified as such and the scratch page is saved multiple times. On restore the ballooned pages are populated with new frames and the domain may use up its allocation before all pages can be restored.

Set ballooned out pages as INVALID_P2M_ENTRY in the p2m (as they were before), preventing them from being saved and re-populated on restore.

Won't that invalide the primal purpose of the scratch page code?

That is cd9151e26d31048b2b5e00fd02e110e07d2200c9

xen/balloon: set a mapping for ballooned out pages
" Allocate a page per cpu and map all the ballooned out pages to the
corresponding mfn. Set the p2m accordingly. This way reading from a ballooned out page won't cause a kernel crash (see
http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html).
"
?

Quoted 40 lines
---
 drivers/xen/balloon.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/xen/balloon.c +5 -7
index b7a506f..5c660c7 100644
@@ -426,20 +426,18 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
 		 * p2m are consistent.
 		 */
 		if (!xen_feature(XENFEAT_auto_translated_physmap)) {
-			unsigned long p;
-			struct page   *scratch_page = get_balloon_scratch_page();
-
 			if (!PageHighMem(page)) {
+				struct page *scratch_page = get_balloon_scratch_page();
+
 				ret = HYPERVISOR_update_va_mapping(
 						(unsigned long)__va(pfn << PAGE_SHIFT),
 						pfn_pte(page_to_pfn(scratch_page),
 							PAGE_KERNEL_RO), 0);
 				BUG_ON(ret);
-			}
-			p = page_to_pfn(scratch_page);
-			__set_phys_to_machine(pfn, pfn_to_mfn(p));
 
-			put_balloon_scratch_page();
+				put_balloon_scratch_page();
+			}
+			__set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
 		}
 #endif
 
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 19 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · David Vrabel

Since cd9151e26d31048b2b5e00fd02e110e07d2200c9 (xen/balloon: set a mapping for ballooned out pages), a ballooned out page had its entry in the p2m set to the MFN of one of the scratch pages. This means that the p2m will contain many entries pointing to the same MFN.

Quoted 8 lines

During a domain save, these many-to-one entries are not identified as such and the scratch page is saved multiple times. On restore the ballooned pages are populated with new frames and the domain may use up its allocation before all pages can be restored.

Set ballooned out pages as INVALID_P2M_ENTRY in the p2m (as they were before), preventing them from being saved and re-populated on restore.

Won't that invalide the primal purpose of the scratch page code?

That is cd9151e26d31048b2b5e00fd02e110e07d2200c9

Quoted 7 lines

xen/balloon: set a mapping for ballooned out pages
" Allocate a page per cpu and map all the ballooned out pages to the
corresponding mfn. Set the p2m accordingly. This way reading from a ballooned out page won't cause a kernel crash (see
http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html).
"
?

No, because we still have a virtual mapping for the ballooned out page.

David

#3 lore raw
Quoted 28 lines · David Vrabel
Quoted 19 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · David Vrabel

Since cd9151e26d31048b2b5e00fd02e110e07d2200c9 (xen/balloon: set a mapping for ballooned out pages), a ballooned out page had its entry in the p2m set to the MFN of one of the scratch pages. This means that the p2m will contain many entries pointing to the same MFN.

Quoted 8 lines

During a domain save, these many-to-one entries are not identified as such and the scratch page is saved multiple times. On restore the ballooned pages are populated with new frames and the domain may use up its allocation before all pages can be restored.

Set ballooned out pages as INVALID_P2M_ENTRY in the p2m (as they were before), preventing them from being saved and re-populated on restore.

Won't that invalide the primal purpose of the scratch page code?

That is cd9151e26d31048b2b5e00fd02e110e07d2200c9

Quoted 7 lines

xen/balloon: set a mapping for ballooned out pages
" Allocate a page per cpu and map all the ballooned out pages to the
corresponding mfn. Set the p2m accordingly. This way reading from a ballooned out page won't cause a kernel crash (see
http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html).
"
?

Quoted 1 line

No, because we still have a virtual mapping for the ballooned out page.

If you could add that comment in that would reflect that - IMHO it would be good.

Quoted 2 lines

David

#4 lore raw
Quoted 29 lines · Konrad Rzeszutek Wilk
Quoted 28 lines · David Vrabel
Quoted 26 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · David Vrabel

Since cd9151e26d31048b2b5e00fd02e110e07d2200c9 (xen/balloon: set a mapping for ballooned out pages), a ballooned out page had its entry in the p2m set to the MFN of one of the scratch pages. This means that the p2m will contain many entries pointing to the same MFN.

Quoted 8 lines

During a domain save, these many-to-one entries are not identified as such and the scratch page is saved multiple times. On restore the ballooned pages are populated with new frames and the domain may use up its allocation before all pages can be restored.

Set ballooned out pages as INVALID_P2M_ENTRY in the p2m (as they were before), preventing them from being saved and re-populated on restore.

Won't that invalide the primal purpose of the scratch page code?

That is cd9151e26d31048b2b5e00fd02e110e07d2200c9

xen/balloon: set a mapping for ballooned out pages
" Allocate a page per cpu and map all the ballooned out pages to the
corresponding mfn. Set the p2m accordingly. This way reading from a ballooned out page won't cause a kernel crash (see
http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html).
"
?

Quoted 4 lines
Quoted 1 line

No, because we still have a virtual mapping for the ballooned out page.

If you could add that comment in that would reflect that - IMHO it would be good.

Agreed.
Aside from that: