From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77D75C4321D for ; Fri, 17 Aug 2018 05:50:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EACA2151C for ; Fri, 17 Aug 2018 05:50:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2EACA2151C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726423AbeHQIwD (ORCPT ); Fri, 17 Aug 2018 04:52:03 -0400 Received: from gate.crashing.org ([63.228.1.57]:57329 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbeHQIwD (ORCPT ); Fri, 17 Aug 2018 04:52:03 -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 w7H4nAsH017258; Thu, 16 Aug 2018 23:49:30 -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 4/6] pci: Add a mutex to pci_dev to protect device state Date: Fri, 17 Aug 2018 14:49:00 +1000 Message-Id: <20180817044902.31420-5-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 adds a pci_dev mutex which will be used to fix a number of races related to the various state bits maintained in that structure. We call it "state_lock" with similarly named accessors to avoid confusion with the pci_dev_lock() which uses the device_lock(). This is a low level mutex meant to protect the mapping between the state fields and the hardware state, for example enabling disabling, setting/clearing bus master etc... These operations can happen while the device_lock() is already held (but don't have to) so a separate mutex is preferable. Signed-off-by: Benjamin Herrenschmidt --- drivers/pci/probe.c | 1 + include/linux/pci.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 440445ac7dfa..3ce287ab6150 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2155,6 +2155,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus) INIT_LIST_HEAD(&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus = pci_bus_get(bus); + mutex_init(&dev->state_lock); return dev; } diff --git a/include/linux/pci.h b/include/linux/pci.h index f58bda204f09..0d4fc22df190 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -443,8 +444,24 @@ struct pci_dev { phys_addr_t rom; /* Physical address if not from BAR */ size_t romlen; /* Length if not from BAR */ char *driver_override; /* Driver name to force a match */ + + unsigned long priv_flags; /* Private flags for the PCI driver */ + + struct mutex state_lock; /* Protect local state bits */ + + /* --- Fields below this line are protected by the state_lock mutex */ }; +static inline void pci_dev_state_lock(struct pci_dev *dev) +{ + mutex_lock(&dev->state_lock); +} + +static inline void pci_dev_state_unlock(struct pci_dev *dev) +{ + mutex_unlock(&dev->state_lock); +} + static inline struct pci_dev *pci_physfn(struct pci_dev *dev) { #ifdef CONFIG_PCI_IOV -- 2.17.1