Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp361517imm; Thu, 16 Aug 2018 22:26:24 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxfSb/Vn+6BtcvfnxFgEecXuItQGu2JRKBvvf1Jkwgk4pjz8lBHvKRrqafo5wQ7IAqw6IEk X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr3897552pgc.172.1534483584240; Thu, 16 Aug 2018 22:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534483584; cv=none; d=google.com; s=arc-20160816; b=QD8RvH7QDyF4kLtSkdLeuoP/9tpR98maL+po3FoAqJ0cpQV6MVXSi5Comlf5etfOmy ToF2dPFqNxFhMNh+RXWtOMx/SEi3fF2iqKJJyTrERy2Q15KIdZod76P9HayeV2f38UMJ h3+NnAFcT5bLINUBH7CdxCmlyk0GEuCJ5Lh29NZnzd5MO2bLUE4fEnYh2lWrvKlUeTWL VaA/kYKTGKNxoC7B9+oCDy+3MP7WUSsaFXuHKya/xjEXUg690+qOBquUHe0mlEN0gbDU SrEsdL3t983Ofe52CX6xheOSwrRQbcekljmCRtwkQHpDZ5cghnEzeEtS8VBbeHZiYUrV 1gIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hEg8epTQF2rIoL4gQWOdppluU/zHYiII3TLI7DKRNns=; b=T/pzYr2o97/d1Wn/ynEW6YDTOWgIct2D1EDH2fBk47EKnQ6QMdoE3nFYnlBOmUnrPK J89UYmrKp4lBQy9Z1mdukEdLn9f3L5WuGWceUp+RLpGd4oSXS2WNuOHUgUpi34Okcprx esV+gQPYoR20eKm9shb6tBmgKlozlrn60/xaMG1mnCj8YTF1H42Rvoh4nqGa2WZrGYaS 6l02WdftyO9LnZYA7wYkwEvZWkgK3s4uPOUlY+wCyZzCd6xI8a1lmU8A94z7E5fWuQ5j nGAoWkdpO7V2YK8Ev0qBIxKCOrmuTg3tae0+Km0Np1Q1wdpGnfKezrffNQ4+ouhDCt2h 05bQ== 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 5-v6si620599pgf.18.2018.08.16.22.26.08; Thu, 16 Aug 2018 22:26:24 -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 S1726481AbeHQI0G (ORCPT + 99 others); Fri, 17 Aug 2018 04:26:06 -0400 Received: from gate.crashing.org ([63.228.1.57]:48469 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbeHQI0G (ORCPT ); Fri, 17 Aug 2018 04:26:06 -0400 Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7H4nAsJ017258; Thu, 16 Aug 2018 23:49:41 -0500 From: Benjamin Herrenschmidt To: Bjorn Helgaas , linux-pci@vger.kernel.org Cc: Hari Vyas , Ray Jui , Srinath Mannam , Guenter Roeck , Jens Axboe , Lukas Wunner , Konstantin Khlebnikov , Marta Rybczynska , Pierre-Yves Kerbrat , linux-kernel@vger.kernel.org, Benjamin Herrenschmidt Subject: [RFC PATCH 6/6] pci: Protect is_busmaster using the state lock Date: Fri, 17 Aug 2018 14:49:02 +1000 Message-Id: <20180817044902.31420-7-benh@kernel.crashing.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180817044902.31420-1-benh@kernel.crashing.org> References: <20180817044902.31420-1-benh@kernel.crashing.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This wraps pci_set_master() and pci_clear_master() with the pci_dev state lock. The clearing of is_busmaster in pci_disable_device() is already covered. This also adds a comment explaining why is_busmaster must not be checked in pci_set_master() due to how the power management code uses it. Signed-off-by: Benjamin Herrenschmidt --- drivers/pci/pci.c | 9 +++++++++ include/linux/pci.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 68152de2b5a0..13d988d5b2a3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4052,11 +4052,18 @@ void __weak pcibios_set_master(struct pci_dev *dev) * * Enables bus-mastering on the device and calls pcibios_set_master() * to do the needed arch specific settings. + * + * Note: This must not check dev->is_busmaster because the power management + * code will call this in order to restore the config space to the + * state of is_busmaster, thus is_busmaster might be set but the + * config space bit cleared. */ void pci_set_master(struct pci_dev *dev) { + pci_dev_state_lock(dev); __pci_set_master(dev, true); pcibios_set_master(dev); + pci_dev_state_unlock(dev); } EXPORT_SYMBOL(pci_set_master); @@ -4066,7 +4073,9 @@ EXPORT_SYMBOL(pci_set_master); */ void pci_clear_master(struct pci_dev *dev) { + pci_dev_state_lock(dev); __pci_set_master(dev, false); + pci_dev_state_unlock(dev); } EXPORT_SYMBOL(pci_clear_master); diff --git a/include/linux/pci.h b/include/linux/pci.h index 0d4fc22df190..a5bac5b21454 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -375,7 +375,6 @@ struct pci_dev { unsigned int multifunction:1; /* Multi-function device */ unsigned int is_added:1; - unsigned int is_busmaster:1; /* Is busmaster */ unsigned int no_msi:1; /* May not use MSI */ unsigned int no_64bit_msi:1; /* May only use 32-bit MSIs */ unsigned int block_cfg_access:1; /* Config space access blocked */ @@ -450,6 +449,7 @@ struct pci_dev { struct mutex state_lock; /* Protect local state bits */ /* --- Fields below this line are protected by the state_lock mutex */ + unsigned int is_busmaster:1; /* Is busmaster */ }; static inline void pci_dev_state_lock(struct pci_dev *dev) -- 2.17.1