Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5653466img; Wed, 27 Mar 2019 12:30:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE0zaVtBZhjGXCkXMRt2fCHBTEP6FerrRo4xBCrPQBwXU4jxoWtU51RjW5vxj9S4ND3bN6 X-Received: by 2002:a17:902:b416:: with SMTP id x22mr39503097plr.285.1553715053424; Wed, 27 Mar 2019 12:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715053; cv=none; d=google.com; s=arc-20160816; b=eJAei8eTcdlvZpgd2vHRU9qElZq9qifiKWUOhdrYKdROh9X2psUJL0MbZKIEIxN96x xBwRQZioVFa5/V1mFZ1sGkAs4ZQSbU6qOzTexLqnCsaX3OgAQMDYRIbwcBkbTL+FGtAj Flx3nkmzSdqs5SdrjA0VPQ7oQflR7kMLd0mVXhVcfV1mbXvt3ka/oXGdHTmwtTjrgRNG XIFTokPhZYt0nEQn8GqxwN7dqrYgkcSyMoZg5HjUfhAEWrD30V+8GUsIw3PzufbdS4hD IoBM3I79jXeldqhwpdaFf/2iFo8tGgoHaQRNlfgNFdC/gHDI3OvMPYf1+zKN8BqjZ8/f oLjQ== 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:message-id:date:subject:cc:to:from :dkim-signature; bh=/Kb/RSyUsURsRl0me6QLHeMBhL9ZzhkBnsebVgil4qM=; b=IisAnB78sTHcj3Ov/yINikv59ExeL/NmuzJxg+qbrQjy8qH5LQE10gPlryBny+gk+o 48/WXoO2c22uU++OzrG0MuWGoHKBygHHDhE30RatP4XbM3yXgXoTveaJm07/ya+ME/1p tH3Ks0FAS28vUW4JqIPiw6S5k0WhaP8alxquuFQHoTAZQDlk9avaoUFxv5yKKQnxbkRA /njKo41HHIK2yCOk8lMjQ3/hpjYg8LZHyVqafGEe/rQHN92CikJ7GDCpixAYVNMPi1RY 9XHboM41andr5KeZr+4zKGV1E/HZf6IEOeKkAVeUfTb+oNMHi03gMyipevZVOuZOI0Xo 56+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1zxqOrdx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si18455105pgp.370.2019.03.27.12.30.38; Wed, 27 Mar 2019 12:30:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=1zxqOrdx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729206AbfC0SDi (ORCPT + 99 others); Wed, 27 Mar 2019 14:03:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:43874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729164AbfC0SDg (ORCPT ); Wed, 27 Mar 2019 14:03:36 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32128217D9; Wed, 27 Mar 2019 18:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709815; bh=wuNY7ljoIS1ZD31d45BkhQfHoi82zPOiPMuDdesqbJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1zxqOrdxXqogK+s4zVm1WrAQmaKM4W14i6Zt/7HEYKUKondByXoxQ4D3S610e/YK6 Oxo7moihOYrNi/VpXm61AdnmJs1GlcS9hEl8vU6/xRZeq1Y7jRUpWCxzI+UeeXZZsv iFohT/9JMVUpieT2JwW0Izaeild6Jzqfut00pDgw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Honghui Zhang , Lorenzo Pieralisi , Sasha Levin , linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 5.0 054/262] PCI: mediatek: Fix memory mapped IO range size computation Date: Wed, 27 Mar 2019 13:58:29 -0400 Message-Id: <20190327180158.10245-54-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Honghui Zhang [ Upstream commit c61df57343bf05743f8abbb31eec9a6f05820dd1 ] Mediatek's HW assigns a MMIO address range (typically starts from 0x20000000 to 0x2fffffff for both mt2712 and mt7622) for PCI usage. This MMIO address space represents the address space that can be allocated to PCI devices through Base Address Registers. Even though the full MMIO address range is available to be allocated, it should be enabled by the PCIE_AHB_TRANS_BASE register in the host controller and the size that is enabled is determined by AHB2PCIE_SIZE bits in this register. Owing to a bug in the MMIO window size computation, current code does not enable the full size of the available MMIO address range in the PCI host controller; if the PCI devices BARs requested size exceeds the size enabled through the PCIE_AHB_TRANS_BASE register the requests targeting the disabled address address space will be blocked by the root complex causing a system error. Existing code has never run into a system error in production because even half of the enabled MMIO range (128MB) is big enough for typical devices BAR requests (4MB) but the full MMIO address range should be enabled regardless. Fix the MMIO window size computation by using resource_size(mem) instead of mem->end - mem->start. Since the MMIO window size for both MT2712 and MT7622 is 0x10000000, this change will update the parameter passed to fls() from 0xfffffff to 0x10000000 and calculate the whole memory mapped IO range size correctly. Detected through coccinelle semantic patch (and related warning): scripts/coccinelle/api/resource_size.cocci: pcie-mediatek.c:720:13-16: WARNING: Suspicious code. resource_size is maybe missing with mem Signed-off-by: Honghui Zhang [lorenzo.pieralisi@arm.com: rewrote the commit log] Signed-off-by: Lorenzo Pieralisi Signed-off-by: Sasha Levin --- drivers/pci/controller/pcie-mediatek.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 55e471c18e8d..c42fe5c4319f 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -654,7 +654,6 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) struct resource *mem = &pcie->mem; const struct mtk_pcie_soc *soc = port->pcie->soc; u32 val; - size_t size; int err; /* MT7622 platforms need to enable LTSSM and ASPM from PCIe subsys */ @@ -706,8 +705,8 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) mtk_pcie_enable_msi(port); /* Set AHB to PCIe translation windows */ - size = mem->end - mem->start; - val = lower_32_bits(mem->start) | AHB2PCIE_SIZE(fls(size)); + val = lower_32_bits(mem->start) | + AHB2PCIE_SIZE(fls(resource_size(mem))); writel(val, port->base + PCIE_AHB_TRANS_BASE0_L); val = upper_32_bits(mem->start); -- 2.19.1