Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2136205ybi; Sun, 9 Jun 2019 04:43:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9rZ5akKgRdRkIQTl3jFizz9F3I3BIwI42uHVjJGfRNngZP6dW1z64ju3HrWcmr3QcFe9f X-Received: by 2002:a17:90a:9514:: with SMTP id t20mr15536799pjo.124.1560080634034; Sun, 09 Jun 2019 04:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560080634; cv=none; d=google.com; s=arc-20160816; b=0UkQprb+Rs8weS0BCR7cFMi5lRe/3ywm8U8YW/tvh7CC2WYdKrdQYGh+Fx3OCeDiUR V9GW1jv3uDUdWQ65AQYem3TV4XdJdrHJewBFnPCrKwQhVEAepqpmGswOEe7LfDiKUZZ8 w/HhoCDYMi14Hvx0XNZ9Cqr/nj5ZeUgPVqDF4Ez0dEe1zm94OYM8RiitPRCox04Ngs07 3AfJC/tNNzAhyHNzmCHkDkitPLW616EKUl0EB8HiUuB81TCufULDtg1gOoYnQmUkxl8X relzmbf/IZ17Uosl+6kXQyujwYIAS+N2hTDZqP3w02dnFB3K7+50/jdEUyCRslhIaw5J 598A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:message-id; bh=yEYXLr1h3kxD+ye36XdoPjMTiOS3sKrBiwrtPCUS5XU=; b=PFXhymO/nGtl7ycxoTmIyvnc4Or5+OJ24R6KEtk761itkqRyibLDJoNBC0GE6T16au 2rhn6zjR2MCu63Ge6ZaSCCgvlLa6mli9h+HYrt2ag+cjtaZhX6HgwXZxbf5j52QARKIy ITqkr8QEeqbYxLfkDQG58FEvOXrAhd/ii6oCQqcLoJwHZni7yYf0XFYpcWmGlT43yoft kqsjZ/C4q2P/5EmEBvN7xh5SjhlWWZY3a+tYDTDTRvCgnmYhyhOiL1KqD7qLHAQEWN0k 1w+mFFzPmPEVqLen5BpvnwXFbrJUuTYDbIkyTIVb0dIEsqkqWVOlRGdgsFgT2cCT+teM NT6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 131si1091493pfu.165.2019.06.09.04.43.38; Sun, 09 Jun 2019 04:43:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728310AbfFILje (ORCPT + 99 others); Sun, 9 Jun 2019 07:39:34 -0400 Received: from mailout1.hostsharing.net ([83.223.95.204]:49679 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728108AbfFILje (ORCPT ); Sun, 9 Jun 2019 07:39:34 -0400 X-Greylist: delayed 567 seconds by postgrey-1.27 at vger.kernel.org; Sun, 09 Jun 2019 07:39:33 EDT Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout1.hostsharing.net (Postfix) with ESMTPS id 1A331101817B7; Sun, 9 Jun 2019 13:30:05 +0200 (CEST) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id B7CC860DAED6; Sun, 9 Jun 2019 13:30:04 +0200 (CEST) X-Mailbox-Line: From 0113014581dbe2d1f938813f1783905bd81b79db Mon Sep 17 00:00:00 2001 Message-Id: <0113014581dbe2d1f938813f1783905bd81b79db.1560079442.git.lukas@wunner.de> From: Lukas Wunner Date: Sun, 9 Jun 2019 13:29:33 +0200 Subject: [PATCH] PCI/PME: Fix race on PME polling To: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mika Westerberg , "Rafael J. Wysocki" , Keith Busch , Alex Williamson , Alexandru Gagniuc Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit df17e62e5bff ("PCI: Add support for polling PME state on suspended legacy PCI devices"), the work item pci_pme_list_scan() polls the PME status flag of devices and wakes them up if the bit is set. The function performs a check whether a device's upstream bridge is in D0 for otherwise the device is inaccessible, rendering PME polling impossible. However the check is racy because it is performed before polling the device. If the upstream bridge runtime suspends to D3hot after pci_pme_list_scan() checks its power state and before it invokes pci_pme_wakeup(), the latter will read the PMCSR as "all ones" and mistake it for a set PME status flag. I am seeing this race play out as a Thunderbolt controller going to D3cold and occasionally immediately going to D0 again because PM polling was performed at just the wrong time. Avoid by checking for an "all ones" PMCSR in pci_check_pme_status(). Fixes: 58ff463396ad ("PCI PM: Add function for checking PME status of devices") Tested-by: Mika Westerberg Signed-off-by: Lukas Wunner Cc: stable@vger.kernel.org # v2.6.34+ Cc: Rafael J. Wysocki --- drivers/pci/pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 8abc843b1615..eed5db9f152f 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1989,6 +1989,8 @@ bool pci_check_pme_status(struct pci_dev *dev) pci_read_config_word(dev, pmcsr_pos, &pmcsr); if (!(pmcsr & PCI_PM_CTRL_PME_STATUS)) return false; + if (pmcsr == 0xffff) + return false; /* Clear PME status. */ pmcsr |= PCI_PM_CTRL_PME_STATUS; -- 2.20.1