Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1062390ybb; Wed, 1 Apr 2020 15:04:00 -0700 (PDT) X-Google-Smtp-Source: APiQypL53JQonn/BprZRGZqNHfVtbwwITyzAEz9lNWsoKf67Md3aOlOUAi5pUiY9N9gkqExKxOdD X-Received: by 2002:aca:4243:: with SMTP id p64mr88303oia.21.1585778640418; Wed, 01 Apr 2020 15:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585778640; cv=none; d=google.com; s=arc-20160816; b=vEJrcUaGlruzl9sZjOPldVGoIMiqqFbeJaKA7jn6mfC3FGw3eR2JMaE0fL6UledpYH vDCehzfJk0768+yS89GXMQAfA0R4SD2QSrvzZyPkfAVWVn67SqUIXArcaZUlUmzWRm4U qcRskgoJuaz1uE+kHkxtcX6IAOEjJKYMtWcKr+5dCfyKUJ6AqdF8nVLJue5Fw9LVCEzz GobilwuqSFdfSlZUw8ogzeXXkzaOmlpXPLu69URux5y9bg7lzbgDdTKklhfC9eEi+1vZ yOjRoog+igOTCoF/sexxtuNMot6/XBybtLvTB2LL+c0G5qjHrQVobjn1SSZLHwa92bhN TfEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=K8pDEelmy7xxYp1QwnSMqwTohO6HdXpcoDkiDESxMFY=; b=Wai3ryCfFidOwKVKInLmYVZR1anCLf0NX0sK3Omm5xp3E4QAVCpBr64BBY6IVHhzum whSz8GNpULayX4Ww6GhV6fc4t/4qEgCInEG40JntsW90ZY0SpU924wI96shlZ57Q0kiP x/pPJ9ZvPES+QbLz3GJ/z6lkmDaUlzN4neWlT/ytSP8zOAkM5yHMkfrDKJWQkzw9JidA pkRaXoDa+KC2wCXoGrxi1xYAOxtTWI19USRoWfNEHhNNa5flgMBC5/es8bp83cGyz8g9 v1jrVk+cfl2RVeO1DrBdyuWuhQ7hspsbTrjtsiFFyOU6RkQfjut1mo+vTdtNG+aYG3n0 UOpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jl9fwFpC; 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 n21si1505734otf.130.2020.04.01.15.03.46; Wed, 01 Apr 2020 15:04:00 -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=jl9fwFpC; 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 S1732809AbgDAWCz (ORCPT + 99 others); Wed, 1 Apr 2020 18:02:55 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:34139 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732357AbgDAWCy (ORCPT ); Wed, 1 Apr 2020 18:02:54 -0400 Received: by mail-lf1-f68.google.com with SMTP id e7so1069198lfq.1 for ; Wed, 01 Apr 2020 15:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K8pDEelmy7xxYp1QwnSMqwTohO6HdXpcoDkiDESxMFY=; b=jl9fwFpCclGippG67yVn6KJ9hwDIFLwwWBO9OjxOceyu0nvj8GddH0nEOpAAUtNawk V2VOz05YaD1F0e21A2+VGL3KOVuebDwIWfAiK1lTlAUMRoI/kdrOR47x9AVO4mPl3Y+q z9yAOPJdMKvz8sJ7NnvJVMr3BypMwW7av9hJqBAL76orlmWMy45r0/qM2nGDDTJypO6F mXC2Z4Q91mIkmTEJ0EQU4/6HWJtAqP9e9u17BIP/wnA5zqMEwZXZfNjaKHWh3NNmYJqT cRQzO+buZANl2K4/W/dA3muGNpZWa+FW2kFCAjEb3w4VKfIIaxrm7oU7K49PFtkB5LgW kBqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K8pDEelmy7xxYp1QwnSMqwTohO6HdXpcoDkiDESxMFY=; b=D72yt+yIkFQRWmLMYSkAreQBBdbDuNCIbDOhFzpn2fdjgq/jXNp0INrfYEzDxw7nuI Q9O1nKNc8HPa/filrVVV6SUOOhb8W0YmjkxsDa4brqmZtysMisjpaqPlNmThh7GgiS4C l1JPPxSGctZj0Kum2SPZAc29b3UKLa0tacrdg68y0j4EYoVSqFtO5ZFxBwKoDOVKqct+ ZKDukbaCppTO6Ckn56ntOAtq8dK83VWOCwvBJBuLwIdll7TbMQhchum9Se79WWL+xr0k yKdMpfQ7e/FiAu32UCZuPvIgnGrQUMzSeid8tyv+Z+ij+TFgWHcxE1wJGnoCGQIyr+DV PdNQ== X-Gm-Message-State: AGi0PubbQ9GFfWhGtb3SAdmtQxCZs/n0wVe3HN+FuN9BKyuN0ZotgQbd bW4LHwAR/aFagIoUT8swgyyUP2ztQu2Umg8MjUWqqA== X-Received: by 2002:a05:6512:685:: with SMTP id t5mr174279lfe.47.1585778569817; Wed, 01 Apr 2020 15:02:49 -0700 (PDT) MIME-Version: 1.0 References: <20200401202937.GA130497@google.com> In-Reply-To: From: Alan Mikhak Date: Wed, 1 Apr 2020 15:02:38 -0700 Message-ID: Subject: Re: [PATCH] PCI: Warn about MEM resource size being too big To: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, linux-pci , Jingoo Han , Gustavo Pimentel , lorenzo.pieralisi@arm.com, amurray@thegoodpenguin.co.uk, Kishon Vijay Abraham I , Paul Walmsley Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 1, 2020 at 2:01 PM Alan Mikhak wrote: > > On Wed, Apr 1, 2020 at 1:29 PM Bjorn Helgaas wrote: > > > > On Tue, Mar 31, 2020 at 01:36:04PM -0700, Alan Mikhak wrote: > > > On Tue, Mar 31, 2020 at 1:12 PM Bjorn Helgaas wrote: > > > > On Mon, Mar 30, 2020 at 05:19:47PM -0700, Alan Mikhak wrote: > > > > > 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. This 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 in > > > > > effect its size gets reduced to 4GB. > > > > > > > > > > ATU programming functions can 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. > > > > > > > > > > Changing the ATU programming functions is high > > > > > impact. Without change, this issue can go > > > > > unnoticed. A warning may prompt the user to > > > > > look into possible issues. > > > > > > > > So this is basically a warning, and we could actually *fix* the > > > > problem with more effort? I vote for the fix. > > > > > > The fix would impact all PCIe drivers that depend on dwc. > > > > Is that another way of saying "the fix would *fix* all the drivers > > that depend on dwc"? > > Thanks Bjorn for your comments. > > Not at all. I'm not suggesting that. I'm just stating the dilemma. > > One option is, as you may be alluding, the *fix* would include > modification to all drivers that depend on dwc to at least not break > the build.. Whoever embarks on such a *fix* would have to take > that on before submitting the patch. > > Another option is to produce an alternate ATU programming > API for the Linux PCI sub-system to support u64 size. That > way individual driver owners can choose if and when to migrate > their drivers to the new API on their own timeline. Such an > alternative API can also be generic to support not only > Designware PCIe controllers but others. > > > > > > I would have no way of validating such a fix without > > > breaking it for everyone let alone the bandwidth it needs. > > > All drivers that depend on dwc seem to be currently happy > > > with the u32 size limit. I suggest we add the warning but > > > keep this issue in mind for a solution that allows existing > > > PCe drivers to phase into the fix on their own individual > > > schedules, if they need to. > > > > Obviously it would *nice* to test all the drivers that depend on dwc, > > but if you're fixing a problem, you verify the fix on your system, and > > the relevant people review it, I don't think exhaustive testing is a > > hard requirement, and I certainly wouldn't expect you to do it. > > That is a relief for whoever commits to take this on. > > > > > If we want to live with a 32-bit limit, I think we should change the > > relevant interfaces to use u32 so there's not a way to venture into > > this region of undefined behavior. I don't think "warning + undefined > > behavior" is a very maintainable situation. > > I cannot live with the 32-bit limit. I need a 64-bit solution. I had > to implement a solution that suits my needs. I have worked > out some of the issue. It is generic enough for my use with PCIe > controllers from more than one vendor. But, it requires pulling a > lot of code from Designware layer into a separate framework > which I believe can become common for Linux PCI subsystem. > If it gets in, others who need 64-bit can migrate over to it without > being migrated involuntarily. > The "undefined" behavior part of the problem can be fixed separately in the function dw_pcie_prog_outbound_atu_unroll() by modifying its internal calculation of the limit address and programming the ATU upper limit address register. With the above fix in dw_pcie_prog_outbound_atu_unroll(), the total problem reduces to the size issued being reduced to 4G max. > > > > > > > This limitation also means that multiple ATUs > > > > > would need to be used to map larger regions. > > > > > > > > > > Signed-off-by: Alan Mikhak > > > > > --- > > > > > 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..37a8c71ef89a 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 too big\n"); > > > > > + pp->mem_size = mem_size; > > > > > pp->mem_bus_addr = pp->mem->start - win->offset; > > > > > break; > > > > > case 0: > > > > > -- > > > > > 2.7.4 > > > > >