Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp527650imm; Fri, 17 Aug 2018 02:04:56 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyQzroQdS0RE7pWbAW0jf4e/aYEwk5OWMF81ElNqebabXGXWPmAWBh1UtKAdLU9eFrpSD+L X-Received: by 2002:a63:5624:: with SMTP id k36-v6mr82154pgb.244.1534496696729; Fri, 17 Aug 2018 02:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534496696; cv=none; d=google.com; s=arc-20160816; b=a7AR8baHASaQEkMT2u1ejJvFeq/6Opu2UC4DxYUnr0xowB5zITOWX5q9EdU6MEp3Su xUUfS5OJgqwJEhlnEpSq8r51eAWFxp7cHYsCAqpisvJt4TwgQi76r4az5Wq/7aql4egq OLZ3+oFWTNZUEbP6seLN3/44SuqfC5aT1gaAWrxiyZw3XC5CyEA55Qnhk4NALbRSQo5H u5yu1xbC2YTm5YzIpGihCaIjBw31FnbEsmCvZgvR8MVbdIeUZXu4rz5NA5dDjDEBYAG0 y6w6tpimh+NPgU9SWVFpCbkrVoqdCLBaas4zPgb748qd47j5QC0Zv/804PNQVD3Wtezj Lp+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=VtDX5JxVZ6bf4rTy9IoKQmn4dHYklQcfEiYjvV/oYFk=; b=JSCiln6LCXyh2PRHIXgn94RVQ6HA3nhANHAk52jEl2WNH76eIPRs475ShvWkO+KXBk vD5Ps0eK/dY1CBJZINGhp1QmsfNHWt33SSUbwHjYK/R0oQoNiV2ScUXrEnSrUnW7J4wO L7muvM2gKunRVy+pQ+efRYrclXqKhgfR6p2zzn57/cB/NITuaA8FqxkGuXmxHUxvNyXC V9+BhDLePhyHI4sGS8DsnqtxxPBstXyHeyQH0UohZvnaRqx/FQv1/4iBleWiDzjn0TED Yrit04L/GdumFgKebChAMTTmrGc/oyhGSaIizuP71sz/qEhUYpmBE2EovUYGmqhlTIRN Obyw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4-v6si1567272pgr.167.2018.08.17.02.04.41; Fri, 17 Aug 2018 02:04:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbeHQMF5 (ORCPT + 99 others); Fri, 17 Aug 2018 08:05:57 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:42339 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbeHQMF5 (ORCPT ); Fri, 17 Aug 2018 08:05:57 -0400 Received: by mail-oi0-f65.google.com with SMTP id b16-v6so12844681oic.9; Fri, 17 Aug 2018 02:03:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VtDX5JxVZ6bf4rTy9IoKQmn4dHYklQcfEiYjvV/oYFk=; b=T17qwFa/Acs3B7YhaquHi88FUzClsiG6KkA4BAN91jtrfqtYWxvPiH07YibXDUja0F 7nwIM3ZDPHfxIQmwBkW5tgyN0oTtQ0hAXfirEI5IpIVetq0txfIU0mBwPZVAkPj3gsXA vVdM30vlzHmgBUfYlZt/EvvhlxUy6JobaqKxVszamP3MsRJs8qkcBSOKLVHK8CBDhWXg rPuok3U5OQAXLHDtdzCU/nJO4i/dO29ltOmKsBnxUoCGB8pdLpk/738s5roKFvG1fykr +1CtEv3+70hnmjj553OzfDTjoK7ZU9eR1eX7kyJFMWVGLM2h7mahyaZYX+hSW9wyc1Sy HYfg== X-Gm-Message-State: AOUpUlGl+THlkkw80OPWUXpGiXR4bbFLsXiuGMXuMID2RJdBbwnh4eK5 P4VpAehH4Hi5O9kKF4JqsTVrZXr/BMaXUrMfuw8= X-Received: by 2002:aca:b885:: with SMTP id i127-v6mr1653792oif.180.1534496601283; Fri, 17 Aug 2018 02:03:21 -0700 (PDT) MIME-Version: 1.0 References: <20180817075901.4608-1-david@redhat.com> <20180817075901.4608-2-david@redhat.com> <20180817084146.GB14725@kroah.com> <5a5d73e9-e4aa-ffed-a2e3-8aef64e61923@redhat.com> In-Reply-To: <5a5d73e9-e4aa-ffed-a2e3-8aef64e61923@redhat.com> From: "Rafael J. Wysocki" Date: Fri, 17 Aug 2018 11:03:09 +0200 Message-ID: Subject: Re: [PATCH RFC 1/2] drivers/base: export lock_device_hotplug/unlock_device_hotplug To: David Hildenbrand Cc: Greg Kroah-Hartman , Linux Kernel Mailing List , Linux Memory Management List , linuxppc-dev , ACPI Devel Maling List , devel@linuxdriverproject.org, linux-s390@vger.kernel.org, xen-devel@lists.xenproject.org, Andrew Morton , Michal Hocko , Vlastimil Babka , Dan Williams , Pavel Tatashin , osalvador@suse.de, Vitaly Kuznetsov , Martin Schwidefsky , Heiko Carstens , kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, Benjamin Herrenschmidt , Paul Mackerras , "Rafael J. Wysocki" , Len Brown , David Rientjes Content-Type: text/plain; charset="UTF-8" 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 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.