Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp41754pxh; Thu, 7 Apr 2022 13:23:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdzQTEqRl/v3Yp6bm80/jyEK4/tkk/RjTn6L7SE0dkNd2WARDzkkUF/dSaOCUstwjIPzLA X-Received: by 2002:a05:6a00:1988:b0:4fa:c15d:190d with SMTP id d8-20020a056a00198800b004fac15d190dmr15541874pfl.44.1649362996275; Thu, 07 Apr 2022 13:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649362996; cv=none; d=google.com; s=arc-20160816; b=rIgR7J8JviZQxEAJ9dYByeOs1zfh0kCUri/dS9zKgFegNwbeUHTNNaYQ1uyx4XBhgX eShNG3KVykfDFa1brXGpjWabRR0VLCvCx9MRFulN1CrszlsEISw8DCECVy8gl7s66Ltn SHZSeHXWlsshLoj+z87fEcZczjBtQwidnsh1sO6zALE3nHJDm76yfsbvzk2QCcZbDM+k 3ln990RkInd6lJsU+vw1L3DFF2rI+ks5MScduAMKKle4uQFd0PSlQiMGVnS6pXPtkd2/ BonVh3eSMv3B2fE9xaAQ2ZeBe9F9l1R65feOfL1JGDwTLkxIaFuuKkbClEnE59K1Y9Uh Ctkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=ZGD1/P1eXCqhTH9MB1Py6yMHa/YFvYh5c7tHdx0u8Pk=; b=QpIymxNtfLUer0mSvJIawx1O/nqKWoOD6jWAo7KZ2QjcLAUik+zAipn9+BYNq83ei1 xHXSEragayTlw9X0DT0r0ABeTKmzMWZQVN6fmVBVFIkJ429S/GkVcq5U2/pAcqLExn8A brzgMx71a8uyST+AR7c2S8fS1mQ63TMneE6TINGabgG9gSTjfN8Jtk540pL/Q/XzW5HV UzjcErlbgJ7VKfLXBFPDWIAQh3rdi9Syo3GlHgNpcExPEGg8I87mYxLiaQAuSm8r6tRM ZKev4XyB7uSRKQqkDQDwg7Nifr1BC7+XHNfI8wpSbkwZmSiS5T5T+7F6yr41zUdCLoEt 1F6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mi6-20020a17090b4b4600b001bf1e011e98si2742419pjb.171.2022.04.07.13.23.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:23:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1CA9B1E8CC2; Thu, 7 Apr 2022 12:41:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238554AbiDGTEO (ORCPT + 99 others); Thu, 7 Apr 2022 15:04:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbiDGTEM (ORCPT ); Thu, 7 Apr 2022 15:04:12 -0400 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5F722EB16; Thu, 7 Apr 2022 12:02:11 -0700 (PDT) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-2db2add4516so72800737b3.1; Thu, 07 Apr 2022 12:02:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZGD1/P1eXCqhTH9MB1Py6yMHa/YFvYh5c7tHdx0u8Pk=; b=av2WMsDE+fRA9olKRhATLjT5Jk7jMYeOKORh97SxOTh1so26WXzl5GII3FenxgV3Uy Ootd3G2R+KrWK1CeuPFw+5CwzpHhiM6mN0IL1bbt9N4DJW1r0v35dYWbLDXKeuDyjjtg 2sSFVskr5dkuyumzObRxsm6UM8a8PC4odSwVkh5/Kjp1vKc34oIy50gVPN6VGRwRWy+J 5w/5CNTRvqiUgRt+VMDrDauNEdTHURK1Hx748MBGwCRhm0x9ywKcIpD8L3N0EDD9D+hW eUIDHCOOmPZrhJ22rZUUgP5RL1Uwbf2gnYeg8lO5E1bklLQPo3dD+lF3axA5vHYt4xSd BE9w== X-Gm-Message-State: AOAM531kTnVV+HB5JGeF0l/nYr+pbH1C4yIlCuCKnj4qnXSgNF4vsL5E EkS+Z/geVXsuCHRdb8wuYG/vuCiOOUzepk/Tt04= X-Received: by 2002:a81:1549:0:b0:2eb:3dc7:bd16 with SMTP id 70-20020a811549000000b002eb3dc7bd16mr12995239ywv.7.1649358130411; Thu, 07 Apr 2022 12:02:10 -0700 (PDT) MIME-Version: 1.0 References: <4198163.ejJDZkT8p0@kreacher> <3623886.MHq7AAxBmi@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Thu, 7 Apr 2022 21:01:59 +0200 Message-ID: Subject: Re: [PATCH v1 1/2] PCI: PM: Avoid leaving devices in D0-uninitialized in pci_power_up() To: Mika Westerberg Cc: "Rafael J. Wysocki" , Linux PCI , Linux PM , LKML , Bjorn Helgaas Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 5, 2022 at 1:45 PM Mika Westerberg wrote: > > On Mon, Apr 04, 2022 at 05:41:13PM +0200, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > In theory, pci_power_up() may leave a device in D0-uninitialized > > during a transition from D3cold to D0. > > > > Say, a PCIe device depending on some ACPI power resources is put into > > D3cold, so the power resources in question are all turned off. Then, > > pci_power_up() is called to put it into D0. > > > > It first calls pci_platform_power_transition() which invokes > > platform_pci_set_power_state() to turn on the ACPI power resources > > depended on by the device and, if that is successful, it calls > > pci_update_current_state() to update the current_state field of > > the PCI device object. If the device's configuration space is > > accessible at this point, which is the case if > > platform_pci_set_power_state() leaves it in D0-uninitialized (and > > there's nothing to prevent it from doing so), current_state will be > > set to PCI_D0 and the pci_raw_set_power_state() called subsequently > > will notice that the device is in D0 already and do nothing. > > However, that is not correct, because it may be still necessary to > > restore the device's BARs at this point. > > > > To address this issue, set current_state temporarily to PCI_D3hot > > in the cases in which pci_raw_set_power_state() may need to do more > > than just changing the power state of the device. > > > > Signed-off-by: Rafael J. Wysocki > > Reviewed-by: Mika Westerberg Thanks, but on second thought, I'm not sure if this is the best way to address the issue. Basically, pci_power_up() is called in two places, in pci_set_power_state() (for the transitions to D0) and in pci_pm_default_resume_early(). In the latter case, pci_restore_state() is called right after it and that covers BARs restoration, so nothing more needs to be done in that case. This means that pci_set_power_state() is the only place needing to restore the BARs when going into D0 from D3hot or deeper and it is better to move BARs restoration directly into it. I'll update the series accordingly and resend. I also think that the mandatory delay is not needed at all when pci_raw_set_power_state() is called for transitions D3cold -> D0, because in that case either the device has been powered up via platform_pci_set_power_state(), or via the bridge resume which takes the delay into account.