History

xen/balloon: Bring alloc(free)_xenballooned_pages helpers back

This patch rolls back some of the changes introduced by commit 121f2faca2c0a "xen/balloon: rename alloc/free_xenballooned_pages" in order to make possible to still allocate xenballooned pages if CONFIG_XEN_UNPOPULATED_ALLOC is enabled. On Arm the unpopulated pages will be allocated on top of extended regions provided by Xen via device-tree (the subsequent patches will add required bits to support unpopulated-alloc feature on Arm). The problem is that extended regions feature has been introduced into Xen quite recently (during 4.16 release cycle). So this effectively means that Linux must only use unpopulated-alloc on Arm if it is running on "new Xen" which advertises these regions. But, it will only be known after parsing the "hypervisor" node at boot time, so before doing that we cannot assume anything. In order to keep working if CONFIG_XEN_UNPOPULATED_ALLOC is enabled and the extended regions are not advertised (Linux is running on "old Xen", etc) we need the fallback to alloc_xenballooned_pages(). This way we wouldn't reduce the amount of memory usable (wasting RAM pages) for any of the external mappings anymore (and eliminate XSA-300) with "new Xen", but would be still functional ballooning out RAM pages with "old Xen". Also rename alloc(free)_xenballooned_pages to xen_alloc(free)_ballooned_pages and make xen_alloc(free)_unpopulated_pages static inline in xen.h if CONFIG_XEN_UNPOPULATED_ALLOC is disabled.

Oleksandr Tyshchenko committed 4 years ago

Commit 9dd060a1 parent 5e1cdb83 files · +26 −11Browse files

Unified · Split

3 files
  1. drivers/xen/balloon.c +9 −11
  2. include/xen/balloon.h +3 −0
  3. include/xen/xen.h +14 −0
drivers/xen/balloon.c+9−11
@@ -581,7 +581,6 @@ void balloon_set_new_target(unsigned long target) · 580 unmodified lines
581581 }
582582 EXPORT_SYMBOL_GPL(balloon_set_new_target);
583583
584−#ifndef CONFIG_XEN_UNPOPULATED_ALLOC
585584 static int add_ballooned_pages(unsigned int nr_pages)
586585 {
587586 enum bp_state st;
@@ -610,12 +609,12 @@ static int add_ballooned_pages(unsigned int nr_pages) · 22 unmodified lines
610609 }
611610
612611 /**
613− * xen_alloc_unpopulated_pages - get pages that have been ballooned out
612+ * xen_alloc_ballooned_pages - get pages that have been ballooned out
614613 * @nr_pages: Number of pages to get
615614 * @pages: pages returned
616615 * @return 0 on success, error otherwise
617616 */
618−int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)
617+int xen_alloc_ballooned_pages(unsigned int nr_pages, struct page **pages)
619618 {
620619 unsigned int pgno = 0;
621620 struct page *page;
@@ -652,23 +651,23 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages) · 30 unmodified lines
652651 return 0;
653652 out_undo:
654653 mutex_unlock(&balloon_mutex);
655− xen_free_unpopulated_pages(pgno, pages);
654+ xen_free_ballooned_pages(pgno, pages);
656655 /*
657− * NB: free_xenballooned_pages will only subtract pgno pages, but since
656+ * NB: xen_free_ballooned_pages will only subtract pgno pages, but since
658657 * target_unpopulated is incremented with nr_pages at the start we need
659658 * to remove the remaining ones also, or accounting will be screwed.
660659 */
661660 balloon_stats.target_unpopulated -= nr_pages - pgno;
662661 return ret;
663662 }
664−EXPORT_SYMBOL(xen_alloc_unpopulated_pages);
663+EXPORT_SYMBOL(xen_alloc_ballooned_pages);
665664
666665 /**
667− * xen_free_unpopulated_pages - return pages retrieved with get_ballooned_pages
666+ * xen_free_ballooned_pages - return pages retrieved with get_ballooned_pages
668667 * @nr_pages: Number of pages
669668 * @pages: pages to return
670669 */
671−void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)
670+void xen_free_ballooned_pages(unsigned int nr_pages, struct page **pages)
672671 {
673672 unsigned int i;
674673
@@ -687,9 +686,9 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages) · 12 unmodified lines
687686
688687 mutex_unlock(&balloon_mutex);
689688 }
690−EXPORT_SYMBOL(xen_free_unpopulated_pages);
689+EXPORT_SYMBOL(xen_free_ballooned_pages);
691690
692−#if defined(CONFIG_XEN_PV)
691+#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC)
693692 static void __init balloon_add_region(unsigned long start_pfn,
694693 unsigned long pages)
695694 {
@@ -712,7 +711,6 @@ static void __init balloon_add_region(unsigned long start_pfn, · 16 unmodified lines
712711 balloon_stats.total_pages += extra_pfn_end - start_pfn;
713712 }
714713 #endif
715−#endif
716714
717715 static int __init balloon_init(void)
718716 {
include/xen/balloon.h+3−0
@@ -26,6 +26,9 @@ extern struct balloon_stats balloon_stats; · 25 unmodified lines
2626
2727 void balloon_set_new_target(unsigned long target);
2828
29+int xen_alloc_ballooned_pages(unsigned int nr_pages, struct page **pages);
30+void xen_free_ballooned_pages(unsigned int nr_pages, struct page **pages);
31+
2932 #ifdef CONFIG_XEN_BALLOON
3033 void xen_balloon_init(void);
3134 #else
include/xen/xen.h+14−0
@@ -52,7 +52,21 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, · 51 unmodified lines
5252 extern u64 xen_saved_max_mem_size;
5353 #endif
5454
55+#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
5556 int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
5657 void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
58+#else
59+#include <xen/balloon.h>
60+static inline int xen_alloc_unpopulated_pages(unsigned int nr_pages,
61+ struct page **pages)
62+{
63+ return xen_alloc_ballooned_pages(nr_pages, pages);
64+}
65+static inline void xen_free_unpopulated_pages(unsigned int nr_pages,
66+ struct page **pages)
67+{
68+ xen_free_ballooned_pages(nr_pages, pages);
69+}
70+#endif
5771
5872 #endif /* _XEN_XEN_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t