Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Link: https://lore.kernel.org/r/1639080336-26573-4-git-send-email-olekstysh@gmail.com
Signed-off-by: Juergen Gross <jgross@suse.com>

authored by

Oleksandr Tyshchenko and committed by
Juergen Gross
9dd060af 5e1cdb8e

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