Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3681637rdh; Tue, 28 Nov 2023 00:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6PDqmcbBKcPHaqtDGtW8vCslmC9zAOC9M2RRsrFG8thaDTvVqMfoW2Mz0zv3hcmUH195j X-Received: by 2002:a9d:4d08:0:b0:6d7:ed0f:8824 with SMTP id n8-20020a9d4d08000000b006d7ed0f8824mr14718237otf.5.1701159533279; Tue, 28 Nov 2023 00:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701159533; cv=none; d=google.com; s=arc-20160816; b=J2C0zNqUe7gZ/t0IF1JNHGG5/dTzr/0kjVYr2BEE3w+jUqqL8CJyexSLj69GvxNAfz O3t+77NY1scWFn8tDfqBjnnCjRhAcs3ADCyh7sjXrMKoLGvQzHmbINLWiLZka8Zk2rJF x5pdX0J+ERPFf95zLnx73u/DAyUHmy9kPUDQ2LC708uqv+n9Gx2psUn5AQm+ET0jr7Oi CTcMdrg4FKt8I2UfjXLSl+uschzk20Ini7u2CEbMjf2uFH1j2QAlIdc1pdCm9qN9tWYv KkAMHE8CsqSmrl1Q3IAsp3eQZ//2COoQpvayffraKijqT5Lhj2Ns7KRyN2BIL96t4DOu x3pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t7RLiPP0P5xQc/jS1ZNG6K3HfqHQ540STNyqKN00cXA=; fh=n9j1ofctKSeYxvmwnbKmIbkuN2/6NCaqclsXgGVH+6A=; b=XuTwIUygF5QBF7V/+Uu1PHqdE1LuPlR7lDpmwm4f1f6nNHv/T90//k4UyPbIUJjjhC Onlc/Get3/S1p3mJuJVVaVx9eOWCr0tw8/fgZxO1HrhXCpPX80AlQh+NF/aEauQwdV8Y /BG90WC8dJ7BI6l2hwHioPAThyxqF2ZFJfc3ux38UqMWEjp/yWBqQbIRf+j50OWJKz1/ 9jSmACR5SSho730bJI79I8OeDSmGijXOThx1PJZnMOEuQnBJQUH1wJJrBRBdlaivx9qM lJqSqUASRCCHSHwLAxKf2iVnAztA7SomEXfqPUsfjdj2bDEQUd4IILg8As4Epj6ndPye Boxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KePGVFYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id g14-20020a63200e000000b005aa0e024d63si11821810pgg.791.2023.11.28.00.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KePGVFYk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2783A804DD8C; Tue, 28 Nov 2023 00:16:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344104AbjK1IPe (ORCPT + 99 others); Tue, 28 Nov 2023 03:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344049AbjK1IPT (ORCPT ); Tue, 28 Nov 2023 03:15:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09CAA100 for ; Tue, 28 Nov 2023 00:15:26 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B1DFC433CC; Tue, 28 Nov 2023 08:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701159324; bh=ldSxVLm151+9Q08xzcfgehlwNmHacduIvn8mLdpw3MU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KePGVFYkKCg+fXwzHWo2HnyjhX9Zr2jHkmy1eiykrci56JAFiNLHSHkkizTcxo6eR uV0uD5HK0PstpCYwy9pmIUtUF5y29g+cvKeBILu5wlhdTCUa9W1cazuJSw8mi5eWLP /AN5grugmjvSA13X9F2lbf2ThCiNRQXxQ+pLo+A/7idYbx1GVcXs7pBpepX7aY0hk0 MrRzhRjdR7dcz1dBvDcOxRdD6dliCErptS7/zOTehlO1g/C1CHzmsKZsC9Pb73EI5P EpJpJoiD7TctTPQO4SHuVY5TcDNc+3fK9GvCZvqRVAjS095HAK8WgTlbJFPqsj2fNN TxIQQDR1TthLQ== Received: from johan by xi.lan with local (Exim 4.96.2) (envelope-from ) id 1r7tG4-00053t-2C; Tue, 28 Nov 2023 09:15:52 +0100 From: Johan Hovold To: "Lorenzo Pieralisi" , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , "Bjorn Helgaas" Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Manivannan Sadhasivam , Rob Herring , Nirmal Patel , Jonathan Derrick , linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Manivannan Sadhasivam Subject: [PATCH v2 3/6] PCI: qcom: Fix deadlock when enabling ASPM Date: Tue, 28 Nov 2023 09:15:09 +0100 Message-ID: <20231128081512.19387-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231128081512.19387-1-johan+linaro@kernel.org> References: <20231128081512.19387-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 28 Nov 2023 00:16:15 -0800 (PST) The qcom_pcie_enable_aspm() helper is called from pci_walk_bus() during host init to enable ASPM. Since pci_walk_bus() already holds a pci_bus_sem read lock, use the new locked helper to enable link states in order to avoid a potential deadlock (e.g. in case someone takes a write lock before reacquiring the read lock). This issue was reported by lockdep: ============================================ WARNING: possible recursive locking detected 6.7.0-rc1 #4 Not tainted -------------------------------------------- kworker/u16:6/147 is trying to acquire lock: ffffbf3ff9d2cfa0 (pci_bus_sem){++++}-{3:3}, at: pci_enable_link_state+0x74/0x1e8 but task is already holding lock: ffffbf3ff9d2cfa0 (pci_bus_sem){++++}-{3:3}, at: pci_walk_bus+0x34/0xbc other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(pci_bus_sem); lock(pci_bus_sem); *** DEADLOCK *** Fixes: 9f4f3dfad8cf ("PCI: qcom: Enable ASPM for platforms supporting 1.9.0 ops") Reviewed-by: Manivannan Sadhasivam Signed-off-by: Johan Hovold --- drivers/pci/controller/dwc/pcie-qcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index ce3ece28fed2..21523115f6a4 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -971,7 +971,7 @@ static int qcom_pcie_enable_aspm(struct pci_dev *pdev, void *userdata) { /* Downstream devices need to be in D0 state before enabling PCI PM substates */ pci_set_power_state(pdev, PCI_D0); - pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); + pci_enable_link_state_locked(pdev, PCIE_LINK_STATE_ALL); return 0; } -- 2.41.0