Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2411541ybm; Thu, 23 May 2019 16:57:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6KImjQV6kBXTiixnki1mj5Wm0oKyRfrpAQehCN7lB226olPlr2wsCs4PKZEgop0CxBII+ X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr31298859plo.99.1558655851794; Thu, 23 May 2019 16:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558655851; cv=none; d=google.com; s=arc-20160816; b=ZBdOPbR96O0KcE6fWqIDjp5iXnxEFsjbz359xQuO6Qybh+SUfeZTpx94jFlJzA/Xfg VQCFi8+Bodh7qDKT4AzvBe/gaHoCCYGQgiDxggh88qcwBeO+vNbyiZu+npJJNvkadtgM f2pisPfT1D2yZiWTtziBf3OD8ygsewm6T2+FPujOjMGUlpqwE5xNGJP2goMc3FAyzfdJ sYnVcRn9N0EQ0isuz1ZXRCLvp/4X2IgjkdXqnH/ZaeNj6EQmrbfD4Ob5YnqOm+Y6h1JE NFAPHRraNlbgPT87I5sNr59EzPWV3PzZhFl3QsiJvqFjPnBrZXEfAuxBoA49coyhf9JP eohw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xQh5W0I98+c3oB3ta6aEBLw922/4T4zsrZf/bWTXTzU=; b=g9rjeb5FL526Dm0BP/COk/wv8H+ZJNFu9naLo//tUKJrfof8Omh0mY50syezRiGQHv CAOJK5veO9z8Ri2zlOQNbMACngrjJmKhDfm2v5LeqyQR+NTDs6plI5GpyjLpPsqUet+z Y7LRNstqtq+bQnecaSfTy8pMmnEJoov7MAVrJ63B9gNjyASNx+zjJIvzv9s2ak8z7Cf5 Sb2CWv4E8FqJsXuamA0RtVIrhwLWCvkpMmZHf72yWDZ5A5R0q5PdNYVDIvEZQ5V/vqkJ jmMzQKZSDjTMdMq1s6lCE8BAato5N0aj+fDuVKhQfYoZVEVBe5tNdNOANqXsblC6gHn/ dMfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=En6Q2o1S; 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 h7si1499991pgk.379.2019.05.23.16.57.11; Thu, 23 May 2019 16:57:31 -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=En6Q2o1S; 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 S2388557AbfEWXzQ (ORCPT + 99 others); Thu, 23 May 2019 19:55:16 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46807 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388232AbfEWXzQ (ORCPT ); Thu, 23 May 2019 19:55:16 -0400 Received: by mail-lf1-f65.google.com with SMTP id l26so5650998lfh.13 for ; Thu, 23 May 2019 16:55:15 -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; bh=xQh5W0I98+c3oB3ta6aEBLw922/4T4zsrZf/bWTXTzU=; b=En6Q2o1SlX3M7Df2OjIoSIT3soWjKBCQy6sPnuSQE+O3wgvYsqwB4X8Q+dyzV1c1Os hQ3hDMwcJ11Nxgi1u46gRXLS3CNrO57rKnfi6fe26xHKpb+46ZFXQGl1vnRKpJhcV4RM Yq1GO/x+1erGD7xCvZgu/Sw09bbOPn3LrB/2IUDKO3wOv3PvXJUreex0VqicRBjnQHJq cP6XZLiRepHxaS9vTHiQaj6NLxsMjmJvPSxihldmZqwb6S5mexNt34YJMhAyRz5leFqY QVH76r4prK2EyCQJMHK0ttiGuZC9+vvpOar4qHvWhLyro1jBNnsExMQVV3V+bjOrU7tA wBGA== 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; bh=xQh5W0I98+c3oB3ta6aEBLw922/4T4zsrZf/bWTXTzU=; b=mwY8LDqlU+9OLjsHRj28R+ODBrLcRV9XkLpOTEbP2xYV6Sg7PL+JrW6XBrU/nfXPCV kcUfIU6RSYthO0IMMrATF36md5/tcQJDVBKpErZnuoPugfhpqxomfppDwVrwVPPY5a3p xk1Ts0/Bk2RCzPEqyEXDgrsaSDzsPOC1BnFAUFbgh5bYjlcJ/NujOtjv47A7LBTT5G9A BP1Vx766aYj3EeS/8o1+Vif1SDkFjEhkSLK5leUDv2vrERR4Jof0eWsVCkeRqEWydS7Z NYKJmEizKC14V0MBeNLMIjIUBu/ak8Y4BHa3bFLD8csXeseh1nVkYgqRNSL4xuXPzfP3 iuSA== X-Gm-Message-State: APjAAAWqduUk86yHqhLRGM956oioABY99x79HGfyTF6jAtzNHy+pig/y DpSqmY4jQj5CIh0TddgvFXRBaGc8DcdM9c7IHcuUKQ== X-Received: by 2002:ac2:4286:: with SMTP id m6mr7504444lfh.150.1558655714383; Thu, 23 May 2019 16:55:14 -0700 (PDT) MIME-Version: 1.0 References: <1558648540-14239-1-git-send-email-alan.mikhak@sifive.com> In-Reply-To: <1558648540-14239-1-git-send-email-alan.mikhak@sifive.com> From: Alan Mikhak Date: Thu, 23 May 2019 16:55:03 -0700 Message-ID: Subject: Re: [PATCH v2] PCI: endpoint: Skip odd BAR when skipping 64bit BAR To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kishon@ti.com, lorenzo.pieralisi@arm.com, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Bjorn Helgaas , gustavo.pimentel@synopsys.com, wen.yang99@zte.com.cn, kjlu@umn.edu 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 +Bjorn Helgaas, +Gustavo Pimentel, +Wen Yang, +Kangjie Lu On Thu, May 23, 2019 at 2:55 PM Alan Mikhak wrote: > > Always skip odd bar when skipping 64bit BARs in pci_epf_test_set_bar() > and pci_epf_test_alloc_space(). > > Otherwise, pci_epf_test_set_bar() will call pci_epc_set_bar() on odd loop > index when skipping reserved 64bit BAR. Moreover, pci_epf_test_alloc_space() > will call pci_epf_alloc_space() on bind for odd loop index when BAR is 64bit > but leaks on subsequent unbind by not calling pci_epf_free_space(). > > Signed-off-by: Alan Mikhak > Reviewed-by: Paul Walmsley > --- > drivers/pci/endpoint/functions/pci-epf-test.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c > index 27806987e93b..96156a537922 100644 > --- a/drivers/pci/endpoint/functions/pci-epf-test.c > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c > @@ -389,7 +389,7 @@ static void pci_epf_test_unbind(struct pci_epf *epf) > > static int pci_epf_test_set_bar(struct pci_epf *epf) > { > - int bar; > + int bar, add; > int ret; > struct pci_epf_bar *epf_bar; > struct pci_epc *epc = epf->epc; > @@ -400,8 +400,14 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) > > epc_features = epf_test->epc_features; > > - for (bar = BAR_0; bar <= BAR_5; bar++) { > + for (bar = BAR_0; bar <= BAR_5; bar += add) { > epf_bar = &epf->bar[bar]; > + /* > + * pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64 > + * if the specific implementation required a 64-bit BAR, > + * even if we only requested a 32-bit BAR. > + */ > + add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; > > if (!!(epc_features->reserved_bar & (1 << bar))) > continue; > @@ -413,13 +419,6 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) > if (bar == test_reg_bar) > return ret; > } > - /* > - * pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64 > - * if the specific implementation required a 64-bit BAR, > - * even if we only requested a 32-bit BAR. > - */ > - if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) > - bar++; > } > > return 0; > @@ -431,7 +430,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) > struct device *dev = &epf->dev; > struct pci_epf_bar *epf_bar; > void *base; > - int bar; > + int bar, add; > enum pci_barno test_reg_bar = epf_test->test_reg_bar; > const struct pci_epc_features *epc_features; > > @@ -445,8 +444,10 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) > } > epf_test->reg[test_reg_bar] = base; > > - for (bar = BAR_0; bar <= BAR_5; bar++) { > + for (bar = BAR_0; bar <= BAR_5; bar += add) { > epf_bar = &epf->bar[bar]; > + add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; > + > if (bar == test_reg_bar) > continue; > > @@ -459,8 +460,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) > dev_err(dev, "Failed to allocate space for BAR%d\n", > bar); > epf_test->reg[bar] = base; > - if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) > - bar++; > } > > return 0; > -- > 2.7.4 >