Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3885961pxa; Sun, 9 Aug 2020 15:31:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzftKsWfL8BLCUeh47OqsQyloVVjGhDIYFejV9XR+8m5CwzH53B3afcN3fAAnjSYzMlVCse X-Received: by 2002:aa7:c383:: with SMTP id k3mr18056161edq.164.1597012305893; Sun, 09 Aug 2020 15:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597012305; cv=none; d=google.com; s=arc-20160816; b=EBoW6Kn4CCs0PXUjdhH5xBvrIt1xOEuJkZldQqDhn2yZcCLogXCFvG+cof3PyFRuF3 X+Lfjx6mXcQ1dNV9jrH2ibjLevZW/AzQqu8WUys8VoMg97uBuxkcfb5IVx+RgTXcQDGH AjH9HJJIlpRwj8BtwH4izzsDEVhDufGRPX17XKGyyMHSRbUKY6kpH0WwZ/0HJrxCO0Mx Mqg72tZWzj4sw2HG3ayiLHuFmwBvMGv9WFzl9gpuS+EbnN8PW8uL9Xt7AzAzDkEPMM+C miYdd0y3PpfYwKhELG6YCA/g/oV6xE5iwl7nEf750PHfdYGt66DkhsmXmzyyTNNsgbXD RUXw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qg4cAIsgYgWAn+pfVyn0FukhyE7z6IGVj7WAq/swEis=; b=Xm+dHzKi/kZ+1JGMa/y4AeipK5Ue5N06MzQFRilGlosBDxegIAlcMm80zEnGnZmKUZ YZy019dGt6MQkhZKKAT/6d/J+YeQfXQwJhb/Hnyr0Cj4a3TvMc2nt4feX1MAUsWwbIV4 z7cUeK8vkBPPIhuE1HsV7LG5g6idmd/R8S1fNvGFelp8bvPDDt1mUhU+KVFx4zw8890L S1EfjEKr9f7yH0omUvwfVgaCbXEgJZcEQAKWMDScUuwsJdEpFVcBJNpLm3fr1TmzMtBb iMpt/Ao5ina3ZhpOP7TylvY66Vysi9H6exa6I1K2S3qpA7IogFOa0dO9jzIPdEOaBhbm XP4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=neNckBou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si10054216edn.543.2020.08.09.15.31.22; Sun, 09 Aug 2020 15:31:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=neNckBou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbgHIWad (ORCPT + 99 others); Sun, 9 Aug 2020 18:30:33 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:35753 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbgHIWad (ORCPT ); Sun, 9 Aug 2020 18:30:33 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4BPv1g6DNgz18; Mon, 10 Aug 2020 00:30:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1597012231; bh=RC+EGr3hNKbzEyRBAUfk1HbJmZCq+eXVA9OuwVcvm0M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=neNckBouIGX0DmnQsYzaXxnC4dIfyRKT4mEBgQ1kY1uS+jhbDNLqxzCflKHBc+nqR SYyN5THi50e9TkPoFE7Edc9s2MANIH2HRIAcNv+lC8Vg1T52G8mwe2dKyqliciNgHD bd5MPJLdqVd5z8xeTSxDPPBwPNHgrFE30/H/BfW+ospEeKokTYcDsfFf/5USGAfEGI ITYfsY0qLC7A/a+NL78OfL8IGVte3gcHPtBj0P87PkMmg+wOGGjtW1K8dmvhLCEx7u WGxN4SL4UsYgKIChCHQfgo2WcWmVC1yE2VNiFGlhS5475V5MfIcXNUrdqz38MafGzZ Gx3olHA9ZLMkw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at mail Date: Mon, 10 Aug 2020 00:30:30 +0200 From: =?iso-8859-2?Q?Micha=B3_Miros=B3aw?= To: Dmitry Osipenko Cc: Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org Subject: Re: [PATCH] regulator: simplify locking Message-ID: <20200809223030.GB5522@qmqm.qmqm.pl> References: <40871bc7-2d6c-10d4-53b3-0aded21edf3b@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <40871bc7-2d6c-10d4-53b3-0aded21edf3b@gmail.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 Mon, Aug 10, 2020 at 12:40:04AM +0300, Dmitry Osipenko wrote: > 10.08.2020 00:16, Michał Mirosław пишет: > > Simplify regulator locking by removing locking around locking. rdev->ref > > is now accessed only when the lock is taken. The code still smells fishy, > > but now its obvious why. > > > > Fixes: f8702f9e4aa7 ("regulator: core: Use ww_mutex for regulators locking") > > Signed-off-by: Michał Mirosław > > --- > > drivers/regulator/core.c | 37 ++++++-------------------------- > > include/linux/regulator/driver.h | 1 - > > 2 files changed, 6 insertions(+), 32 deletions(-) > > > > diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c > > index 9e18997777d3..b0662927487c 100644 > > --- a/drivers/regulator/core.c > > +++ b/drivers/regulator/core.c > > @@ -45,7 +45,6 @@ > > pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) > > > > static DEFINE_WW_CLASS(regulator_ww_class); > > -static DEFINE_MUTEX(regulator_nesting_mutex); > > static DEFINE_MUTEX(regulator_list_mutex); > > static LIST_HEAD(regulator_map_list); > > static LIST_HEAD(regulator_ena_gpio_list); > > @@ -150,32 +149,13 @@ static bool regulator_ops_is_valid(struct regulator_dev *rdev, int ops) > > static inline int regulator_lock_nested(struct regulator_dev *rdev, > > struct ww_acquire_ctx *ww_ctx) > > { > > - bool lock = false; > > int ret = 0; > > > > - mutex_lock(®ulator_nesting_mutex); > > + if (ww_ctx || !mutex_trylock_recursive(&rdev->mutex.base)) > > Have you seen comment to the mutex_trylock_recursive()? > > https://elixir.bootlin.com/linux/v5.8/source/include/linux/mutex.h#L205 > > * This function should not be used, _ever_. It is purely for hysterical GEM > * raisins, and once those are gone this will be removed. > > I knew about this function and I don't think it's okay to use it, hence > this is why there is that "nesting_mutex" and "owner" checking. > > If you disagree, then perhaps you should make another patch to remove > the stale comment to trylock_recursive(). I think that reimplementing the function just to not use it is not the right solution. The whole locking protocol is problematic and this patch just uncovers one side of it. Best Regards, Michał Mirosław