drivers/base/memory: add memory block to memory group after registration succeeded
Subsystems (4)
PATCH 1/1 drivers/base/memory: add memory block to memory group after registration succeeded
If register_memory() fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.
We do handle it properly during unregister_memory(), but that's not called when the registration fails.
--- drivers/base/memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/base/memory.c +5 -3
@@ -663,14 +663,16 @@ static int init_memory_block(unsigned long block_id, unsigned long state, mem->nr_vmemmap_pages = nr_vmemmap_pages;INIT_LIST_HEAD (&mem->group_next); + ret =register_memory (mem); +if (ret) +return ret; +if (group) { mem->group = group;list_add (&mem->group_next, &group->memory_blocks); } - ret =register_memory (mem); - -return ret; +return 0 ; }static int add_memory_block (unsigned long base_section_nr)
Signature · 1 line
2.34.1
Quoted 7 lines · David Hildenbrand
If
register_memory()fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.We do handle it properly during
unregister_memory(), but that's not called when the registration fails.
Quoted 8 lines
Fixes 028fc57a1c36 ("drivers/base/memory: introduce "memory groups" to logically group memory blocks")Cc [email protected] # v5.15+Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Andrew Morton <[email protected]>Cc Michal Hocko <[email protected]>Cc Oscar Salvador <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
Andrew Morton
maintainerQuoted 7 lines · On Fri, 28 Jan 2022 15:45:40 +0100 David Hildenbrand <[email protected]> wrote:
If
register_memory()fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.We do handle it properly during
unregister_memory(), but that's not called when the registration fails.
I guess this has never been known to happen. So I queued the fix for 5.18-rc1, cc:stable.
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 28 Jan 2022 15:45:40 +0100 David Hildenbrand <[email protected]> wrote:
If
register_memory()fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.
Quoted 6 lines
Quoted 3 lines
We do handle it properly during
unregister_memory(), but that's not called when the registration fails.I guess this has never been known to happen. So I queued the fix for 5.18-rc1, cc:stable.
Triggering that registration error is fairly hard, usually we fail memory hotplug because we fail to allocate the (largish) memmap. So I am not aware that this BUG actually triggered.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 6 lines · Andrew Morton
Quoted 4 lines · On Fri, 28 Jan 2022 15:45:40 +0100 David Hildenbrand <[email protected]> wrote:
If
register_memory()fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.
Quoted 6 lines
Quoted 3 lines
We do handle it properly during
unregister_memory(), but that's not called when the registration fails.I guess this has never been known to happen. So I queued the fix for 5.18-rc1, cc:stable.
I do not think this is worth stable backporting. Chances of a failure are pretty small and I am not aware of any existing report.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 7 lines · David Hildenbrand
If
register_memory()fails, we freed the memory block but already added the memory block to the group list, not good. Let's defer adding the block to the memory group to after registering the memory block device.We do handle it properly during
unregister_memory(), but that's not called when the registration fails.
Quoted 8 lines
Fixes 028fc57a1c36 ("drivers/base/memory: introduce "memory groups" to logically group memory blocks")Cc [email protected] # v5.15+Cc Greg Kroah-Hartman <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Andrew Morton <[email protected]>Cc Michal Hocko <[email protected]>Cc Oscar Salvador <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Thanks!
Quoted 30 lines
--- drivers/base/memory.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/base/memory.c +5
-3@@ -663,14 +663,16 @@ static int init_memory_block(unsigned long block_id, unsigned long state, mem->nr_vmemmap_pages = nr_vmemmap_pages;INIT_LIST_HEAD (&mem->group_next); + ret =register_memory (mem); +if (ret) +return ret; +if (group) { mem->group = group;list_add (&mem->group_next, &group->memory_blocks); } - ret =register_memory (mem); - -return ret; +return 0 ; }static int add_memory_block (unsigned long base_section_nr)Signature · 1 line
2.34.1
Signature · 2 lines
Michal Hocko SUSE Labs