Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4878ybb; Tue, 31 Mar 2020 15:49:27 -0700 (PDT) X-Google-Smtp-Source: APiQypJpgLy/fnVBHIwrBD0f/EWH+hFVUMlIVId/WTGIrLISPjSjzxlDL3ME9H8HHLotBxRV4nVG X-Received: by 2002:aca:fcd6:: with SMTP id a205mr896323oii.28.1585694967148; Tue, 31 Mar 2020 15:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585694967; cv=none; d=google.com; s=arc-20160816; b=swM1rRpQJFxkimnscqh1WBUoR3j+MHqmqdin0kiZabUZID5oC+hj0wMtZ3DlfguHRU e96vHpO0FjySh5TDgBQPxmXQsTDMcZVGfGsNHWALxadZJE4CI6AeJJ51r3eFQFfntF8z AEdTH+ngby9teLH6t9Nc8w4EypIiOlQO2UlZ7h2XbcHA2SFL0r5g3u6muOb83zOMBXnC ADrUjPesRduUOk5bZGN9lS93rzDog2Cood91NqE4gFMXohgSTqjG1ypTbzyiXeGunOa/ yYx4b1bkfSd8ZJ/HDx2pFc7G0OKFbdGQiiLMXL90oYysugGnzitGCoaowGYQPeERg6ap eTlw== 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=PzUxe8ko8vz1S1g23peXxZLjPYDb7Lz9ppyXcN8eAuw=; b=dSBNoxH9dBbGwRkLRWlhvl9kpRTg6ITwd6WXzkbkSEZzOAntDho7r4/57hcULS7dI9 zd3+f8oMJBZ3RtsF1lS1ODBwREb6Kf39bHms+tAhTCrXUWXt+GAvh0kN8gTmQHplsW3G IOEk+KCrKrOyFZuNAWQBA7+ot5fk+TOYGG2jIcNln1Po6fsj+lt3/SB1GphiH45lBkat tYkIVE3WdWB9VUirqPSL/3zGqeIqP2rDHxPlsOV6t+8yoC1uq6S3Iu5emGaTnpXcHv0v 11eQZlsIAzQFceIW49pu+B5iDpRuzfiNxrcCnKRGH1bvnyQ+l9Z9dag+KxeKG5CWLySk tnPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=naBdxTbY; 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 t144si117330oie.129.2020.03.31.15.49.13; Tue, 31 Mar 2020 15:49:27 -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=naBdxTbY; 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 S1731345AbgCaWst (ORCPT + 99 others); Tue, 31 Mar 2020 18:48:49 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:35370 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731259AbgCaWst (ORCPT ); Tue, 31 Mar 2020 18:48:49 -0400 Received: by mail-pj1-f68.google.com with SMTP id g9so1777982pjp.0 for ; Tue, 31 Mar 2020 15:48:48 -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=PzUxe8ko8vz1S1g23peXxZLjPYDb7Lz9ppyXcN8eAuw=; b=naBdxTbYLPllr28JdItkaY0txWH0NLxTtGo3sh2eGsw+cz3uQyPl0Rsi5YuCe3zC3n /LjqrIyB3giSCzTCcFxs5fgLLyqdBLvBw5eADih+f0RBO5P7a/Y1gptbORl9Fw4GpXM/ HGix4fz7zBuR/ljJV/EGs+BpM9ME0/2894ssYuRyFcc8JUpk3snOJRGxCEG6mF0aw5/l l0d1UAXbQtMLcJczthPZbiwElkHwkbF6yJMAvN1WTWD8cbLpuB1Yt1geMxMslVzr+c8j Oky0l46dkr+bnWjx6KSXfhPvrD+CN7pXrLHIv3NYoDxCd41QZjC6x7fVv5R8+lVD8nx6 QriA== 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=PzUxe8ko8vz1S1g23peXxZLjPYDb7Lz9ppyXcN8eAuw=; b=jOdlFPwSCEJaX0vk2ayqM1FRU1GnYuZuOmo20Wk3srJxFYMvqAj3UmuUbCC/rfz1Sa O8Uk2uqLA7X7nhNrsqPwvFvbTmrj7HIzB6vrE9xaBwtIa2Fb2XdAQZzC61chT4d2AlrY aYkl8lM53jYyO0/hAG0fk07c/J2ZL/e8ccVaaYRkC5R5EuM2D/UTaibRMuKMP9afFar5 CwjBPpzncm2k+JRQSSp3u14ewCSdEwYnBJ4tzDJ6wGpDKK4WZUJWu8PXg8bkKA6AR2Tc OuTcz6T/ZQuVlJH5oAktOEotD63MhB101bpCc7eJHSPZ9iUep7VcL85W72/2PHSQyYJR D4aQ== X-Gm-Message-State: AGi0PuYgexUZ7nAiNMz27MXpCZ/zdGwJs/JSkcYln02JDWfprehYuCpv rrEyWvcARO0LjtdIVwQwaWuCcoJrSlM= X-Received: by 2002:a17:902:8546:: with SMTP id d6mr9102382plo.280.1585694927175; Tue, 31 Mar 2020 15:48:47 -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 k14sm158906pfg.15.2020.03.31.15.48.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Mar 2020 15:48:46 -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 v2] PCI: dwc: Warn MEM resource size exceeds max for 32-bits Date: Tue, 31 Mar 2020 15:48:35 -0700 Message-Id: <1585694915-32005-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 Output a warning for MEM resource size with non-zero upper 32-bits. ATU programming functions limit the size of the translated region to 4GB by using a u32 size parameter. Function dw_pcie_prog_outbound_atu() does not program the upper 32-bit ATU limit register. These issues may result in 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. This would be a problem for a 128GB PCIe space because the internal calculation of the limit address in ATU programming functions in effect reduces the size to 4GB. This may also produce undefined behavior since the ATU limit address may be lower than the ATU base address. This limitation also means that multiple ATUs would need to be used to map larger regions. ATU programming functions may be changed to specify a u64 size parameter for the translated region. Along with this change, the internal calculation of the limit address, the address of the last byte in the translated region, needs to change such that both the lower 32-bit and upper 32-bit limit registers can be programmed correctly. Without change, this issue can go unnoticed. A warning may prompt the user to look for possible issues. Changing the ATU programming functions impacts all PCIe drivers that depend on dwc which seem to be currently happy with the u32 size limit. A solution that allows existing PCIe drivers to phase into the fix on their own individual schedules, if they need to, may be desirable. Signed-off-by: Alan Mikhak Acked-by: Gustavo Pimentel --- drivers/pci/controller/dwc/pcie-designware-host.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 395feb8ca051..df5ebe02ffca 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -325,6 +325,7 @@ int dw_pcie_host_init(struct pcie_port *pp) struct pci_bus *child; struct pci_host_bridge *bridge; struct resource *cfg_res; + resource_size_t mem_size; u32 hdr_type; int ret; @@ -362,7 +363,10 @@ int dw_pcie_host_init(struct pcie_port *pp) case IORESOURCE_MEM: pp->mem = win->res; pp->mem->name = "MEM"; - pp->mem_size = resource_size(pp->mem); + mem_size = resource_size(pp->mem); + if (upper_32_bits(mem_size)) + dev_warn(dev, "MEM resource size exceeds max for 32 bits\n"); + pp->mem_size = mem_size; pp->mem_bus_addr = pp->mem->start - win->offset; break; case 0: -- 2.7.4