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
581}581}
582EXPORT_SYMBOL_GPL(balloon_set_new_target);582EXPORT_SYMBOL_GPL(balloon_set_new_target);
583 583
584#ifndef CONFIG_XEN_UNPOPULATED_ALLOC
585static int add_ballooned_pages(unsigned int nr_pages)584static int add_ballooned_pages(unsigned int nr_pages)
586{585{
587 enum bp_state st;586 enum bp_state st;
@@ -610,12 +609,12 @@ static int add_ballooned_pages(unsigned int nr_pages) · 22 unmodified lines
610}609}
611 610
612/**611/**
613 * xen_alloc_unpopulated_pages - get pages that have been ballooned out612 * xen_alloc_ballooned_pages - get pages that have been ballooned out
614 * @nr_pages: Number of pages to get613 * @nr_pages: Number of pages to get
615 * @pages: pages returned614 * @pages: pages returned
616 * @return 0 on success, error otherwise615 * @return 0 on success, error otherwise
617 */616 */
618int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)617int xen_alloc_ballooned_pages(unsigned int nr_pages, struct page **pages)
619{618{
620 unsigned int pgno = 0;619 unsigned int pgno = 0;
621 struct page *page;620 struct page *page;
@@ -652,23 +651,23 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages) · 30 unmodified lines
652 return 0;651 return 0;
653 out_undo:652 out_undo:
654 mutex_unlock(&balloon_mutex);653 mutex_unlock(&balloon_mutex);
655 xen_free_unpopulated_pages(pgno, pages);654 xen_free_ballooned_pages(pgno, pages);
656 /*655 /*
657 * NB: free_xenballooned_pages will only subtract pgno pages, but since656 * NB: xen_free_ballooned_pages will only subtract pgno pages, but since
658 * target_unpopulated is incremented with nr_pages at the start we need657 * target_unpopulated is incremented with nr_pages at the start we need
659 * to remove the remaining ones also, or accounting will be screwed.658 * to remove the remaining ones also, or accounting will be screwed.
660 */659 */
661 balloon_stats.target_unpopulated -= nr_pages - pgno;660 balloon_stats.target_unpopulated -= nr_pages - pgno;
662 return ret;661 return ret;
663}662}
664EXPORT_SYMBOL(xen_alloc_unpopulated_pages);663EXPORT_SYMBOL(xen_alloc_ballooned_pages);
665 664
666/**665/**
667 * xen_free_unpopulated_pages - return pages retrieved with get_ballooned_pages666 * xen_free_ballooned_pages - return pages retrieved with get_ballooned_pages
668 * @nr_pages: Number of pages667 * @nr_pages: Number of pages
669 * @pages: pages to return668 * @pages: pages to return
670 */669 */
671void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)670void xen_free_ballooned_pages(unsigned int nr_pages, struct page **pages)
672{671{
673 unsigned int i;672 unsigned int i;
674 673
@@ -687,9 +686,9 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages) · 12 unmodified lines
687 686
688 mutex_unlock(&balloon_mutex);687 mutex_unlock(&balloon_mutex);
689}688}
690EXPORT_SYMBOL(xen_free_unpopulated_pages);689EXPORT_SYMBOL(xen_free_ballooned_pages);
691 690
692#if defined(CONFIG_XEN_PV)691#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC)
693static void __init balloon_add_region(unsigned long start_pfn,692static void __init balloon_add_region(unsigned long start_pfn,
694 unsigned long pages)693 unsigned long pages)
695{694{
@@ -712,7 +711,6 @@ static void __init balloon_add_region(unsigned long start_pfn, · 16 unmodified lines
712 balloon_stats.total_pages += extra_pfn_end - start_pfn;711 balloon_stats.total_pages += extra_pfn_end - start_pfn;
713}712}
714#endif713#endif
715#endif
716 714
717static int __init balloon_init(void)715static int __init balloon_init(void)
718{716{
include/xen/balloon.h+3−0
@@ -26,6 +26,9 @@ extern struct balloon_stats balloon_stats; · 25 unmodified lines
26 26
27void balloon_set_new_target(unsigned long target);27void balloon_set_new_target(unsigned long target);
28 28
29int xen_alloc_ballooned_pages(unsigned int nr_pages, struct page **pages);
30void xen_free_ballooned_pages(unsigned int nr_pages, struct page **pages);
31
29#ifdef CONFIG_XEN_BALLOON32#ifdef CONFIG_XEN_BALLOON
30void xen_balloon_init(void);33void xen_balloon_init(void);
31#else34#else
include/xen/xen.h+14−0
@@ -52,7 +52,21 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, · 51 unmodified lines
52extern u64 xen_saved_max_mem_size;52extern u64 xen_saved_max_mem_size;
53#endif53#endif
54 54
55#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
55int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);56int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages);
56void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);57void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages);
58#else
59#include <xen/balloon.h>
60static 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}
65static 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
57 71
58#endif /* _XEN_XEN_H */72#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