aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/memory.c
diff options
context:
space:
mode:
authorJohn Allen <jallen@linux.vnet.ibm.com>2016-01-14 18:22:16 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-14 19:00:49 -0500
commitcb5490a5eea415106d7438df440da5fb1e17318d (patch)
tree4688bc1ae9cdfbbcc05d18bed409d0579d23a74f /drivers/base/memory.c
parentfec174d6699e2e39d34c7c6ee2fe360e518e68c0 (diff)
drivers/base/memory.c: fix kernel warning during memory hotplug on ppc64
Fix a bug where a kernel warning is triggered when performing a memory hotplug on ppc64. This warning may also occur on any architecture that uses the memory_probe_store interface. WARNING: at drivers/base/memory.c:200 CPU: 9 PID: 13042 Comm: systemd-udevd Not tainted 4.4.0-rc4-00113-g0bd0f1e-dirty #7 NIP [c00000000055e034] pages_correctly_reserved+0x134/0x1b0 LR [c00000000055e7f8] memory_subsys_online+0x68/0x140 Call Trace: memory_subsys_online+0x68/0x140 device_online+0xb4/0x120 store_mem_state+0xb0/0x180 dev_attr_store+0x34/0x60 sysfs_kf_write+0x64/0xa0 kernfs_fop_write+0x17c/0x1e0 __vfs_write+0x40/0x160 vfs_write+0xb8/0x200 SyS_write+0x60/0x110 system_call+0x38/0xd0 The warning is triggered because there is a udev rule that automatically tries to online memory after it has been added. The udev rule varies from distro to distro, but will generally look something like: SUBSYSTEM=="memory", ACTION=="add", ATTR{state}=="offline", ATTR{state}="online" On any architecture that uses memory_probe_store to reserve memory, the udev rule will be triggered after the first section of the block is reserved and will subsequently attempt to online the entire block, interrupting the memory reservation process and causing the warning. This patch modifies memory_probe_store to add a block of memory with a single call to add_memory as opposed to looping through and adding each section individually. A single call to add_memory is protected by the mem_hotplug mutex which will prevent the udev rule from onlining memory until the reservation of the entire block is complete. Signed-off-by: John Allen <jallen@linux.vnet.ibm.com> Acked-by: Dave Hansen <dave.hansen@intel.com> Cc: Nathan Fontenot <nfont@linux.vnet.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/base/memory.c')
-rw-r--r--drivers/base/memory.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 6d7b14c2798e..619fe584a44c 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -450,8 +450,7 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,
450 const char *buf, size_t count) 450 const char *buf, size_t count)
451{ 451{
452 u64 phys_addr; 452 u64 phys_addr;
453 int nid; 453 int nid, ret;
454 int i, ret;
455 unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; 454 unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block;
456 455
457 ret = kstrtoull(buf, 0, &phys_addr); 456 ret = kstrtoull(buf, 0, &phys_addr);
@@ -461,15 +460,12 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,
461 if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) 460 if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
462 return -EINVAL; 461 return -EINVAL;
463 462
464 for (i = 0; i < sections_per_block; i++) { 463 nid = memory_add_physaddr_to_nid(phys_addr);
465 nid = memory_add_physaddr_to_nid(phys_addr); 464 ret = add_memory(nid, phys_addr,
466 ret = add_memory(nid, phys_addr, 465 MIN_MEMORY_BLOCK_SIZE * sections_per_block);
467 PAGES_PER_SECTION << PAGE_SHIFT);
468 if (ret)
469 goto out;
470 466
471 phys_addr += MIN_MEMORY_BLOCK_SIZE; 467 if (ret)
472 } 468 goto out;
473 469
474 ret = count; 470 ret = count;
475out: 471out: