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=-18.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 6B83DC43460 for ; Tue, 11 May 2021 16:06:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43028611F0 for ; Tue, 11 May 2021 16:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbhEKQHi (ORCPT ); Tue, 11 May 2021 12:07:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22744 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbhEKQHf (ORCPT ); Tue, 11 May 2021 12:07:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620749188; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8UV1wByeUIYlPOcdwlcmJhFE5ghODP+1p9OllaOX3sI=; b=gLw/Y6msZanJ7HEyDxnjR54Ay+Aq2OMEwTFqnlQLVTiO6v1VrvBL3CqIBFuah4OSqhWABS 1NHLS9mXvrmkYPTdt1FmsFz9IAUYjV2uNiqlQzNOwKYDteA0KIRkJT1/zslzBCbD24Jr5D MQ9GeWecEPZLPh1a07Pftny/e/uZx9Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-541-LePH9WAtNran78JB9Xx15w-1; Tue, 11 May 2021 12:06:25 -0400 X-MC-Unique: LePH9WAtNran78JB9Xx15w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E05B91854E2A; Tue, 11 May 2021 16:06:19 +0000 (UTC) Received: from [10.3.115.19] (ovpn-115-19.phx2.redhat.com [10.3.115.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FF4F9CA0; Tue, 11 May 2021 16:06:17 +0000 (UTC) Subject: Re: [PATCH 10/16] dma-mapping: Add flags to dma_map_ops to indicate PCI P2PDMA support To: Logan Gunthorpe , 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_K=c3=b6nig?= , John Hubbard , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy References: <20210408170123.8788-1-logang@deltatee.com> <20210408170123.8788-11-logang@deltatee.com> From: Don Dutile Message-ID: <92704199-4cee-3811-3902-08ccf6cc1f5f@redhat.com> Date: Tue, 11 May 2021 12:06:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20210408170123.8788-11-logang@deltatee.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On 4/8/21 1:01 PM, Logan Gunthorpe wrote: > 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 | 3 +++ > include/linux/dma-mapping.h | 5 +++++ > kernel/dma/mapping.c | 18 ++++++++++++++++++ > 3 files changed, 26 insertions(+) > > diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h > index 51872e736e7b..481892822104 100644 > --- a/include/linux/dma-map-ops.h > +++ b/include/linux/dma-map-ops.h > @@ -12,6 +12,9 @@ > struct cma; > > struct dma_map_ops { > + unsigned int flags; > +#define DMA_F_PCI_P2PDMA_SUPPORTED (1 << 0) > + I'm not a fan of in-line define's; if we're going to add a flags field to the dma-ops -- and logically it'd be good to have p2pdma go through the dma-ops struct -- then let's move this up in front of the dma-ops description. And now that the dma-ops struct is being 'opened' for p2pdma, should p2pdma ops be added to this struct, so all this work can be mimic'd/reflected/leveraged/refactored for CXL, GenZ, etc. p2pdma in (the near?) future? > 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 50b8f586cf59..c31980ecca62 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -146,6 +146,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); > @@ -247,6 +248,10 @@ static inline int dma_supported(struct device *dev, u64 mask) > { > return 0; > } > +static inline bool dma_pci_p2pdma_supported(struct device *dev) > +{ > + return 0; > +} > 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 923089c4267b..ce44a0fcc4e5 100644 > --- a/kernel/dma/mapping.c > +++ b/kernel/dma/mapping.c > @@ -573,6 +573,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; So, this means one cannot have p2pdma with IOMMU's? ... -- or is this 'for now' and this may change?  if it may change, add a note here. > + > + /* > + * 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; that's a bool? > +} > +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