From 791f0d4beb9a31be6debabf79e60a3282f28b661 Mon Sep 17 00:00:00 2001 From: Andrea Reale Date: Fri, 28 Apr 2017 14:20:16 +0530 Subject: [PATCH 1/2] arm64: Add "remove" probe driver for memory hot-remove Allows to remove sections of memory that have been previously offlined from userspace. This is symmetric to the "memory probe" interface, as described in Documentation/memory-hotplug.txt. It can be used to manually notify the OS that one memory section has been removed. Please, remind that a memory section can only be removed after it has been logically off-lined; trying to remove a section which has not been previously off-lined is not supported and will have undefined (but most likely very bad) behaviour. To offline a section one can: To use the remove interface to remove the section: where 0xYYYYYY is the physical address of the memory section to remove. Change-Id: I1ab2fafe17b2697a5c667feae25c4ac0655f394e Signed-off-by: Andrea Reale Signed-off-by: Maciej Bielski Patch-mainline: linux-kernel @ 11 Apr 2017, 18:25 Signed-off-by: Srivatsa Vaddagiri Signed-off-by: Sudarshan Rajagopalan [isaacm@codeaurora.org: resolved merge conflicts due to API changes] Signed-off-by: Isaac J. Manjarres --- drivers/base/memory.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 84c4e1f72cbd..d09e52e6cfb6 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -519,7 +519,36 @@ out: } static DEVICE_ATTR_WO(probe); -#endif + +#ifdef CONFIG_MEMORY_HOTREMOVE +static ssize_t remove_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + u64 phys_addr; + int nid, ret; + unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; + + ret = kstrtoull(buf, 0, &phys_addr); + if (ret) + return ret; + + if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) + return -EINVAL; + + nid = memory_add_physaddr_to_nid(phys_addr); + ret = lock_device_hotplug_sysfs(); + if (ret) + return ret; + + remove_memory(nid, phys_addr, + MIN_MEMORY_BLOCK_SIZE * sections_per_block); + unlock_device_hotplug(); + return count; +} +static DEVICE_ATTR_WO(remove); +#endif /* CONFIG_MEMORY_HOTREMOVE */ +#endif /* CONFIG_ARCH_MEMORY_PROBE */ #ifdef CONFIG_MEMORY_FAILURE /* @@ -775,6 +804,9 @@ bool is_memblock_offlined(struct memory_block *mem) static struct attribute *memory_root_attrs[] = { #ifdef CONFIG_ARCH_MEMORY_PROBE &dev_attr_probe.attr, +#ifdef CONFIG_MEMORY_HOTREMOVE + &dev_attr_remove.attr, +#endif #endif #ifdef CONFIG_MEMORY_FAILURE From e5198921dc3b01aa16011ca815dbb80f57ef9439 Mon Sep 17 00:00:00 2001 From: Arun KS Date: Wed, 20 Sep 2017 13:20:41 +0530 Subject: [PATCH 2/2] mm/Kconfig: Enable MEMORY_HOTPLUG for arm64 Add arm64 to the list of architectures which supports memory hotplug. Change-Id: Iefeb8294bf06eaebb17a3b3aa8b33bb3b7133099 Signed-off-by: Arun KS Signed-off-by: Srivatsa Vaddagiri Signed-off-by: Sudarshan Rajagopalan Signed-off-by: Isaac J. Manjarres --- mm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/Kconfig b/mm/Kconfig index 0372bea0ca4c..63be730cea7b 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -154,6 +154,7 @@ config MEMORY_HOTPLUG bool "Allow for memory hot-add" depends on SPARSEMEM || X86_64_ACPI_NUMA depends on ARCH_ENABLE_MEMORY_HOTPLUG + depends on ARM64 config MEMORY_HOTPLUG_SPARSE def_bool y