Return-Path: Received: from mail-by2nam01on0104.outbound.protection.outlook.com ([104.47.34.104]:11884 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753890AbeARVBT (ORCPT ); Thu, 18 Jan 2018 16:01:19 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Sumit Semwal , Bjorn Helgaas , Sasha Levin Subject: [added to the 4.1 stable tree] PCI: Update BARs using property bits appropriate for type Date: Thu, 18 Jan 2018 21:00:04 +0000 Message-ID: <20180118205908.3220-78-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Sumit Semwal This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 45d004f4afefdd8d79916ee6d97a9ecd94bb1ffe ] The BAR property bits (0-3 for memory BARs, 0-1 for I/O BARs) are supposed to be read-only, but we do save them in res->flags and include them when updating the BAR. Mask the I/O property bits with ~PCI_BASE_ADDRESS_IO_MASK (0x3) instead of PCI_REGION_FLAG_MASK (0xf) to make it obvious that we can't corrupt bits 2-3 of I/O addresses. Use PCI_ROM_ADDRESS_MASK for ROM BARs. This means we'll only check the top 21 bits (instead of the 28 bits we used to check) of a ROM BAR to see if the update was successful. Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/setup-res.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index b1b88bfaddc0..00f32ff6f74e 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -53,12 +53,17 @@ static void pci_std_update_resource(struct pci_dev *dev= , int resno) return; =20 pcibios_resource_to_bus(dev->bus, ®ion, res); + new =3D region.start; =20 - new =3D region.start | (res->flags & PCI_REGION_FLAG_MASK); - if (res->flags & IORESOURCE_IO) + if (res->flags & IORESOURCE_IO) { mask =3D (u32)PCI_BASE_ADDRESS_IO_MASK; - else + new |=3D res->flags & ~PCI_BASE_ADDRESS_IO_MASK; + } else if (resno =3D=3D PCI_ROM_RESOURCE) { + mask =3D (u32)PCI_ROM_ADDRESS_MASK; + } else { mask =3D (u32)PCI_BASE_ADDRESS_MEM_MASK; + new |=3D res->flags & ~PCI_BASE_ADDRESS_MEM_MASK; + } =20 if (resno < PCI_ROM_RESOURCE) { reg =3D PCI_BASE_ADDRESS_0 + 4 * resno; --=20 2.11.0