{"push_id":2912979002,"size":6,"distinct_size":6,"ref":"refs/heads/_v3,6_6__memory-hotplug_txt_Add_some_details_about_locking_internals_mbox_next","head":"b58fb8e65f04729d7847bff4b14a50e4509ce856","before":"0e7f9e83d2f154ade092f2e063ccb7ceb3267504","commits":[{"sha":"fc2db7b62ee54bf18749e88dba5eea31497e389b","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"mm/memory_hotplug: make remove_memory() take the device_hotplug_lock\n\nremove_memory() is exported right now but requires the\ndevice_hotplug_lock, which is not exported. So let's provide a variant\nthat takes the lock and only export that one.\n\nThe lock is already held in\n\tarch/powerpc/platforms/pseries/hotplug-memory.c\n\tdrivers/acpi/acpi_memhotplug.c\n\tarch/powerpc/platforms/powernv/memtrace.c\n\nApart from that, there are not other users in the tree.\n\nCc: Benjamin Herrenschmidt <benh@kernel.crashing.org>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Michael Ellerman <mpe@ellerman.id.au>\nCc: \"Rafael J. Wysocki\" <rjw@rjwysocki.net>\nCc: Len Brown <lenb@kernel.org>\nCc: Rashmica Gupta <rashmica.g@gmail.com>\nCc: Michael Neuling <mikey@neuling.org>\nCc: Balbir Singh <bsingharora@gmail.com>\nCc: Nathan Fontenot <nfont@linux.vnet.ibm.com>\nCc: John Allen <jallen@linux.vnet.ibm.com>\nCc: Andrew Morton <akpm@linux-foundation.org>\nCc: Michal Hocko <mhocko@suse.com>\nCc: Dan Williams <dan.j.williams@intel.com>\nCc: Joonsoo Kim <iamjoonsoo.kim@lge.com>\nCc: Vlastimil Babka <vbabka@suse.cz>\nCc: Pavel Tatashin <pasha.tatashin@oracle.com>\nCc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\nCc: Oscar Salvador <osalvador@suse.de>\nCc: YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>\nCc: Mathieu Malaterre <malat@debian.org>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/fc2db7b62ee54bf18749e88dba5eea31497e389b"},{"sha":"552c6c974ebfbc915359f01ccd4e994ea64274c3","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"mm/memory_hotplug: make add_memory() take the device_hotplug_lock\n\nadd_memory() currently does not take the device_hotplug_lock, however\nis aleady called under the lock from\n\tarch/powerpc/platforms/pseries/hotplug-memory.c\n\tdrivers/acpi/acpi_memhotplug.c\nto synchronize against CPU hot-remove and similar.\n\nIn general, we should hold the device_hotplug_lock when adding memory\nto synchronize against online/offline request (e.g. from user space) -\nwhich already resulted in lock inversions due to device_lock() and\nmem_hotplug_lock - see 30467e0b3be (\"mm, hotplug: fix concurrent memory\nhot-add deadlock\"). add_memory()/add_memory_resource() will create memory\nblock devices, so this really feels like the right thing to do.\n\nHolding the device_hotplug_lock makes sure that a memory block device\ncan really only be accessed (e.g. via .online/.state) from user space,\nonce the memory has been fully added to the system.\n\nThe lock is not held yet in\n\tdrivers/xen/balloon.c\n\tarch/powerpc/platforms/powernv/memtrace.c\n\tdrivers/s390/char/sclp_cmd.c\n\tdrivers/hv/hv_balloon.c\nSo, let's either use the locked variants or take the lock.\n\nDon't export add_memory_resource(), as it once was exported to be used\nby XEN, which is never built as a module. If somebody requires it, we\nalso have to export a locked variant (as device_hotplug_lock is never\nexported).\n\nCc: Benjamin Herrenschmidt <benh@kernel.crashing.org>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Michael Ellerman <mpe@ellerman.id.au>\nCc: \"Rafael J. Wysocki\" <rjw@rjwysocki.net>\nCc: Len Brown <lenb@kernel.org>\nCc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\nCc: Boris Ostrovsky <boris.ostrovsky@oracle.com>\nCc: Juergen Gross <jgross@suse.com>\nCc: Nathan Fontenot <nfont@linux.vnet.ibm.com>\nCc: John Allen <jallen@linux.vnet.ibm.com>\nCc: Andrew Morton <akpm@linux-foundation.org>\nCc: Michal Hocko <mhocko@suse.com>\nCc: Dan Williams <dan.j.williams@intel.com>\nCc: Joonsoo Kim <iamjoonsoo.kim@lge.com>\nCc: Vlastimil Babka <vbabka@suse.cz>\nCc: Oscar Salvador <osalvador@suse.de>\nCc: Mathieu Malaterre <malat@debian.org>\nCc: Pavel Tatashin <pavel.tatashin@microsoft.com>\nCc: YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/552c6c974ebfbc915359f01ccd4e994ea64274c3"},{"sha":"123afe47a823543be9f9932addbbb1fc703904b3","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"mm/memory_hotplug: fix online/offline_pages called w.o. mem_hotplug_lock\n\nThere seem to be some problems as result of 30467e0b3be (\"mm, hotplug:\nfix concurrent memory hot-add deadlock\"), which tried to fix a possible\nlock inversion reported and discussed in [1] due to the two locks\n\ta) device_lock()\n\tb) mem_hotplug_lock\n\nWhile add_memory() first takes b), followed by a) during\nbus_probe_device(), onlining of memory from user space first took a),\nfollowed by b), exposing a possible deadlock.\n\nIn [1], and it was decided to not make use of device_hotplug_lock, but\nrather to enforce a locking order.\n\nThe problems I spotted related to this:\n\n1. Memory block device attributes: While .state first calls\n   mem_hotplug_begin() and the calls device_online() - which takes\n   device_lock() - .online does no longer call mem_hotplug_begin(), so\n   effectively calls online_pages() without mem_hotplug_lock.\n\n2. device_online() should be called under device_hotplug_lock, however\n   onlining memory during add_memory() does not take care of that.\n\nIn addition, I think there is also something wrong about the locking in\n\n3. arch/powerpc/platforms/powernv/memtrace.c calls offline_pages()\n   without locks. This was introduced after 30467e0b3be. And skimming over\n   the code, I assume it could need some more care in regards to locking\n   (e.g. device_online() called without device_hotplug_lock. This will\n   be addressed in the following patches.\n\nNow that we hold the device_hotplug_lock when\n- adding memory (e.g. via add_memory()/add_memory_resource())\n- removing memory (e.g. via remove_memory())\n- device_online()/device_offline()\n\nWe can move mem_hotplug_lock usage back into\nonline_pages()/offline_pages().\n\nWhy is mem_hotplug_lock still needed? Essentially to make\nget_online_mems()/put_online_mems() be very fast (relying on\ndevice_hotplug_lock would be very slow), and to serialize against\naddition of memory that does not create memory block devices (hmm).\n\n[1] http://driverdev.linuxdriverproject.org/pipermail/ driverdev-devel/\n    2015-February/065324.html\n\nThis patch is partly based on a patch by Vitaly Kuznetsov.\n\nCc: Benjamin Herrenschmidt <benh@kernel.crashing.org>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Michael Ellerman <mpe@ellerman.id.au>\nCc: \"Rafael J. Wysocki\" <rjw@rjwysocki.net>\nCc: Len Brown <lenb@kernel.org>\nCc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>\nCc: \"K. Y. Srinivasan\" <kys@microsoft.com>\nCc: Haiyang Zhang <haiyangz@microsoft.com>\nCc: Stephen Hemminger <sthemmin@microsoft.com>\nCc: Martin Schwidefsky <schwidefsky@de.ibm.com>\nCc: Heiko Carstens <heiko.carstens@de.ibm.com>\nCc: Boris Ostrovsky <boris.ostrovsky@oracle.com>\nCc: Juergen Gross <jgross@suse.com>\nCc: Rashmica Gupta <rashmica.g@gmail.com>\nCc: Michael Neuling <mikey@neuling.org>\nCc: Balbir Singh <bsingharora@gmail.com>\nCc: Kate Stewart <kstewart@linuxfoundation.org>\nCc: Thomas Gleixner <tglx@linutronix.de>\nCc: Philippe Ombredanne <pombredanne@nexb.com>\nCc: Andrew Morton <akpm@linux-foundation.org>\nCc: Michal Hocko <mhocko@suse.com>\nCc: Pavel Tatashin <pavel.tatashin@microsoft.com>\nCc: Vlastimil Babka <vbabka@suse.cz>\nCc: Dan Williams <dan.j.williams@intel.com>\nCc: Oscar Salvador <osalvador@suse.de>\nCc: YASUAKI ISHIMATSU <yasu.isimatu@gmail.com>\nCc: Mathieu Malaterre <malat@debian.org>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/123afe47a823543be9f9932addbbb1fc703904b3"},{"sha":"6d70fc8773a14877e59b0802c991fb62a7c44bb0","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"powerpc/powernv: hold device_hotplug_lock when calling device_online()\n\ndevice_online() should be called with device_hotplug_lock() held.\n\nCc: Benjamin Herrenschmidt <benh@kernel.crashing.org>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Michael Ellerman <mpe@ellerman.id.au>\nCc: Rashmica Gupta <rashmica.g@gmail.com>\nCc: Balbir Singh <bsingharora@gmail.com>\nCc: Michael Neuling <mikey@neuling.org>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/6d70fc8773a14877e59b0802c991fb62a7c44bb0"},{"sha":"2141656b6ebee0fa845fc388a2e755353beb74f9","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"powerpc/powernv: hold device_hotplug_lock when calling memtrace_offline_pages()\n\nLet's perform all checking + offlining + removing under\ndevice_hotplug_lock, so nobody can mess with these devices via\nsysfs concurrently.\n\nCc: Benjamin Herrenschmidt <benh@kernel.crashing.org>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Michael Ellerman <mpe@ellerman.id.au>\nCc: Rashmica Gupta <rashmica.g@gmail.com>\nCc: Balbir Singh <bsingharora@gmail.com>\nCc: Michael Neuling <mikey@neuling.org>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nAcked-by: Balbir Singh <bsingharora@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/2141656b6ebee0fa845fc388a2e755353beb74f9"},{"sha":"b58fb8e65f04729d7847bff4b14a50e4509ce856","author":{"name":"David Hildenbrand","email":"aa743a0aaec8f7d7a1f01442503957f4d7a2d634@redhat.com"},"message":"memory-hotplug.txt: Add some details about locking internals\n\nLet's document the magic a bit, especially why device_hotplug_lock is\nrequired when adding/removing memory and how it all play together with\nrequests to online/offline memory from user space.\n\nCc: Jonathan Corbet <corbet@lwn.net>\nCc: Michal Hocko <mhocko@suse.com>\nCc: Andrew Morton <akpm@linux-foundation.org>\nReviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>\nReviewed-by: Rashmica Gupta <rashmica.g@gmail.com>\nSigned-off-by: David Hildenbrand <david@redhat.com>","distinct":true,"url":"https://api.github.com/repos/ruscur/linux/commits/b58fb8e65f04729d7847bff4b14a50e4509ce856"}]}
{"actor":{"display_login":"ruscur"}}