From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7748C7618B for ; Thu, 25 Jul 2019 16:00:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ADCF22C7E for ; Thu, 25 Jul 2019 16:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389788AbfGYQAq (ORCPT ); Thu, 25 Jul 2019 12:00:46 -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 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-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@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