Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11163552ybi; Thu, 25 Jul 2019 11:05:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNkreb1+fMNAUTP9H/JcOy6M3lshyevtSExjf/DpxBnqyyl1Nf9gRY017uj4iY1Z1W7vcW X-Received: by 2002:a17:90a:de02:: with SMTP id m2mr93690182pjv.18.1564077932885; Thu, 25 Jul 2019 11:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564077932; cv=none; d=google.com; s=arc-20160816; b=ZttxtWNeZ9VPTfuSz/KLZPusizeyPrTlUlnxF6tUbhmB9BLvdeAODsxsYSMictmChA bUpcCz5bf2hpw4+xQOmg62y14e88QNlWByQ6BoA5aw5w8KmiC35+NzsKh2dV3yf4v4qb mXP+xKXxENd1iJycxZ1R0BQ+Qy1ndKHXPyAUPFDYbFaSc4KB7qf2dxHg8cEfG9X/coso zSHoTDoDO9VyvLCuVQr2frySnORJCx7amlHtBcnCDRpo0u9jJS4CiP0Wk7hcIWNJY4cA /hFLiv05xazCsDtCKpW94jA4N+S5leo8susGIiZl4/Pe9/CXqnwUcRok0UUrU2uMxCoJ Qbww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to; bh=tC8gygQFfEacNQCZvCwhWWBv1TAFJCFi5jIJGkEVdqg=; b=dSA2xbeqDLBAKDgHq/5mso/25RUR3CdAk3IwiHmTa4xu5CbbIZdtlXP5G1cYUudUgD QGT6bfrdpbF946DcZzdK5qFXiPp2v2/H1djt1969/20Q5l+LyBZQwPX+EVfmwFaP3l9L 0OguKzoa44nUVzQ4Ddb9nw5gbdycUngYX7aDbA0xVmZpg2LOWJVg+ELQXtzJdYG/6iyT 1At2n77UCeKQUH7eNkoHQEkjfcYtjv2UOifYOuUmBSJ7rong2qF87gFN++PmUxdbzSgb oZdgw/WFxxv7Psjg+d04a/M9wzEQml3S1VJV41cLU9FDREtaGSUfQuzPwGBZ5tXxOOhJ pMMg== 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 t185si16851681pgd.596.2019.07.25.11.05.16; Thu, 25 Jul 2019 11:05:32 -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 S2389816AbfGYQAr (ORCPT + 99 others); Thu, 25 Jul 2019 12:00:47 -0400 Received: from ale.deltatee.com ([207.54.116.67]:38154 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387874AbfGYQAq (ORCPT ); Thu, 25 Jul 2019 12:00:46 -0400 Received: from s01061831bf6ec98c.cg.shawcable.net ([68.147.80.180] helo=[192.168.6.132]) by ale.deltatee.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1hqgAQ-00081J-CN; Thu, 25 Jul 2019 10:00:31 -0600 To: Christoph Hellwig Cc: 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 References: <20190722230859.5436-1-logang@deltatee.com> <20190722230859.5436-12-logang@deltatee.com> <20190724063232.GB1804@lst.de> <7173a4dd-0c9c-48de-98cd-93513313fd8d@deltatee.com> <20190725061005.GB24875@lst.de> From: Logan Gunthorpe Message-ID: Date: Thu, 25 Jul 2019 10:00:25 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190725061005.GB24875@lst.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 68.147.80.180 X-SA-Exim-Rcpt-To: sbates@raithlin.com, epilmore@gigaio.com, dan.j.williams@intel.com, axboe@fb.com, kbusch@kernel.org, sagi@grimberg.me, jgg@mellanox.com, Christian.Koenig@amd.com, bhelgaas@google.com, linux-rdma@vger.kernel.org, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, hch@lst.de X-SA-Exim-Mail-From: logang@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [PATCH 11/14] PCI/P2PDMA: dma_map P2PDMA map requests that traverse the host bridge X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-07-25 12:10 a.m., Christoph Hellwig wrote: > 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. Oh, yes, I'll take a look at this. Of the two callers: NVMe should be easy we could just pass the PCI device instead of the struct device. RDMA is significantly more unclear: would you add a pci_dev to struct ib_device? Or maybe we should be able to simply rely on the fact that the DMA device *must* be a PCI device and just use to_pci_dev() directly? >>> >>>> + 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; > } Ok, will change for v2. Thanks, Logan