Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp396079img; Tue, 26 Feb 2019 01:56:28 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaw+GbIy7IdFL9ko4v6ZwgDlIF6MBhptqK8FzBZKvB70wyIlQomvAWpCGlUq0NTR39RjdkW X-Received: by 2002:a63:c80c:: with SMTP id z12mr23693718pgg.397.1551174988638; Tue, 26 Feb 2019 01:56:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551174988; cv=none; d=google.com; s=arc-20160816; b=s4rUnvm1phE6maEHJzdZo+cNzR2jyQV8V2o3E9Bb7rxaygGJ3SUnqzEIsi00gz0wnf VaXrmupt6l6HZEKLTiGsLWa9kGJvr8K0chNbsrNOO3gGS5oOzaenFZvt1lESbPK89uJu 2KhSNH5+9sAydlBORYTmqbsX7kk6LdNl/nK5yh8ZZ4fUh6qQtOXas9phHKFjTJZ1jxws wsOL1SYH6Tbe2mVYwA5i6L5FraX4LcQsQDZiFflpsz33hWZ0VYmMK2vr6Hg3DItBl7gM NjyH/1/VszhVmTFlw6lEjzvr2F1/ePYavvY0I5f8cpBuqGGUy1tlfYEzb5LlLeIhplQX RLBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=GGDfq8gyIRW6P77kWmoItADXSQYhOhSagTVgZhBHwdg=; b=Zve918NP1zY+R/qmx+5egY5vYQh58jFSuirHGDZNnfEiJkQ0PFU8JQV9R9ARwDqJJX aHD0sCh2oKlPSw11I+B27PJ8VZvYODbC4mLnoQl1OJ/rVSHtIGXbK55QoZpFK+uc7Dow dnIzVhDPkdFsipS/1Re42gkll7q6f5Nm0p75RVSCmOSKkY/XWzWwp6mxgupYM8C5OCNP VWjPQp7Njp1B5ouUylhKUZS0/gNxRqiVQPQd4mGOrQcwBvBOjTGK/d3nDDQdp0z0XW1c gebAkENO70Pz90KM4gc1POcCUUQy1rnkzzJUHyhtWMLYk4pxI09KWNwZKRZgyed0B+2Z 1Org== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@agner.ch header.s=dkim header.b=GHM0ZCcK; 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 g79si7599810pfb.214.2019.02.26.01.56.13; Tue, 26 Feb 2019 01:56:28 -0800 (PST) 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; dkim=pass header.i=@agner.ch header.s=dkim header.b=GHM0ZCcK; 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 S1727745AbfBZJzx (ORCPT + 99 others); Tue, 26 Feb 2019 04:55:53 -0500 Received: from mail.kmu-office.ch ([178.209.48.109]:55804 "EHLO mail.kmu-office.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727631AbfBZJzv (ORCPT ); Tue, 26 Feb 2019 04:55:51 -0500 Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 1C50E5C00AC; Tue, 26 Feb 2019 10:55:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1551174948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GGDfq8gyIRW6P77kWmoItADXSQYhOhSagTVgZhBHwdg=; b=GHM0ZCcK1vXHql+UXFpxM4Ofg/X0kmXb7rCJi7mMl85g147wr2yZy8qgA+1+/mnu3XBd0Y reYkIrE+dzpYFmHybfreUtkVCMQQGTBNqcLR8ZWAaF/HGHIOxlQOxVSuF3mH7reWXIvjKt ghnk0xKSNbv1sNzp2byKhvmZTRCBOfE= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Tue, 26 Feb 2019 10:55:48 +0100 From: Stefan Agner To: Bjorn Helgaas Cc: Trent Piepho , leonard.crestez@nxp.com, hongxing.zhu@nxp.com, linux-kernel@vger.kernel.org, jingoohan1@gmail.com, lorenzo.pieralisi@arm.com, gustavo.pimentel@synopsys.com, linux-pci@vger.kernel.org, l.stach@pengutronix.de, Thinh Nguyen Subject: Re: [PATCH v7] PCI: imx6: limit DBI register length In-Reply-To: References: <20190225160226.11924-1-stefan@agner.ch> <34b23c031a8e0964b3e87a6252dd5cefaa62cc95.camel@nxp.com> <1551113572.3075.172.camel@impinj.com> Message-ID: X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.3.7 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.02.2019 21:19, Bjorn Helgaas wrote: > [+cc Thinh] > > On Mon, Feb 25, 2019 at 10:52 AM Trent Piepho wrote: >> On Mon, 2019-02-25 at 16:15 +0000, Leonard Crestez wrote: >> > On Mon, 2019-02-25 at 17:02 +0100, Stefan Agner wrote: >> > > Define the length of the DBI registers and limit config space to its >> > > length. This makes sure that the kernel does not access registers >> > > beyond that point, avoiding the following abort on a i.MX 6Quad: >> > > >> > > +static void imx6_pcie_quirk(struct pci_dev *dev) >> > > +{ >> > > + struct pci_bus *bus = dev->bus; >> > > + struct pcie_port *pp = bus->sysdata; >> > > + >> > > + if (bus->number == pp->root_bus_nr) { >> > > + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); >> > > + struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci); >> > > + >> > > + /* >> > > + * Limit config length to avoid the kernel reading beyond >> > > + * the register set and causing an abort on i.MX 6Quad >> > > + */ >> > > + if (imx6_pcie->drvdata->dbi_length) >> > > + dev->cfg_size = imx6_pcie->drvdata->dbi_length; >> > > + } >> > > +} >> > > +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SYNOPSYS, 0xabcd, imx6_pcie_quirk); >> > >> > This looks like a default from SYNOPSYS so it likely run on other SOCs >> > using the DesignWare PCI IP and crash because of those unchecked casts. >> >> Yes, it's used on IMX7d too. But it's worse than that, there's a USB >> controller core that uses the same vendor and device id, >> PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3. The quirk for that one uses class == >> PCI_CLASS_SERIAL_USB_DEVICE to avoid matching this PCI-e IP. See >> thread "PCI: Check for USB xHCI class for HAPS platform" > > If we could get these vendors to allocate their own Vendor/Device IDs, > maybe we could consider a DECLARE_PCI_FIXUP_EARLY quirk that would fix > up pdev->vendor and pdev->device? That might be cleaner than > cluttering all these quirks with details of this screwup. According to www.pcilookup.com there is a vendor/product id allocated for recovery mode (Freescale i.MX 6, 15a2:0054). Is this a real PCI id? The same Vendor/Device ID is used for USB recovery... -- Stefan