From patchwork Tue Aug 13 19:11:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13762432 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 9AF211A4F22 for ; Tue, 13 Aug 2024 19:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723576292; cv=none; b=fMPHqTC+BMlmLL8TRyuET+CvRUo51PEctE6ugjdIziUVlJ1GMEr/NpZafhfm/vcJ6kqZV13Fr5NvJxAtorpfCQbMf3XAp/6SJN/pN9PKEWZjOHAv9OgNg21mbbF+BDiom27xkN7ZW74Edh8+PNwO9T2uolNeNaVmaoKzYN21rEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723576292; c=relaxed/simple; bh=mWILBLZHbB1X/mnl4rN42BdL76EDoT2h6V0HD1WKzGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FfPn63cnsobrOEzsOEaQ9MoQEzZC9XG3WHb1Q/2chi3G7XyW51aaaYxY5991K449Nes53tb/d3Q5zyVLEbo6nvBxVR+lucXf/KEo4oUmV1hUUaL8HANmJ6+icjOEIKlZ3cqAGkDNDsYmcJn2qJeYOVXLKoBGBncWvMoW5kyVL40= 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=m9KmNKyi; arc=none smtp.client-ip=209.85.128.42 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="m9KmNKyi" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4281faefea9so43596275e9.2 for ; Tue, 13 Aug 2024 12:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1723576289; x=1724181089; 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=Cd+Ltzvt2y78lpUCgzPi2AZ1lJGgupHq0LCVF6fTzhc=; b=m9KmNKyih6czKfZE4tEc3ZKhTZNF0ImLMG4+JCdHGsFTjGASYmxhLABdvXUk7iuAXe T5gLg4WvsSrE8rCLh+mAirV02I8CEWgDOWBPFrtq9FntBNCZi9p7TRZoAbv6wKUm+KD+ ISz+f9GTeqwGtpGTLbMQoNMvQIKqtpcSlbCjMoWdKwY9GIf2di3AfqwJlj8fuLhUnunr YEC3hY0vjxsFJZHcP3/4FKjX7Lo3BV2DFBn/9iSOvK7OqmQ/O/u3LxbK7dYkUVYD252b 0b5RiBTH2oaw3D/ulTVAsXGw6tNhwvYjCNPvhclzViP7mVzjqkDNYRxrNCP7crU+G6cy ld6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723576289; x=1724181089; 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=Cd+Ltzvt2y78lpUCgzPi2AZ1lJGgupHq0LCVF6fTzhc=; b=PJqteAbFOwhKtHih2bQup9tC0SBSTxm4A0NDXp2x1Wrg3FfCQFMQu+4s6g7i4OtEOb HXDjxutb4BcXWFzHOxlaChAR6RkILaBpI15DnBOymuj3M7xcX21foXHNHpHKZWFdXRIk 9kO88JMcfL59jrGYqfQqYpAJuxFNsmZ64uFm35CAv+AB12SXBrpiF8GesZMK7rXNf1Rr a/iu+oQtx+9mO9QWyGlvoVZ0XIQ3R3+0Zsx6uaqDQ6SQKCBUrZOGokcQ7f/wXgIz5twa kO5uvn0jAHJzLP2im0cQLxgpV3TzaME+JykafzRpWtlU00fZ5ITSSFJpnNFNnb4zHVAH UAgg== X-Gm-Message-State: AOJu0Yw6pKWKYRMWBpQHG44RDBu2LhHhe3Ig1Oadfwn1M8Z5h8AbHS7/ 3gDhvTQgHxUp4RYovCFSUD5nZW+A5ND/mYnXdcfxWgGpTHWJYZZ3jLS1xMVEkjg= X-Google-Smtp-Source: AGHT+IGTb4phP4GJdlEPLX/IDQBPfgNuZKbxgy0+kCBn16LjtlKF1r5S3f6vp8AZuv/Z7KuuIe1zxA== X-Received: by 2002:a05:600c:5116:b0:426:5dd0:a1e4 with SMTP id 5b1f17b1804b1-429dd22f272mr3517245e9.8.1723576288824; Tue, 13 Aug 2024 12:11:28 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:dc:7e00:3979:ff54:1b42:968a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429c7734595sm147511405e9.36.2024.08.13.12.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 12:11:25 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/2] PCI: don't rely on of_platform_depopulate() for reused OF-nodes Date: Tue, 13 Aug 2024 21:11:17 +0200 Message-ID: <20240813191119.155103-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813191119.155103-1-brgl@bgdev.pl> References: <20240813191119.155103-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 nodes of the port node") Signed-off-by: Bartosz Golaszewski --- drivers/pci/remove.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 910387e5bdbf..7d78d0c0b7e2 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include "pci.h" @@ -16,13 +17,26 @@ static void pci_free_resources(struct pci_dev *dev) static void pci_stop_dev(struct pci_dev *dev) { + struct platform_device *pdev; + struct device_node *child; + pci_pme_active(dev, false); if (pci_dev_is_added(dev)) { - of_platform_depopulate(&dev->dev); device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); + + if (dev_of_node(&dev->dev)) { + for_each_child_of_node(dev_of_node(&dev->dev), child) { + pdev = of_find_device_by_node(child); + if (pdev) { + of_device_unregister(pdev); + of_node_clear_flag(child, OF_POPULATED); + } + } + } + of_pci_remove_node(dev); pci_dev_assign_added(dev, false); From patchwork Tue Aug 13 19:11:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13762433 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 937691A4F39 for ; Tue, 13 Aug 2024 19:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723576295; cv=none; b=EAqldfEIoa7khoxX2aAywuED8J/3fp4R4h9b8p36o5S3NtR8y88d7oSZbm9kSLwUYFwyImigsiBtTk13PAcpIUARYKbDYd1IYTP7NwoMkHS5EMoopA7sLZ4Djl58hARckmdTFtT1zkChw4A7B/vkkPBv4iIJ8+QqI7RrRN8QLUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723576295; c=relaxed/simple; bh=VlEWS+I2qBUoAZu3MZiZFqikaq4uXZWuP6/ITJZxiQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F3KK+PY68IOqJNAJBdE+/Fa3LiFCdt2ofVl03uU0fzCmTZp23GjhxUXNreav7gdhvmiXAGgMuyizESRFuOtQfi/DJj+BfeKG9xyL+WRBXkaILFsPfJQzMe7bSF7TVq0EFP/aiLXo7ugekrDrPADfHTLdu3xLH8JDkdg5PWNxpqg= 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=KeIE104k; arc=none smtp.client-ip=209.85.167.52 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="KeIE104k" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52efc60a6e6so7791665e87.1 for ; Tue, 13 Aug 2024 12:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1723576292; x=1724181092; 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=KeIE104k0MD+98/9MRSadoHuI4TX3AeyclfFDTXqkdImmNnlHfZAVSL8JMOn91GubK RDm2c/ByPZmHd8prc5zKYHWHJvYQLblC8iCufDP72C5PROmKAtKjPuhPXFQdaZgzDTdv Y1abW3L0VmzYeRkSC1IMwSgqacYTRBDo92PIUFw77Q8cShAFck3iueeL+h1gaguzLlLh mrUBEtlsNKi8XpR1XkNX2Y6qsi/cLN5MYoN72lKXrgCY1uD+AIVn5CZQQgYzG8OahJc4 ql02f+3HFnL8UFYWNfF7xv8+3Att5y71chOZNxmPJ1vWmqCM5tI4CnIh7lR2UARm37jQ qbeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723576292; x=1724181092; 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=F9IGBmbk4hJyFpCILkLLUu69qpIix2s6Nhl0lS3augh/YWBiamPBw8EyH852hK+ntS i/F9OtY7rpaVAASQGAu0dqTDBnNqd8SzngMMQRm/JX/0C70nggIj+ngEwCWFOhcxFTmL hB0vocCKFxP80s88JlO9iGEQ63sEzWeQl2ftr+bA7lIpXmRP6Tcs/6EoJAnUm4P2u7q+ xeT/IGmKN9cg7aPcLWShsgegU1CpR1AeslUCK8x42fzVYqK7260fk4NpCbKKXcXPPfIR 9fiAgggLojI6a2BFzwqwqb8MSCCcm99KynQjF8G8R8Geu1i/UNgG3ehSmPZGSdx6f/iH UJLw== X-Gm-Message-State: AOJu0YzyqK0AgjxiwP+q/GjHpd6X8rx9ia9kHMh9lM/UKMk6UObmlYvd APd8RLIos9qwo7C3Z/kM4yqSriKUgmHu2GmJLpjm0udNfKwTsnD2z5VMVJCeLZw= X-Google-Smtp-Source: AGHT+IEaG5qL+48HD+ToLdhBsaWWHAg9Y7cW8RYNV07QZZNy1UgbvfAPhuohNo07mQICyOp3KP0bYw== X-Received: by 2002:a05:6512:2347:b0:52c:e030:144e with SMTP id 2adb3069b0e04-532edbbc97fmr224018e87.47.1723576291477; Tue, 13 Aug 2024 12:11:31 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:dc:7e00:3979:ff54:1b42:968a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429c7734595sm147511405e9.36.2024.08.13.12.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 12:11:29 -0700 (PDT) From: Bartosz Golaszewski To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski , Konrad Dybcio Subject: [PATCH 2/2] PCI/pwrctl: put the bus rescan on a different thread Date: Tue, 13 Aug 2024 21:11:18 +0200 Message-ID: <20240813191119.155103-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240813191119.155103-1-brgl@bgdev.pl> References: <20240813191119.155103-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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; } +static void rescan_work_func(struct work_struct *work) +{ + struct pci_pwrctl *pwrctl = 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 = 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; - pci_lock_rescan_remove(); - pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus); - pci_unlock_rescan_remove(); + schedule_work(&pwrctl->work); return 0; } diff --git a/drivers/pci/pwrctl/pci-pwrctl-pwrseq.c b/drivers/pci/pwrctl/pci-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; - data->ctx.dev = dev; + pci_pwrctl_init(&data->ctx, dev); ret = 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__ #include +#include 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; }; +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,