Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8138936ybi; Tue, 23 Jul 2019 03:29:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4MGPD9fn14JehtMK1O1vG+NUQV4TGbv8I6X0plnsNV/afqKhIX6QdrMDLex7RP87SlUqW X-Received: by 2002:a17:90a:ac13:: with SMTP id o19mr81876324pjq.143.1563877792762; Tue, 23 Jul 2019 03:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563877792; cv=none; d=google.com; s=arc-20160816; b=xnA5rtqvIErHhpP4RLVb319GuAbre/Tvy0OgtIRggSqpaTpoQQ86+2QnNz6UuM3OWz ICIIqh1j2kz/fwPIirqdLE7OaICoQvfEzjLdCX9oXW+D7/WmSRf4Sj/+3kCEMNoPdTvw 5CitHqBgK0DEdAp14E/HtWDsBKfNwOvfKlOR9elRCkOf9b4p3vbDtrCJMgSjuIiU7OVq X+oPoFO2sUPCJTfp1VEdmitSFbpoiH5EPcQhko+Lqr9PHNLSsTzJOgz4FmNbrcxprTVs /YzBxUOTzwOgIbCuSKsyLTQJ4+qhvTJnu8n7WxGdlEj3pfbwRyjtcONZiqEk2QKmyBRL nuyw== 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 :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=KSm+yFVIBY/lOp/emkZI7e5LXg+pRTDV+zT+rFYo1O4=; b=P04BQoe+whxeeDpIXu5FWG1LNKiuAlAfKubMsHnVW/NhXxD5XUNilEXewQvBDhsbbI +ICmtVNyOvwoOFkZTJMMYZ7Dku1l67xmkUT9OSGlCcZvSRMF0Cv18SIdNtUGSjROkuB5 RYW5qduW8yPLtME/DlWX1t5YIpLxk7wzJvOQzDwEDWRFGpxYgU1xjB1Qs90JeF26QOm7 TA3Aq5oe9W5GWqR87THREY1MBJpN7/eqC29dAvQKBXdHk5sLABb3pcZdJxCxqBaTn8oF 4tdesQbkMf0seuQoS6VSuUraVNtBQ55i+0hGaWniPsX3cwTscYeRWkX7k9OTtnF+nNPf OrgA== 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 h5si11060811pls.280.2019.07.23.03.29.37; Tue, 23 Jul 2019 03:29:52 -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 S2387436AbfGVXJa (ORCPT + 99 others); Mon, 22 Jul 2019 19:09:30 -0400 Received: from ale.deltatee.com ([207.54.116.67]:40308 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733281AbfGVXJQ (ORCPT ); Mon, 22 Jul 2019 19:09:16 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hphQc-0002k6-I0; Mon, 22 Jul 2019 17:09:15 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1hphQW-0001R8-RF; Mon, 22 Jul 2019 17:09:04 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-nvme@lists.infradead.org, linux-rdma@vger.kernel.org Cc: Bjorn Helgaas , Christoph Hellwig , Christian Koenig , Jason Gunthorpe , Sagi Grimberg , Keith Busch , Jens Axboe , Dan Williams , Eric Pilmore , Stephen Bates , Logan Gunthorpe Date: Mon, 22 Jul 2019 17:08:56 -0600 Message-Id: <20190722230859.5436-12-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722230859.5436-1-logang@deltatee.com> References: <20190722230859.5436-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, bhelgaas@google.com, hch@lst.de, Christian.Koenig@amd.com, jgg@mellanox.com, sagi@grimberg.me, kbusch@kernel.org, axboe@fb.com, dan.j.williams@intel.com, epilmore@gigaio.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@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.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [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 Any requests that traverse the host bridge will need to be mapped into the IOMMU, so call dma_map_sg() inside pci_p2pdma_map_sg() when appropriate. Similarly, call dma_unmap_sg() inside pci_p2pdma_unmap_sg(). Signed-off-by: Logan Gunthorpe --- drivers/pci/p2pdma.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 5f43f92f9336..76f51678342c 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -830,8 +830,22 @@ int pci_p2pdma_map_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 (WARN_ON_ONCE(!client)) + return 0; - return __pci_p2pdma_map_sg(pgmap, dev, sg, nents); + dist = upstream_bridge_distance(pgmap->pci_p2pdma_provider, + client, NULL); + 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); } 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); + if (dist & P2PDMA_NOT_SUPPORTED) + return; + + if (dist & P2PDMA_THRU_HOST_BRIDGE) + dma_unmap_sg_attrs(dev, sg, nents, dir, attrs); } EXPORT_SYMBOL_GPL(pci_p2pdma_unmap_sg_attrs); -- 2.20.1