linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: linux-mm@kvack.org
Cc: linuxarm@huawei.com, Oscar Salvador <osalvador@techadventures.net>
Subject: [RFC] mm/memory_hotplug: wrong node identified if memory was never on-lined.
Date: Wed, 12 Sep 2018 15:02:18 +0100	[thread overview]
Message-ID: <20180912150218.00002cbc@huawei.com> (raw)

Hi All,

I've been accidentally (i.e. due to a script bug) testing some odd corner
cases of memory hotplug and run into this issue.

If we hot add some memory we have carefully avoided the need to use
get_nid_for_pfn as it isn't set until we online the memory.

Unfortunately if we never online the memory but instead just remove it again
we don't have any such protection so in unregister_mem_sect_under_nodes
we end up trying to call sysfs_remove_link for memory on (typically) node0
instead of the intended node.

So the path to this problem is

add_memory(Node, addr, size);
-> add_memory_resource(Node ...)
---> link_mem_sections(Node ...)
------> register_mem_sect_under_node(
----------> sysfs_create_link_nowarn(&node_devices[Node]->dev.kobj,...
(which creates the link to say
/sys/bus/nodes/devices/node5/memory84

Note that in code we avoid checking the nid set for the pfn in hotplug
paths.

remove_memory(Node, addr, size);
-> arch_remove_memory(start, size, NULL);
---> __remove_pages
-----> __remove_section
-------> unregister_memory_section
----------> remove_memory_section(Node,... -- Node set to 0 but not used at all.
-------------> unregister_mem_sect_under_node() - node not passed in anyway
---------------->get_nid_for_pfn(pfn).  (try to get it back again)
-------------------->sysfs_remove_link (wrong node number)
tries to remove
/sys/bus/nodes/devices/node0/memory84 which doesn't exist.

So not tidy, but not critical - but you get BUG_ON when you try
to add the memory again as there is a left over link in the way.


Now I'm not sure what the preferred fix for this would be.
1) Actually set the nid for each pfn during hot add rather than waiting for
   online.
2) Modify the whole call chain to pass the nid through as we know it at the
   remove_memory call for hotplug cases...

I personally favour option 2 but don't really have a deep enough understanding
to know if this is going to cause trouble anywhere else.

I mocked up option 2 using some updated arm64 hotplug patches and it seems
superficially fine if fairly invasive.

The whole structure is a little odd in that in the probe path the sysfs links
are not called via architecture specific code whilst in the remove they are.

Jonathan

             reply	other threads:[~2018-09-12 14:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 14:02 Jonathan Cameron [this message]
2018-09-18 12:13 ` [RFC] mm/memory_hotplug: wrong node identified if memory was never on-lined Oscar Salvador
2018-09-18 12:24   ` Jonathan Cameron
2019-03-24  6:12 ` Anshuman Khandual

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180912150218.00002cbc@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=linuxarm@huawei.com \
    --cc=osalvador@techadventures.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).