Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2657056lqp; Mon, 25 Mar 2024 05:57:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrQbFnSoMwTHzoZ0MUEj9KWWYioshc5LGM8ZF8lfE/jrCCegxxoOcPoRkiDTFTMxUh3QmqCfzPMPmIfBLC03+5xib0Xsqty3e5RO4ANg== X-Google-Smtp-Source: AGHT+IE19cxiNP29TZpk6hPN9Euq0/siWZ71ll0GIhFV0lgS6gqpxMwd3qwEsxZMEhJxdjDnAeUq X-Received: by 2002:a5b:c0b:0:b0:dc3:7041:b81b with SMTP id f11-20020a5b0c0b000000b00dc37041b81bmr5117114ybq.36.1711371466646; Mon, 25 Mar 2024 05:57:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711371466; cv=pass; d=google.com; s=arc-20160816; b=S6kx7TYGFwpOTZzJxoEBRc3Vo+lZdSAZbwaKmdNrhRCK4mGP23DnJklx8WYbsQtFrO obMZxJBmQgOXJbYSH4aY88iuLq1+HEz4zfPeC7RfK3T1SZj6+7ZFBdhbRe8LuepFI08p S8fGfsUHMvVpl83nZRVCrA8Klup82Na+W+l8A9auMsZCz0Q4PWLBH97dXQLJDhlT+58h apsSOM0I/b6fPiGGah+dbNQHJ7rVQb+n2YGpPwMg6YSpLOus+PA0ane4fkk+PjqnCCUE UIENWhYNQ5G6z5NbAVhq3QMQ0eT61r8QIVKsrW5iROQ88EBiq7H5EzRSt0aZT1SpIFPz UzgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=gr8D5m+lLjC+E3puayJoxIUALHh45YJdiuYEB1NQzVU=; fh=tn6CQFdg3XWtPb8/rlbCIEcKmU8qhMw/BupQ/AkEefk=; b=wNRhnOWquDsP7XBiy+XNm+IR6OS08fxuM/wcWsHeWn+dYQZuPPcgwg3sTxcjdskwV8 18xi3FxBI7vGAoCJGqR4G8fwUFok7eV0SrdRO6qp2Iq8HmgvmmL37c6P8sch+M7mSwDW t85s9FY6q9I1SRLJGcjoIe3dNBNNvs9t1cpUCpLkAreDs6h2Omy9F7i2ZxTWnFNJRMGi qtOdeP+1ZEzSGiJjT6m2XZNoTYybBR14g/HOXE+W9A06C4FBDIQF4o94NdKSecF+7q9u N+9ir0iwDp9DqNxdn4djQshfbVYmC64hfRC4+pIed0eYDOsiPc8MzSOK9MQvr2MLpS3k rJxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rwUwJwMF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116544-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jm12-20020ad45ecc000000b006967e37c3a8si4279258qvb.172.2024.03.25.05.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 05:57:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rwUwJwMF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116544-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116544-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 622B01C35125 for ; Mon, 25 Mar 2024 12:57:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F395414198A; Mon, 25 Mar 2024 07:57:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rwUwJwMF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D4931411F7; Mon, 25 Mar 2024 05:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711345445; cv=none; b=bYtCv73T4wesbsmU/JbKHYBlxDGDjhbux/ziB2RX1il/72W70LUXi97Rq1H8H44vZ7Ce0YBrSnXshWjEATjTKu9fnBLBx0HD2w2MiNDRwZLj+KpCYNUoTXLvJVH6XQJxrCxkw52Mx2J8vT1Loevdq7zGXD+unaiEL8AVgsuZg0w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711345445; c=relaxed/simple; bh=S6KN9NZ86rsgC3JbJzRsAdTxPonS8+fxlmqhl9tZ1yg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lS8YKp20fDs6SLZAlVpja/YX5UZzMU3bKGv3wFXfigYIhLuC8hcvhGN/G/9prEfI2fM+zCK/yDFl7K/3CxKlfbBfU2+J2MD22MxL7/GXL6pCDasGAXzlG81/eE5MRqyDumNEHpGcL+4uXh/OGiMMbrYTVoH7UmEHRuvEFtmx7qg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rwUwJwMF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75841C433C7; Mon, 25 Mar 2024 05:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711345445; bh=S6KN9NZ86rsgC3JbJzRsAdTxPonS8+fxlmqhl9tZ1yg=; h=From:To:Cc:Subject:Date:From; b=rwUwJwMFeRA31ZENhBOdCiysC+P6+e/hadizGOz4gmwvM4riRhQSW8seRjHUBUoTC CGUcZ7DGUVR1iLCIDuKnEBn6iReIvWPbD6XLAJuXrtUhv6Ow+a2l+9hvOZavJzoVR3 n7xd07fbPWA77PhEBtup8DXBOTbPqeov3fE4Bha8INIG4S3dehxvCLnC292LP8CgrS h8Igu7BDaaPCt2CzvmPxvEvm5r/R8+CXBvZCcb7RVVJOKVWUtkDRWPqJbHLo8xgWMN QfDYl4o5wHBXUX3WTdaGnJ9g7A3nBcgzg9v3AAFWi0AX/fna+fYzPnhlKjVYMgz3YT tKzvSk6aHK1vA== From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, linux-arm-msm@vger.kernel.org, Douglas Anderson , Krzysztof Kozlowski , Marek Szyprowski , Taniya Das , Ulf Hansson Subject: [PATCH 0/5] Fix a deadlock with clk_pm_runtime_get() Date: Sun, 24 Mar 2024 22:43:57 -0700 Message-ID: <20240325054403.592298-1-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch series fixes a deadlock reported[1] on ChromeOS devices (Qualcomm sc7180 Trogdor). To get there, we allow __clk_release() to run without the prepare_lock held. Then we add runtime PM enabled clk_core structs to a list that we iterate and enable runtime PM for each entry before grabbing the prepare_lock to walk the clk tree. The details are in patch #4. The patch after that is based on the analysis in the disable unused patch. We similarly resume devices from runtime suspend when walking the clk tree for the debugfs clk_summary. Unfortunately this doesn't fix all problems with the usage of runtime PM in the clk framework. We still have a problem if preparing a clk happens in parallel to the device providing that clk runtime resuming or suspending. In that case, the task will go to sleep waiting for the runtime PM state to change, and we'll deadlock. This is primarily a problem with the global prepare_lock. I suspect we'll be able to fix this by implementing per-clk locking, because then we will be able to split up the big prepare_lock into smaller locks that don't deadlock on some device runtime PM transitions. I'll start working on that problem in earnest now because I'm worried we're going to run into that problem very soon. Stephen Boyd (5): clk: Remove prepare_lock hold assertion in __clk_release() clk: Don't hold prepare_lock when calling kref_put() clk: Initialize struct clk_core kref earlier clk: Get runtime PM before walking tree during disable_unused clk: Get runtime PM before walking tree for clk_summary drivers/clk/clk.c | 142 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 115 insertions(+), 27 deletions(-) Cc: Douglas Anderson Cc: Krzysztof Kozlowski Cc: Marek Szyprowski Cc: Taniya Das Cc: Ulf Hansson [1] https://lore.kernel.org/all/20220922084322.RFC.2.I375b6b9e0a0a5348962f004beb3dafee6a12dfbb@changeid/ base-commit: e8f897f4afef0031fe618a8e94127a0934896aba -- https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/ https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git