From nobody Sun Feb 8 01:33:55 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81D6714A092 for ; Fri, 23 Aug 2024 09:33:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724405617; cv=none; b=CM173VHqeMXf7TAzfznlm4CiITbQhaGnrSIAR/mDRLbL/euQp3PAm07fCbqHwEOis53BQaFqp/ulj+srGbkZ1SM2rMmxHPVKEYfKDwZLSKRtliTO4CrANfisShOqkJKKhmu0bUKYQOxnsfLchgGRv1rRxv0nlMtBfGAjLWrvw3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724405617; c=relaxed/simple; bh=SDW+jhpHqOJq3t1ya0ovj2sjAIj5GyPFm3xRSUy/2F0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AoQcOL6XKiqNdGtc6RNqoU0aEHuo60GDi10w4+fyTAPPgCAQPSi8pG8ie1kBtOn0Kl7VpCXif5Pa1CX3SJAjq4Gyd9qIApIdnL2IyQOsGQK4SZcrMhUaCTIXeZppLT9HQ6aukMxSgXkiRBc35o5icabmMB57ztoFdLVWUgvshrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=O4dRrsTJ; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="O4dRrsTJ" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-428119da952so13728125e9.0 for ; Fri, 23 Aug 2024 02:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1724405614; x=1725010414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UV0kDEyv+rHlN+IT+BwYqyEyzLehqMc19rUT/kqAz5s=; b=O4dRrsTJCYE8pGZG+zP/kEpBQUHJLNnc8A6R4ACfr33ts6TqwlnUGekD1iZI+z/XJQ OiuEANBDmki6RVSfUI6is0xxiE/JXA6+hVs5X1WrwgQuYkAAvvy2j2d38/8oC0izK3yS jJpGNtqYDKzlx2nmITa86WkVQ7BlbvT7Tv26Br9+zyypYoRRN5jRoOE9P7NOlZOA0PRS xkkEygVQNrPoofuTjt184TeWLuVDgxexR+xcEybyxMojbbmT2VrbJEp7r/S02CxLNtZk WwNojfOwb2v2dZNAIxr9N2KYry2SHKeABwYuxI/ioLCulLi09u8GfbxvHM5EVJ0yy7U6 5j8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724405614; x=1725010414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UV0kDEyv+rHlN+IT+BwYqyEyzLehqMc19rUT/kqAz5s=; b=Yd3/Q3M9Wpm4rsWwRwAWDxQVjWsT3cC7BDUwhTsDu1dm6D4S8+J7J57TGQdGUV4UU1 0C7IFBEThCqPeG62o3zuH4G857rMpCNOTdJbiZoV2d9b2Lg7s/+3qZjzAox0oafqN+Lp +6HmWUijhsnmlQE0McQOBM82OzOBVmUWnyf6II2xnpQX7Whu5ZVXr6N2yha4SpvfKf+g XtHpOIX+sDFX14M0UPq6+RRuVY9uxr9/AO7g7ew4+0VfGtAujTsBOGdWnz+hZgQLJ83Q qB8Jka1pX8hOrIlCVnkJAkaBMg5eKGlirtf7NOtC/9CUsU4VO9M6G39dl3G8N/G6yp8I C/bQ== X-Forwarded-Encrypted: i=1; AJvYcCXG6Z2JbjRl/dgV62RygNN+hLje/ingiM+e/Rw6UKzzXDrUH+y4vqqHd/iBOLcuOYYTUrXxHsb0JsBtP5Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yybz2F81VmdfCx+e3+t4EjnYtp0A0QxCYbEqtwvcrM3m02uaodR U1iLgcukoCn9ynDeOc/+ptAz8lueDG4aHzhUAAz/vxpsEzIeRC3rIhJQhFmAQXY= X-Google-Smtp-Source: AGHT+IEeAv1jnkfW+fOz1SblCfxZMUL3ovR6NdTgXGEH2aaFFKUhFX0IWkYCwyAUiU4W+DH5ULiI6w== X-Received: by 2002:a05:600c:1c9c:b0:429:e67f:1249 with SMTP id 5b1f17b1804b1-42acc8d525emr12713535e9.3.1724405613016; Fri, 23 Aug 2024 02:33:33 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:dc:7e00:58fc:2464:50b0:90c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abee86d5esm87612035e9.15.2024.08.23.02.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 02:33:32 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas , Krishna chaitanya chundru , Manivannan Sadhasivam Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 1/2] PCI: don't rely on of_platform_depopulate() for reused OF-nodes Date: Fri, 23 Aug 2024 11:33:22 +0200 Message-ID: <20240823093323.33450-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240823093323.33450-1-brgl@bgdev.pl> References: <20240823093323.33450-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski of_platform_depopulate() doesn't play nice with reused OF nodes - it ignores the ones that are not marked explicitly as populated and it may happen that the PCI device goes away before the platform device in which case the PCI core clears the OF_POPULATED bit. We need to unconditionally unregister the platform devices for child nodes when stopping the PCI device. Fixes: 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF node= s of the port node") Signed-off-by: Bartosz Golaszewski Acked-by: Manivannan Sadhasivam --- drivers/pci/remove.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 910387e5bdbf..4770cb87e3f0 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -1,7 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include +#include + #include "pci.h" =20 static void pci_free_resources(struct pci_dev *dev) @@ -14,12 +17,25 @@ static void pci_free_resources(struct pci_dev *dev) } } =20 +static int pci_pwrctl_unregister(struct device *dev, void *data) +{ + struct device_node *pci_node =3D data, *plat_node =3D dev_of_node(dev); + + if (dev_is_platform(dev) && plat_node && plat_node =3D=3D pci_node) { + of_device_unregister(to_platform_device(dev)); + of_node_clear_flag(plat_node, OF_POPULATED); + } + + return 0; +} + static void pci_stop_dev(struct pci_dev *dev) { pci_pme_active(dev, false); =20 if (pci_dev_is_added(dev)) { - of_platform_depopulate(&dev->dev); + device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev), + pci_pwrctl_unregister); device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); --=20 2.43.0 From nobody Sun Feb 8 01:33:55 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FACC13A86C for ; Fri, 23 Aug 2024 09:33:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724405620; cv=none; b=tZdQQmosKaS3C+pRSw+EzhB/wpV1h5WEd/rzvIur51i2vJbjXzrNE2loD4SPJQJkWeudQ8S7EAjyKXjv7Y0v/Haj7g9rL+YH1RUzORvBA3yS+GgUb2jN/dY5nuY/fbz/bR4owDwJMLkwR7zZ6QvcYgMFo88czu/Ui6EVRSvb8L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724405620; c=relaxed/simple; bh=VlEWS+I2qBUoAZu3MZiZFqikaq4uXZWuP6/ITJZxiQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lc9xBrGy2JJQp+XCMgR177RS1mOCxH+U7aDhvmyuIQGe/vnd4+pzVIIy21e1+1tHM3FQupf2G6/uFNYs9WT7jYYJAC/3aixSqWLlrLp2cwB1LdnAUKXorRfTGjoW7IduIQuGjWgeOElgvFgzvPSIOaXIPZDAVK21icNHBq6niMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=GProBBiS; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="GProBBiS" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-429da8b5feaso17572545e9.2 for ; Fri, 23 Aug 2024 02:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1724405616; x=1725010416; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ns4EUZZ3nTL5odSKliuQhTwD1CbjvkOmQ7rToMzAA/s=; b=GProBBiSE10kSUudTPOUq83MZLnurR8SZLXlzMtQjWYn72Hd1C5o+Mh2ZhzBxYv6Oj xYhVMCxw8k4i8pZSc9UR7DH+gqgAzm4PoD5u9EMumGDFsVghYtxe6CzAuOWiBk54dXTu EC/GZ6XHOU/eQ32Oh+5NtVeVbmzdX2SMkSM2vGni1Zo+TvpiXpuuGB2NkcWUO8pN0J0U E8k0dYTuIKoz27Q1GOH3B3jpo7kb8kPCCmDRA+ZVz7L/hhQPZF6PVoruCRbAkNmIHRZT uY1szmYClOEf8D3+xXi3Aq+HNnn5rA+/gHKpR0tkP+aBfr4nQBZBLobu6Dxx1HEdd7rt Gy0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724405616; x=1725010416; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ns4EUZZ3nTL5odSKliuQhTwD1CbjvkOmQ7rToMzAA/s=; b=e7hrgC2FJC3y/cHceM/n9jcwmMNkWfLzLNjwVR44iX8JT1/JE5MX/3fxsB4G63e3Hl EZRymVwnt1VH+AftHd7zVfQpfcwMQMTBtbeS6HTtRtofSEGy76GVV/yi30ffW5RDGc+r Kfg83uzumINQgIFqwevsg3oub+oHQfmNafHpZIW0uSCeDdHczxnHNDXDlJbJuq63doN7 d+7DgKSfzFqq61j5DJN1bQ6CYqlpBoDJq+bot3W9NdsGJqsEEcdPwl9HWRkQjpjtzi8b ipdxpnVbiAJ3qqZ6CZuPiEIU+uYZR18qKW4ZXyfqlHq3AHOmLN97UZwu9fUx8gL6oLzO n0gA== X-Forwarded-Encrypted: i=1; AJvYcCWgDER3ronQ2BJ94pX22i/qoSqrm+PnAF+6A4VmadFQJsGfDuHhxeeMwNNbA92lJ0ItnJAUS6CT280v2w8=@vger.kernel.org X-Gm-Message-State: AOJu0YxcU80vp10hPvowKpbXTS0adUcEgB5zAqEKewFRiBqgZ0C+hZaN dOcjIZXpGatlcDAKIqRFG+s6HwktHyTaigYqKLJsdn4zWZQQInwUXLR7Qy0QuTE= X-Google-Smtp-Source: AGHT+IFDN6ciVAxxG2thf6jNJ/OndV0vdP06G8DkZr6xUCbixfP6dzAPR8cgPbEm9FRU4nH0OyFf6g== X-Received: by 2002:a05:600c:35cd:b0:428:15b0:c8dd with SMTP id 5b1f17b1804b1-42acd57c113mr12461705e9.20.1724405615130; Fri, 23 Aug 2024 02:33:35 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:dc:7e00:58fc:2464:50b0:90c5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abee86d5esm87612035e9.15.2024.08.23.02.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 02:33:33 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas , Krishna chaitanya chundru , Manivannan Sadhasivam Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Konrad Dybcio Subject: [PATCH v3 2/2] PCI/pwrctl: put the bus rescan on a different thread Date: Fri, 23 Aug 2024 11:33:23 +0200 Message-ID: <20240823093323.33450-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240823093323.33450-1-brgl@bgdev.pl> References: <20240823093323.33450-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bartosz Golaszewski If we trigger the bus rescan from sysfs, we'll try to lock the PCI rescan mutex recursively and deadlock - the platform device will be populated and probed on the same thread that handles the sysfs write. Add a workqueue to the pwrctl code on which we schedule the rescan for controlled PCI devices. While at it: add a new interface for initializing the pwrctl context where we'd now assign the parent device address and initialize the workqueue. Fixes: 4565d2652a37 ("PCI/pwrctl: Add PCI power control core code") Reported-by: Konrad Dybcio Signed-off-by: Bartosz Golaszewski Reviewed-by: Manivannan Sadhasivam --- drivers/pci/pwrctl/core.c | 26 +++++++++++++++++++++++--- drivers/pci/pwrctl/pci-pwrctl-pwrseq.c | 2 +- include/linux/pci-pwrctl.h | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pwrctl/core.c b/drivers/pci/pwrctl/core.c index feca26ad2f6a..01d913b60316 100644 --- a/drivers/pci/pwrctl/core.c +++ b/drivers/pci/pwrctl/core.c @@ -48,6 +48,28 @@ static int pci_pwrctl_notify(struct notifier_block *nb, = unsigned long action, return NOTIFY_DONE; } =20 +static void rescan_work_func(struct work_struct *work) +{ + struct pci_pwrctl *pwrctl =3D container_of(work, struct pci_pwrctl, work); + + pci_lock_rescan_remove(); + pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus); + pci_unlock_rescan_remove(); +} + +/** + * pci_pwrctl_init() - Initialize the PCI power control context struct + * + * @pwrctl: PCI power control data + * @dev: Parent device + */ +void pci_pwrctl_init(struct pci_pwrctl *pwrctl, struct device *dev) +{ + pwrctl->dev =3D dev; + INIT_WORK(&pwrctl->work, rescan_work_func); +} +EXPORT_SYMBOL_GPL(pci_pwrctl_init); + /** * pci_pwrctl_device_set_ready() - Notify the pwrctl subsystem that the PCI * device is powered-up and ready to be detected. @@ -74,9 +96,7 @@ int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl) if (ret) return ret; =20 - pci_lock_rescan_remove(); - pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus); - pci_unlock_rescan_remove(); + schedule_work(&pwrctl->work); =20 return 0; } diff --git a/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c b/drivers/pci/pwrctl/pc= i-pwrctl-pwrseq.c index c7a113a76c0c..f07758c9edad 100644 --- a/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c +++ b/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c @@ -50,7 +50,7 @@ static int pci_pwrctl_pwrseq_probe(struct platform_device= *pdev) if (ret) return ret; =20 - data->ctx.dev =3D dev; + pci_pwrctl_init(&data->ctx, dev); =20 ret =3D devm_pci_pwrctl_device_set_ready(dev, &data->ctx); if (ret) diff --git a/include/linux/pci-pwrctl.h b/include/linux/pci-pwrctl.h index 45e9cfe740e4..0d23dddf59ec 100644 --- a/include/linux/pci-pwrctl.h +++ b/include/linux/pci-pwrctl.h @@ -7,6 +7,7 @@ #define __PCI_PWRCTL_H__ =20 #include +#include =20 struct device; struct device_link; @@ -41,8 +42,10 @@ struct pci_pwrctl { /* Private: don't use. */ struct notifier_block nb; struct device_link *link; + struct work_struct work; }; =20 +void pci_pwrctl_init(struct pci_pwrctl *pwrctl, struct device *dev); int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl); void pci_pwrctl_device_unset_ready(struct pci_pwrctl *pwrctl); int devm_pci_pwrctl_device_set_ready(struct device *dev, --=20 2.43.0