From: Easwar Hariharan <eahariha@linux.microsoft.com>
To: Leon Romanovsky <leon@kernel.org>, Christoph Hellwig <hch@lst.de>,
Robin Murphy <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Jason Gunthorpe <jgg@nvidia.com>
Cc: eahariha@linux.microsoft.com, Leon Romanovsky <leonro@nvidia.com>,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev
Subject: Re: [PATCH 2/2] dma: Add IOMMU static calls with clear default ops
Date: Fri, 12 Jul 2024 13:51:36 -0700 [thread overview]
Message-ID: <3912d498-5696-4e87-bab0-f35ef7ac6083@linux.microsoft.com> (raw)
In-Reply-To: <f2b699aea8fff5589a674da2a567fd593ed2d386.1720693745.git.leon@kernel.org>
On 7/11/2024 3:38 AM, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> Most of the IOMMU drivers are using the same DMA operations, which are
> default ones implemented in drivers/iomem/dma-iomem.c. So it makes sense
> to properly set them as a default with direct call without need to
> perform function pointer dereference.
>
> During system initialization, the IOMMU driver can set its own DMA and
> in such case, the default DMA operations will be overridden.
>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> MAINTAINERS | 1 +
> drivers/iommu/dma-iommu.c | 24 +++++++-------
> include/linux/iommu-dma.h | 50 +++++++++++++++++++++++++++++
> kernel/dma/iommu.h | 67 +++++++++++++++++++++++++++++++++++++++
> kernel/dma/mapping.c | 9 +++---
> 5 files changed, 134 insertions(+), 17 deletions(-)
> create mode 100644 include/linux/iommu-dma.h
> create mode 100644 kernel/dma/iommu.h
>
<snip>
> diff --git a/include/linux/iommu-dma.h b/include/linux/iommu-dma.h
> new file mode 100644
> index 000000000000..b42487bf8f8e
> --- /dev/null
> +++ b/include/linux/iommu-dma.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved
> + *
> + * DMA operations that map physical memory through IOMMU.
> + */
> +#ifndef _LINUX_IOMMU_DMA_H
> +#define _LINUX_IOMMU_DMA_H
> +
> +#include <linux/dma-direction.h>
> +
> +#ifdef CONFIG_IOMMU_API
> +dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
> + unsigned long offset, size_t size,
> + enum dma_data_direction dir, unsigned long attrs);
> +void iommu_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
> + size_t size, enum dma_data_direction dir,
> + unsigned long attrs);
> +int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
> + enum dma_data_direction dir, unsigned long attrs);
> +void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
> + enum dma_data_direction dir, unsigned long attrs);
> +#else
> +static inline dma_addr_t iommu_dma_map_page(struct device *dev,
> + struct page *page,
> + unsigned long offset, size_t size,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + return DMA_MAPPING_ERROR;
> +}
> +static inline void iommu_dma_unmap_page(struct device *dev,
> + dma_addr_t dma_handle, size_t size,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> +}
> +static inline int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
> + int nents, enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + return -EINVAL;
> +}
> +static void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
> + int nents, enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> +}
> +#endif /* CONFIG_IOMMU_API */
> +#endif /* _LINUX_IOMMU_DMA_H */
> diff --git a/kernel/dma/iommu.h b/kernel/dma/iommu.h
> new file mode 100644
> index 000000000000..4abaea2dfc49
> --- /dev/null
> +++ b/kernel/dma/iommu.h
> @@ -0,0 +1,67 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved
> + *
> + * DMA operations that map physical memory through IOMMU.
> + */
> +#ifndef _KERNEL_DMA_IOMMU_H
> +#define _KERNEL_DMA_IOMMU_H
> +
> +#include <linux/iommu-dma.h>
> +
> +static inline dma_addr_t dma_iommu_map_page(struct device *dev,
> + struct page *page, size_t offset,
> + size_t size,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + const struct dma_map_ops *ops = get_dma_ops(dev);
> +
> + if (ops->map_page)
> + return ops->map_page(dev, page, offset, size, dir, attrs);
> +
> + return iommu_dma_map_page(dev, page, offset, size, dir, attrs);
> +}
> +
> +static inline void dma_iommu_unmap_page(struct device *dev, dma_addr_t addr,
> + size_t size,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + const struct dma_map_ops *ops = get_dma_ops(dev);
> +
> + if (ops->unmap_page) {
> + ops->unmap_page(dev, addr, size, dir, attrs);
> + return;
> + }
> +
> + iommu_dma_unmap_page(dev, addr, size, dir, attrs);
> +}
> +
> +static inline int dma_iommu_map_sg(struct device *dev, struct scatterlist *sg,
> + int nents, enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + const struct dma_map_ops *ops = get_dma_ops(dev);
> +
> + if (ops->map_sg)
> + return ops->map_sg(dev, sg, nents, dir, attrs);
> +
> + return iommu_dma_map_sg(dev, sg, nents, dir, attrs);
> +}
> +
> +static inline void dma_iommu_unmap_sg(struct device *dev,
> + struct scatterlist *sg, int nents,
> + enum dma_data_direction dir,
> + unsigned long attrs)
> +{
> + const struct dma_map_ops *ops = get_dma_ops(dev);
> +
> + if (ops->unmap_sg) {
> + ops->unmap_sg(dev, sg, nents, dir, attrs);
> + return;
> + }
> +
> + iommu_dma_unmap_sg(dev, sg, nents, dir, attrs);
> +}
Can we use _dma_iommu_* instead of the transposition pattern we have
going on here? Having dma_iommu_* call iommu_dma_* is, I feel, a recipe
for confusion when reading the code, especially after a few passes when
the eyes start to glaze over.
I think you're going for the typical pattern of iommu_dma* being an
internal detail that provides an implementation, but correct me if
there's some significance to the current naming scheme.
Thanks,
Easwar
next prev parent reply other threads:[~2024-07-12 20:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-11 10:38 [PATCH 1/2] dma: call unconditionally to unmap_page and unmap_sg callbacks Leon Romanovsky
2024-07-11 10:38 ` [PATCH 2/2] dma: Add IOMMU static calls with clear default ops Leon Romanovsky
2024-07-11 17:27 ` Leon Romanovsky
2024-07-11 18:17 ` Easwar Hariharan
2024-07-11 18:45 ` Leon Romanovsky
2024-07-11 18:23 ` Robin Murphy
2024-07-11 18:57 ` Leon Romanovsky
2024-07-11 20:08 ` Robin Murphy
2024-07-12 5:50 ` Leon Romanovsky
2024-07-12 14:21 ` Robin Murphy
2024-07-13 5:18 ` Christoph Hellwig
2024-07-13 9:32 ` Leon Romanovsky
2024-07-12 4:49 ` Christoph Hellwig
2024-07-12 6:02 ` Leon Romanovsky
2024-07-12 20:51 ` Easwar Hariharan [this message]
2024-07-13 9:30 ` Leon Romanovsky
2024-07-11 18:02 ` [PATCH 1/2] dma: call unconditionally to unmap_page and unmap_sg callbacks Robin Murphy
2024-07-12 5:47 ` Leon Romanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3912d498-5696-4e87-bab0-f35ef7ac6083@linux.microsoft.com \
--to=eahariha@linux.microsoft.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=leon@kernel.org \
--cc=leonro@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox