Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1148827ybb; Wed, 1 Apr 2020 17:00:18 -0700 (PDT) X-Google-Smtp-Source: APiQypIm6+/Tz40K0vWA4FMT+3qVYXE4xtzYlH9DN8acV4fRbk/iP33+Hy05knxs0MyjuztSg/k/ X-Received: by 2002:aca:4d13:: with SMTP id a19mr355067oib.105.1585785618183; Wed, 01 Apr 2020 17:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585785618; cv=none; d=google.com; s=arc-20160816; b=uLh66wOxtOM70iyvOHyPbfMXYuYP73k9H+GpWoXZdywPbZ70jTqVH68RIDE4tJ0Akz KNTt98cEPUWr/uc+SoYZfPzdpAWcfqTp+xIlyfuHLWg0EPCC8ykC4i6zInwytzkiENQW T6CvRxxAVscNem7y6yKZU4vVcAlJ4zMwdP3RBbbnNPl3ack1akRIcgbb0uh0LYG1j4j9 Uh0Zfnot1DcOWMGpsDqm0nAUxGe5P7KBEqzqdgZdZriLJb4Ho1CfEXWoH5i4iOc9zmj4 HlLsrOYTs/rTjDfvbA0Z044Kt/mQmh7qv0DaosJhMA9BnVmhapdsNK6fQeRxBMn6QKEL w8Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=6HaOIWdsOvizBvUG72A610lipCbSG/hDyB8c4hgjxM4=; b=DVTMA2uy9CKs6gpDHQbwkF8QhXx8WGqE1h39fZzJF72OJaepLYWacZxWP3n/6hejKu xQjIvsbwLCggTdSNipCnkifi8vm/R+m9hc1dsOX8yIq4KouFtcV3hWCcVal5rVaUcP/3 xVWDdEuYCjZuvHUY94fZ7Z1JmOnzuqlgTfOuMNNBwADwRZnRpKB5cVpv8rbQPSMV6QpZ tu0bRm0y9sY+e0YBMnxqClehcOIZZht2C61xuiiJfttraOsjm/xeb7EBdELXf8CicfhH cSwXoPApJ4l702Ny2tVpeyQgO3W91kSS9EIpsgJo889YKnYbNvz2Fdtj6z30v5MHt6MX RDvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=TIDyu6sF; 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 m19si1682087otn.256.2020.04.01.17.00.05; Wed, 01 Apr 2020 17:00:18 -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=@sifive.com header.s=google header.b=TIDyu6sF; 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 S1733182AbgDAX6m (ORCPT + 99 others); Wed, 1 Apr 2020 19:58:42 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34003 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732560AbgDAX6m (ORCPT ); Wed, 1 Apr 2020 19:58:42 -0400 Received: by mail-pl1-f194.google.com with SMTP id a23so646136plm.1 for ; Wed, 01 Apr 2020 16:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=6HaOIWdsOvizBvUG72A610lipCbSG/hDyB8c4hgjxM4=; b=TIDyu6sFaiElP3YA0sQ8+IyF0Dbte0xNsHwxCQVD2RygK+ekQ1sy1up8ezowMNa53O BDFkGog/4C6cuAplYC1JQ+4p0ceAKuuCVgKqIXhBGw6UXB6Jk7/TphmATJnp8tl9sZaD YeDYTenE0xhy511z4M3NoTSs6Pydy3mHwoEMXAg29WNYU+0WnnyuVWRK26gFAXtXuq3/ H4GRC4rV7VhnqZB73GB8BamTWtO7aWlPJPdo/qE6lv8/JhV8n8xMz9RXZ6Dp6G7dmDt4 y0d/kbespU0DOgH/PU+GhNoPWZAIzUdx8SraS1wMIuF4oOPY7O6fO6oV8PbObSV/nyn+ /vPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6HaOIWdsOvizBvUG72A610lipCbSG/hDyB8c4hgjxM4=; b=Y1AiAJI8yT4FGj95R5AKaVm/vzNCOQ3gi/QHpBisKHW5FK2Cxi0QTbZ625hyj7Gbz7 s99G1NPtaIcnLivAPi92MzqFsTNE3QApw944w9NqJ6/sYpDPyThVXeRHUKs2107ZddDc wmVCEOvdTyRWt/2C5vaNOqiJWJq5IgDKEIxzlzBK1RGz/FVqdVQlDEcsJhRcFp0bBIBx n9bKkDnz8aVyhFa/1CEMvWYHu3edCzFNgL63EQeCvJsVlDmJJ8Y2WQJjDf19cgwYKxMT 98Dj+NjVtJQrTomDni+BLHRNgv1CfqbpXRQ+ofFPtKj5/LV1hWp4/th+PWUxBxYGKC3b 9a/w== X-Gm-Message-State: AGi0Pub1FXo/sZgra1mkSaSSQKL+t/kreyeE8AzfytEphh1yGeSf5Zr2 W5mx/mvTWE58n0BYgskZSNyA1bSO9lg= X-Received: by 2002:a17:90a:71c5:: with SMTP id m5mr592961pjs.193.1585785519306; Wed, 01 Apr 2020 16:58:39 -0700 (PDT) Received: from nuc7.sifive.com (c-24-5-48-146.hsd1.ca.comcast.net. [24.5.48.146]) by smtp.gmail.com with ESMTPSA id o29sm2405893pfp.208.2020.04.01.16.58.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Apr 2020 16:58:38 -0700 (PDT) From: Alan Mikhak X-Google-Original-From: Alan Mikhak < alan.mikhak@sifive.com > To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, jingoohan1@gmail.com, gustavo.pimentel@synopsys.com, lorenzo.pieralisi@arm.com, amurray@thegoodpenguin.co.uk, bhelgaas@google.com, kishon@ti.com, paul.walmsley@sifive.com Cc: Alan Mikhak Subject: [PATCH] PCI: dwc: Program outbound ATU upper limit register Date: Wed, 1 Apr 2020 16:58:13 -0700 Message-Id: <1585785493-23210-1-git-send-email-alan.mikhak@sifive.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Mikhak Function dw_pcie_prog_outbound_atu_unroll() does not program the upper 32-bit ATU limit register. Since ATU programming functions limit the size of the translated region to 4GB by using a u32 size parameter, these issues may combine into undefined behavior for resource sizes with non-zero upper 32-bits. For example, a 128GB address space starting at physical CPU address of 0x2000000000 with size of 0x2000000000 needs the following values programmed into the lower and upper 32-bit limit registers: 0x3fffffff in the upper 32-bit limit register 0xffffffff in the lower 32-bit limit register Currently, only the lower 32-bit limit register is programmed with a value of 0xffffffff but the upper 32-bit limit register is not being programmed. As a result, the upper 32-bit limit register remains at its default value after reset of 0x0. These issues may combine to produce undefined behavior since the ATU limit address may be lower than the ATU base address. Programming the upper ATU limit address register prevents such undefined behavior despite the region size getting truncated due to the 32-bit size limit. Signed-off-by: Alan Mikhak --- drivers/pci/controller/dwc/pcie-designware.c | 7 +++++-- drivers/pci/controller/dwc/pcie-designware.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 681548c88282..c92496e36fd5 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -244,13 +244,16 @@ static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index, u64 pci_addr, u32 size) { u32 retries, val; + u64 limit_addr = cpu_addr + size - 1; dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_BASE, lower_32_bits(cpu_addr)); dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_BASE, upper_32_bits(cpu_addr)); - dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT, - lower_32_bits(cpu_addr + size - 1)); + dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_LIMIT, + lower_32_bits(limit_addr)); + dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_LIMIT, + upper_32_bits(limit_addr)); dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET, lower_32_bits(pci_addr)); dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET, diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index a22ea5982817..5ce1aef706c5 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -112,9 +112,10 @@ #define PCIE_ATU_UNR_REGION_CTRL2 0x04 #define PCIE_ATU_UNR_LOWER_BASE 0x08 #define PCIE_ATU_UNR_UPPER_BASE 0x0C -#define PCIE_ATU_UNR_LIMIT 0x10 +#define PCIE_ATU_UNR_LOWER_LIMIT 0x10 #define PCIE_ATU_UNR_LOWER_TARGET 0x14 #define PCIE_ATU_UNR_UPPER_TARGET 0x18 +#define PCIE_ATU_UNR_UPPER_LIMIT 0x20 /* * The default address offset between dbi_base and atu_base. Root controller -- 2.7.4