hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/xen/balloon.c
....@@ -46,7 +46,7 @@
4646 #include <linux/freezer.h>
4747 #include <linux/kthread.h>
4848 #include <linux/mm.h>
49
-#include <linux/bootmem.h>
49
+#include <linux/memblock.h>
5050 #include <linux/pagemap.h>
5151 #include <linux/highmem.h>
5252 #include <linux/mutex.h>
....@@ -61,8 +61,6 @@
6161 #include <linux/moduleparam.h>
6262
6363 #include <asm/page.h>
64
-#include <asm/pgalloc.h>
65
-#include <asm/pgtable.h>
6664 #include <asm/tlb.h>
6765
6866 #include <asm/xen/hypervisor.h>
....@@ -86,9 +84,6 @@
8684
8785 #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
8886
89
-static int zero;
90
-static int one = 1;
91
-
9287 static struct ctl_table balloon_table[] = {
9388 {
9489 .procname = "hotplug_unpopulated",
....@@ -96,8 +91,8 @@
9691 .maxlen = sizeof(int),
9792 .mode = 0644,
9893 .proc_handler = proc_dointvec_minmax,
99
- .extra1 = &zero,
100
- .extra2 = &one,
94
+ .extra1 = SYSCTL_ZERO,
95
+ .extra2 = SYSCTL_ONE,
10196 },
10297 { }
10398 };
....@@ -166,8 +161,10 @@
166161 (GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
167162
168163 /* 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)
170165 {
166
+ __SetPageOffline(page);
167
+
171168 /* Lowmem is re-populated first, so highmem pages go at list tail. */
172169 if (PageHighMem(page)) {
173170 list_add_tail(&page->lru, &ballooned_pages);
....@@ -177,11 +174,6 @@
177174 balloon_stats.balloon_low++;
178175 }
179176 wake_up(&balloon_wq);
180
-}
181
-
182
-static void balloon_append(struct page *page)
183
-{
184
- __balloon_append(page);
185177 }
186178
187179 /* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
....@@ -202,6 +194,7 @@
202194 else
203195 balloon_stats.balloon_low--;
204196
197
+ __ClearPageOffline(page);
205198 return page;
206199 }
207200
....@@ -277,20 +270,6 @@
277270 return NULL;
278271 }
279272
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
-
294273 return res;
295274 }
296275
....@@ -357,7 +336,7 @@
357336 mutex_unlock(&balloon_mutex);
358337 /* add_memory_resource() requires the device_hotplug lock */
359338 lock_device_hotplug();
360
- rc = add_memory_resource(nid, resource, memhp_auto_online);
339
+ rc = add_memory_resource(nid, resource, MEMHP_MERGE_RESOURCE);
361340 unlock_device_hotplug();
362341 mutex_lock(&balloon_mutex);
363342
....@@ -374,14 +353,18 @@
374353 return BP_ECANCELED;
375354 }
376355
377
-static void xen_online_page(struct page *page)
356
+static void xen_online_page(struct page *page, unsigned int order)
378357 {
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;
380361
362
+ pr_debug("Online %lu pages starting at pfn 0x%lx\n", size, start_pfn);
381363 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
+ }
385368 mutex_unlock(&balloon_mutex);
386369 }
387370
....@@ -704,12 +687,11 @@
704687 }
705688 EXPORT_SYMBOL(free_xenballooned_pages);
706689
707
-#ifdef CONFIG_XEN_PV
690
+#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC)
708691 static void __init balloon_add_region(unsigned long start_pfn,
709692 unsigned long pages)
710693 {
711694 unsigned long pfn, extra_pfn_end;
712
- struct page *page;
713695
714696 /*
715697 * If the amount of usable memory has been limited (e.g., with
....@@ -719,11 +701,10 @@
719701 extra_pfn_end = min(max_pfn, start_pfn + pages);
720702
721703 for (pfn = start_pfn; pfn < extra_pfn_end; pfn++) {
722
- page = pfn_to_page(pfn);
723704 /* totalram_pages and totalhigh_pages do not
724705 include the boot-time balloon extension, so
725706 don't subtract from it. */
726
- __balloon_append(page);
707
+ balloon_append(pfn_to_page(pfn));
727708 }
728709
729710 balloon_stats.total_pages += extra_pfn_end - start_pfn;
....@@ -762,7 +743,7 @@
762743 register_sysctl_table(xen_root);
763744 #endif
764745
765
-#ifdef CONFIG_XEN_PV
746
+#if defined(CONFIG_XEN_PV) && !defined(CONFIG_XEN_UNPOPULATED_ALLOC)
766747 {
767748 int i;
768749