Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11171178ybi; Thu, 25 Jul 2019 11:12:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgx1wL8btX/EFElJXo9J3JZ5wMZR1UufiaHLkZD54jUDaCgbTfIVV5bWXJjEep0Z/2bLan X-Received: by 2002:aa7:9117:: with SMTP id 23mr18052397pfh.206.1564078347897; Thu, 25 Jul 2019 11:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564078347; cv=none; d=google.com; s=arc-20160816; b=oaRhHosqPUJ8G7D+XAj0iiNuvo2v1oVFm1s24xqE3z923wYVn8y9Y0vjgiAhT/bwC1 gHF9PwLtOTkEksNLEEa6YU3aO/cLdaxHQgXHCU5j90JfWL9T8+LzMAqEGXzkWJisFaGm n44cIUoswgrAJcTj48KuRJ72S6/He9xDkcB9nO0FvUdeeocsMi14wMQWZ0EFFVAUNbDN cUBSW3gr1gafcjRh63W2OEXOtE+U/iRqakRVaKTVU/Pb/7BIlWqIVMR+/iSqyfatHhlL YmrJej5LPHShFlHFmaEZfNxt+ydoKS2HSa0CUNmcU7kDOnZ0GrOb6YffZVqsbVPeN51S 22WA== 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=gKSc1DwYnpopHNerMEdhDl5X/QxGEYZDaukMIbTQJbA=; b=OfeqzSa4aC6iDD6MVYwnYwucryw9hkzw8k/V9eFAI8Ozbt+Z6YIsMTe+xxqiyB+a+m YpfuWyyykeftQFhvTPX5t8cCq0KDbxaorERS9Eco6ggSu2c/rM+4jUstmqGqouxbHgL6 dR/4zPXifsrz0h7+3WwapttlgCjLLtuPYtGMhNV255bob3PmrnISPCG3ljCBEj6x5T9c pUd2roaQYirY1ZyceY4pMXsw5KThACvcQwNjRI/tVc2lA1fFGFDxg/HXcNUQVOH1DkEu 7B0eBnKUvU4M6ses/g1E6Tp1S8JHwDh5Aw9InCGrwPWJl4+IAyPLDM4GmXr5Dw70L0Al FnjQ== 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 e66si16173229plb.254.2019.07.25.11.12.12; Thu, 25 Jul 2019 11:12:27 -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 S1729833AbfGYRW6 (ORCPT + 99 others); Thu, 25 Jul 2019 13:22:58 -0400 Received: from ale.deltatee.com ([207.54.116.67]:39540 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726283AbfGYRW6 (ORCPT ); Thu, 25 Jul 2019 13:22:58 -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 1hqhRz-0001I0-Mk; Thu, 25 Jul 2019 11:22:44 -0600 To: Jason 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 , 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> <20190725163438.GF7450@mellanox.com> From: Logan Gunthorpe Message-ID: <486e2a25-f6e6-75d4-a8b7-6a38fff8546a@deltatee.com> Date: Thu, 25 Jul 2019 11:22:39 -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: <20190725163438.GF7450@mellanox.com> 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, 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, jgg@mellanox.com 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 10:34 a.m., Jason Gunthorpe wrote: > On Thu, Jul 25, 2019 at 10:00:25AM -0600, Logan Gunthorpe wrote: >> >> >> 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? > > AFAIK you need to use the ib_device->dma_device and add some kind of > is_pci_dev to make it safe Yes, that's my thinking. The dma_device *should* be a PCI device. We can just be sure by doing is_pci_dev() and failing the mapping if it is not. So I *think* we should be able to simply replace the find_parent_pci_dev() with: if (!dev_is_pci(dev)) return 0; client = to_pci_dev(dev); Which should be fast and reliable. The alternative is to push this out into the caller which may have a bit more information (like the nvme driver does). Logan