Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp341601imm; Thu, 16 Aug 2018 21:59:09 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyxnjKOiJY3enh7wo9mYAueI/RQ52K7qJaGc223Y6b2oEdyvH3aGcehRnNBNZr8NltoyA8K X-Received: by 2002:a63:1d22:: with SMTP id d34-v6mr31388862pgd.133.1534481949173; Thu, 16 Aug 2018 21:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534481949; cv=none; d=google.com; s=arc-20160816; b=U7d59pm2NQd+Js5y8TROKMcRWYrHcRG00c4ckpeXcbk9R+6WKJ8IyUprQr8m0gYZaQ NrETEk4IDqpxYQ2jDe3h+Qc+omKL54Kd4GfmksuM0BIi0SByKVW6ZM2MHinxqoIejaj2 1X31Uvrdbq/IkvuPK3nVkJaYiGHuBlVm5q6DpMtH/kMFLhNNkIVn/KS5CXro3cONJ00i T1Hb6gTAb/Lpyi5ajnxwJDiSU+3Xmi2uH4jXBFJq/Uj24yqB+zop5yJ1qMVEKgUH3VCi 7EUf1stKT9ZvMEIYVEqjwZ2w7SotKI/8vPE2Iq0VLLOgpb9XaNkX8e78PI/9xufsLHTv D1oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=9RwXGVqPDrkdf41BSLUVr/7iY3cdMfQ6mC/M7ZFCCTk=; b=1HvgGa02FPmIFlxsc+1F0ejc0GflMuZ83ynk7ZHhyC5gHAIziwd662222wZvbdrOv8 Ex4uSzvCT6cNSLKhNp0U2op9uTJ9H3SvhaM+h/fmPEdLV8gfgLuO5hBJZE08Dzlth09s fhFnqzrz17ZGGmrxKK55veHxg267raG0oN1xZnKdTW0BEPYfExnRKAoMuqe+/VImb0/L CIzEZ2jW3CHTxBRUefaCqTNR6h4P3fiHqL9RGgVLqBoOQEJxVnyHiZugogPPIbPK4tg7 NeSPexL3eQiriZn1Hzotj/JijIJs0B6y61ocldHPAG8Gedh+8WbdB77xJICJVK3vazLa ZcBw== 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 l5-v6si1221980pgh.451.2018.08.16.21.58.51; Thu, 16 Aug 2018 21:59:09 -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 S1726226AbeHQH7Y (ORCPT + 99 others); Fri, 17 Aug 2018 03:59:24 -0400 Received: from gate.crashing.org ([63.228.1.57]:34181 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbeHQH7Y (ORCPT ); Fri, 17 Aug 2018 03:59:24 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7H4v9Ra017504; Thu, 16 Aug 2018 23:57:10 -0500 Message-ID: <65c8e4cb4732f9331fb320f6fd7910756c14fc35.camel@kernel.crashing.org> Subject: Re: [RFC PATCH 1/6] Revert "PCI: Fix is_added/is_busmaster race condition" 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 Date: Fri, 17 Aug 2018 14:57:08 +1000 In-Reply-To: <20180817044902.31420-2-benh@kernel.crashing.org> References: <20180817044902.31420-1-benh@kernel.crashing.org> <20180817044902.31420-2-benh@kernel.crashing.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-08-17 at 14:48 +1000, Benjamin Herrenschmidt wrote: > This reverts commit 44bda4b7d26e9fffed6d7152d98a2e9edaeb2a76. > > The new pci state mutex provides a simpler way of addressing > this race and avoids the relative includes added to the powerpc > code. Ignore the cset comment, my "fix" no longer relies on a state mutex, I'll re-post with a better comment after discussions. The actual fix is in patch 2: [RFC PATCH 2/6] pci: Set pci_dev->is_added before calling device_add (and yes that was supposed be device_attach ... ugh, not enough caffeine today). > Signed-off-by: Benjamin Herrenschmidt > --- > arch/powerpc/kernel/pci-common.c | 4 +--- > arch/powerpc/platforms/powernv/pci-ioda.c | 3 +-- > arch/powerpc/platforms/pseries/setup.c | 3 +-- > drivers/pci/bus.c | 6 +++--- > drivers/pci/hotplug/acpiphp_glue.c | 2 +- > drivers/pci/pci.h | 11 ----------- > drivers/pci/probe.c | 4 ++-- > drivers/pci/remove.c | 5 ++--- > include/linux/pci.h | 1 + > 9 files changed, 12 insertions(+), 27 deletions(-) > > diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c > index 471aac313b89..fe9733ffffaa 100644 > --- a/arch/powerpc/kernel/pci-common.c > +++ b/arch/powerpc/kernel/pci-common.c > @@ -42,8 +42,6 @@ > #include > #include > > -#include "../../../drivers/pci/pci.h" > - > /* hose_spinlock protects accesses to the the phb_bitmap. */ > static DEFINE_SPINLOCK(hose_spinlock); > LIST_HEAD(hose_list); > @@ -1016,7 +1014,7 @@ void pcibios_setup_bus_devices(struct pci_bus *bus) > /* Cardbus can call us to add new devices to a bus, so ignore > * those who are already fully discovered > */ > - if (pci_dev_is_added(dev)) > + if (dev->is_added) > continue; > > pcibios_setup_device(dev); > diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c > index 70b2e1e0f23c..5bd0eb6681bc 100644 > --- a/arch/powerpc/platforms/powernv/pci-ioda.c > +++ b/arch/powerpc/platforms/powernv/pci-ioda.c > @@ -46,7 +46,6 @@ > > #include "powernv.h" > #include "pci.h" > -#include "../../../../drivers/pci/pci.h" > > #define PNV_IODA1_M64_NUM 16 /* Number of M64 BARs */ > #define PNV_IODA1_M64_SEGS 8 /* Segments per M64 BAR */ > @@ -3139,7 +3138,7 @@ static void pnv_pci_ioda_fixup_iov_resources(struct pci_dev *pdev) > struct pci_dn *pdn; > int mul, total_vfs; > > - if (!pdev->is_physfn || pci_dev_is_added(pdev)) > + if (!pdev->is_physfn || pdev->is_added) > return; > > pdn = pci_get_pdn(pdev); > diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c > index 8a4868a3964b..139f0af6c3d9 100644 > --- a/arch/powerpc/platforms/pseries/setup.c > +++ b/arch/powerpc/platforms/pseries/setup.c > @@ -71,7 +71,6 @@ > #include > > #include "pseries.h" > -#include "../../../../drivers/pci/pci.h" > > int CMO_PrPSP = -1; > int CMO_SecPSP = -1; > @@ -665,7 +664,7 @@ static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev) > const int *indexes; > struct device_node *dn = pci_device_to_OF_node(pdev); > > - if (!pdev->is_physfn || pci_dev_is_added(pdev)) > + if (!pdev->is_physfn || pdev->is_added) > return; > /*Firmware must support open sriov otherwise dont configure*/ > indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL); > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > index 5cb40b2518f9..35b7fc87eac5 100644 > --- a/drivers/pci/bus.c > +++ b/drivers/pci/bus.c > @@ -330,7 +330,7 @@ void pci_bus_add_device(struct pci_dev *dev) > return; > } > > - pci_dev_assign_added(dev, true); > + dev->is_added = 1; > } > EXPORT_SYMBOL_GPL(pci_bus_add_device); > > @@ -347,14 +347,14 @@ void pci_bus_add_devices(const struct pci_bus *bus) > > list_for_each_entry(dev, &bus->devices, bus_list) { > /* Skip already-added devices */ > - if (pci_dev_is_added(dev)) > + if (dev->is_added) > continue; > pci_bus_add_device(dev); > } > > list_for_each_entry(dev, &bus->devices, bus_list) { > /* Skip if device attach failed */ > - if (!pci_dev_is_added(dev)) > + if (!dev->is_added) > continue; > child = dev->subordinate; > if (child) > diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c > index ef0b1b6ba86f..3a17b290df5d 100644 > --- a/drivers/pci/hotplug/acpiphp_glue.c > +++ b/drivers/pci/hotplug/acpiphp_glue.c > @@ -509,7 +509,7 @@ static void enable_slot(struct acpiphp_slot *slot) > > list_for_each_entry(dev, &bus->devices, bus_list) { > /* Assume that newly added devices are powered on already. */ > - if (!pci_dev_is_added(dev)) > + if (!dev->is_added) > dev->current_state = PCI_D0; > } > > diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h > index 6e0d1528d471..473aa10a5dbf 100644 > --- a/drivers/pci/pci.h > +++ b/drivers/pci/pci.h > @@ -295,7 +295,6 @@ struct pci_sriov { > > /* pci_dev priv_flags */ > #define PCI_DEV_DISCONNECTED 0 > -#define PCI_DEV_ADDED 1 > > static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) > { > @@ -308,16 +307,6 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) > return test_bit(PCI_DEV_DISCONNECTED, &dev->priv_flags); > } > > -static inline void pci_dev_assign_added(struct pci_dev *dev, bool added) > -{ > - assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added); > -} > - > -static inline bool pci_dev_is_added(const struct pci_dev *dev) > -{ > - return test_bit(PCI_DEV_ADDED, &dev->priv_flags); > -} > - > #ifdef CONFIG_PCIEAER > #include > > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > index ec784009a36b..440445ac7dfa 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -2525,13 +2525,13 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) > dev = pci_scan_single_device(bus, devfn); > if (!dev) > return 0; > - if (!pci_dev_is_added(dev)) > + if (!dev->is_added) > nr++; > > for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) { > dev = pci_scan_single_device(bus, devfn + fn); > if (dev) { > - if (!pci_dev_is_added(dev)) > + if (!dev->is_added) > nr++; > dev->multifunction = 1; > } > diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c > index 461e7fd2756f..01ec7fcb5634 100644 > --- a/drivers/pci/remove.c > +++ b/drivers/pci/remove.c > @@ -18,12 +18,11 @@ static void pci_stop_dev(struct pci_dev *dev) > { > pci_pme_active(dev, false); > > - if (pci_dev_is_added(dev)) { > + if (dev->is_added) { > device_release_driver(&dev->dev); > pci_proc_detach_device(dev); > pci_remove_sysfs_dev_files(dev); > - > - pci_dev_assign_added(dev, false); > + dev->is_added = 0; > } > > if (dev->bus->self) > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 9b87f1936906..9799109c5e25 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -373,6 +373,7 @@ struct pci_dev { > unsigned int transparent:1; /* Subtractive decode bridge */ > 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 */