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 372B1C46CA1 for ; Mon, 18 Sep 2023 17:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjIRRGM (ORCPT ); Mon, 18 Sep 2023 13:06:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjIRRGL (ORCPT ); Mon, 18 Sep 2023 13:06:11 -0400 Received: from bmailout3.hostsharing.net (bmailout3.hostsharing.net [176.9.242.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F03F8E for ; Mon, 18 Sep 2023 10:06:02 -0700 (PDT) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id DDD42100B0390; Mon, 18 Sep 2023 15:24:24 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 92E68595A2E; Mon, 18 Sep 2023 15:24:24 +0200 (CEST) Date: Mon, 18 Sep 2023 15:24:24 +0200 From: Lukas Wunner To: Mario Limonciello Cc: Mika Westerberg , Bjorn Helgaas , "Rafael J . Wysocki" , linux-pci@vger.kernel.org Subject: Re: [PATCH] PCI/sysfs: Protect driver's D3cold preference from user space Message-ID: <20230918132424.GA11357@wunner.de> References: <20230918130742.GU1599918@black.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Mon, Sep 18, 2023 at 08:14:21AM -0500, Mario Limonciello wrote: > On 9/18/2023 08:07, Mika Westerberg wrote: > > 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. > > > > Makes sense. I just wonder should the sysfs write fail from userspace > > perspective if the driver has opted out and userspace tries to force it? > > Or it does that already? > > What's the history behind why userspace is allowed to opt a device out of > D3cold in the first place? > > It feels like it should have been a debugging only thing to me. That's a fair question. Apparently the default for d3cold_allowed was originally "false" and user space could opt in to D3cold. Then commit 4f9c1397e2e8 ("PCI/PM: Enable D3/D3cold by default for most devices") changed the default to "true". That was 11 years ago. I agree that today this should all work automatically and a user space option to disable D3cold on a per-device basis only really makes sense as a debugging aid, hence belongs in debugfs. Thanks, Lukas