From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 2B0952FE56A for ; Fri, 17 Oct 2025 17:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760721068; cv=none; b=M9m8boezXAWMtubw25+dCfIcJFr98E7Zj9KJBShZIlLaRL9V8bdc4a4cOvLvGSlJh8M+CkxRTP0y8CnWCiSsOJk3MDVSMPpReAMAvvuTuQ09+AVqsAVN+iQvWZsrLdPNqg1utb1TdWgdJv9R0GpnNiiDG2K7yrUakSxwx+1QZ/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760721068; c=relaxed/simple; bh=aBjjIxnkY/FA3VjaRF/v5raEcuHOjy9Oe4kTong4tPk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Oo6yBbWTDMwb+BCNlUYaBH0r7iV3ZXtuvOY3F1y1DXtgbeiFjvbxh8+Kw4pwPRZZkn/hexDKfmixWxSJCHE7JTlHxHV4lDrOy2fmRhvOmvP/0cisLXkpq3DCmnVEiNdRVIm4/RYm4LlBr7e8P5cWMG80hcW/m4SjId8Rxli3spg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=crq1HVv8; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="crq1HVv8" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3352018e051so2552576a91.0 for ; Fri, 17 Oct 2025 10:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1760721064; x=1761325864; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=wBM/oeHMFZtatvJ+zW6/cnV/R+5GapNosgNZTWLHrZg=; b=crq1HVv8qH695bk3+v5Cz9kS/qrgPWdQ+zJLT3PY0JJ8YKP3aBkrnfiAeOjnylfV70 a+MQaEhTO7ktQ710/nlibXmsxK9xO8J6PrMcSn6nefbYxkjIzUdwMKR9+6YTj/0hFfn1 fxIM9WNbdM+YFxjwiu0xcEA9gfklIZ3MJm5MY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760721064; x=1761325864; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wBM/oeHMFZtatvJ+zW6/cnV/R+5GapNosgNZTWLHrZg=; b=C7Ds+L9lM4VVfSw4YqbOCXRLIlR5/oLOUzjbKU0UymmKGr9hjsDwCzO10U+dAd2+4n ZHHmQ/n0Yqnt3VSaa98TqMOtqfYKmuMKfcN7uKaeongeTt5XFQhB0RiSqsciWsQRLJpY 4osXdiZKTo1F0r/Xnjy8b5i5SFz++uB2IDumkaeNkUTfAXv6vPVawKI4zVqjaW1ZTpmE TXQ45Pej6mbwN/3el1ERdth9zL/lwJEA7BYsm/1KzANYt9G3JMZqqRsalPwvIlbnQXOo TaRC06U/ynKEQRf0JJor7gWw3dc3i2rELur3PFPkQYY0jsmrgJAA0QhGEhZEYP1ILxM5 gKlA== X-Forwarded-Encrypted: i=1; AJvYcCUPRnfxHAjLD3ut7G7plGf73oVr5uKhFZmsGWHDCDEej7JvtPmkkLHu6G/yvWPfNreCKrkFRqoyC8EhRPE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0BdRI7HhdUl1mz2zpIy4OczGAIQ6uKuJtxxVqMxe9qqzb62fR fO31pp4A7FWT9800fW0eW9SzBDbdaVPl0S+4ZVKLlfkd6GNMpfYB8t4/G21pADe0Cg== X-Gm-Gg: ASbGncsXkOr6IumIPOCfcH8H9SXrTfsarii1oRch+KaLwDrDb7PRn84r9boDYTEz73y pqqT+Hp4pnVYl10MrdA+efJV+xj1iVSC+LjkiLnnq096NxFk+hWeV6mvUH2LSOMZXOnpvqgJlk3 P3Pq3AkU1DXdpRyfWf3Zq0/jQ65oPMiMvbZd9632BiapsAYFahd6bNszy0iEGLMwkrGSXDvnwma vhwKA0tbAkwdwECujoesL1xrb7ojOviRR7GKHtojeX4mrrYMKs9gtpSwXDF5uQXzoynHff/eTXF hLYp+tgMhRYx9kY5GHsCCSRhXl8sa1OwN+Bpkr+s1qDsQEqzffHNlEwJrVcaBNHN7GLJNo8zJkU NMcYv1yV/NcKVFzWCDhmnwka46tqgMibBa4Li6Xvv/kF4pWBk0UBYeCuMAXQXxNmKJ43XOBab4+ h91kPnoprwmhzPfMTfd+nwCqeA/PqhRlRljPQxQSup47mkoqhJhhYoZRWWgRo= X-Google-Smtp-Source: AGHT+IHKYNW+lzSgEoR/ftLOyWk4dENf+z842xkhdFHWXcXQluEhrxtoUMASXE6ncX8JmfeiyZU3fg== X-Received: by 2002:a17:90b:3dc4:b0:332:8133:b377 with SMTP id 98e67ed59e1d1-33bcf87f8c3mr4875586a91.15.1760721064328; Fri, 17 Oct 2025 10:11:04 -0700 (PDT) Received: from localhost ([2a00:79e0:2e7c:8:5ca9:a8d0:7547:32c6]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-33bb65222a6sm6105739a91.4.2025.10.17.10.11.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Oct 2025 10:11:03 -0700 (PDT) Date: Fri, 17 Oct 2025 10:11:01 -0700 From: Brian Norris To: "Rafael J. Wysocki" Cc: Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Lukas Wunner , linux-pci@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] PCI/PM: Prevent runtime suspend before devices are fully initialized Message-ID: References: <20251016155335.1.I60a53c170a8596661883bd2b4ef475155c7aa72b@changeid> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Hi Rafael, On Fri, Oct 17, 2025 at 11:45:14AM +0200, Rafael J. Wysocki wrote: > On Fri, Oct 17, 2025 at 1:28 AM Brian Norris wrote: > > > > PCI devices are created via pci_scan_slot() and similar, and are > > promptly configured for runtime PM (pci_pm_init()). They are initially > > prevented from suspending by way of pm_runtime_forbid(); however, it's > > expected that user space may override this via sysfs [1]. > > > > Now, sometime after initial scan, a PCI device receives its BAR > > configuration (pci_assign_unassigned_bus_resources(), etc.). > > > > If a PCI device is allowed to suspend between pci_scan_slot() and > > pci_assign_unassigned_bus_resources(), then pci-driver.c will > > save/restore incorrect BAR configuration for the device, and the device > > may cease to function. > > > > This behavior races with user space, since user space may enable runtime > > PM [1] as soon as it sees the device, which may be before BAR > > configuration. > > > > Prevent suspending in this intermediate state by holding a runtime PM > > reference until the device is fully initialized and ready for probe(). > > > > [1] echo auto > /sys/bus/pci/devices/.../power/control > > > > Cc: > > Signed-off-by: Brian Norris > > --- > > > > drivers/pci/bus.c | 7 +++++++ > > drivers/pci/pci.c | 6 ++++++ > > 2 files changed, 13 insertions(+) > > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > index f26aec6ff588..227a8898acac 100644 > > --- a/drivers/pci/bus.c > > +++ b/drivers/pci/bus.c > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -375,6 +376,12 @@ void pci_bus_add_device(struct pci_dev *dev) > > put_device(&pdev->dev); > > } > > > > + /* > > + * Now that resources are assigned, drop the reference we grabbed in > > + * pci_pm_init(). > > + */ > > + pm_runtime_put_noidle(&dev->dev); > > + > > if (!dn || of_device_is_available(dn)) > > pci_dev_allow_binding(dev); > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index b14dd064006c..06a901214f2c 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -3226,6 +3226,12 @@ void pci_pm_init(struct pci_dev *dev) > > pci_pm_power_up_and_verify_state(dev); > > pm_runtime_forbid(&dev->dev); > > pm_runtime_set_active(&dev->dev); > > + /* > > + * We cannot allow a device to suspend before its resources are > > + * configured. Otherwise, we may allow saving/restoring unexpected BAR > > + * configuration. > > + */ > > + pm_runtime_get_noresume(&dev->dev); > > pm_runtime_enable(&dev->dev); > > So runtime PM should not be enabled here, should it? Hmm, I suppose not. Does that imply it would be a better solution to simply defer pm_runtime_enable() to pci_bus_add_device() or some similar point? I'll give that a shot, since that seems like a simpler and cleaner solution. Thanks, Brian > > } > > > > --