• Pavel Tatashin's avatar
    mm/hotplug: make remove_memory() interface usable · 71494c7b
    Pavel Tatashin authored
    [ Upstream commit eca499ab ]
    Presently the remove_memory() interface is inherently broken.  It tries
    to remove memory but panics if some memory is not offline.  The problem
    is that it is impossible to ensure that all memory blocks are offline as
    this function also takes lock_device_hotplug that is required to change
    memory state via sysfs.
    So, between calling this function and offlining all memory blocks there
    is always a window when lock_device_hotplug is released, and therefore,
    there is always a chance for a panic during this window.
    Make this interface to return an error if memory removal fails.  This
    way it is safe to call this function without panicking machine, and also
    makes it symmetric to add_memory() which already returns an error.
    Link: http://lkml.kernel.org/r/20190517215438.6487-3-pasha.tatashin@soleen.comSigned-off-by: default avatarPavel Tatashin <pasha.tatashin@soleen.com>
    Reviewed-by: David Hildenbrand's avatarDavid Hildenbrand <david@redhat.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Cc: Bjorn Helgaas <bhelgaas@google.com>
    Cc: Borislav Petkov <bp@suse.de>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Cc: Dave Hansen <dave.hansen@intel.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Dave Jiang <dave.jiang@intel.com>
    Cc: Fengguang Wu <fengguang.wu@intel.com>
    Cc: Huang Ying <ying.huang@intel.com>
    Cc: James Morris <jmorris@namei.org>
    Cc: Jérôme Glisse <jglisse@redhat.com>
    Cc: Keith Busch <keith.busch@intel.com>
    Cc: Ross Zwisler <zwisler@kernel.org>
    Cc: Sasha Levin <sashal@kernel.org>
    Cc: Takashi Iwai <tiwai@suse.de>
    Cc: Tom Lendacky <thomas.lendacky@amd.com>
    Cc: Vishal Verma <vishal.l.verma@intel.com>
    Cc: Yaowei Bai <baiyaowei@cmss.chinamobile.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
memory_hotplug.c 49 KB