| .. | .. |
|---|
| 46 | 46 | #include <linux/freezer.h> |
|---|
| 47 | 47 | #include <linux/kthread.h> |
|---|
| 48 | 48 | #include <linux/mm.h> |
|---|
| 49 | | -#include <linux/bootmem.h> |
|---|
| 49 | +#include <linux/memblock.h> |
|---|
| 50 | 50 | #include <linux/pagemap.h> |
|---|
| 51 | 51 | #include <linux/highmem.h> |
|---|
| 52 | 52 | #include <linux/mutex.h> |
|---|
| .. | .. |
|---|
| 61 | 61 | #include <linux/moduleparam.h> |
|---|
| 62 | 62 | |
|---|
| 63 | 63 | #include <asm/page.h> |
|---|
| 64 | | -#include <asm/pgalloc.h> |
|---|
| 65 | | -#include <asm/pgtable.h> |
|---|
| 66 | 64 | #include <asm/tlb.h> |
|---|
| 67 | 65 | |
|---|
| 68 | 66 | #include <asm/xen/hypervisor.h> |
|---|
| .. | .. |
|---|
| 86 | 84 | |
|---|
| 87 | 85 | #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG |
|---|
| 88 | 86 | |
|---|
| 89 | | -static int zero; |
|---|
| 90 | | -static int one = 1; |
|---|
| 91 | | - |
|---|
| 92 | 87 | static struct ctl_table balloon_table[] = { |
|---|
| 93 | 88 | { |
|---|
| 94 | 89 | .procname = "hotplug_unpopulated", |
|---|
| .. | .. |
|---|
| 96 | 91 | .maxlen = sizeof(int), |
|---|
| 97 | 92 | .mode = 0644, |
|---|
| 98 | 93 | .proc_handler = proc_dointvec_minmax, |
|---|
| 99 | | - .extra1 = &zero, |
|---|
| 100 | | - .extra2 = &one, |
|---|
| 94 | + .extra1 = SYSCTL_ZERO, |
|---|
| 95 | + .extra2 = SYSCTL_ONE, |
|---|
| 101 | 96 | }, |
|---|
| 102 | 97 | { } |
|---|
| 103 | 98 | }; |
|---|
| .. | .. |
|---|
| 166 | 161 | (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC) |
|---|
| 167 | 162 | |
|---|
| 168 | 163 | /* balloon_append: add the given page to the balloon. */ |
|---|
| 169 | | -static void __balloon_append(struct page *page) |
|---|
| 164 | +static void balloon_append(struct page *page) |
|---|
| 170 | 165 | { |
|---|
| 166 | + __SetPageOffline(page); |
|---|
| 167 | + |
|---|
| 171 | 168 | /* Lowmem is re-populated first, so highmem pages go at list tail. */ |
|---|
| 172 | 169 | if (PageHighMem(page)) { |
|---|
| 173 | 170 | list_add_tail(&page->lru, &ballooned_pages); |
|---|
| .. | .. |
|---|
| 177 | 174 | balloon_stats.balloon_low++; |
|---|
| 178 | 175 | } |
|---|
| 179 | 176 | wake_up(&balloon_wq); |
|---|
| 180 | | -} |
|---|
| 181 | | - |
|---|
| 182 | | -static void balloon_append(struct page *page) |
|---|
| 183 | | -{ |
|---|
| 184 | | - __balloon_append(page); |
|---|
| 185 | 177 | } |
|---|
| 186 | 178 | |
|---|
| 187 | 179 | /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ |
|---|
| .. | .. |
|---|
| 202 | 194 | else |
|---|
| 203 | 195 | balloon_stats.balloon_low--; |
|---|
| 204 | 196 | |
|---|
| 197 | + __ClearPageOffline(page); |
|---|
| 205 | 198 | return page; |
|---|
| 206 | 199 | } |
|---|
| 207 | 200 | |
|---|
| .. | .. |
|---|
| 277 | 270 | return NULL; |
|---|
| 278 | 271 | } |
|---|
| 279 | 272 | |
|---|
| 280 | | -#ifdef CONFIG_SPARSEMEM |
|---|
| 281 | | - { |
|---|
| 282 | | - unsigned long limit = 1UL << (MAX_PHYSMEM_BITS - PAGE_SHIFT); |
|---|
| 283 | | - unsigned long pfn = res->start >> PAGE_SHIFT; |
|---|
| 284 | | - |
|---|
| 285 | | - if (pfn > limit) { |
|---|
| 286 | | - pr_err("New System RAM resource outside addressable RAM (%lu > %lu)\n", |
|---|
| 287 | | - pfn, limit); |
|---|
| 288 | | - release_memory_resource(res); |
|---|
| 289 | | - return NULL; |
|---|
| 290 | | - } |
|---|
| 291 | | - } |
|---|
| 292 | | -#endif |
|---|
| 293 | | - |
|---|
| 294 | 273 | return res; |
|---|
| 295 | 274 | } |
|---|
| 296 | 275 | |
|---|
| .. | .. |
|---|
| 357 | 336 | mutex_unlock(&balloon_mutex); |
|---|
| 358 | 337 | /* add_memory_resource() requires the device_hotplug lock */ |
|---|
| 359 | 338 | lock_device_hotplug(); |
|---|
| 360 | | - rc = add_memory_resource(nid, resource, memhp_auto_online); |
|---|
| 339 | + rc = add_memory_resource(nid, resource, MEMHP_MERGE_RESOURCE); |
|---|
| 361 | 340 | unlock_device_hotplug(); |
|---|
| 362 | 341 | mutex_lock(&balloon_mutex); |
|---|
| 363 | 342 | |
|---|
| .. | .. |
|---|
| 374 | 353 | return BP_ECANCELED; |
|---|
| 375 | 354 | } |
|---|
| 376 | 355 | |
|---|
| 377 | | -static void xen_online_page(struct page *page) |
|---|
| 356 | +static void xen_online_page(struct page *page, unsigned int order) |
|---|
| 378 | 357 | { |
|---|
| 379 | | - __online_page_set_limits(page); |
|---|
| 358 | + unsigned long i, size = (1 << order); |
|---|
| 359 | + unsigned long start_pfn = page_to_pfn(page); |
|---|
| 360 | + struct page *p; |
|---|
| 380 | 361 | |
|---|
| 362 | + pr_debug("Online %lu pages starting at pfn 0x%lx\n", size, start_pfn); |
|---|
| 381 | 363 | mutex_lock(&balloon_mutex); |
|---|
| 382 | | - |
|---|
| 383 | | - __balloon_append(page); |
|---|
| 384 | | - |
|---|
| 364 | + for (i = 0; i < size; i++) { |
|---|
| 365 | + p = pfn_to_page(start_pfn + i); |
|---|
| 366 | + balloon_append(p); |
|---|
| 367 | + } |
|---|
| 385 | 368 | mutex_unlock(&balloon_mutex); |
|---|
| 386 | 369 | } |
|---|
| 387 | 370 | |
|---|
| .. | .. |
|---|
| 704 | 687 | } |
|---|
| 705 | 688 | EXPORT_SYMBOL(free_xenballooned_pages); |
|---|
| 706 | 689 | |
|---|
| 707 | | -#ifdef CONFIG_XEN_PV |
|---|
| 690 | +#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC) |
|---|
| 708 | 691 | static void __init balloon_add_region(unsigned long start_pfn, |
|---|
| 709 | 692 | unsigned long pages) |
|---|
| 710 | 693 | { |
|---|
| 711 | 694 | unsigned long pfn, extra_pfn_end; |
|---|
| 712 | | - struct page *page; |
|---|
| 713 | 695 | |
|---|
| 714 | 696 | /* |
|---|
| 715 | 697 | * If the amount of usable memory has been limited (e.g., with |
|---|
| .. | .. |
|---|
| 719 | 701 | extra_pfn_end = min(max_pfn, start_pfn + pages); |
|---|
| 720 | 702 | |
|---|
| 721 | 703 | for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) { |
|---|
| 722 | | - page = pfn_to_page(pfn); |
|---|
| 723 | 704 | /* totalram_pages and totalhigh_pages do not |
|---|
| 724 | 705 | include the boot-time balloon extension, so |
|---|
| 725 | 706 | don't subtract from it. */ |
|---|
| 726 | | - __balloon_append(page); |
|---|
| 707 | + balloon_append(pfn_to_page(pfn)); |
|---|
| 727 | 708 | } |
|---|
| 728 | 709 | |
|---|
| 729 | 710 | balloon_stats.total_pages += extra_pfn_end - start_pfn; |
|---|
| .. | .. |
|---|
| 762 | 743 | register_sysctl_table(xen_root); |
|---|
| 763 | 744 | #endif |
|---|
| 764 | 745 | |
|---|
| 765 | | -#ifdef CONFIG_XEN_PV |
|---|
| 746 | +#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC) |
|---|
| 766 | 747 | { |
|---|
| 767 | 748 | int i; |
|---|
| 768 | 749 | |
|---|