Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4227023ybi; Tue, 11 Jun 2019 03:09:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLPbFm1tutcnwOV4vPVOK4kZsgpHGId9XYEb4lpdJ2PujPgKDUMsXAjAM9iaZr7Lk/UCjP X-Received: by 2002:a62:2c8e:: with SMTP id s136mr35121375pfs.3.1560247777447; Tue, 11 Jun 2019 03:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560247777; cv=none; d=google.com; s=arc-20160816; b=bziIz1052lDkwW+A5i1DS7RrLbb8eIoUHLDYU4pVTTp9SaGFOPUVWSiMXNQJuEOzS6 ktQIUkeTwsOCmG5tn9H8ri+E/xz9rzNxxrCEdg+doWEwx7a+kLwq+u7LNusD77KEJ6pV F/xE4cU45YlHigmo2YsIo/1XcPVxFb0CzkGmvPECAYVxGpZt9AIA2zv3kP4ROWQ+0n0C bvye+PaJs/om8ZvI80a7prPBUIOloHUjC6hdAtYJr3cV9biyaFMRH2WAu7epFWr65j3P sz4sZ77Yctj/gV8fglGhTAqV/uEY4+Ihef+wv9zXl888xLabeJmx0SKVK/nJUA561UeS 8FCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=p7Ee+ZJ6W6ror4lzha4/qjLwlOgeIChemvg72AfRcoI=; b=ChsjJWzO6wSPkA4nsZ6HogW2YC2Lk87cjHuAIuVgo8Ej3RPmnB8SiccMJfDX4ywxMF tvmu4/O6rLH8Mz+fCzsdDm4JEgAb+zMA9kiy6ET6zYYzSMGYfnykIbKR5IaQ1vO7coMM m1Opqn1kjSC/9nRBn/mIjIBYYY4+dzB9MgDRwnNuolBHYIh+yxS83mRS2S4Ri6fy740L VeM9ptPJlHk0NUuJFsVFcSxiybF+3+ScARIhuVHJ8cjeV3OUCCALjG9E+spGulWhV4hr nui0vJ1VhjbeLN0M7Wc9ksBgeA8+Bqb8uPaTfxya8eMeuWgobXrABW6U+8iZR3Njz2/E iDtA== ARC-Authentication-Results: i=1; mx.google.com; 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 d9si4888077pgj.505.2019.06.11.03.09.21; Tue, 11 Jun 2019 03:09:37 -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; 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 S2405223AbfFKKIt (ORCPT + 99 others); Tue, 11 Jun 2019 06:08:49 -0400 Received: from foss.arm.com ([217.140.110.172]:57448 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405185AbfFKKIt (ORCPT ); Tue, 11 Jun 2019 06:08:49 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 608CF337; Tue, 11 Jun 2019 03:08:48 -0700 (PDT) Received: from redmoon (unknown [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B3B353F557; Tue, 11 Jun 2019 03:10:29 -0700 (PDT) Date: Tue, 11 Jun 2019 11:08:45 +0100 From: Lorenzo Pieralisi To: Alan Mikhak Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kishon@ti.com, linux-riscv@lists.infradead.org, palmer@sifive.com, paul.walmsley@sifive.com Subject: Re: [PATCH v2] PCI: endpoint: Skip odd BAR when skipping 64bit BAR Message-ID: <20190611100845.GC29976@redmoon> References: <1558648540-14239-1-git-send-email-alan.mikhak@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1558648540-14239-1-git-send-email-alan.mikhak@sifive.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 02:55:40PM -0700, 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(-) Applied to pci/endpoint for v5.3, thanks. Lorenzo > 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 >