Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp379394imm; Thu, 16 Aug 2018 22:51:20 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx4OOUjmNXCJY8WSttq/KeQaCpOb0SgtbOhQ0KYZAR8xxWZXi/L+qtP7x5Q9TcoP+bFoO/5 X-Received: by 2002:a65:6086:: with SMTP id t6-v6mr6788901pgu.424.1534485080521; Thu, 16 Aug 2018 22:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534485080; cv=none; d=google.com; s=arc-20160816; b=0BlzSM3rxEhuwdWIV0I0kUaj3Ra9HEjS2a4u004ITDmpgiqdkFIuOOKS2jaF4fABZV OWJiq6f/M2jWUDR2WKzj5dW5JXBx3GRFuEJjo0Rd/oQCPBeXkUZEB8AaOdcQXMmmhg1A JqIRrZjbygswIG9VP61Sh/pQQiYLSjlPui5tM03NwXeASrnZaDfNNtJQ5NWSJBeaOq1T NOE3aA9Ju+mJhE1XzlvyM9IVavLzAhOBjiE60oTBWwbr/XzDD49hp+6DxXqOLo2sVuD0 Te9sIlS0bgJUZLjn4CJRzq6LcsMfcI3vnk7X6t2VaQyVE1Za1b4bWjez3I57qOLGrZBR SJxQ== 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=nnn6LskYsylT+OEaq6cvj4y0h2tuGrz5pfTyqC/J1Nw=; b=IK3fn0E1Zmde3Er8GFE6dypSj7j4xJKlJvvICUR2s932KLLwhsVHLllL/smVz6Fbnr V02UFiCzGmEd0yYFjjkTSe+CYmqXIJY9Y+Xzdkmsi20mvGPbjKSD8OgomSIqKuwKrIFn aSkD5RZSQuDnp6ywi9VdJ5MYIkwkIcL03D0gT43of3m3BNNMXxQ58aHwL/fD3RT0+jOB QYVoE+GwQB1+rU79VWFVrU77hdksCzaFQnpSBKcrc8qahvXKyiQWswgKOveSOkOfNNlD UgQIqkpCcffZq318O+eRugGYVK+1SyutJePY7s8lNTsM0BSacg1omOlCrHHlxCkm9/PC JgbQ== 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 25-v6si1282910pgk.438.2018.08.16.22.51.05; Thu, 16 Aug 2018 22:51:20 -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 S1726410AbeHQIwD (ORCPT + 99 others); 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