Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2162948pxb; Fri, 17 Sep 2021 03:47:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU+gjTQF5mriybeCJWr6P1B+7EOM2JZnTdseYJSDmG8Tu2E0YbR+rIQkkZqVW0TT1KxVra X-Received: by 2002:a17:906:a3c3:: with SMTP id ca3mr11586909ejb.337.1631875678683; Fri, 17 Sep 2021 03:47:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631875678; cv=none; d=google.com; s=arc-20160816; b=K2iwBlP6ot+LJmlzvao98T1WExmgEfIFkENpBnj2QZ7VMV48vL4ViYeGOE7ojFBRTP gz23rBEH1LxVF5hq5yIgv0obcbk3CYSlhzxpZ6TURxWNJGbSwvZ9KGWFl55vFEAi+LZM NRFymcImTHGqRt4LEM+E2oqlmx3m2b4AwQoA+vte0IBz+Yv6o5kvvzYBNKUOHbNVxwVz z7xjkKJsb2Bgsrkmv/Pl1202UCWvusLqVtA0eGPm3mHRazbgpk7vG+jfMwYxjZNFr4tO 4Px/6i6J76WBV8tBDmVGrnV+SqWc8AAHlaX6ZdbLbc3NGF6qY5wqUc6zagohVSJUAsve 2Bxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=SUhj8YW4TKyKXdbuHR1PtoAzIeP797v8JHmvpqp4UGs=; b=N5VTtIClxMP8cevDpudOer82PauDE10fuLo+icjHIqyj8gLteKqjAiN2SoVGm0Rfvc 5QLBZx7AJ4u6IYwKolj1Gr8BwKkAzQ64hG8Iazt06kiq6AIzmL6RAE9vEH6NL6AgCykw AK+QDfrK/44DJOPBd76Ac7UZ57VNFqOr9M/g1WWsmsiBup3shWiV2/hM5nsyM4TNdaFO FFLPo3PLlGtU9968e/6VYzr1gRin7jQzguzBfuFu7/D+b8nb2nHuZA35h/kpCEiI5g0r 1gPrMwpzZy6DFgqSsIf65td2yBaTKznpMIvaLl0MLUCoEu3qMAOZEva3d73+tOvq67C+ KSAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=US2nbdXe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si6616433eji.655.2021.09.17.03.47.34; Fri, 17 Sep 2021 03:47:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=US2nbdXe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241045AbhIPXn1 (ORCPT + 99 others); Thu, 16 Sep 2021 19:43:27 -0400 Received: from ale.deltatee.com ([204.191.154.188]:40764 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbhIPXmi (ORCPT ); Thu, 16 Sep 2021 19:42:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=SUhj8YW4TKyKXdbuHR1PtoAzIeP797v8JHmvpqp4UGs=; b=US2nbdXeHZ4YK1t/LQVqqQEeKt kRiPXEINhZotB2XVMeU6hV6ESntSYVx8GLm+bPNDMQSWD/SydpExElXSEhA3jWSYMYWjBV5TtuoP4 Cb0TgQ8HhbNQDB79QLXrk44pIErDx2pLRCAgmI83UWV79CO7eOuMmT9HXaQG+RAhs1TpMbe4adklX 1q0NaAgfLepzX2aTUFlglmRhTl0ema/QCO86Q4PMC6HahUt1qYuZeiAAVG6u8RuqfCni3MFO38k/1 rHFuCwDyVo4Yn4sRGaPEtkF32ooybj5KEy/j2DMR4t5p+LLhE0d6n9V0mM0uthlOZMw4yXm0vr8cI C8UaQYsw==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mR10G-0008I1-Hd; Thu, 16 Sep 2021 17:41:17 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1mR104-000Vr7-E3; Thu, 16 Sep 2021 17:41:04 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?q?Christian=20K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Logan Gunthorpe Date: Thu, 16 Sep 2021 17:40:47 -0600 Message-Id: <20210916234100.122368-8-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210916234100.122368-1-logang@deltatee.com> References: <20210916234100.122368-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-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, sbates@raithlin.com, hch@lst.de, jgg@ziepe.ca, christian.koenig@amd.com, jhubbard@nvidia.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, helgaas@kernel.org, dan.j.williams@intel.com, andrzej.jakowski@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.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=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH v3 07/20] dma-mapping: add flags to dma_map_ops to indicate PCI P2PDMA support X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a flags member to the dma_map_ops structure with one flag to indicate support for PCI P2PDMA. Also, add a helper to check if a device supports PCI P2PDMA. Signed-off-by: Logan Gunthorpe --- include/linux/dma-map-ops.h | 10 ++++++++++ include/linux/dma-mapping.h | 5 +++++ kernel/dma/mapping.c | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 0d5b06b3a4a6..b60d6870c847 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -11,7 +11,17 @@ struct cma; +/* + * Values for struct dma_map_ops.flags: + * + * DMA_F_PCI_P2PDMA_SUPPORTED: Indicates the dma_map_ops implementation can + * handle PCI P2PDMA pages in the map_sg/unmap_sg operation. + */ +#define DMA_F_PCI_P2PDMA_SUPPORTED (1 << 0) + struct dma_map_ops { + unsigned int flags; + void *(*alloc)(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs); diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index dca2b1355bb1..f7c61b2b4b5e 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -140,6 +140,7 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, unsigned long attrs); bool dma_can_mmap(struct device *dev); int dma_supported(struct device *dev, u64 mask); +bool dma_pci_p2pdma_supported(struct device *dev); int dma_set_mask(struct device *dev, u64 mask); int dma_set_coherent_mask(struct device *dev, u64 mask); u64 dma_get_required_mask(struct device *dev); @@ -250,6 +251,10 @@ static inline int dma_supported(struct device *dev, u64 mask) { return 0; } +static inline bool dma_pci_p2pdma_supported(struct device *dev) +{ + return false; +} static inline int dma_set_mask(struct device *dev, u64 mask) { return -EIO; diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 7315ae31cf1d..23a02fe1832a 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -727,6 +727,24 @@ int dma_supported(struct device *dev, u64 mask) } EXPORT_SYMBOL(dma_supported); +bool dma_pci_p2pdma_supported(struct device *dev) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + /* if ops is not set, dma direct will be used which supports P2PDMA */ + if (!ops) + return true; + + /* + * Note: dma_ops_bypass is not checked here because P2PDMA should + * not be used with dma mapping ops that do not have support even + * if the specific device is bypassing them. + */ + + return ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; +} +EXPORT_SYMBOL_GPL(dma_pci_p2pdma_supported); + #ifdef CONFIG_ARCH_HAS_DMA_SET_MASK void arch_dma_set_mask(struct device *dev, u64 mask); #else -- 2.30.2