From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936912AbdEWRYN (ORCPT ); Tue, 23 May 2017 13:24:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:48716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934714AbdEWRYM (ORCPT ); Tue, 23 May 2017 13:24:12 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2C13239DC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Date: Tue, 23 May 2017 12:24:09 -0500 From: Bjorn Helgaas To: Marc Gonzalez Cc: linux-pci , Marc Zyngier , Thomas Gleixner , Robin Murphy , Lorenzo Pieralisi , Liviu Dudau , David Laight , Linux ARM , Thibaud Cornic , Phuong Nguyen , LKML , Mason Subject: Re: [PATCH v4 2/2] PCI: Add tango PCIe host bridge support Message-ID: <20170523172409.GD24431@bhelgaas-glaptop.roam.corp.google.com> References: <4a354b33-d59c-4ebb-4b31-0388ac8090d4@sigmadesigns.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a354b33-d59c-4ebb-4b31-0388ac8090d4@sigmadesigns.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 20, 2017 at 04:31:25PM +0200, Marc Gonzalez wrote: > This driver is required to work around several hardware bugs in the > PCIe controller. > > NB: Revision 1 does not support legacy interrupts, or IO space. > > Signed-off-by: Marc Gonzalez > --- > Documentation/devicetree/bindings/pci/tango-pcie.txt | 32 ++++++++ > drivers/pci/host/Kconfig | 8 ++ > drivers/pci/host/Makefile | 1 + > drivers/pci/host/pcie-tango.c | 161 +++++++++++++++++++++++++++++++++++++++ > include/linux/pci_ids.h | 2 + > 5 files changed, 204 insertions(+) > ... > +static int smp8759_config_read(struct pci_bus *bus, > + unsigned int devfn, int where, int size, u32 *val) > +{ > + int ret; > + struct pci_config_window *cfg = bus->sysdata; > + struct tango_pcie *pcie = dev_get_drvdata(cfg->parent); > + > + /* > + * QUIRK #1 > + * Reads in configuration space outside devfn 0 return garbage. > + */ > + if (devfn != 0) > + return PCIBIOS_FUNC_NOT_SUPPORTED; > + > + /* > + * QUIRK #2 > + * Unfortunately, config and mem spaces are muxed. > + * Linux does not support such a setting, since drivers are free > + * to access mem space directly, at any time. > + * Therefore, we can only PRAY that config and mem space accesses > + * NEVER occur concurrently. > + */ > + writel_relaxed(1, pcie->mux); > + ret = pci_generic_config_read(bus, devfn, where, size, val); > + writel_relaxed(0, pcie->mux); This is a major issue and possibly even a security problem. Unprivileged users can cause config accesses via lspci/setpci. I don't have a good suggestion for addressing it, but if you can't make this work reliably, you need at least a dev_err() in the probe function and probably a taint of the kernel (see add_taint()). > + return ret; > +} > + > +static int smp8759_config_write(struct pci_bus *bus, > + unsigned int devfn, int where, int size, u32 val) > +{ > + int ret; > + struct pci_config_window *cfg = bus->sysdata; > + struct tango_pcie *pcie = dev_get_drvdata(cfg->parent); > + > + writel_relaxed(1, pcie->mux); > + ret = pci_generic_config_write(bus, devfn, where, size, val); > + writel_relaxed(0, pcie->mux); > + > + return ret; > +} > + > +static struct pci_ecam_ops smp8759_ecam_ops = { > + .bus_shift = 20, > + .pci_ops = { > + .map_bus = pci_ecam_map_bus, > + .read = smp8759_config_read, > + .write = smp8759_config_write, > + } > +};