Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9186807ybi; Tue, 23 Jul 2019 23:33:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdwnnLgqY05rxzumqSkqPpZti/Kd3+LqNef7e22ylNjn7XBBCqdh01Pqte5FTIeiAvC/2f X-Received: by 2002:a65:5c02:: with SMTP id u2mr10336488pgr.367.1563950009063; Tue, 23 Jul 2019 23:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563950009; cv=none; d=google.com; s=arc-20160816; b=izP339xZmZ0XSdmMVQUHlJGP9g9R7X8f8dZShO7VKXO6mHvdxMX3SCP7Y8R5SrXUvg p58g84DChg1PvVvjJWARVOXY+NHL5yCYORMhIXMktu79vOAdDn0ZUB1R+qh7TtPxDdfR 3DO3XLmNNKZeIleOR+ougrmnqVe0QYc/Xrd8q44T0kjtnnwaicURjK0mYgxtojb9zmeB Jp+jJwqVPaPQAFZxnlYvi1kFJMlHcw6dmW3y8oxOZ7AgZ8DDTNq+Hzcq4RCMqFTA+rnS Pbs6V4yhBCSxGe/ZN1Cs49HQO9SbI24dVfWCD6Ko7K034OwYMe4wKJTyM0GovEWUu+fK KVoA== 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=q9Rp8/TV6Yy54nlwnftzRBL6d8s1PY1JeX3slNXPvP8=; b=AXBURsR/r+0n/rcEDUJ/LvnzLuEgCvAV1TEh/7wzeTHmAbompVEw0uGJUPvSkT74EH QVLhoKyOfoSEpLqz9FExyut4j+ATQyUcwZ4/OPH++kQjgJY5TmrShUUvrV2IOvQ+pfUl itBjLnVVZy7Mvw6CRyilOVkfEiou3TGOPqjktogeUUhYZWw+k0SgvqN/shde9mPwFyzT ZeuEwKcYcmwmSWOelNZn8ZHOvmk65JUbEfR1u8yQevZ7uWhqMxwDho+BHmmWSg0DD04A Ixi6ScaiYCPHaA+uamFR4/ITr3hzviB2VyNuyXLUHK1I0cq+vXNH9pfuc3Qw22D8T77G Ab6w== 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 e11si15701268pgi.121.2019.07.23.23.33.14; Tue, 23 Jul 2019 23:33:29 -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 S1726303AbfGXGcg (ORCPT + 99 others); Wed, 24 Jul 2019 02:32:36 -0400 Received: from verein.lst.de ([213.95.11.211]:48034 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbfGXGcf (ORCPT ); Wed, 24 Jul 2019 02:32:35 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 3292A68BFE; Wed, 24 Jul 2019 08:32:33 +0200 (CEST) Date: Wed, 24 Jul 2019 08:32:32 +0200 From: Christoph Hellwig To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org, Bjorn Helgaas , Christoph Hellwig , 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: <20190724063232.GB1804@lst.de> References: <20190722230859.5436-1-logang@deltatee.com> <20190722230859.5436-12-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190722230859.5436-12-logang@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 > 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.. > + 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? > } > 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..