Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp577924imm; Fri, 17 Aug 2018 03:07:28 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzpwo/owms2uK4aP0ultvh3szQ05exegCwL5NMgdLoHIj2NS+e6+rGs2p3xZV14Sj0AN9mp X-Received: by 2002:a63:5922:: with SMTP id n34-v6mr32541364pgb.113.1534500448352; Fri, 17 Aug 2018 03:07:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534500448; cv=none; d=google.com; s=arc-20160816; b=I+fXcWpmBULMMI2K7LwfsNLIEtmuRYUkUvxKsdK4UGDcR1QNbxFYxzWdTHJzwQCQED XD22oXT1hY15UD7ACZYNmmcft2hS6oBhGBgNo5W6+5inZCx6CmnEQFfw3w4ATg7+Ni+3 IwOfLNrJ2U5N8bYDThktSP22Pz1HNGBGZV3QZjJAyuGsHPr0YFhITKt0aW9XV4gGCz/3 IB/i3p6gyZNNyRkPzZOhWXd6tTYRbwVgPRXeF8NCLXgln0CF8R1XoIr0tUnHxfLQ67A1 hLgylAFa8PB/GfpCxMdI8f1q5h1FUCrFfepEtrP04kYedKbD7o8ybNkMz5bnlXdCu67b xgTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=NYOlLpzBkVpgm0buG3JrYKz1sMXF9cpvcJQ9akS4lBs=; b=VDj34INuJn38UPIgy06HOqRjrK96oKFlUU6v3lCzNk6vYKogkgX2WB/cmD0GogCgC5 ntHa/LBV3tXDxY33QWlUHwX0ZNaImpYix7NsZE7yt7S8bWscsJ1JEutdXuXFfYouTx6M B+WJ83921uBd6UGcE4S9/pTgo4Y6JRoFrP4/jkLiZAWZVI+DQgitc9YpQlAadUovz+0Y OHZY4CIJX/gTW8jBWPKHoiC0i6Ue4EdZVc/v+TK4aFyyNlNVWVDd7zWlBavNtDJSDaG1 XWkmiVvM45x4RpYLaSEKQdWpH0t9+fMSltBj5LE0bgoE1/iaK1+gt2lSZyxo96HVB4Fr DLYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a20-v6si1864594pls.237.2018.08.17.03.07.13; Fri, 17 Aug 2018 03:07:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726946AbeHQNI5 (ORCPT + 99 others); Fri, 17 Aug 2018 09:08:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33558 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbeHQNI5 (ORCPT ); Fri, 17 Aug 2018 09:08:57 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B582FDC2; Fri, 17 Aug 2018 10:06:06 +0000 (UTC) Date: Fri, 17 Aug 2018 12:06:04 +0200 From: Greg Kroah-Hartman To: David Hildenbrand Cc: "Rafael J. Wysocki" , Michal Hocko , Benjamin Herrenschmidt , Heiko Carstens , 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 Subject: Re: [PATCH RFC 1/2] drivers/base: export lock_device_hotplug/unlock_device_hotplug Message-ID: <20180817100604.GA18164@kroah.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42df9062-f647-3ad6-5a07-be2b99531119@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 17, 2018 at 11:41:24AM +0200, David Hildenbrand wrote: > On 17.08.2018 11:03, Rafael J. Wysocki wrote: > > On Fri, Aug 17, 2018 at 10:56 AM David Hildenbrand wrote: > >> > >> On 17.08.2018 10:41, Greg Kroah-Hartman wrote: > >>> On Fri, Aug 17, 2018 at 09:59:00AM +0200, David Hildenbrand wrote: > >>>> From: Vitaly Kuznetsov > >>>> > >>>> Well require to call add_memory()/add_memory_resource() with > >>>> device_hotplug_lock held, to avoid a lock inversion. Allow external modules > >>>> (e.g. hv_balloon) that make use of add_memory()/add_memory_resource() to > >>>> lock device hotplug. > >>>> > >>>> Signed-off-by: Vitaly Kuznetsov > >>>> [modify patch description] > >>>> Signed-off-by: David Hildenbrand > >>>> --- > >>>> drivers/base/core.c | 2 ++ > >>>> 1 file changed, 2 insertions(+) > >>>> > >>>> diff --git a/drivers/base/core.c b/drivers/base/core.c > >>>> index 04bbcd779e11..9010b9e942b5 100644 > >>>> --- a/drivers/base/core.c > >>>> +++ b/drivers/base/core.c > >>>> @@ -700,11 +700,13 @@ void lock_device_hotplug(void) > >>>> { > >>>> mutex_lock(&device_hotplug_lock); > >>>> } > >>>> +EXPORT_SYMBOL_GPL(lock_device_hotplug); > >>>> > >>>> void unlock_device_hotplug(void) > >>>> { > >>>> mutex_unlock(&device_hotplug_lock); > >>>> } > >>>> +EXPORT_SYMBOL_GPL(unlock_device_hotplug); > >>> > >>> If these are going to be "global" symbols, let's properly name them. > >>> device_hotplug_lock/unlock would be better. But I am _really_ nervous > >>> about letting stuff outside of the driver core mess with this, as people > >>> better know what they are doing. > >> > >> The only "problem" is that we have kernel modules (for paravirtualized > >> devices) that call add_memory(). This is Hyper-V right now, but we might > >> have other ones in the future. Without them we would not have to export > >> it. We might also get kernel modules that want to call remove_memory() - > >> which will require the device_hotplug_lock as of now. > >> > >> What we could do is > >> > >> a) add_memory() -> _add_memory() and don't export it > >> b) add_memory() takes the device_hotplug_lock and calls _add_memory() . > >> We export that one. > >> c) Use add_memory() in external modules only > >> > >> Similar wrapper would be needed e.g. for remove_memory() later on. > > > > That would be safer IMO, as it would prevent developers from using > > add_memory() without the lock, say. > > > > If the lock is always going to be required for add_memory(), make it > > hard (or event impossible) to use the latter without it. > > > > 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...