mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: iommu@lists.linux.dev, linux-media@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Leon Romanovsky <leon@kernel.org>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Sibi Sankar <sibi.sankar@oss.qualcomm.com>,
	Honglei Huang <honghuan@amd.com>,
	prakash.gupta@oss.qualcomm.com,
	Alex Williamson <alex@shazbot.org>,
	Vikash Garodia <vikash.garodia@oss.qualcomm.com>,
	Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	Bryan O'Donoghue <bod@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags
Date: Fri, 27 Nov 2026 12:58:47 +0100	[thread overview]
Message-ID: <20261127115849.2780625-4-m.szyprowski@samsung.com> (raw)
In-Reply-To: <20261127115849.2780625-1-m.szyprowski@samsung.com>

dma_iova_state::__size uses its top bit to record that SWIOTLB was used
for one of the linked ranges. Users that mask or validate sizes refer to
DMA_IOVA_USE_SWIOTLB directly, so adding another flag would require
updating all of them.

Add DMA_IOVA_FLAGS covering all flags kept in __size and use it in
dma_iova_size(), in the size check of dma_iova_try_alloc() and in the
vfio-pci dma-buf length validation. No functional change.

Cc: stable@vger.kernel.org # v7.3+
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/iommu/dma-iommu.c          | 8 ++++----
 drivers/vfio/pci/vfio_pci_dmabuf.c | 2 +-
 include/linux/dma-mapping.h        | 8 +++++++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 78742aeba932..99eb382a1359 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1838,11 +1838,11 @@ bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state,
 		return false;
 
 	/*
-	 * DMA_IOVA_USE_SWIOTLB is flag which is set by dma-iommu
-	 * internals, make sure that caller didn't set it and/or
-	 * didn't use this interface to map SIZE_MAX.
+	 * DMA_IOVA_FLAGS are set by dma-iommu internals, make sure that
+	 * caller didn't set them and/or didn't use this interface to map
+	 * SIZE_MAX.
 	 */
-	if (WARN_ON_ONCE((u64)size & DMA_IOVA_USE_SWIOTLB))
+	if (WARN_ON_ONCE((u64)size & DMA_IOVA_FLAGS))
 		return false;
 
 	addr = iommu_dma_alloc_iova(domain,
diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index c16f460c01d6..8bda610dd988 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -211,7 +211,7 @@ static int validate_dmabuf_input(struct vfio_device_feature_dma_buf *dma_buf,
 	 * dma_iova_try_alloc() will WARN on if userspace proposes a size that
 	 * is too big, eg with lots of ranges.
 	 */
-	if ((u64)(length) & DMA_IOVA_USE_SWIOTLB)
+	if ((u64)(length) & DMA_IOVA_FLAGS)
 		return -EINVAL;
 
 	*lengthp = length;
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index efde0e5a58dc..0ebf3090ea0f 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -135,10 +135,16 @@ struct dma_iova_state {
  */
 #define DMA_IOVA_USE_SWIOTLB		(1ULL << 63)
 
+/*
+ * All flags stored in the upper bits of dma_iova_state::__size. Sizes passed
+ * to dma_iova_try_alloc() must not overlap with them.
+ */
+#define DMA_IOVA_FLAGS			DMA_IOVA_USE_SWIOTLB
+
 static inline size_t dma_iova_size(struct dma_iova_state *state)
 {
 	/* Casting is needed for 32-bits systems */
-	return (size_t)(state->__size & ~DMA_IOVA_USE_SWIOTLB);
+	return (size_t)(state->__size & ~DMA_IOVA_FLAGS);
 }
 
 #ifdef CONFIG_DMA_API_DEBUG
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 11:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261127115858eucas1p1ac63e4ce0f221453e8666ab9723a2ae0@eucas1p1.samsung.com>
2026-11-27 11:58 ` [PATCH 0/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
     [not found]   ` <CGME20261127115859eucas1p1ae20b01eec39080daf19dbd71aba10e9@eucas1p1.samsung.com>
2026-11-27 11:58     ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
2026-11-27 12:41       ` Vikash Garodia
2026-11-27 14:29       ` Jason Gunthorpe
2026-11-27 15:24         ` Leon Romanovsky
2026-11-27 17:21         ` Bryan O'Donoghue
2026-11-27 17:26           ` Jason Gunthorpe
     [not found]   ` <CGME20261127115900eucas1p268ca3a6688c2fd99513317dfc99dbf59@eucas1p2.samsung.com>
2026-11-27 11:58     ` [PATCH 2/4] media: iris: " Marek Szyprowski
2026-11-27 12:41       ` Vikash Garodia
     [not found]   ` <CGME20261127115901eucas1p22ee3dbe744707c23f8ac2442f755e041@eucas1p2.samsung.com>
2026-11-27 11:58     ` Marek Szyprowski [this message]
2026-11-27 14:37       ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Jason Gunthorpe
     [not found]   ` <CGME20261127115903eucas1p27ccc4cddb7f705d6afa5c2603597b97a@eucas1p2.samsung.com>
2026-11-27 11:58     ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
2026-11-27 14:37       ` Jason Gunthorpe
2026-11-27 14:45         ` Marek Szyprowski
2026-11-27 15:17           ` Jason Gunthorpe
2026-11-27 16:29             ` Marek Szyprowski
2026-11-27 17:18               ` Marek Szyprowski
2026-11-27 15:31       ` 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=20261127115849.2780625-4-m.szyprowski@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=alex@shazbot.org \
    --cc=bod@kernel.org \
    --cc=dikshita.agarwal@oss.qualcomm.com \
    --cc=honghuan@amd.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=prakash.gupta@oss.qualcomm.com \
    --cc=robin.murphy@arm.com \
    --cc=sibi.sankar@oss.qualcomm.com \
    --cc=stable@vger.kernel.org \
    --cc=vikash.garodia@oss.qualcomm.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

all inboxes | Powered by JetHome®