[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 24/24] xen/pvshim: memory hotplug
From: Roger Pau Monne <roger.pau@xxxxxxxxxx> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx> --- v2 -> v3 - adapted for Vixen --- xen/arch/x86/guest/vixen.c | 110 ++++++++++++++++++++++++++++++++++++++ xen/common/memory.c | 14 +++++ xen/include/asm-x86/guest/vixen.h | 4 ++ 3 files changed, 128 insertions(+) diff --git a/xen/arch/x86/guest/vixen.c b/xen/arch/x86/guest/vixen.c index 7e367ef..4d59cd8 100644 --- a/xen/arch/x86/guest/vixen.c +++ b/xen/arch/x86/guest/vixen.c @@ -48,6 +48,9 @@ static volatile struct xencons_interface *vixen_xencons_iface; static uint16_t vixen_xencons_port; static spinlock_t vixen_xencons_lock; +static PAGE_LIST_HEAD(balloon); +static DEFINE_SPINLOCK(balloon_lock); + integer_param("vixen_domid", vixen_domid); boolean_param("vixen_ptver", vixen_ptver); @@ -558,3 +561,110 @@ vixen_transform(struct domain *dom0, share_xen_page_with_guest(mfn_to_page(xatp.gpfn), dom0, XENSHARE_writable); } } + +static unsigned long batch_memory_op(int cmd, struct page_list_head *list) +{ + struct xen_memory_reservation xmr = { + .domid = DOMID_SELF, + }; + unsigned long pfns[64]; + struct page_info *pg; + unsigned long done = 0; + + set_xen_guest_handle(xmr.extent_start, pfns); + page_list_for_each ( pg, list ) + { + pfns[xmr.nr_extents++] = page_to_mfn(pg); + if ( xmr.nr_extents == ARRAY_SIZE(pfns) || !page_list_next(pg, list) ) + { + long nr = xen_hypercall_memory_op(cmd, &xmr); + + done += nr > 0 ? nr : 0; + if ( nr != xmr.nr_extents ) + break; + xmr.nr_extents = 0; + } + } + + return done; +} + +void vixen_online_memory(unsigned int nr, unsigned int order) +{ + struct page_info *page, *tmp; + PAGE_LIST_HEAD(list); + + spin_lock(&balloon_lock); + page_list_for_each_safe ( page, tmp, &balloon ) + { + if ( page->v.free.order != order ) + continue; + + page_list_del(page, &balloon); + page_list_add_tail(page, &list); + if ( !--nr ) + break; + } + spin_unlock(&balloon_lock); + + if ( nr ) + gprintk(XENLOG_WARNING, + "failed to allocate %u extents of order %u for onlining\n", + nr, order); + + nr = batch_memory_op(XENMEM_populate_physmap, &list); + while ( nr-- ) + { + BUG_ON((page = page_list_remove_head(&list)) == NULL); + free_domheap_pages(page, order); + } + + if ( !page_list_empty(&list) ) + { + gprintk(XENLOG_WARNING, + "failed to online some of the memory regions\n"); + spin_lock(&balloon_lock); + while ( (page = page_list_remove_head(&list)) != NULL ) + page_list_add_tail(page, &balloon); + spin_unlock(&balloon_lock); + } +} + +void vixen_offline_memory(unsigned int nr, unsigned int order) +{ + struct page_info *page; + PAGE_LIST_HEAD(list); + + while ( nr-- ) + { + page = alloc_domheap_pages(NULL, order, 0); + if ( !page ) + break; + + page_list_add_tail(page, &list); + page->v.free.order = order; + } + + if ( nr + 1 ) + gprintk(XENLOG_WARNING, + "failed to reserve %u extents of order %u for offlining\n", + nr + 1, order); + + + nr = batch_memory_op(XENMEM_decrease_reservation, &list); + spin_lock(&balloon_lock); + while ( nr-- ) + { + BUG_ON((page = page_list_remove_head(&list)) == NULL); + page_list_add_tail(page, &balloon); + } + spin_unlock(&balloon_lock); + + if ( !page_list_empty(&list) ) + { + gprintk(XENLOG_WARNING, + "failed to offline some of the memory regions\n"); + while ( (page = page_list_remove_head(&list)) != NULL ) + free_domheap_pages(page, order); + } +} diff --git a/xen/common/memory.c b/xen/common/memory.c index 5a1508a..5a7ecf0 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -29,6 +29,10 @@ #include <public/memory.h> #include <xsm/xsm.h> +#ifdef CONFIG_X86 +#include <asm/guest/vixen.h> +#endif + struct memop_args { /* INPUT */ struct domain *domain; /* Domain to be affected. */ @@ -993,6 +997,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) return start_extent; } +#ifdef CONFIG_X86 + if ( is_vixen() && op != XENMEM_decrease_reservation && !args.nr_done ) + vixen_online_memory(args.nr_extents, args.extent_order); +#endif + switch ( op ) { case XENMEM_increase_reservation: @@ -1015,6 +1024,11 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) __HYPERVISOR_memory_op, "lh", op | (rc << MEMOP_EXTENT_SHIFT), arg); +#ifdef CONFIG_X86 + if ( is_vixen() && op == XENMEM_decrease_reservation ) + vixen_offline_memory(args.nr_extents, args.extent_order); +#endif + break; case XENMEM_exchange: diff --git a/xen/include/asm-x86/guest/vixen.h b/xen/include/asm-x86/guest/vixen.h index 851281d..35d7593 100644 --- a/xen/include/asm-x86/guest/vixen.h +++ b/xen/include/asm-x86/guest/vixen.h @@ -93,4 +93,8 @@ vixen_transform(struct domain *dom0, bool vixen_ring_process(uint16_t port); +void vixen_online_memory(unsigned int nr, unsigned int order); + +void vixen_offline_memory(unsigned int nr, unsigned int order); + #endif -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |