From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CE3DE7734B for ; Fri, 29 Sep 2023 22:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232748AbjI2Wsb (ORCPT ); Fri, 29 Sep 2023 18:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjI2Wsa (ORCPT ); Fri, 29 Sep 2023 18:48:30 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 388261B4 for ; Fri, 29 Sep 2023 15:48:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A04A5C433C8; Fri, 29 Sep 2023 22:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696027707; bh=LTdeKaEfByvbWI/bXUM/E65QTLw+Od1Li/G8s5MJgBs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=u21Z2Uiv0CTbVaqtVLJ9LgzGnVVQL09szyqbQqxrMUhkYEzYhFa3l3UCuWZbplSXL xV5m/OPSd550s0TY2jkjBtNWFLSTyy7XmcgXOhKmEsrg+3ElvprnXj80YuRmpRsMxB MRQ87dzxWX7h0HVAo6LlAA2t8jALF4Adj3JRoqSFpKZqen7K5ZZci7iilCe9CLixws LfEe/sW2hGXwNd1xdy3vP4ghdr12VOX+JPpjUPJqFl4sBfFnpE4v1TSV0jWdGYpJ04 xMUOGNnEZytnSBZggF7Da6gTXJ/u4JxCIAyH3ItboF273MlMZtTWxYPakEyv+f3xdV Uczk/UKjDw00g== Date: Fri, 29 Sep 2023 17:48:25 -0500 From: Bjorn Helgaas To: Lukas Wunner Cc: Mika Westerberg , "Rafael J . Wysocki" , linux-pci@vger.kernel.org, Mario Limonciello Subject: Re: [PATCH] PCI/sysfs: Protect driver's D3cold preference from user space Message-ID: <20230929224825.GA559886@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Mon, Sep 18, 2023 at 02:48:01PM +0200, Lukas Wunner wrote: > struct pci_dev contains two flags which govern whether the device may > suspend to D3cold: > > * no_d3cold provides an opt-out for drivers (e.g. if a device is known > to not wake from D3cold) > > * d3cold_allowed provides an opt-out for user space (default is true, > user space may set to false) > > Since commit 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend"), > the user space setting overwrites the driver setting. Essentially user > space is trusted to know better than the driver whether D3cold is > working. > > That feels unsafe and wrong. Assume that the change was introduced > inadvertently and do not overwrite no_d3cold when d3cold_allowed is > modified. Instead, consider d3cold_allowed in addition to no_d3cold > when choosing a suspend state for the device. > > That way, user space may opt out of D3cold if the driver hasn't, but it > may no longer force an opt in if the driver has opted out. > > Fixes: 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend") > Signed-off-by: Lukas Wunner > Cc: stable@vger.kernel.org # v4.8+ > Cc: Mika Westerberg Applied with Reviewed-by from Mika and Mario to pci/pm for v6.7, thanks! > --- > drivers/pci/pci-acpi.c | 2 +- > drivers/pci/pci-sysfs.c | 5 +---- > 2 files changed, 2 insertions(+), 5 deletions(-) > > diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c > index 7aa1c20..2f5eddf 100644 > --- a/drivers/pci/pci-acpi.c > +++ b/drivers/pci/pci-acpi.c > @@ -911,7 +911,7 @@ pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) > { > int acpi_state, d_max; > > - if (pdev->no_d3cold) > + if (pdev->no_d3cold || !pdev->d3cold_allowed) > d_max = ACPI_STATE_D3_HOT; > else > d_max = ACPI_STATE_D3_COLD; > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c > index ba38fc4..e18ccd2 100644 > --- a/drivers/pci/pci-sysfs.c > +++ b/drivers/pci/pci-sysfs.c > @@ -530,10 +530,7 @@ static ssize_t d3cold_allowed_store(struct device *dev, > return -EINVAL; > > pdev->d3cold_allowed = !!val; > - if (pdev->d3cold_allowed) > - pci_d3cold_enable(pdev); > - else > - pci_d3cold_disable(pdev); > + pci_bridge_d3_update(pdev); > > pm_runtime_resume(dev); > > -- > 2.39.2 >