Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3935526pxa; Sun, 9 Aug 2020 17:26:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQoSYI9gPAjvYcKmc0wydRpQzznWVFuT99uSN5/UtAmpbekFJryb9XJkpA0GOZkouG0qLp X-Received: by 2002:a50:cbc3:: with SMTP id l3mr18887940edi.58.1597019195879; Sun, 09 Aug 2020 17:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597019195; cv=none; d=google.com; s=arc-20160816; b=HglZfUxycjI3MVVL8UKZ+SDTEMoSsgNRyWoHSpsPJ6Sk63Y2J4G5gnTl+bdU098cDy Kpc8/yF+LJyHgAohZzFMNzN7y2Al8qtf+WySN5sMuNhGFee2XFYbWulUpZEeO4d7ziGr q3WwnoP1bzLXeCQjb2PQIa8EUeZknWgcfmhi9lkTiIub6XXoO1KAu66yfEBu/JHgtdR0 2HNoZeXX5is+9nNLPdxQDCuxUC6WtvewzCWP+MuJtYycYuAoQbKTWyQuv4WtGbTsVmi0 jmtssVdFPyhHW0GFbwwWw8nHF91fjKCHdlaYEL2rqveuqf0WvdNsZ0kj08RQbN5HvtEs PDIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=P/ypPDyRPbCocww+YFXAuHCLF+0kpPQwbXzkE6ttE/Y=; b=Vud+FaoLg4a9cKBLewMxmENPQa4YIZc6v6RzwGaxxByBkYS3XJ+klRPu2Wj1XogLx8 +JtQSDVTyKZ4SSpImH03OQU1n45CaTx7e9BeYzdxonsF6HIJE3iLWefBZ0w9zzKQBQxN SufGfH5Mix5xpvwFMkMIly/FK26AMtlUg+JFffmmkjkjlKMweD6mCMeAhcCER/iezey3 8k2c28zYaEuDf9bMqV+vruVAMn5NP8x6DWJfdg+c8s2Qra2OlCpMhwef55iCjKpgzByq b+s1QYH7b4kbdxKP3Jg0i8iiv09xejwdQajmI0KH1gysO39+wbY7+sgS9Fs8YPwAYC1O 2YFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XBU2Rmmg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si9488909ejd.406.2020.08.09.17.26.00; Sun, 09 Aug 2020 17:26:35 -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=@gmail.com header.s=20161025 header.b=XBU2Rmmg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726472AbgHJAVv (ORCPT + 99 others); Sun, 9 Aug 2020 20:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726219AbgHJAVu (ORCPT ); Sun, 9 Aug 2020 20:21:50 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23FD4C061756 for ; Sun, 9 Aug 2020 17:21:50 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id h8so3793032lfp.9 for ; Sun, 09 Aug 2020 17:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=P/ypPDyRPbCocww+YFXAuHCLF+0kpPQwbXzkE6ttE/Y=; b=XBU2Rmmg0TsRVZ76/PqiHpNNtcQvigRFiiGwNRKu/VoeJsv9IPVAGHYMz/PEKPv3WB ZKJv7C/cWl2LmtC/iFbkZ4w9uKWiAXIexssMhkeabZaptSP0wK8p85osz0vMW8eDMpH3 EqhbZUep83r0kb4wDLLhKWXr66e1YraeVCwP0FO2+oQxa1VmFKzk+oz/5mEvOnJ5F5/w 9Kyf39z8bHprOW5cy8Joh21ZhRDmPcbaakJFffBlhEkZOdbb6K+aBnwl9dicday8vZP2 zY30SbeC94gaZ/wFNuQcHcyrqgkxH2hgvvWgx4y+Eyabgvd3Lmegr4qq2A3A2AiurLZQ iLiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=P/ypPDyRPbCocww+YFXAuHCLF+0kpPQwbXzkE6ttE/Y=; b=lHztYgSCltMiOWYVMjDEhXdy3YgbIHBmf30vRJHJPLbNjOPpMkCRE4tHeTbXcnON4Z RRsnJ4UtgvGlzySJ+HGRQzZJztohTymv5UIjWXjdw2ivokr1cV3z3U+UPJBf9zmNEhav OIzJ6xyRz5HT/Bo68qI+b9cZbeGNIe7Az2GxipLQsCunR4mwXO4jIOOaR9e4O9C/JOJn BSLlT6w1KWcMm1krmVBzF0Z1a0XH51vc6L5muUvb0mE4IiGuEAKCIZ7pj92A1VjUtQTF zo3FDUMLUG3txr2jVXWn5k4UU71ZY6IAYg2ghLSm0R3a/DB6Msq+jLSj1Q3hYbq1hvi4 BDew== X-Gm-Message-State: AOAM532gYrdZLZvPszdPkwV8JbpAJMAO5okzNu0VSbhZgzvZ1SFPJHYh daR2ROlYEH+0yDpqnNEObotYi0nf X-Received: by 2002:a19:814c:: with SMTP id c73mr11508672lfd.16.1597018908388; Sun, 09 Aug 2020 17:21:48 -0700 (PDT) Received: from [192.168.2.145] (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.googlemail.com with ESMTPSA id b15sm2422214lji.140.2020.08.09.17.21.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Aug 2020 17:21:47 -0700 (PDT) Subject: Re: [PATCH] regulator: simplify locking To: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org References: <40871bc7-2d6c-10d4-53b3-0aded21edf3b@gmail.com> <20200809223030.GB5522@qmqm.qmqm.pl> From: Dmitry Osipenko Message-ID: <8850c09f-4b24-7ab2-a0f7-e0d752f5a404@gmail.com> Date: Mon, 10 Aug 2020 03:21:47 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200809223030.GB5522@qmqm.qmqm.pl> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 10.08.2020 01:30, Michał Mirosław пишет: > 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. It's not clear to me what is uncovered, the ref_cnt was always accessed under lock. Could you please explain in a more details? Would be awesome if you could improve the code, but then you should un-deprecate the trylock_recursive() before making use of it. Maybe nobody will mind and it all will be good in the end.