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.3 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 D0C60C7618B for ; Wed, 24 Jul 2019 15:59:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4A8D2083B for ; Wed, 24 Jul 2019 15:59:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726847AbfGXP7Q (ORCPT ); Wed, 24 Jul 2019 11:59:16 -0400 Received: from ale.deltatee.com ([207.54.116.67]:43522 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbfGXP7P (ORCPT ); Wed, 24 Jul 2019 11:59:15 -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 1hqJfR-0005E5-5g; Wed, 24 Jul 2019 09:59:02 -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> From: Logan Gunthorpe Message-ID: <7173a4dd-0c9c-48de-98cd-93513313fd8d@deltatee.com> Date: Wed, 24 Jul 2019 09:58:59 -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: <20190724063232.GB1804@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-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. > >> + 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. >> } >> EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg_attrs); >> >> @@ -847,6 +861,21 @@ EXPORT_SYMBOL_GPL(pci_p2pdma_map_sg_attrs); >> void pci_p2pdma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, >> int nents, enum dma_data_direction dir, unsigned long attrs) >> { >> + struct dev_pagemap *pgmap = sg_page(sg)->pgmap; >> + struct pci_dev *client; >> + int dist; >> + >> + client = find_parent_pci_dev(dev); >> + if (!client) >> + return; >> + >> + dist = upstream_bridge_distance(pgmap->pci_p2pdma_provider, >> + client, NULL); > > And then we do it for every unmap again.. Yup, I don't think there's much else we can do here. This is why I was fighting against doing lookups against the phys_addr_t because that means you have to do these additional lookups. My hope is if we can move to the phys_addr_t and flags as I described here[1] we can get rid of these hot path lookups, but with the way things are structured now this is necessary. Logan [1] https://lore.kernel.org/linux-block/e63d0259-e17f-effe-b76d-43dbfda8ae3a@deltatee.com/