Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5702327pxu; Thu, 22 Oct 2020 08:59:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaWYg6y+LPUrmWCX6DJ8JY94mUS9ARjSoVKimlo9mKvxuGRsGnrQ9vbJKTBcd2z5olS6j0 X-Received: by 2002:a05:6402:d06:: with SMTP id eb6mr2728509edb.289.1603382398622; Thu, 22 Oct 2020 08:59:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603382398; cv=none; d=google.com; s=arc-20160816; b=nkbTN+0XysGrvIgqeAsUarN/D8iKudW0rkdhAyP577N/X053Qn/mK0Y08YhL9ZGo/r x1/ee/p7+KRn7aBoL5vBrDfBZJ9jTa4pwcVKMeFGM0Kyp+24M/OuiY6sWbxReMqAKXDu q17/q9d8q8yHW2RwWf2ZwMMEv3u9Ez56HudNuOuAurQGWfwRoNYsZvJ2qrFyK/WO6iOS Db7gDFXEcM0v6NCDX82sN0k21c9ib/LCyEAHGojPtESPsfVGLkY0bKW8hbwIjRQZBjKx tvMBN+vvELa174FiNeiix/JzJr5zCHDaT5niS5996DiX1jdoNSSsS/P5iaUIJbbH71YO 9utQ== 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=TVfb7WnwNXKGUxz4iiR3sXsOPTJFuGFroopSW7eD6Gk=; b=RKrktg/lx9ABPRwK1KM8RSJCgVX2/xKLGwU40qrEi90TKOvQTnSYygDn1/XWm3/ajx wbkneYWx8G6bUhVULvVVhl5oGnUnFAoSd5HlB6o1xWilw3Vp9bVQp06yOpKyhLxuRzdM 3421ZdsgJt2Aaq3A7pb5HNmoEeYl7wNlwV7HcmzuJX9wMkG0fCzfb92hSxX7DLUEnZKs 9MWGsIAYsbPAJ9JoUpb6OrtTAx8sNF9hMfFsE70gPhPt8HepsALS994V1C784SFi/oQa 3QQUtqmVNUPrcXzPhd/qlhlI8VuSYnxJKBhcdN6FfnQcsD7yqdHbeD1seRGT4lRfBWBY 8fsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VXy3s7Qj; 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 n10si1197472edv.296.2020.10.22.08.59.36; Thu, 22 Oct 2020 08:59:58 -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=VXy3s7Qj; 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 S2509243AbgJVIIN (ORCPT + 99 others); Thu, 22 Oct 2020 04:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2894377AbgJVIGt (ORCPT ); Thu, 22 Oct 2020 04:06:49 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EE42C0613CE for ; Thu, 22 Oct 2020 01:06:47 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id g16so590543pjv.3 for ; Thu, 22 Oct 2020 01:06:47 -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=TVfb7WnwNXKGUxz4iiR3sXsOPTJFuGFroopSW7eD6Gk=; b=VXy3s7QjvhLDl7KsBOg8MVmOhDTShSxGrDo6aWcBaOc02FD0F85qf0Ti+YtY62gqo0 fQvsKNmMSTtfrleV5GPKxLU+JcUEc2NSUgl+bZqbTTJxWGVdAW4Ks+6O+WpMyT0UYZQU Rk77fNgDCNEX1rBFx3tEw9PNvK5zoEOTcw4Exzt4s4Kw7B/lg/rPlU9NFNmT5+fHkPsJ L6jVrWsH6VfFT6UlRDL93//CvMxZ+gekuFnxD58I6yOGqSKCXsq41PVDX1T/ttn8Zw46 jyhR4qHH+pZ/cQmtByv3Eoc+7RyZzWcCjxuptfiSir3cOI6jaqjAtUWeYCqvGt5RwgoA 0OuA== 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=TVfb7WnwNXKGUxz4iiR3sXsOPTJFuGFroopSW7eD6Gk=; b=TshxFjEtG1V9ct72fAPQfiYgpY1gOPnL+AqWGwXTWp5Qk3X8Vv6/pGodZi78ViZHA+ oMcOCem3HmBNSg5MUN2XxJBQPrFsHnWn3YkEx1fAU/nGaCffInL1PAWD7yWekZ0zDI58 WQ20twcsK9EI4+JuiPPc8yJPH5nDkOG6a3iTPRE78P93fMQvy1IT5Rwdyg3ddYjiRt1t 4ReiI66VfYY6uvmcpAOPGqjjqJwq5suYN5CVNXBHNMlEPL5eYErtBnQH8KGJhauRHPNI oLphsefzWNxgamUyPi+f5rXlMJoj1iIoJJCV82W8XcBbLwPsLBX/AQyVnGmAWfk++m5/ FwdA== X-Gm-Message-State: AOAM530L8HdUie0bV8o557M6bllghLh+Sm2FUD0ryxygNvHyauh5EbvM gddRMzzBbj/QI3CLNjqb+b3XxlTYeZxm3w== X-Received: by 2002:a17:902:7fcd:b029:d3:f037:d9dc with SMTP id t13-20020a1709027fcdb02900d3f037d9dcmr1305142plb.79.1603354007060; Thu, 22 Oct 2020 01:06:47 -0700 (PDT) Received: from localhost ([122.181.54.133]) by smtp.gmail.com with ESMTPSA id v13sm1292150pgl.6.2020.10.22.01.06.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2020 01:06:46 -0700 (PDT) Date: Thu, 22 Oct 2020 13:36:44 +0530 From: Viresh Kumar To: Rob Clark Cc: Daniel Vetter , dri-devel , Rob Clark , Sean Paul , David Airlie , "open list:DRM DRIVER FOR MSM ADRENO GPU" , "open list:DRM DRIVER FOR MSM ADRENO GPU" , open list , "Menon, Nishanth" Subject: Re: [PATCH v2 07/22] drm/msm: Do rpm get sooner in the submit path Message-ID: <20201022080644.2ck4okrxygmkuatn@vireshk-i7> References: <20201012020958.229288-1-robdclark@gmail.com> <20201012020958.229288-8-robdclark@gmail.com> <20201012143555.GA438822@phenom.ffwll.local> <20201020090729.qgqish5kqamhvatj@vireshk-i7> <20201020112413.xbk2vow2kgjky3pb@vireshk-i7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-391-311a52 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20-10-20, 07:13, Rob Clark wrote: > On Tue, Oct 20, 2020 at 4:24 AM Viresh Kumar wrote: > > > > On 20-10-20, 12:56, Daniel Vetter wrote: > > > Yeah that's bad practice. Generally you shouldn't need to hold locks > > > in setup/teardown code, since there's no other thread which can > > > possible hold a reference to anything your touching anymore. Ofc > > > excluding quickly grabbing/dropping a lock to insert/remove objects > > > into lists and stuff. > > > > > > The other reason is that especially with anything related to sysfs or > > > debugfs, the locking dependencies you're pulling in are enormous: vfs > > > locks pull in mm locks (due to mmap) and at that point there's pretty > > > much nothing left you're allowed to hold while acquiring such a lock. > > > For simple drivers this is no issue, but for fancy drivers (like gpu > > > drivers) which need to interact with core mm) this means your > > > subsystem is a major pain to use. > > > > > > Usually the correct fix is to only hold your subsystem locks in > > > setup/teardown when absolutely required, and fix any data > > > inconsistency issues by reordering your setup/teardown code: When you > > > register as the last step and unregister as the first step, there's no > > > need for any additional locking. And hence no need to call debugfs > > > functions while holding your subsystem locks. > > > > > > The catch phrase I use for this is "don't solve object lifetime issues > > > with locking". Instead use refcounting and careful ordering in > > > setup/teardown code. > > > > This is exactly what I have done in the OPP core, the locks were taken > > only when really necessary, though as we have seen now I have missed > > that at a single place and that should be fixed as well. Will do that, > > thanks. > > I do have an easy enough way to repro the issue, so if you have a > patch I can certainly test it. Does this fix it for you ? There is one more place still left where we are taking the opp_table_lock while adding stuff to debugfs and that's not that straight forward to fix. But I didn't see that path in your circular dependency trace, so who knows :) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2483e765318a..4cc0fb716381 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