From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 403B9C4321D for ; Fri, 17 Aug 2018 11:56:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EACD52088E for ; Fri, 17 Aug 2018 11:56:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EACD52088E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbeHQO7w (ORCPT ); Fri, 17 Aug 2018 10:59:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41026 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726213AbeHQO7v (ORCPT ); Fri, 17 Aug 2018 10:59:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABB29401EF07; Fri, 17 Aug 2018 11:56:39 +0000 (UTC) Received: from [10.36.117.49] (ovpn-117-49.ams2.redhat.com [10.36.117.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B58EB10EE6CD; Fri, 17 Aug 2018 11:56:35 +0000 (UTC) Subject: Re: [PATCH RFC 1/2] drivers/base: export lock_device_hotplug/unlock_device_hotplug To: Heiko Carstens Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Michal Hocko , Benjamin Herrenschmidt , Linux Memory Management List , Paul Mackerras , linux-s390@vger.kernel.org, sthemmin@microsoft.com, Pavel Tatashin , ACPI Devel Maling List , David Rientjes , xen-devel@lists.xenproject.org, Len Brown , haiyangz@microsoft.com, Dan Williams , Andrew Morton , Vlastimil Babka , osalvador@suse.de, "Rafael J. Wysocki" , Linux Kernel Mailing List , Martin Schwidefsky , devel@linuxdriverproject.org, Vitaly Kuznetsov , linuxppc-dev References: <20180817075901.4608-1-david@redhat.com> <20180817075901.4608-2-david@redhat.com> <20180817084146.GB14725@kroah.com> <5a5d73e9-e4aa-ffed-a2e3-8aef64e61923@redhat.com> <42df9062-f647-3ad6-5a07-be2b99531119@redhat.com> <20180817100604.GA18164@kroah.com> <4ac624be-d2d6-5975-821f-b20a475781dc@redhat.com> <20180817112850.GB3565@osiris> From: David Hildenbrand Openpgp: preference=signencrypt Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZ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thSwI836FoMASwOl C7tHsTjnSGufB+D7F7ZBT61BffNBBIm1KdMxcxqLUVXpBQHHlGkbwI+3Ye+nE6HmZH7IwLwV W+Ajl7oYF+jeKaH4DZFtgLYGLtZ1LDwKPjX7VAsa4Yx7S5+EBAaZGxK510MjIx6SGrZWBrrV TEvdV00F2MnQoeXKzD7O4WFbL55hhyGgfWTHwZ457iN9SgYi1JLPqWkZB0JRXIEtjd4JEQcx +8Umfre0Xt4713VxMygW0PnQt5aSQdMD58jHFxTk092mU+yIHj5LeYgvwSgZN4airXk5yRXl SE+xAvmumFBY Organization: Red Hat GmbH Message-ID: Date: Fri, 17 Aug 2018 13:56:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180817112850.GB3565@osiris> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 17 Aug 2018 11:56:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 17 Aug 2018 11:56:39 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17.08.2018 13:28, Heiko Carstens wrote: > On Fri, Aug 17, 2018 at 01:04:58PM +0200, David Hildenbrand wrote: >>>> If there are no objections, I'll go into that direction. But I'll wait >>>> for more comments regarding the general concept first. >>> >>> It is the middle of the merge window, and maintainers are really busy >>> right now. I doubt you will get many review comments just yet... >>> >> >> This has been broken since 2015, so I guess it can wait a bit :) > > I hope you figured out what needs to be locked why. Your patch description > seems to be "only" about locking order ;) Well I hope so, too ... but there is a reason for the RFC mark ;) There is definitely a lot of magic in the current code. And that's why it is also not that obvious that locking is wrong. To avoid/fix the locking order problem was the motivation for the original patch that dropped mem_hotplug_lock on one path. So I focused on that in my description. > > I tried to figure out and document that partially with 55adc1d05dca ("mm: > add private lock to serialize memory hotplug operations"), and that wasn't > easy to figure out. I was especially concerned about sprinkling Haven't seen that so far as that was reworked by 3f906ba23689 ("mm/memory-hotplug: switch locking to a percpu rwsem"). Thanks for the pointer. There is a long history to all this. > lock/unlock_device_hotplug() calls, which has the potential to make it the > next BKL thing. Well, the thing with memory hotplug and device_hotplug_lock is that a) ACPI already holds it while adding/removing memory via add_memory() b) we hold it during online/offline of memory (via sysfs calls to device_online()/device_offline()) So it is already pretty much involved in all memory hotplug/unplug activities on x86 (except paravirt). And as far as I understand, there are good reasons to hold the lock in core.c and ACPI. (as mentioned by Rafael) The exceptions are add_memory() called on s390x, hyper-v, xen and ppc (including manual probing). And device_online()/device_offline() called from the kernel. Holding device_hotplug_lock when adding/removing memory from the system doesn't sound too wrong (especially as devices are created/removed). At least that way (documenting and following the rules in the patch description) we might at least get locking right. I am very open to other suggestions (but as noted by Greg, many maintainers might be busy by know). E.g. When adding the memory block devices, we know that there won't be a driver to attach to (as there are no drivers for the "memory" subsystem) - the bus_probe_device() function that takes the device_lock() could pretty much be avoided for that case. But burying such special cases down in core driver code definitely won't make locking related to memory hotplug easier. Thanks for having a look! -- Thanks, David / dhildenb