From: Leon Romanovsky <leon@kernel.org>
To: 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>
Cc: Leon Romanovsky <leonro@nvidia.com>,
Easwar Hariharan <eahariha@linux.microsoft.com>,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
Jason Gunthorpe <jgg@nvidia.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH v4 1/2] dma: call unconditionally to unmap_page and unmap_sg callbacks
Date: Wed, 24 Jul 2024 21:04:48 +0300 [thread overview]
Message-ID: <595d2716d252cac013a650bb3a94555ddb0d1d43.1721818168.git.leon@kernel.org> (raw)
In-Reply-To: <cover.1721818168.git.leon@kernel.org>
From: Leon Romanovsky <leonro@nvidia.com>
Almost all users of ->map_page()/map_sg() callbacks implement
->unmap_page()/unmap_sg() callbacks too. One user which doesn't do it,
is dummy DMA ops interface, and the use of this interface is to fail
the operation and in such case, there won't be any call to
->unmap_page()/unmap_sg().
This patch removes the existence checks of ->unmap_page()/unmap_sg()
and calls to it directly to create symmetrical interface to
->map_page()/map_sg().
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
---
kernel/dma/dummy.c | 21 +++++++++++++++++++++
kernel/dma/mapping.c | 4 ++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/dummy.c b/kernel/dma/dummy.c
index b492d59ac77e..92de80e5b057 100644
--- a/kernel/dma/dummy.c
+++ b/kernel/dma/dummy.c
@@ -17,6 +17,15 @@ static dma_addr_t dma_dummy_map_page(struct device *dev, struct page *page,
{
return DMA_MAPPING_ERROR;
}
+static void dma_dummy_unmap_page(struct device *dev, dma_addr_t dma_handle,
+ size_t size, enum dma_data_direction dir, unsigned long attrs)
+{
+ /*
+ * Dummy ops doesn't support map_page, so unmap_page should never be
+ * called.
+ */
+ WARN_ON_ONCE(true);
+}
static int dma_dummy_map_sg(struct device *dev, struct scatterlist *sgl,
int nelems, enum dma_data_direction dir,
@@ -25,6 +34,16 @@ static int dma_dummy_map_sg(struct device *dev, struct scatterlist *sgl,
return -EINVAL;
}
+static void dma_dummy_unmap_sg(struct device *dev, struct scatterlist *sgl,
+ int nelems, enum dma_data_direction dir,
+ unsigned long attrs)
+{
+ /*
+ * Dummy ops doesn't support map_sg, so unmap_sg should never be called.
+ */
+ WARN_ON_ONCE(true);
+}
+
static int dma_dummy_supported(struct device *hwdev, u64 mask)
{
return 0;
@@ -33,6 +52,8 @@ static int dma_dummy_supported(struct device *hwdev, u64 mask)
const struct dma_map_ops dma_dummy_ops = {
.mmap = dma_dummy_mmap,
.map_page = dma_dummy_map_page,
+ .unmap_page = dma_dummy_unmap_page,
.map_sg = dma_dummy_map_sg,
+ .unmap_sg = dma_dummy_unmap_sg,
.dma_supported = dma_dummy_supported,
};
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 81de84318ccc..6832fd6f0796 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -177,7 +177,7 @@ void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, size_t size,
if (dma_map_direct(dev, ops) ||
arch_dma_unmap_page_direct(dev, addr + size))
dma_direct_unmap_page(dev, addr, size, dir, attrs);
- else if (ops->unmap_page)
+ else
ops->unmap_page(dev, addr, size, dir, attrs);
debug_dma_unmap_page(dev, addr, size, dir);
}
@@ -291,7 +291,7 @@ void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
if (dma_map_direct(dev, ops) ||
arch_dma_unmap_sg_direct(dev, sg, nents))
dma_direct_unmap_sg(dev, sg, nents, dir, attrs);
- else if (ops->unmap_sg)
+ else
ops->unmap_sg(dev, sg, nents, dir, attrs);
}
EXPORT_SYMBOL(dma_unmap_sg_attrs);
--
2.45.2
next prev parent reply other threads:[~2024-07-24 18:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 18:04 [PATCH v4 0/2] DMA IOMMU static calls Leon Romanovsky
2024-07-24 18:04 ` Leon Romanovsky [this message]
2024-08-13 12:23 ` [PATCH v4 1/2] dma: call unconditionally to unmap_page and unmap_sg callbacks Robin Murphy
2024-07-24 18:04 ` [PATCH v4 2/2] dma: add IOMMU static calls with clear default ops Leon Romanovsky
2024-08-15 16:54 ` Robin Murphy
2024-08-15 17:06 ` Leon Romanovsky
2024-08-16 7:11 ` Christoph Hellwig
2024-08-16 8:13 ` Christoph Hellwig
2024-08-19 13:16 ` Robin Murphy
2024-08-20 12:22 ` Christoph Hellwig
2024-08-27 11:57 ` Robin Murphy
2024-09-04 14:59 ` Nícolas F. R. A. Prado
2024-09-04 15:45 ` Leon Romanovsky
2024-09-04 17:58 ` Nícolas F. R. A. Prado
2024-09-04 18:02 ` Leon Romanovsky
2024-09-10 19:01 ` Nícolas F. R. A. Prado
2024-09-11 6:43 ` Leon Romanovsky
2024-09-11 8:04 ` Christoph Hellwig
2024-09-11 9:05 ` Leon Romanovsky
2024-08-05 12:20 ` [PATCH v4 0/2] DMA IOMMU static calls Leon Romanovsky
2024-08-13 9:58 ` Greg Kroah-Hartman
2024-08-13 11:50 ` Christoph Hellwig
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=595d2716d252cac013a650bb3a94555ddb0d1d43.1721818168.git.leon@kernel.org \
--to=leon@kernel.org \
--cc=eahariha@linux.microsoft.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.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
Powered by JetHome