Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3944652pxv; Mon, 28 Jun 2021 17:23:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkUac0CTq5d4Wm0u3hBSbjEsaNGbxTcuxSdHHt8pEfdokJdrrG7gTwYTzHKIQoBRgD5gix X-Received: by 2002:a02:641:: with SMTP id 62mr1843231jav.125.1624926233258; Mon, 28 Jun 2021 17:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624926233; cv=none; d=google.com; s=arc-20160816; b=J8EKaVgm6Uo7aqV1Ab36e1ONf6iyobWYKpYzjPOOxajSDCsCuIXH7Szs83XLqHuYcP x9f/JsQsV1nfRe+ghjq+iu7OvocSjjGsz8Caui0HRpWRHRboCap+vaZz1bjliv9lJZ5x HxDbCSuEKVaOwnzkzZsoaZuJ2jUG6+Rl0hSGBfBVN304zRMYL9JtLJZD8JgQ6EUEBJT3 bJRJBgb1QKU6dTyM8bOIEwKl6FgxQGp6wost5FoppKFhTckgvRPEjYVbRv5S/PXLdHBT aVnSo0n3fS3FK5Z1ZiVcMG07F/E3nHgjY/4YMjVGSHYkeTHVWFe9MPuGYXgmSgpmlQjX fWfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Ku4iTgeK6Xjj0yanjIzQMw08wHZgQNbkjae0X6i2vzM=; b=lpedikwJ1DpVJv3NutiWU2attr2R7l4nWzwvX1LulylAxeSAk2eq/RrBviPwxTetN0 TF8adU4Xun80GZ5+xIe0pBpX05vHcQ9bFZqT4axUgRHoP4F7EX0HIDYS263TeV6tg1E6 HIJq4xFboYhKU8n3kGVFBFWvb2BXCDwW+6dDfKKFa1e14XBqhkMkifDY1FNLLXL55tvY QNMZ/CqBFG3zm6viPvfsBVfCGBmnReXFr3pyodX147uiDisA6e2I+BEYEJNhS9W0Y8je pztE8GI1TPJ7PaNcEFMGgY7qfDCGtqxoqop7iIuV1ZOI7+hsVD7gHWkcmdcuI5OL4Ibs 4fhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JfKqO5zm; 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 g18si21104483ioo.53.2021.06.28.17.23.41; Mon, 28 Jun 2021 17:23:53 -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=JfKqO5zm; 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 S237143AbhF1T56 (ORCPT + 99 others); Mon, 28 Jun 2021 15:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237113AbhF1T55 (ORCPT ); Mon, 28 Jun 2021 15:57:57 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD0ACC061574 for ; Mon, 28 Jun 2021 12:55:29 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id d25so27467997lji.7 for ; Mon, 28 Jun 2021 12:55:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Ku4iTgeK6Xjj0yanjIzQMw08wHZgQNbkjae0X6i2vzM=; b=JfKqO5zmBhGRkrwTiSshl0RJndtwXIq085K+lspTtIe19J1/UyC+CcijmTLz610mhz s6dBuomcQG6ykbYh8c6stKjfr/095cPgQH7X3+eEHAXxRgzdqkJHzsrKq8YZ78Joqby3 G/Gi7RCY55qbnSkZ2mXYTqx1RwsrC96EhpuAP+DKodZ8W0KqrKyXe2rN9xaQcnWcVzgw MjorHwH8eE2Ze+L2vMjC7bGyaZZc6vp4R31NzRjTeeHNJ+09igZw1mgre9LRK2ATuzWd PRi9UxPGUzSSr1wGaliV2Rro29RRLvxEyXHb8/xjUED7vcT8ro6Ve1U9dJEvLTGDt2qJ Hevg== 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=Ku4iTgeK6Xjj0yanjIzQMw08wHZgQNbkjae0X6i2vzM=; b=NUAg+fA6OE2/kUqlkFT/YT3GUXwK0/uP9m+FugY1xYzCtHBrICjk7DOTCEtAaG69E0 0EtMhn9lKXVSDnVAdrwL16UISV058wm7IKH6VhFaeicrDDwshfrs1ioelgVfOe+sVRgu mmwbRBTqnPyVgsKrsVDPQRwdymNtpbJ9sNh+/ACCUSiXbjzUeynN8EejjP4QdHHTUzz0 aVg5PvDcY88YHOOnEAHPrMAJmQQv3ercVaW2rD4niuvt3WcuFk+4eFi5WQYfxHKuleHj 9oe/sgiPWjBuCKKgv1O1fUhgMqwBfAWP6WtVOMwj1MVflao6nyTEd0F5XflhZhqXjN4B DMBg== X-Gm-Message-State: AOAM530Rp7cSBXMPwx1ugYyQa7aItZBuel5TeIjSskrneXIGxU0EHMrD oanKFU3sOiQVPtBw910idEy+8A== X-Received: by 2002:a2e:5352:: with SMTP id t18mr629176ljd.420.1624910128099; Mon, 28 Jun 2021 12:55:28 -0700 (PDT) Received: from [192.168.43.7] ([188.162.64.209]) by smtp.gmail.com with ESMTPSA id d22sm1666695ljc.55.2021.06.28.12.55.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Jun 2021 12:55:27 -0700 (PDT) Subject: Re: [PATCH 2/2] PM: domain: use per-genpd lockdep class To: Ulf Hansson , Bjorn Andersson Cc: Mark Brown , Stephen Boyd , "Rafael J. Wysocki" , Kevin Hilman , Greg Kroah-Hartman , Linux PM , Linux Kernel Mailing List , Rajendra Nayak References: <20210611101540.3379937-1-dmitry.baryshkov@linaro.org> <20210611101540.3379937-3-dmitry.baryshkov@linaro.org> From: Dmitry Baryshkov Message-ID: Date: Mon, 28 Jun 2021 22:55:25 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 17/06/2021 12:07, Ulf Hansson wrote: > + Rajendra > > On Tue, 15 Jun 2021 at 17:55, Bjorn Andersson > wrote: >> >> On Tue 15 Jun 05:17 CDT 2021, Ulf Hansson wrote: >> >>> + Mark >>> >>> On Fri, 11 Jun 2021 at 16:34, Dmitry Baryshkov >>> wrote: >>>> >>>> Added Stephen to Cc list >>>> >>>> On Fri, 11 Jun 2021 at 16:50, Ulf Hansson wrote: >>>>> >>>>> On Fri, 11 Jun 2021 at 12:15, Dmitry Baryshkov >>>>> wrote: >>>>>> >>>>>> In case of nested genpds it is easy to get the following warning from >>>>>> lockdep, because all genpd's mutexes share same locking class. Use the >>>>>> per-genpd locking class to stop lockdep from warning about possible >>>>>> deadlocks. It is not possible to directly use genpd nested locking, as >>>>>> it is not the genpd code calling genpd. There are interim calls to >>>>>> regulator core. >>>>>> >>>>>> [ 3.030219] ============================================ >>>>>> [ 3.030220] WARNING: possible recursive locking detected >>>>>> [ 3.030221] 5.13.0-rc3-00054-gf8f0a2f2b643-dirty #2480 Not tainted >>>>>> [ 3.030222] -------------------------------------------- >>>>>> [ 3.030223] kworker/u16:0/7 is trying to acquire lock: >>>>>> [ 3.030224] ffffde0eabd29aa0 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x18/0x2c >>>>>> [ 3.030236] >>>>>> [ 3.030236] but task is already holding lock: >>>>>> [ 3.030236] ffffde0eabcfd6d0 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x18/0x2c >>>>>> [ 3.030240] >>>>>> [ 3.030240] other info that might help us debug this: >>>>>> [ 3.030240] Possible unsafe locking scenario: >>>>>> [ 3.030240] >>>>>> [ 3.030241] CPU0 >>>>>> [ 3.030241] ---- >>>>>> [ 3.030242] lock(&genpd->mlock); >>>>>> [ 3.030243] lock(&genpd->mlock); >>>>>> [ 3.030244] >>>>>> [ 3.030244] *** DEADLOCK *** >>>>>> [ 3.030244] >>>>>> [ 3.030244] May be due to missing lock nesting notation >>>>>> [ 3.030244] >>>>>> [ 3.030245] 6 locks held by kworker/u16:0/7: >>>>>> [ 3.030246] #0: ffff6cca00010938 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work+0x1f0/0x730 >>>>>> [ 3.030252] #1: ffff8000100c3db0 (deferred_probe_work){+.+.}-{0:0}, at: process_one_work+0x1f0/0x730 >>>>>> [ 3.030255] #2: ffff6cca00ce3188 (&dev->mutex){....}-{3:3}, at: __device_attach+0x3c/0x184 >>>>>> [ 3.030260] #3: ffffde0eabcfd6d0 (&genpd->mlock){+.+.}-{3:3}, at: genpd_lock_mtx+0x18/0x2c >>>>>> [ 3.030264] #4: ffff8000100c3968 (regulator_ww_class_acquire){+.+.}-{0:0}, at: regulator_lock_dependent+0x6c/0x1b0 >>>>>> [ 3.030270] #5: ffff6cca00a59158 (regulator_ww_class_mutex){+.+.}-{3:3}, at: regulator_lock_recursive+0x94/0x1d0 >>>>>> [ 3.030273] >>>>>> [ 3.030273] stack backtrace: >>>>>> [ 3.030275] CPU: 6 PID: 7 Comm: kworker/u16:0 Not tainted 5.13.0-rc3-00054-gf8f0a2f2b643-dirty #2480 >>>>>> [ 3.030276] Hardware name: Qualcomm Technologies, Inc. Robotics RB5 (DT) >>>>>> [ 3.030278] Workqueue: events_unbound deferred_probe_work_func >>>>>> [ 3.030280] Call trace: >>>>>> [ 3.030281] dump_backtrace+0x0/0x1a0 >>>>>> [ 3.030284] show_stack+0x18/0x24 >>>>>> [ 3.030286] dump_stack+0x108/0x188 >>>>>> [ 3.030289] __lock_acquire+0xa20/0x1e0c >>>>>> [ 3.030292] lock_acquire.part.0+0xc8/0x320 >>>>>> [ 3.030294] lock_acquire+0x68/0x84 >>>>>> [ 3.030296] __mutex_lock+0xa0/0x4f0 >>>>>> [ 3.030299] mutex_lock_nested+0x40/0x50 >>>>>> [ 3.030301] genpd_lock_mtx+0x18/0x2c >>>>>> [ 3.030303] dev_pm_genpd_set_performance_state+0x94/0x1a0 >>>>>> [ 3.030305] reg_domain_enable+0x28/0x4c >>>>>> [ 3.030308] _regulator_do_enable+0x420/0x6b0 >>>>>> [ 3.030310] _regulator_enable+0x178/0x1f0 >>>>>> [ 3.030312] regulator_enable+0x3c/0x80 >>>>> >>>>> At a closer look, I am pretty sure that it's the wrong code design >>>>> that triggers this problem, rather than that we have a real problem in >>>>> genpd. To put it simply, the code in genpd isn't designed to work like >>>>> this. We will end up in circular looking paths, leading to deadlocks, >>>>> sooner or later if we allow the above code path. >>>>> >>>>> To fix it, the regulator here needs to be converted to a proper PM >>>>> domain. This PM domain should be assigned as the parent to the one >>>>> that is requested to be powered on. >>>> >>>> This more or less resembles original design, replaced per review >>>> request to use separate regulator >>>> (https://lore.kernel.org/linux-arm-msm/160269659638.884498.4031967462806977493@swboyd.mtv.corp.google.com/, >>>> https://lore.kernel.org/linux-arm-msm/20201023131925.334864-1-dmitry.baryshkov@linaro.org/). >>> >>> Thanks for the pointers. In hindsight, it looks like the >>> "regulator-fixed-domain" DT binding wasn't the right thing. >>> >>> Fortunately, it looks like the problem can be quite easily fixed, by >>> moving to a correct model of the domain hierarchy. >>> >> >> Can you give some pointers to how we actually fix this? >> >> The problem that lead us down this path is that drivers/clk/qcom/gdsc.c >> describes power domains, which are parented by domains provided by >> drivers/soc/qcom/rpmhpd.c. >> >> But I am unable to find a way for the gdsc driver to get hold of the >> struct generic_pm_domain of the resources exposed by the rpmhpd driver. > > You don't need a handle to the struct generic_pm_domain, to assign a > parent/child domain. Instead you can use of_genpd_add_subdomain(), > which takes two "struct of_phandle_args*" corresponding to the > parent/child device nodes of the genpd providers and then let genpd > internally do the look up. I've taken a look onto of_genpd_add_subdomain. Please correct me if I'm wrong, I have the feeling that this function is badly designed. It provokes to use the following sequence: - register child domain - register child's domain provider - mark child as a subdomain of a parent. So we have a (short) timeslice when users can get hold of child domain, but the system knows about a child domain, but does not about a parent/child relationship. I think this function should be changed to take struct generic_pm_domain as a second argument. I will attempt refactoring cpuidle-psci-domain to follow this, let's see if this will work. Another option would be to export genpd_get_from_provider() and to use genpd_add_subdomain() directly. I think I'd need this function anyway for the gdsc code. During gdsc_init() we check gdsc status and this requires register access (and thus powering on the parent domain) before the gdsc is registered itself as a power domain. -- With best wishes Dmitry