Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10777779ybi; Thu, 25 Jul 2019 05:07:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+uqQ8g+eusc+RRaQAlFyeaFjomaCZa2Lcq/dyAvEGQLiP67Zkr3RRELoVV4EIbfo4kHfd X-Received: by 2002:a65:6108:: with SMTP id z8mr54629405pgu.289.1564056443304; Thu, 25 Jul 2019 05:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564056443; cv=none; d=google.com; s=arc-20160816; b=N9xW6YdRS+M8AjDZkm/IpHDWWxdsbW/bmBzdI5L3hm5dGEZfhk0kLyzfdeW6lGXL4G t/9LpUPQfAyd+9niLRB2NhcH1BjC7o0mmkFM/uRNGgZDkhnl1pIA5TkQX1jm87IaBexE tl6FQapv7y59oEn6mkyH0j9N0KCpGCGiwnU8a8c1YuVfKLLqmDldwFAktVUSBamCJ8jd 2K7/cX9JqSLqRo4B9fSB4pD3hkIl6PiPndaEc59IqM84UySA+et2LAPrpy/9ERKOOt3m blCrlMOJPRYeGE5QMz1IE2VDaNP8dsA7VSvUZFC2UN9vBTzoUKSRlGgGxALPnHR73P0Q NUIQ== 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=vEPpAGuQYLZlofvpTUUFjf2j9w9Z33jSq8CLzMmnolk=; b=mt2r+ZiXMHHuZiPzduFujTL24Xp05eVLl6S4O0nQzKAS378AgUxDu4nvomBLFnvu7I i+4qFyT4So4aENbDhoqc9qO2cWi9SUV0hOU7MJ68bfKGOrfgDVC4KU7DotaN/M3U7/QG Vs7tRHGKqXZlKnWTpvGeG377xiKhoOikvf3cGigOqrpy3UVP0xCkrq1dWM2005lYZhtW Femle+eO9OWsXgHucb85LnMYAOjVqUyWLKVOb9l3KMikYFNLebVI3+xzjaIKwiwLEASZ PN6UXYr1RpnMy94xIj9RqpbJ0HzVBsH4MALj/6gmWIYVmz20csw9CfY+cT0WiuaMywQL 8yWQ== 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 cj14si17743120plb.141.2019.07.25.05.07.08; Thu, 25 Jul 2019 05:07:23 -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 S1729043AbfGYGKL (ORCPT + 99 others); Thu, 25 Jul 2019 02:10:11 -0400 Received: from verein.lst.de ([213.95.11.211]:58481 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfGYGKK (ORCPT ); Thu, 25 Jul 2019 02:10:10 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 0ECA268B20; Thu, 25 Jul 2019 08:10:06 +0200 (CEST) Date: Thu, 25 Jul 2019 08:10:05 +0200 From: Christoph Hellwig To: Logan Gunthorpe Cc: Christoph Hellwig , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org, Bjorn Helgaas , Christian Koenig , Jason Gunthorpe , Sagi Grimberg , Keith Busch , Jens Axboe , Dan Williams , Eric Pilmore , Stephen Bates Subject: Re: [PATCH 11/14] PCI/P2PDMA: dma_map P2PDMA map requests that traverse the host bridge Message-ID: <20190725061005.GB24875@lst.de> References: <20190722230859.5436-1-logang@deltatee.com> <20190722230859.5436-12-logang@deltatee.com> <20190724063232.GB1804@lst.de> <7173a4dd-0c9c-48de-98cd-93513313fd8d@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7173a4dd-0c9c-48de-98cd-93513313fd8d@deltatee.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 24, 2019 at 09:58:59AM -0600, Logan Gunthorpe wrote: > > > On 2019-07-24 12:32 a.m., Christoph Hellwig wrote: > >> struct dev_pagemap *pgmap = sg_page(sg)->pgmap; > >> + struct pci_dev *client; > >> + int dist; > >> + > >> + client = find_parent_pci_dev(dev); > >> + if (WARN_ON_ONCE(!client)) > >> + return 0; > >> > >> + dist = upstream_bridge_distance(pgmap->pci_p2pdma_provider, > >> + client, NULL); > > > > Doing this on every mapping call sounds expensive.. > > The result of this function is cached in an xarray (per patch 4) so, on > the hot path, it should just be a single xa_load() which should be a > relatively fast lookup which is similarly used for other hot path > operations. We don't cache find_parent_pci_dev, though. So we should probably export find_parent_pci_dev with a proper namespaces name and cache that in the caler. > > > >> + if (WARN_ON_ONCE(dist & P2PDMA_NOT_SUPPORTED)) > >> + return 0; > >> + > >> + if (dist & P2PDMA_THRU_HOST_BRIDGE) > >> + return dma_map_sg_attrs(dev, sg, nents, dir, attrs); > >> + else > >> + return __pci_p2pdma_map_sg(pgmap, dev, sg, nents); > > > > Can't we organize the values so that we can switch on the return > > value instead of doing flag checks? > > Sorry, I don't follow what you are saying here. If you mean for > upstream_bridge_distance() to just return how to map and not the > distance that would interfere with other uses of that function. The point is that in the map path we don't even care about the distance. I think we should just have a function that returns the P2PDMA_ values from the xarray (maybe also store it there as two values, but that isn't quite as important), and get rid of even the concept of distance in the map path. e.g.: switch (pci_p2pdma_supported(pgmap->pci_p2pdma_provider, client))) { case P2PDMA_HOST_BRIDGE: return dma_map_sg_attrs(dev, sg, nents, dir, attrs); case P2PDMA_SWITCH: return __pci_p2pdma_map_sg(pgmap, dev, sg, nents); default: WARN_ON_ONCE(1); return 0; }