Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp892826yba; Thu, 18 Apr 2019 11:19:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgjkhMcZ6XOcCtC2Cp18y4mojdNfsd/JhyUFaUjQO0IKX4lHtgEVIvlQP8MxHCh9hTDX26 X-Received: by 2002:a17:902:9341:: with SMTP id g1mr59973692plp.81.1555611560251; Thu, 18 Apr 2019 11:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611560; cv=none; d=google.com; s=arc-20160816; b=Le/NHf2qzQigwxOHaep6OOdammqN9MOB2NoBJfVz5+4FHlTxdl3k2X6RPY8Nk2hCke +scLDvjOfg33I0CfgGzDy9LgOXo6e32n83/ytL76conIC8mS+mS4AOOTSQgUfgDnTZJG LNfSJyjWKI2uBDAY5ttvtiBsOSVAd7Bi8tC+1Cmh9smjsqsNPy5WDf81Gvsb7+AoU2XH coutMJ4f5VEtX7ggkj3IpUhJe60OZ8DfFB4Cjyz6koBG7O14JWKRRJby6wRmykn7+wkL fzk2x3nYKtUrvU39pOAEV2Cb7zpgXttz9ljGDmEZ0rYhkmOMuxxxw/fUFP0lftUumjaK 942g== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=15nwBqmQOuiWV2XNEfe8T7gad3d1/5wIuiZA0DsZAKU=; b=Ec4Jy+gt5M3BWzBWeslsvPpz1vSYHz71xJQVaMa0+j9yuRI6lFs5bHu75hnMLg4pyT 1KPB/XvL4r+G0eTx6krR7eX3fMlogCfeWo8GkFqk4v+KgHnTSUtiAzPF42S3v23BjtcX aVz3rPE7dIiOBZoEtVMae/6sVnKiTeGZbGad3VF7ZLDgSJkc1uFg0n0Gik+jeMLljEr1 DnGERSgfWDbutMURXxFpV2xVwOJqWDaz1OjPyOsK7hIqgD6DY0rNSD6OWnPSGHT89KMD MCXNyeT5EsLZUA2LXQC4HivnmdbwETd5VQ2jIT9i0vGRK43ZPLAH1QNrA0dth1urEdbu YfMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yTVVh9sk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y29si2579012pgk.120.2019.04.18.11.19.05; Thu, 18 Apr 2019 11:19:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yTVVh9sk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404227AbfDRSRd (ORCPT + 99 others); Thu, 18 Apr 2019 14:17:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:43458 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391686AbfDRSLR (ORCPT ); Thu, 18 Apr 2019 14:11:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC20520652; Thu, 18 Apr 2019 18:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611076; bh=bKqwVv9yjqHquJY/6k654Djzhp7VUy5HUN6yxtJ7BEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yTVVh9sk5qBu+CWpNT9DBityvZ+KvTwkZPGR2PM8YSAQ5aKqlp0DdDDyToDkWlafu iGWwZkQVhDSOiee7XlWrhyw0i9zNNu/ydbv004n+5cJ5T/vjhh1/2XkrTdh13H72Q2 rB6T4339mWyMwfsWPJcS2Eb7LUxjMrOlNU3tSm4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiada Wang , Ulf Hansson , Geert Uytterhoeven , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.0 50/93] PM / Domains: Avoid a potential deadlock Date: Thu, 18 Apr 2019 19:57:28 +0200 Message-Id: <20190418160442.790170632@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 2071ac985d37efe496782c34318dbead93beb02f ] Lockdep warns that prepare_lock and genpd->mlock can cause a deadlock the deadlock scenario is like following: First thread is probing cs2000 cs2000_probe() clk_register() __clk_core_init() clk_prepare_lock() ----> acquires prepare_lock cs2000_recalc_rate() i2c_smbus_read_byte_data() rcar_i2c_master_xfer() dma_request_chan() rcar_dmac_of_xlate() rcar_dmac_alloc_chan_resources() pm_runtime_get_sync() __pm_runtime_resume() rpm_resume() rpm_callback() genpd_runtime_resume() ----> acquires genpd->mlock Second thread is attaching any device to the same PM domain genpd_add_device() genpd_lock() ----> acquires genpd->mlock cpg_mssr_attach_dev() of_clk_get_from_provider() __of_clk_get_from_provider() __clk_create_clk() clk_prepare_lock() ----> acquires prepare_lock Since currently no PM provider access genpd's critical section in .attach_dev, and .detach_dev callbacks, so there is no need to protect these two callbacks with genpd->mlock. This patch avoids a potential deadlock by moving out .attach_dev and .detach_dev from genpd->mlock, so that genpd->mlock won't be held when prepare_lock is acquired in .attach_dev and .detach_dev Signed-off-by: Jiada Wang Reviewed-by: Ulf Hansson Tested-by: Geert Uytterhoeven Reviewed-by: Geert Uytterhoeven Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/base/power/domain.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 500de1dee967..a00ca6b8117b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1467,12 +1467,12 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (IS_ERR(gpd_data)) return PTR_ERR(gpd_data); - genpd_lock(genpd); - ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; if (ret) goto out; + genpd_lock(genpd); + dev_pm_domain_set(dev, &genpd->domain); genpd->device_count++; @@ -1480,9 +1480,8 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); - out: genpd_unlock(genpd); - + out: if (ret) genpd_free_dev_data(dev, gpd_data); else @@ -1531,15 +1530,15 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd->device_count--; genpd->max_off_time_changed = true; - if (genpd->detach_dev) - genpd->detach_dev(genpd, dev); - dev_pm_domain_set(dev, NULL); list_del_init(&pdd->list_node); genpd_unlock(genpd); + if (genpd->detach_dev) + genpd->detach_dev(genpd, dev); + genpd_free_dev_data(dev, gpd_data); return 0; -- 2.19.1