Received: by 10.223.185.116 with SMTP id b49csp83757wrg; Fri, 2 Mar 2018 14:07:22 -0800 (PST) X-Google-Smtp-Source: AG47ELucwpJz9/JxZyeC5E8Aos/UHQG3mVA2N8qY2iD68brW2G3A5UJKTWcDdYcS41MNAQxyNJsD X-Received: by 10.98.238.2 with SMTP id e2mr7033015pfi.68.1520028442117; Fri, 02 Mar 2018 14:07:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520028442; cv=none; d=google.com; s=arc-20160816; b=AJtuLDEzLui4RMko+kpQg0CWXTty1WoYqzczPDwmIhCOqEF4G5sjkVtxGa9JsCnNQY nrSl8ciUhdXqeFFN5HiyeTAMf+oh1ybI+r3kT173HyNViLki5rVUpHYx8nJsKEr7QEYD KnYFgDSFOwW2mRG6ZHlNroVqJEnkau8KP59G5N3egfcgdVmWyUh8Q8NEALEaaf9AjxqB 2TNJBLQfvtyjQrHM7D8QKLT30Oyo428CMY4/e7SYGrDj9kwb5ZkT7AkQ+bede4ezSzG7 1s5wv7B9FXNZCtbgelJ+odSjeKoxn0iaRjs6tPtfjR173VQm1W+zSRwQbfK+jOf1skdo STEw== 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:dmarc-filter:arc-authentication-results; bh=ym9LYkfzHbocsiQCJF/+G8bI2Agr5vu2SVeq11SMyXc=; b=Xl7bVhpcapmRAmZYKCkvBra9/FcUnZYX97FAYN6SiJyjeUXcIvlu3qYFK3Jkg3h2Uo kHGMPFmM43YI+I2yEqxWqn77nnAkgnxGOzkuGIFS8sFL1ruV3pnGIEB34dezbaHEYwQZ hM+ELFclIRYlZktpPc62aJ9Df6oJXR0H+Y28ftuqORrOHJNDyCa1uB6+LsKNPBpW9G8F R8OTQh0HpEW8y6kA1P2m7MyjRKGWf/fu1JXt1NRwjHZjnLgbFb3ovUmJG6rfxTWp9DHL 3j4OAjGrPYxvdqhgRR9g5/kCHCIvw1p3ObQzTh3rh+1QA7AX8O+oWHQMesbOaCcQZ/8A oALg== 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 l184si4563811pge.224.2018.03.02.14.07.07; Fri, 02 Mar 2018 14:07:22 -0800 (PST) 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 S932247AbeCBVtA (ORCPT + 99 others); Fri, 2 Mar 2018 16:49:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:44572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932131AbeCBVs7 (ORCPT ); Fri, 2 Mar 2018 16:48:59 -0500 Received: from localhost (unknown [69.55.156.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 48C1E2179F; Fri, 2 Mar 2018 21:48:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48C1E2179F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Date: Fri, 2 Mar 2018 15:48:57 -0600 From: Bjorn Helgaas To: KarimAllah Ahmed Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Bjorn Helgaas Subject: Re: [PATCH v3 2/2] PCI/IOV: Use the cached VF BARs size instead of re-reading them Message-ID: <20180302214857.GD202062@bhelgaas-glaptop.roam.corp.google.com> References: <1519939897-14596-1-git-send-email-karahmed@amazon.de> <1519939897-14596-2-git-send-email-karahmed@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1519939897-14596-2-git-send-email-karahmed@amazon.de> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 01, 2018 at 10:31:37PM +0100, KarimAllah Ahmed wrote: > Use the cached VF BARs size instead of re-reading them from the hardware. > That avoids doing unnecessarily bus transactions which is specially > noticable when you have a PF with a large number of VFs. Thanks a lot for breaking this out! It seems trivial, but it did make it much easier for me to think about this one. > Cc: Bjorn Helgaas > Cc: linux-pci@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: KarimAllah Ahmed > --- > drivers/pci/probe.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c > index a96837e..aeaa10a 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -180,6 +180,7 @@ static inline unsigned long decode_bar(struct pci_dev *dev, u32 bar) > int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, > struct resource *res, unsigned int pos) > { > + int bar = res - dev->resource; > u32 l = 0, sz = 0, mask; > u64 l64, sz64, mask64; > u16 orig_cmd; > @@ -199,9 +200,13 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, > res->name = pci_name(dev); > > pci_read_config_dword(dev, pos, &l); > - pci_write_config_dword(dev, pos, l | mask); > - pci_read_config_dword(dev, pos, &sz); > - pci_write_config_dword(dev, pos, l); > + if (dev->is_virtfn) { > + sz = dev->physfn->sriov->barsz[bar] & 0xffffffff; > + } else { > + pci_write_config_dword(dev, pos, l | mask); > + pci_read_config_dword(dev, pos, &sz); > + pci_write_config_dword(dev, pos, l); > + } I don't quite understand this. This is reading the regular BARs (config offsets 0x10, 0x14, ..., 0x24). Per sec 9.3.4.1.11, these are all RO Zero for VFs. That should make them look like they're all unimplemented. But this patch makes us use the size we discovered from the PF's VF BARn registers in its SR-IOV capability. Won't that cause us to fill in the VF's dev->resource[n], when we didn't do it before? > /* > * All bits set in sz means the device isn't working properly. > @@ -241,9 +246,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, > > if (res->flags & IORESOURCE_MEM_64) { > pci_read_config_dword(dev, pos + 4, &l); > - pci_write_config_dword(dev, pos + 4, ~0); > - pci_read_config_dword(dev, pos + 4, &sz); > - pci_write_config_dword(dev, pos + 4, l); > + > + if (dev->is_virtfn) { > + sz = (dev->physfn->sriov->barsz[bar] >> 32) & 0xffffffff; > + } else { > + pci_write_config_dword(dev, pos + 4, ~0); > + pci_read_config_dword(dev, pos + 4, &sz); > + pci_write_config_dword(dev, pos + 4, l); > + } > > l64 |= ((u64)l << 32); > sz64 |= ((u64)sz << 32); > @@ -332,6 +342,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) > for (pos = 0; pos < howmany; pos++) { > struct resource *res = &dev->resource[pos]; > reg = PCI_BASE_ADDRESS_0 + (pos << 2); > + if (dev->is_virtfn && dev->physfn->sriov->barsz[pos] == 0) > + continue; Since we know the VF BARs are all zero (the ones in the VF config space, not the ones in the PF SR-IOV capability), including the VF ROM BAR, it would make sense to me to totally skip this whole function, e.g., if (dev->non_compliant_bars) return; if (dev->is_virtfn) return; > pos += __pci_read_base(dev, pci_bar_unknown, res, reg); > } > > -- > 2.7.4 >