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

mm/memory_hotplug: prepare passing flags to add_memory() and friends

We soon want to pass flags, e.g., to mark added System RAM resources.
mergeable. Prepare for that.

This patch is based on a similar patch by Oscar Salvador:

https://lkml.kernel.org/r/20190625075227.15193-3-osalvador@suse.de

Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Juergen Gross <jgross@suse.com> # Xen related part
Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Acked-by: Wei Liu <wei.liu@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Baoquan He <bhe@redhat.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: "Oliver O'Halloran" <oohall@gmail.com>
Cc: Pingfan Liu <kernelfans@gmail.com>
Cc: Nathan Lynch <nathanl@linux.ibm.com>
Cc: Libor Pechacek <lpechacek@suse.cz>
Cc: Anton Blanchard <anton@ozlabs.org>
Cc: Leonardo Bras <leobras.c@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Julien Grall <julien@xen.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Roger Pau Monné <roger.pau@citrix.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richardw.yang@linux.intel.com>
Link: https://lkml.kernel.org/r/20200911103459.10306-5-david@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Hildenbrand and committed by
Linus Torvalds
b6117199 3a0aaefe

+30 -20
+1 -1
arch/powerpc/platforms/powernv/memtrace.c
··· 224 224 ent->mem = 0; 225 225 } 226 226 227 - if (add_memory(ent->nid, ent->start, ent->size)) { 227 + if (add_memory(ent->nid, ent->start, ent->size, MHP_NONE)) { 228 228 pr_err("Failed to add trace memory to node %d\n", 229 229 ent->nid); 230 230 ret += 1;
+1 -1
arch/powerpc/platforms/pseries/hotplug-memory.c
··· 606 606 block_sz = memory_block_size_bytes(); 607 607 608 608 /* Add the memory */ 609 - rc = __add_memory(lmb->nid, lmb->base_addr, block_sz); 609 + rc = __add_memory(lmb->nid, lmb->base_addr, block_sz, MHP_NONE); 610 610 if (rc) { 611 611 invalidate_lmb_associativity_index(lmb); 612 612 return rc;
+2 -1
drivers/acpi/acpi_memhotplug.c
··· 194 194 if (node < 0) 195 195 node = memory_add_physaddr_to_nid(info->start_addr); 196 196 197 - result = __add_memory(node, info->start_addr, info->length); 197 + result = __add_memory(node, info->start_addr, info->length, 198 + MHP_NONE); 198 199 199 200 /* 200 201 * If the memory block has been used by the kernel, add_memory()
+2 -1
drivers/base/memory.c
··· 432 432 433 433 nid = memory_add_physaddr_to_nid(phys_addr); 434 434 ret = __add_memory(nid, phys_addr, 435 - MIN_MEMORY_BLOCK_SIZE * sections_per_block); 435 + MIN_MEMORY_BLOCK_SIZE * sections_per_block, 436 + MHP_NONE); 436 437 437 438 if (ret) 438 439 goto out;
+1 -1
drivers/dax/kmem.c
··· 109 109 * this as RAM automatically. 110 110 */ 111 111 rc = add_memory_driver_managed(numa_node, range.start, 112 - range_len(&range), kmem_name); 112 + range_len(&range), kmem_name, MHP_NONE); 113 113 114 114 if (rc) { 115 115 dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n",
+1 -1
drivers/hv/hv_balloon.c
··· 726 726 727 727 nid = memory_add_physaddr_to_nid(PFN_PHYS(start_pfn)); 728 728 ret = add_memory(nid, PFN_PHYS((start_pfn)), 729 - (HA_CHUNK << PAGE_SHIFT)); 729 + (HA_CHUNK << PAGE_SHIFT), MHP_NONE); 730 730 731 731 if (ret) { 732 732 pr_err("hot_add memory failed error is %d\n", ret);
+1 -1
drivers/s390/char/sclp_cmd.c
··· 406 406 if (!size) 407 407 goto skip_add; 408 408 for (addr = start; addr < start + size; addr += block_size) 409 - add_memory(0, addr, block_size); 409 + add_memory(0, addr, block_size, MHP_NONE); 410 410 skip_add: 411 411 first_rn = rn; 412 412 num = 1;
+1 -1
drivers/virtio/virtio_mem.c
··· 424 424 425 425 dev_dbg(&vm->vdev->dev, "adding memory block: %lu\n", mb_id); 426 426 return add_memory_driver_managed(nid, addr, memory_block_size_bytes(), 427 - vm->resource_name); 427 + vm->resource_name, MHP_NONE); 428 428 } 429 429 430 430 /*
+1 -1
drivers/xen/balloon.c
··· 331 331 mutex_unlock(&balloon_mutex); 332 332 /* add_memory_resource() requires the device_hotplug lock */ 333 333 lock_device_hotplug(); 334 - rc = add_memory_resource(nid, resource); 334 + rc = add_memory_resource(nid, resource, MHP_NONE); 335 335 unlock_device_hotplug(); 336 336 mutex_lock(&balloon_mutex); 337 337
+12 -4
include/linux/memory_hotplug.h
··· 57 57 MMOP_ONLINE_MOVABLE, 58 58 }; 59 59 60 + /* Flags for add_memory() and friends to specify memory hotplug details. */ 61 + typedef int __bitwise mhp_t; 62 + 63 + /* No special request */ 64 + #define MHP_NONE ((__force mhp_t)0) 65 + 60 66 /* 61 67 * Extended parameters for memory hotplug: 62 68 * altmap: alternative allocator for memmap array (optional) ··· 345 339 346 340 #ifdef CONFIG_MEMORY_HOTPLUG 347 341 extern void __ref free_area_init_core_hotplug(int nid); 348 - extern int __add_memory(int nid, u64 start, u64 size); 349 - extern int add_memory(int nid, u64 start, u64 size); 350 - extern int add_memory_resource(int nid, struct resource *resource); 342 + extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); 343 + extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); 344 + extern int add_memory_resource(int nid, struct resource *resource, 345 + mhp_t mhp_flags); 351 346 extern int add_memory_driver_managed(int nid, u64 start, u64 size, 352 - const char *resource_name); 347 + const char *resource_name, 348 + mhp_t mhp_flags); 353 349 extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, 354 350 unsigned long nr_pages, 355 351 struct vmem_altmap *altmap, int migratetype);
+7 -7
mm/memory_hotplug.c
··· 1039 1039 * 1040 1040 * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG 1041 1041 */ 1042 - int __ref add_memory_resource(int nid, struct resource *res) 1042 + int __ref add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) 1043 1043 { 1044 1044 struct mhp_params params = { .pgprot = PAGE_KERNEL }; 1045 1045 u64 start, size; ··· 1119 1119 } 1120 1120 1121 1121 /* requires device_hotplug_lock, see add_memory_resource() */ 1122 - int __ref __add_memory(int nid, u64 start, u64 size) 1122 + int __ref __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) 1123 1123 { 1124 1124 struct resource *res; 1125 1125 int ret; ··· 1128 1128 if (IS_ERR(res)) 1129 1129 return PTR_ERR(res); 1130 1130 1131 - ret = add_memory_resource(nid, res); 1131 + ret = add_memory_resource(nid, res, mhp_flags); 1132 1132 if (ret < 0) 1133 1133 release_memory_resource(res); 1134 1134 return ret; 1135 1135 } 1136 1136 1137 - int add_memory(int nid, u64 start, u64 size) 1137 + int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) 1138 1138 { 1139 1139 int rc; 1140 1140 1141 1141 lock_device_hotplug(); 1142 - rc = __add_memory(nid, start, size); 1142 + rc = __add_memory(nid, start, size, mhp_flags); 1143 1143 unlock_device_hotplug(); 1144 1144 1145 1145 return rc; ··· 1168 1168 * "System RAM ($DRIVER)". 1169 1169 */ 1170 1170 int add_memory_driver_managed(int nid, u64 start, u64 size, 1171 - const char *resource_name) 1171 + const char *resource_name, mhp_t mhp_flags) 1172 1172 { 1173 1173 struct resource *res; 1174 1174 int rc; ··· 1186 1186 goto out_unlock; 1187 1187 } 1188 1188 1189 - rc = add_memory_resource(nid, res); 1189 + rc = add_memory_resource(nid, res, mhp_flags); 1190 1190 if (rc < 0) 1191 1191 release_memory_resource(res); 1192 1192