Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2608881rwo; Thu, 3 Aug 2023 11:59:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHMhp+qmYUynALK8sEBn7D5kbDhjAJ653Js1YEiOd5hVOiQ4eexKzugJb4x7JJiUkIOvl6U X-Received: by 2002:a54:4418:0:b0:3a7:3056:3d2b with SMTP id k24-20020a544418000000b003a730563d2bmr14203294oiw.10.1691089159478; Thu, 03 Aug 2023 11:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691089159; cv=none; d=google.com; s=arc-20160816; b=wL1l1+4SWzcwM5fRTjDy6vSTE/UeaHl0hFqfeaQ3ArV4nY/6KfO5GkHBR0FhWKrrjL YT8PpJYkDFVS3/W0D6wTNkknbmNnZ6HYC8E98xIMpBGqEwyyDpgGJQbWDhtpb9F2yp6+ CTqWte9OLL4cxChYgjKxKpVpB0jbCNvTzSEyPaVGZLZMCtiisc7geSAsLj5ESfaFvm0o 1T/BFet/O/cTLC/wd9pthClCoc5ciz8gSLNeyIt9UaAfUa2kMSMwjhEmZw1XPh2pOXaQ 6f0BNCcNglMZDpptM0DqVazDOHvRgfj9p8HOkeScH2PrW7fO1McESj8fRHYVFkUP0dj9 5iYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i4rNHvY4SBHV3GZTxHfmC+xvKSqh+4xt/RUop3WDQyg=; fh=EkXd9mulaEwhN/gYQbLN171OqS+TkA74SfbkC4a6Z8Y=; b=Z5Cx77qh91tbmhzYPtA4Y/I6mm956bfh34FYR1VgeZBdP1tWUpFka08TkaXfvw5Gso 6+r1bK65q+9xPWpRKlFm/J/O6PlOtoCtxOlpg2GHB9PQBq/YX8b3krqCCju35MQWTYRE Rh64foEqXTvlBLOHv645gx7FjqW7c5bcrWelyb+HQljYh3qL7ydcDET5wYIt1QD69sFv RXB9tK+fo5l00a4RoB/oTG+yujGV11/78aymW5qJnTXsOshoxLf37F71km0g2237SeKt CxxHA7YEkjH5K1kSjFuNQgmeZvGimxr9ceTWUJ4WJf+2fy6NEyJJy4ZDNJ+Mi+ulwaOl fgVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZfQFNF+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a17090a6b4700b0025baa49fa95si510498pjl.1.2023.08.03.11.59.06; Thu, 03 Aug 2023 11:59:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZfQFNF+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234750AbjHCRNt (ORCPT + 99 others); Thu, 3 Aug 2023 13:13:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234587AbjHCRNk (ORCPT ); Thu, 3 Aug 2023 13:13:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F7A62D43 for ; Thu, 3 Aug 2023 10:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691082767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i4rNHvY4SBHV3GZTxHfmC+xvKSqh+4xt/RUop3WDQyg=; b=ZfQFNF+eZLx1ZVVljYzBUsUDoCpEiRAXNzADmTbTWBX5G7LSqW3YIOZmCDzxFilBACBT5E Ce9PWqdE8eWcrtVlAjoXqI0YdFIVhWfEABol3DY7XZfo6ztWqyfoDPJzZ+MrLXyOGcioVc KRNPyxPSgyIIbIGGLsB4sm77orUedEk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-241-it8Yw8nBOjSFtKIOfzR0Dg-1; Thu, 03 Aug 2023 13:12:45 -0400 X-MC-Unique: it8Yw8nBOjSFtKIOfzR0Dg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02099104458B; Thu, 3 Aug 2023 17:12:44 +0000 (UTC) Received: from omen.home.shazbot.org (unknown [10.22.10.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C1004021CE; Thu, 3 Aug 2023 17:12:43 +0000 (UTC) From: Alex Williamson To: bhelgaas@google.com Cc: Alex Williamson , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, eric.auger@redhat.com Subject: [PATCH v2 2/2] PCI: Fix runtime PM race with PME polling Date: Thu, 3 Aug 2023 11:12:33 -0600 Message-Id: <20230803171233.3810944-3-alex.williamson@redhat.com> In-Reply-To: <20230803171233.3810944-1-alex.williamson@redhat.com> References: <20230803171233.3810944-1-alex.williamson@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Testing that a device is not currently in a low power state provides no guarantees that the device is not immenently transitioning to such a state. We need to increment the PM usage counter before accessing the device. Since we don't wish to wake the device for PME polling, do so only if the device is already active by using pm_runtime_get_if_active(). Signed-off-by: Alex Williamson --- drivers/pci/pci.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 60230da957e0..bc266f290b2c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2415,10 +2415,13 @@ static void pci_pme_list_scan(struct work_struct *work) mutex_lock(&pci_pme_list_mutex); list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) { - if (pme_dev->dev->pme_poll) { - struct pci_dev *bridge; + struct pci_dev *pdev = pme_dev->dev; + + if (pdev->pme_poll) { + struct pci_dev *bridge = pdev->bus->self; + struct device *dev = &pdev->dev; + int pm_status; - bridge = pme_dev->dev->bus->self; /* * If bridge is in low power state, the * configuration space of subordinate devices @@ -2426,14 +2429,20 @@ static void pci_pme_list_scan(struct work_struct *work) */ if (bridge && bridge->current_state != PCI_D0) continue; + /* - * If the device is in D3cold it should not be - * polled either. + * If the device is in a low power state it + * should not be polled either. */ - if (pme_dev->dev->current_state == PCI_D3cold) + pm_status = pm_runtime_get_if_active(dev, true); + if (!pm_status) continue; - pci_pme_wakeup(pme_dev->dev, NULL); + if (pdev->current_state != PCI_D3cold) + pci_pme_wakeup(pdev, NULL); + + if (pm_status > 0) + pm_runtime_put(dev); } else { list_del(&pme_dev->list); kfree(pme_dev); -- 2.40.1