memory-hotplug: Fix kernel warning during memory hotplug on ppc64
Subsystems (2)
PATCH 1/1 memory-hotplug: Fix kernel warning during memory hotplug on ppc64
This patch fixes a bug where a kernel warning is triggered when performing a memory hotplug on ppc64. This warning may also occur on any architecture that has multiple sections per memory block.
[ 78.300767] ------------[ cut here ]------------ [ 78.300768] WARNING: at ../drivers/base/memory.c:210 [ 78.300769] Modules linked in: rpadlpar_io(X) rpaphp(X) tcp_diag udp_diag inet_diag unix_diag af_packet_diag netlink_diag af_packet xfs libcrc32c ibmveth(X) rtc_generic btrfs xor raid6_pq xts gf128mul dm_crypt sd_mod sr_mod cdrom crc_t10dif ibmvscsi(X) scsi_transport_srp scsi_tgt dm_mod sg scsi_mod autofs4 [ 78.300789] Supported: Yes, External [ 78.300791] CPU: 1 PID: 3090 Comm: systemd-udevd Tainted: G X 3.12.45-1-default #1 [ 78.300793] task: c0000004d7d1d970 ti: c0000004d7b90000 task.ti: c0000004d7b90000 [ 78.300794] NIP: c0000000004fcff8 LR: c0000000004fda84 CTR: 0000000000000000 [ 78.300795] REGS: c0000004d7b93930 TRAP: 0700 Tainted: G X (3.12.45-1-default) [ 78.300796] MSR: 8000000000029033 <SF,EE,ME,IR,DR,RI,LE> CR: 24088848 XER: 00000000 [ 78.300800] CFAR: c0000000004fcf98 SOFTE: 1
GPR00: 0000000000000537 c0000004d7b93bb0 c000000000e7f200 0000000000053000
GPR04: 0000000000001000 0000000000000001 c000000000e0f200 0000000000000000
GPR08: 0000000000000000 0000000000000001 0000000000000537 00000000014dc000
GPR12: 0000000000054000 c00000000e7f0900 0000000010041040 0000000000000000
GPR16: 00000100206f0010 000000001003ff78 000000001006c824 00000000100410b0
GPR20: 000000001003ff90 000000001006c00c 000001002073cd20 00000100206f0760
GPR24: 00000100206f85a0 c00000000076d950 c0000004ef7c95e0 c0000004d7b93e00
GPR28: c0000004de601738 0000000000000001 c000000001218f80 00000000003fffff
[ 78.300818] NIP [c0000000004fcff8] memory_block_action+0x258/0x2e0 [ 78.300820] LR [c0000000004fda84] memory_subsys_online+0x54/0x100 [ 78.300821] Call Trace: [ 78.300822] [c0000004d7b93bb0] [c000000009071ce0] 0xc000000009071ce0 (unreliable) [ 78.300824] [c0000004d7b93c40] [c0000000004fda84] memory_subsys_online+0x54/0x100 [ 78.300826] [c0000004d7b93c70] [c0000000004df784] device_online+0xb4/0x120 [ 78.300828] [c0000004d7b93cb0] [c0000000004fd738] store_mem_state+0x88/0x220 [ 78.300830] [c0000004d7b93cf0] [c0000000004db448] dev_attr_store+0x68/0xa0 [ 78.300833] [c0000004d7b93d30] [c00000000031f938] sysfs_write_file+0xf8/0x1d0 [ 78.300835] [c0000004d7b93d90] [c00000000027d29c] vfs_write+0xec/0x250 [ 78.300837] [c0000004d7b93de0] [c00000000027dfdc] SyS_write+0x6c/0xf0 [ 78.300839] [c0000004d7b93e30] [c00000000000a17c] syscall_exit+0x0/0x7c [ 78.300840] Instruction dump: [ 78.300841] 780a0560 79482ea4 7ce94214 2fa70000 41de0014 7d09402a 396b4000 7907ffe3 [ 78.300844] 4082ff54 3cc2fff9 8926b83a 69290001 <0b090000> 2fa90000 40de006c 3860fff0 [ 78.300847] ---[ end trace dfec8da06ebbc762 ]---
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, this can interrupt the memory reservation process. This patch modifies memory_probe_store to take the hotplug sysfs lock to prevent the online of added memory before the completion of the probe.
---
drivers/base/memory.c +6 -0
@@ -457,6 +457,10 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,if (phys_addr & ((pages_per_block <<PAGE_SHIFT ) -1 ))return -EINVAL ; + ret =lock_device_hotplug_sysfs (); +if (ret) +return ret; +for (i =0 ; i < sections_per_block; i++) { nid =memory_add_physaddr_to_nid (phys_addr); ret = add_memory(nid, phys_addr,
@@ -467,6 +471,8 @@ memory_probe_store(struct device *dev, struct device_attribute *attr, phys_addr +=MIN_MEMORY_BLOCK_SIZE ; } +unlock_device_hotplug (); + ret = count; out:return ret;
Quoted 68 lines · John Allen
This patch fixes a bug where a kernel warning is triggered when performing a memory hotplug on ppc64. This warning may also occur on any architecture that has multiple sections per memory block.
[ 78.300767] ------------[ cut here ]------------ [ 78.300768] WARNING: at ../drivers/base/memory.c:210 [ 78.300769] Modules linked in: rpadlpar_io(X) rpaphp(X) tcp_diag udp_diag inet_diag unix_diag af_packet_diag netlink_diag af_packet xfs libcrc32c ibmveth(X) rtc_generic btrfs xor raid6_pq xts gf128mul dm_crypt sd_mod sr_mod cdrom crc_t10dif ibmvscsi(X) scsi_transport_srp scsi_tgt dm_mod sg scsi_mod autofs4 [ 78.300789] Supported: Yes, External [ 78.300791] CPU: 1 PID: 3090 Comm: systemd-udevd Tainted: G X 3.12.45-1-default #1 [ 78.300793] task: c0000004d7d1d970 ti: c0000004d7b90000 task.ti: c0000004d7b90000 [ 78.300794] NIP: c0000000004fcff8 LR: c0000000004fda84 CTR: 0000000000000000 [ 78.300795] REGS: c0000004d7b93930 TRAP: 0700 Tainted: G X (3.12.45-1-default) [ 78.300796] MSR: 8000000000029033 <SF,EE,ME,IR,DR,RI,LE> CR: 24088848 XER: 00000000 [ 78.300800] CFAR: c0000000004fcf98 SOFTE: 1GPR00: 0000000000000537
c0000004d7b93bb0c000000000e7f2000000000000053000
GPR04: 0000000000001000 0000000000000001c000000000e0f2000000000000000000
GPR08: 0000000000000000 0000000000000001 000000000000053700000000014dc000
GPR12: 0000000000054000c00000000e7f09000000000010041040 0000000000000000
GPR16:00000100206f0010000000001003ff78000000001006c82400000000100410b0
GPR20:000000001003ff90000000001006c00c000001002073cd2000000100206f0760
GPR24:00000100206f85a0c00000000076d950c0000004ef7c95e0c0000004d7b93e00
GPR28:c0000004de6017380000000000000001c000000001218f8000000000003fffff[ 78.300818] NIP [c0000000004fcff8] memory_block_action+0x258/0x2e0 [ 78.300820] LR [c0000000004fda84] memory_subsys_online+0x54/0x100 [ 78.300821] Call Trace: [ 78.300822] [c0000004d7b93bb0] [c000000009071ce0] 0xc000000009071ce0 (unreliable) [ 78.300824] [c0000004d7b93c40] [c0000000004fda84] memory_subsys_online+0x54/0x100 [ 78.300826] [c0000004d7b93c70] [c0000000004df784] device_online+0xb4/0x120 [ 78.300828] [c0000004d7b93cb0] [c0000000004fd738] store_mem_state+0x88/0x220 [ 78.300830] [c0000004d7b93cf0] [c0000000004db448] dev_attr_store+0x68/0xa0 [ 78.300833] [c0000004d7b93d30] [c00000000031f938] sysfs_write_file+0xf8/0x1d0 [ 78.300835] [c0000004d7b93d90] [c00000000027d29c] vfs_write+0xec/0x250 [ 78.300837] [c0000004d7b93de0] [c00000000027dfdc] SyS_write+0x6c/0xf0 [ 78.300839] [c0000004d7b93e30] [c00000000000a17c] syscall_exit+0x0/0x7c [ 78.300840] Instruction dump: [ 78.300841] 780a0560 79482ea4 7ce94214 2fa70000 41de0014 7d09402a 396b4000 7907ffe3 [ 78.300844] 4082ff54 3cc2fff9 8926b83a 69290001 <0b090000> 2fa90000 40de006c 3860fff0 [ 78.300847] ---[ end trace dfec8da06ebbc762 ]---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_storeto reserve memory, this can interrupt the memory reservation process. This patch modifiesmemory_probe_storeto take the hotplug sysfs lock to prevent the online of added memory before the completion of the probe.Signed-off-by John Allen <[email protected]>---
drivers/base/memory.c +4
-0@@ -457,6 +457,10 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,if (phys_addr & ((pages_per_block <<PAGE_SHIFT ) -1 ))return -EINVAL ; + ret =lock_device_hotplug_sysfs (); +if (ret) +return ret; +for (i =0 ; i < sections_per_block; i++) { nid =memory_add_physaddr_to_nid (phys_addr); ret = add_memory(nid, phys_addr,
drivers/base/memory.c memory_probe_store(struct device *dev, struct device_attribute *attr, · line 475
Quoted 5 lines
drivers/base/memory.c +2
-0@@ -467,6 +471,8 @@ memory_probe_store(struct device *dev, struct device_attribute *attr, phys_addr +=MIN_MEMORY_BLOCK_SIZE ; } +unlock_device_hotplug (); +
I realized that there is actually a bug here. If the call to add_memory in the above loop fails, we goto out and skip unlocking the device hotplug lock. I will be sending a v2 patch to address this issue shortly.
John
Quoted 4 lines
drivers/base/memory.c +0
-0ret = count; out:return ret;