Skip to content

Commit 9dd060a

Browse files
Oleksandr Tyshchenkojgross1
authored andcommitted
xen/balloon: Bring alloc(free)_xenballooned_pages helpers back
This patch rolls back some of the changes introduced by commit 121f2fa "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. Signed-off-by: Oleksandr Tyshchenko <[email protected]> Reviewed-by: Stefano Stabellini <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Juergen Gross <[email protected]>
1 parent 5e1cdb8 commit 9dd060a

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

drivers/xen/balloon.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ void balloon_set_new_target(unsigned long target)
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)
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)
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)
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,
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ extern struct balloon_stats balloon_stats;
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
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 */

0 commit comments

Comments
 (0)