drivers/base/memory: set mem->altmap after successful device registration
commit a2b8d7827f48ee54a686cb80e4a1d0ff954ec42a upstream.
If __add_memory_block() fails at xa_store() (under memory pressure for
example), device_unregister() is called, which eventually triggers
memory_block_release() with mem->altmap still set, causing a
WARN_ON(mem->altmap). This was triggered by modifying virtio-mem driver.
Fix this by delaying the assignment of mem->altmap until after
__add_memory_block() has succeeded.
Link: https://lore.kernel.org/20260514092657.3057141-1-georgi.djakov@oss.qualcomm.com
Fixes: 1a8c64e110 ("mm/memory_hotplug: embed vmem_altmap details in memory block")
Signed-off-by: Georgi Djakov <georgi.djakov@oss.qualcomm.com>
Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Richard Cheng <icheng@nvidia.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Georgi Djakov <djakov@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
778b9dda4b
commit
059ac6252a
1 changed files with 2 additions and 1 deletions
|
|
@ -807,7 +807,6 @@ static int add_memory_block(unsigned long block_id, int nid, unsigned long state
|
||||||
mem->start_section_nr = block_id * sections_per_block;
|
mem->start_section_nr = block_id * sections_per_block;
|
||||||
mem->state = state;
|
mem->state = state;
|
||||||
mem->nid = nid;
|
mem->nid = nid;
|
||||||
mem->altmap = altmap;
|
|
||||||
INIT_LIST_HEAD(&mem->group_next);
|
INIT_LIST_HEAD(&mem->group_next);
|
||||||
|
|
||||||
#ifndef CONFIG_NUMA
|
#ifndef CONFIG_NUMA
|
||||||
|
|
@ -825,6 +824,8 @@ static int add_memory_block(unsigned long block_id, int nid, unsigned long state
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
mem->altmap = altmap;
|
||||||
|
|
||||||
if (group) {
|
if (group) {
|
||||||
mem->group = group;
|
mem->group = group;
|
||||||
list_add(&mem->group_next, &group->memory_blocks);
|
list_add(&mem->group_next, &group->memory_blocks);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue