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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66B1AD3A66B for ; Tue, 29 Oct 2024 15:11:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA6456B008A; Tue, 29 Oct 2024 11:11:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E562A6B008C; Tue, 29 Oct 2024 11:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF6E86B0092; Tue, 29 Oct 2024 11:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B03276B008A for ; Tue, 29 Oct 2024 11:11:09 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5B8F7C1491 for ; Tue, 29 Oct 2024 15:11:09 +0000 (UTC) X-FDA: 82726976640.01.332A78E Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf10.hostedemail.com (Postfix) with ESMTP id C02B6C0022 for ; Tue, 29 Oct 2024 15:10:56 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LyBQOUO2; spf=pass (imf10.hostedemail.com: domain of helgaas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=helgaas@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730214613; h=from:from:sender: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: in-reply-to:in-reply-to:references:dkim-signature; bh=q/ppnKPqjq1ZOWgFdXtmo78cQBjKVN58gXA7eOZBfs4=; b=deXj4RX8nMP6y6/v0yH4V5rhRcZZidWYk0sSUviMsf3GKEkIteY3syuS22XuQSfvH2+a2z 8lGrd0f4orpNm7BhIRCNOxWMiHrH32KBEzCWMibq0zVnl3AwDEZCs3OCJN04vILRvtoIxC aoLpLh+HEIAiDa2eizC9UHRzSrboM8c= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LyBQOUO2; spf=pass (imf10.hostedemail.com: domain of helgaas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=helgaas@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730214613; a=rsa-sha256; cv=none; b=7WS4wwIaODe0iY66t7Npl6cN7QDMjG+r9/DgxysOgCPWu3JHE2QrJJqVFl2Nzf/CTlbCbv ulgeFCdYfvZZ2x+KAbpqjjfn1MFQzUwekzsuoCjE+mWv5I3IwgLYMICkeSu5NomqoCgZgu 5uOCgAbbVSa4OvBZzM1FXOlpUVS1MLc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id ED0DBA42F75; Tue, 29 Oct 2024 15:09:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 518F5C4CEE5; Tue, 29 Oct 2024 15:11:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730214665; bh=SQQchx1vtsZlKAa985I87v+ow+U4p33UlUeg+FERc0I=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=LyBQOUO2cEsu+Tni0G/a2shPNK+3v0pcWANBtQ3I2TpwqpZtXMDurKkmJNCB2oohh FDq6iFWCCGs1KozCEG39c2+UBJ4oZAul+Fh/hrzx93pik7koNtaiystZtJXr9nHeci OVwi2t8duMu/ih5zjJmkGrY1Z7RUHbWslWh8nCjnILiVUmGdP96opvDh6vYyZzJkDL iqTq3OInuyi1xereyTOtUDDWIjp64Dk1bkhfTokQgnE7hOvGaX6nT86WvQCFXPs9aA 8JqhSVbH+n/fg2UKLL9y5lDCFyFvtph8fNrcQaCSJLpiFtY+LSFpMwaLG+EvyuCA64 9EBM45hwMqjQg== Date: Tue, 29 Oct 2024 10:11:04 -0500 From: Bjorn Helgaas To: Leon Romanovsky Cc: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg , Keith Busch , Bjorn Helgaas , Logan Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , Marek Szyprowski , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Andrew Morton , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 02/18] dma-mapping: move the PCI P2PDMA mapping helpers to pci-p2pdma.h Message-ID: <20241029151104.GA1156518@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27698e7cc55f6ca5371c3d86c50fd3afce9afddd.1730037276.git.leon@kernel.org> X-Rspam-User: X-Stat-Signature: d4dx57qrjfgy9kbkboaid649sup67de7 X-Rspamd-Queue-Id: C02B6C0022 X-Rspamd-Server: rspam11 X-HE-Tag: 1730214656-584097 X-HE-Meta: U2FsdGVkX19I9jv0JJI2XJ1iWZHZ21l2N8qHkdaRz1trB65t938HcqKvwszMNEnZfheIrwb1GD92OcP4T77uDXnnjqBlkm+eWN+RlHs/HV1vOJSEmYARmPmPHcVT3GsCwp5rHThuOCw3rcSTaUtGEAGRHQ4ND06JL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08UkTG24ECruHuoGCJYJDSsV1d70Bzdb8LvcrD4a3s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sun, Oct 27, 2024 at 04:21:02PM +0200, Leon Romanovsky wrote: > From: Christoph Hellwig > > To support the upcoming non-scatterlist mapping helpers, we need to go > back to have them called outside of the DMA API. Thus move them out of > dma-map-ops.h, which is only for DMA API implementations to pci-p2pdma.h, > which is for driver use. > > Note that the core helper is still not exported as the mapping is > expected to be done only by very highlevel subsystem code at least for > now. > > Signed-off-by: Christoph Hellwig > Signed-off-by: Leon Romanovsky Acked-by: Bjorn Helgaas > --- > drivers/iommu/dma-iommu.c | 1 + > include/linux/dma-map-ops.h | 84 ------------------------------------- > include/linux/pci-p2pdma.h | 84 +++++++++++++++++++++++++++++++++++++ > kernel/dma/direct.c | 1 + > 4 files changed, 86 insertions(+), 84 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 6e50023c8112..c422e36c0d66 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > #include > diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h > index 49edcbda19d1..6ee626e50708 100644 > --- a/include/linux/dma-map-ops.h > +++ b/include/linux/dma-map-ops.h > @@ -435,88 +435,4 @@ static inline void debug_dma_dump_mappings(struct device *dev) > > extern const struct dma_map_ops dma_dummy_ops; > > -enum pci_p2pdma_map_type { > - /* > - * PCI_P2PDMA_MAP_UNKNOWN: Used internally for indicating the mapping > - * type hasn't been calculated yet. Functions that return this enum > - * never return this value. > - */ > - PCI_P2PDMA_MAP_UNKNOWN = 0, > - > - /* > - * Not a PCI P2PDMA transfer. > - */ > - PCI_P2PDMA_MAP_NONE, > - > - /* > - * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will > - * traverse the host bridge and the host bridge is not in the > - * allowlist. DMA Mapping routines should return an error when > - * this is returned. > - */ > - PCI_P2PDMA_MAP_NOT_SUPPORTED, > - > - /* > - * PCI_P2PDMA_BUS_ADDR: Indicates that two devices can talk to > - * each other directly through a PCI switch and the transaction will > - * not traverse the host bridge. Such a mapping should program > - * the DMA engine with PCI bus addresses. > - */ > - PCI_P2PDMA_MAP_BUS_ADDR, > - > - /* > - * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk > - * to each other, but the transaction traverses a host bridge on the > - * allowlist. In this case, a normal mapping either with CPU physical > - * addresses (in the case of dma-direct) or IOVA addresses (in the > - * case of IOMMUs) should be used to program the DMA engine. > - */ > - PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, > -}; > - > -struct pci_p2pdma_map_state { > - struct dev_pagemap *pgmap; > - enum pci_p2pdma_map_type map; > - u64 bus_off; > -}; > - > -/* helper for pci_p2pdma_state(), do not use directly */ > -void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state, > - struct device *dev, struct page *page); > - > -/** > - * pci_p2pdma_state - check the P2P transfer state of a page > - * @state: P2P state structure > - * @dev: device to transfer to/from > - * @page: page to map > - * > - * Check if @page is a PCI P2PDMA page, and if yes of what kind. Returns the > - * map type, and updates @state with all information needed for a P2P transfer. > - */ > -static inline enum pci_p2pdma_map_type > -pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev, > - struct page *page) > -{ > - if (IS_ENABLED(CONFIG_PCI_P2PDMA) && is_pci_p2pdma_page(page)) { > - if (state->pgmap != page->pgmap) > - __pci_p2pdma_update_state(state, dev, page); > - return state->map; > - } > - return PCI_P2PDMA_MAP_NONE; > -} > - > -/** > - * pci_p2pdma_bus_addr_map - map a PCI_P2PDMA_MAP_BUS_ADDR P2P transfer > - * @state: P2P state structure > - * @paddr: physical address to map > - * > - * Map a physically contigous PCI_P2PDMA_MAP_BUS_ADDR transfer. > - */ > -static inline dma_addr_t > -pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr) > -{ > - WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR); > - return paddr + state->bus_off; > -} > - > #endif /* _LINUX_DMA_MAP_OPS_H */ > diff --git a/include/linux/pci-p2pdma.h b/include/linux/pci-p2pdma.h > index 2c07aa6b7665..66b71f60a811 100644 > --- a/include/linux/pci-p2pdma.h > +++ b/include/linux/pci-p2pdma.h > @@ -104,4 +104,88 @@ static inline struct pci_dev *pci_p2pmem_find(struct device *client) > return pci_p2pmem_find_many(&client, 1); > } > > +enum pci_p2pdma_map_type { > + /* > + * PCI_P2PDMA_MAP_UNKNOWN: Used internally for indicating the mapping > + * type hasn't been calculated yet. Functions that return this enum > + * never return this value. > + */ > + PCI_P2PDMA_MAP_UNKNOWN = 0, > + > + /* > + * Not a PCI P2PDMA transfer. > + */ > + PCI_P2PDMA_MAP_NONE, > + > + /* > + * PCI_P2PDMA_MAP_NOT_SUPPORTED: Indicates the transaction will > + * traverse the host bridge and the host bridge is not in the > + * allowlist. DMA Mapping routines should return an error when > + * this is returned. > + */ > + PCI_P2PDMA_MAP_NOT_SUPPORTED, > + > + /* > + * PCI_P2PDMA_BUS_ADDR: Indicates that two devices can talk to > + * each other directly through a PCI switch and the transaction will > + * not traverse the host bridge. Such a mapping should program > + * the DMA engine with PCI bus addresses. > + */ > + PCI_P2PDMA_MAP_BUS_ADDR, > + > + /* > + * PCI_P2PDMA_MAP_THRU_HOST_BRIDGE: Indicates two devices can talk > + * to each other, but the transaction traverses a host bridge on the > + * allowlist. In this case, a normal mapping either with CPU physical > + * addresses (in the case of dma-direct) or IOVA addresses (in the > + * case of IOMMUs) should be used to program the DMA engine. > + */ > + PCI_P2PDMA_MAP_THRU_HOST_BRIDGE, > +}; > + > +struct pci_p2pdma_map_state { > + struct dev_pagemap *pgmap; > + enum pci_p2pdma_map_type map; > + u64 bus_off; > +}; > + > +/* helper for pci_p2pdma_state(), do not use directly */ > +void __pci_p2pdma_update_state(struct pci_p2pdma_map_state *state, > + struct device *dev, struct page *page); > + > +/** > + * pci_p2pdma_state - check the P2P transfer state of a page > + * @state: P2P state structure > + * @dev: device to transfer to/from > + * @page: page to map > + * > + * Check if @page is a PCI P2PDMA page, and if yes of what kind. Returns the > + * map type, and updates @state with all information needed for a P2P transfer. > + */ > +static inline enum pci_p2pdma_map_type > +pci_p2pdma_state(struct pci_p2pdma_map_state *state, struct device *dev, > + struct page *page) > +{ > + if (IS_ENABLED(CONFIG_PCI_P2PDMA) && is_pci_p2pdma_page(page)) { > + if (state->pgmap != page->pgmap) > + __pci_p2pdma_update_state(state, dev, page); > + return state->map; > + } > + return PCI_P2PDMA_MAP_NONE; > +} > + > +/** > + * pci_p2pdma_bus_addr_map - map a PCI_P2PDMA_MAP_BUS_ADDR P2P transfer > + * @state: P2P state structure > + * @paddr: physical address to map > + * > + * Map a physically contigous PCI_P2PDMA_MAP_BUS_ADDR transfer. > + */ > +static inline dma_addr_t > +pci_p2pdma_bus_addr_map(struct pci_p2pdma_map_state *state, phys_addr_t paddr) > +{ > + WARN_ON_ONCE(state->map != PCI_P2PDMA_MAP_BUS_ADDR); > + return paddr + state->bus_off; > +} > + > #endif /* _LINUX_PCI_P2P_H */ > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > index a793400161c2..47e124561fff 100644 > --- a/kernel/dma/direct.c > +++ b/kernel/dma/direct.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include "direct.h" > > /* > -- > 2.46.2 >