From nobody Sun Feb 8 05:41:28 2026 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 E03431A4F3D for ; Tue, 13 Aug 2024 19:11:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723576295; cv=none; b=FDw8QseIgq1xz+Lp2OXCRGk++vo2517Co+4K7PV9prUUNlI70EbPDeTEZBaJL8GiszA74kyHTGIBJEvWj2mtmIspPdAinMSArwLmgH1f0Uk9TJWLnPC5LEO9ehg79JrCZs0WWz46WpDNcwT7i6h9ap6GKxXyKz9sW4R73v3LbuA= 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.44 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-f44.google.com with SMTP id 2adb3069b0e04-5320d8155b4so3207740e87.3 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=CVTVZPOlDCjbO98kxHyY8fx6xLmCuOmgIA5IT2kESMLIpEypgA3Y+8Ir9Q0U8lq+io fzRpW6lIES7L7NaKVgQXyCiefnOoeswVjGjwzoC7ZcRGHuT86c6y1aRIj7YemAuy7A3a SMvLe8WVUhNQrbqI4S2O/PkiGf6XPGC+Eweo7osHyhWKgRNT2xpUs7Muj0FVhCRU0Ty4 GEEvmiHQr4n3t0e6p3is62ohFxgrZJ9bJTVCJ9C/et400bpVLir+CMxzPlIs8lR+gVxT zt0IUkQjNsRc3xIgTwZ1uFmntZGRQNHr0EHm/f+vQ1Gm/hq17ACFO04NXziNBTfFfzTy MLoQ== X-Forwarded-Encrypted: i=1; AJvYcCU8M9BkD3hRUsBIz0BY2LXE8Gc+lbndJQn5XphkBQvCT6NqRjMdQAuYcCRrMQ0QtwXX5Bn3Zpov19F6HeE=@vger.kernel.org X-Gm-Message-State: AOJu0YxWybaezZuDl5XdYNsxYBcUzTZh08mGQSPfVYSvnQJ1W9YeiR0m 0+3WyZXzrijIrWsfBxsNv9beMYuw6T5g5YLI4RZFZcfSARHgNHCQGAbGncR4yhdWyV9TMDcGcx5 VR2A= 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-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 --- 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