Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1359877pxx; Tue, 27 Oct 2020 15:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSm21Qw+bhZ5ZCSyHkX/QPVCmSF50qPRE0zb+3xxn9aO9ZGDUSDKo59vJTPmOqkICs8sUk X-Received: by 2002:a05:6402:1e6:: with SMTP id i6mr4627593edy.152.1603836282395; Tue, 27 Oct 2020 15:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603836282; cv=none; d=google.com; s=arc-20160816; b=kaFwAhjfcIaQ4FD7j2gFtIwOMCSY2QpsNJd99Wf8H6EUdbIZ3kkUTwINVu7PoXUUNO Yh9YW8AfP5GUiq7jjPVSQBwBWl9btah7nLFkIsPA1rUjhOokQiqvm2M9n38e6FJV80ms kQSI8wkkFKVxhPx1rBnLAKuq3Rw7dMv38YJzpSuwnQMgpR/1ECar+m/3qB+X8NsabtEy jTbLdIj1Im1RPD0MQ7UqJVtf8wj3yqOb1y5y7TlNQFKtb4VLQL7HhiMtLIRUB9SC+s/+ 2xvUpS9rPrhU6sSbpn6pYBzthB7V8MWJ2JujuOUqHil2cWNl+H0rc1VzEgMYXiNXiuM1 M0jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=RQEP5hZqG2K6tNEaxMR+sF9wkLrep88WEdk8ACgqhWM=; b=YSnADxMHWTmrrPzKlF+kIgyX6EKByUrNynd6Crob7C6HtFVBIEFFiMwJ3ATkhRKl84 14UsjIadpxcRcKQCZvAKUS7+3sbLNbhlFlUO1jifFuwizs9MglMc/vAh7enG0rnXCTE3 zDi6ZWePIiqDelbfMT7JO4rPEy53PY/cgshMwphbuHukx7lLBvQzNkQue62bB/ElgDYG o6Z/q2B4jyKVrrIkP7kMggGYHDwwo/j0/Uve4fjszKmungtllCdR3fAlEsI5aQpMBdI5 KtUkhvvL/uAutz10AE1ilzNq1Njje7voYNUxf2ehooUBHnoDEFB/5+u0AqS74ZOmlyXk w9sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OeplTnTZ; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si1817849ejz.322.2020.10.27.15.04.20; Tue, 27 Oct 2020 15:04:42 -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=@linaro.org header.s=google header.b=OeplTnTZ; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505732AbgJ0FKU (ORCPT + 99 others); Tue, 27 Oct 2020 01:10:20 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36732 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505729AbgJ0FKS (ORCPT ); Tue, 27 Oct 2020 01:10:18 -0400 Received: by mail-pl1-f195.google.com with SMTP id r10so146544plx.3 for ; Mon, 26 Oct 2020 22:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RQEP5hZqG2K6tNEaxMR+sF9wkLrep88WEdk8ACgqhWM=; b=OeplTnTZ8cios1tUcJtmxMxW/XjtujPrVbRNVQkBWUo4Vm/OisXbot5tqg0LhW7HKR CRS6gMNiU0N8Fvs7b8uedyYRTq64pVs9n9m4CmfPdOrVH24s1utC/sk0EfpFXKn+DsNT 9VqIkZYIiSIM0UZfHkKrgoK4TyD9wD270321/i+TDSXRvB0f4CGZPfhQaNfCbpQBMyeB wtiDnlZ1Ruq4hB6OB8CxVDQpxy5GfEbwFlzqmI6NP5rukik+NpHmD+aiDe21PclM9aag 78s984K5fddIvkYrh4dRtcAZfews6H8YgME97CBLV3XsML64ABIWydNoC/7knVQ82P9E 1WGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RQEP5hZqG2K6tNEaxMR+sF9wkLrep88WEdk8ACgqhWM=; b=WSTWE43jKCHbMa73PYAeiQWG6Aq+BU/0yFgbkyj6YeXWBoTqHuGfikOaQNJnVJr3/e uS5aag8S/aI++Swoemt4ixVOVm1QId16bMZ22i9lPN6lH4E/W5R5FGSaVJbjQQpPtH3j YxPvQegCbEbXvqhP3N/okT4delUmchP+Mr3Bl0/ZVCxQmJbLH8b5WWPROjNEUra8DG/M QjUmmBJ4c0axVtdF33KmdSNs2AkcZodtvmkFe5OoaJ0dHvQSXtU3MfCgJGFQpHZRKqOe fiXinoe5nOeGJzYUrWMluZxQ6/FSyjNE8j2knNOu4u5mp13cI5UzQnrrUiPIclF0NL5J SvfQ== X-Gm-Message-State: AOAM531wSmYW+F1qWGZ4bDmlze9YgMT/rlQoN68i6zQc2Vvo2UzVO7KK 29CpRD5sQ5zZpf0nslSa3KjAnw== X-Received: by 2002:a17:90a:8906:: with SMTP id u6mr427458pjn.35.1603775416396; Mon, 26 Oct 2020 22:10:16 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id i21sm379783pgh.2.2020.10.26.22.10.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2020 22:10:15 -0700 (PDT) Date: Tue, 27 Oct 2020 10:40:13 +0530 From: Viresh Kumar To: Dmitry Osipenko Cc: Thierry Reding , Jonathan Hunter , Georgi Djakov , Rob Herring , Michael Turquette , Stephen Boyd , Peter De Schrijver , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Mikko Perttunen , Viresh Kumar , Peter Geis , Nicolas Chauvet , Krzysztof Kozlowski , linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: Re: [PATCH v6 46/52] opp: Put interconnect paths outside of opp_table_lock Message-ID: <20201027051013.5gr4s3wuuwxsd7ax@vireshk-i7> References: <20201025221735.3062-1-digetx@gmail.com> <20201025221735.3062-47-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201025221735.3062-47-digetx@gmail.com> User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26-10-20, 01:17, Dmitry Osipenko wrote: > This patch fixes lockup which happens when OPP table is released if > interconnect provider uses OPP in the icc_provider->set() callback > and bandwidth of the ICC path is set to 0 by the ICC core when path > is released. The icc_put() doesn't need the opp_table_lock protection, > hence let's move it outside of the lock in order to resolve the problem. > > In particular this fixes tegra-devfreq driver lockup on trying to unload > the driver module. The devfreq driver uses OPP-bandwidth API and its ICC > provider also uses OPP for DVFS, hence they both take same opp_table_lock > when OPP table of the devfreq is released. > > Signed-off-by: Dmitry Osipenko > --- > drivers/opp/core.c | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/drivers/opp/core.c b/drivers/opp/core.c > index 2483e765318a..1134df360fe0 100644 > --- a/drivers/opp/core.c > +++ b/drivers/opp/core.c > @@ -1187,12 +1187,6 @@ static void _opp_table_kref_release(struct kref *kref) > if (!IS_ERR(opp_table->clk)) > clk_put(opp_table->clk); > > - if (opp_table->paths) { > - for (i = 0; i < opp_table->path_count; i++) > - icc_put(opp_table->paths[i]); > - kfree(opp_table->paths); > - } > - > WARN_ON(!list_empty(&opp_table->opp_list)); > > list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) { > @@ -1209,9 +1203,22 @@ static void _opp_table_kref_release(struct kref *kref) > mutex_destroy(&opp_table->genpd_virt_dev_lock); > mutex_destroy(&opp_table->lock); > list_del(&opp_table->node); > - kfree(opp_table); > > mutex_unlock(&opp_table_lock); > + > + /* > + * Interconnect provider may use OPP too, hence icc_put() needs to be > + * invoked outside of the opp_table_lock in order to prevent nested > + * locking which happens when bandwidth of the ICC path is set to 0 > + * by ICC core on release of the path. > + */ > + if (opp_table->paths) { > + for (i = 0; i < opp_table->path_count; i++) > + icc_put(opp_table->paths[i]); > + kfree(opp_table->paths); > + } > + > + kfree(opp_table); > } Never make such _fixes_ part of such a big patchset. Always send them separately. Having said that, I already have a patch with me which shall fix it for you as well: diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 4ac4e7ce6b8b..0e0a5269dc82 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1181,6 +1181,10 @@ static void _opp_table_kref_release(struct kref *kref) struct opp_device *opp_dev, *temp; int i; + /* Drop the lock as soon as we can */ + list_del(&opp_table->node); + mutex_unlock(&opp_table_lock); + _of_clear_opp_table(opp_table); /* Release clk */ @@ -1208,10 +1212,7 @@ static void _opp_table_kref_release(struct kref *kref) mutex_destroy(&opp_table->genpd_virt_dev_lock); mutex_destroy(&opp_table->lock); - list_del(&opp_table->node); kfree(opp_table); - - mutex_unlock(&opp_table_lock); } void dev_pm_opp_put_opp_table(struct opp_table *opp_table) -- viresh