mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] media: intel/ipu6: serialize vma_list accesses in the DMA ops
@ 2026-12-04 12:21 manik.bajpai
  2026-12-04 12:49 ` Sakari Ailus
  0 siblings, 1 reply; 3+ messages in thread
From: manik.bajpai @ 2026-12-04 12:21 UTC (permalink / raw)
  To: Sakari Ailus, Antti Laakso
  Cc: Sarang Sapre, Divyamani Tripathi, Bingbu Cao, Hans Verkuil,
	linux-media, linux-kernel, manik.bajpai, stable

From: Manik Bajpai <manik.bajpai@intel.com>

Serialise access to vma_list in struct ipu6_mmu.

Fixes: 9163d83573e4 ("media: intel/ipu6: add IPU6 DMA mapping API and MMU table")
Cc: stable@vger.kernel.org
Signed-off-by: Manik Bajpai <manik.bajpai@intel.com>
---
Changes since v1:
- Simplify the commit message.
- Drop the Assisted-by: tag and add Cc: stable.
- Unlock vma_lock before the cache flush in ipu6_dma_sync_single().
- Use guard() and scoped_guard() instead of explicit mutex_lock()/mutex_unlock().

 drivers/media/pci/intel/ipu6/ipu6-dma.c | 44 +++++++++++++++----------
 drivers/media/pci/intel/ipu6/ipu6-mmu.c |  1 +
 drivers/media/pci/intel/ipu6/ipu6-mmu.h |  2 ++
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
index 91c3c978387c..e45fd5e10f18 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/cacheflush.h>
+#include <linux/cleanup.h>
 #include <linux/dma-mapping.h>
 #include <linux/iova.h>
 #include <linux/list.h>
@@ -119,15 +120,18 @@ void ipu6_dma_sync_single(struct ipu6_bus_device *sys, dma_addr_t dma_handle,
 	struct vm_info *info;
 	struct ipu6_mmu *mmu = sys->mmu;
 
-	info = get_vm_info(mmu, dma_handle);
-	if (WARN_ON(!info))
-		return;
+	scoped_guard(mutex, &mmu->vma_lock) {
+		info = get_vm_info(mmu, dma_handle);
+		if (WARN_ON(!info))
+			return;
 
-	offset = dma_handle - info->ipu6_iova;
-	if (WARN_ON(size > (info->size - offset)))
-		return;
+		offset = dma_handle - info->ipu6_iova;
+		if (WARN_ON(size > (info->size - offset)))
+			return;
+
+		vaddr = info->vaddr + offset;
+	}
 
-	vaddr = info->vaddr + offset;
 	clflush_cache_range(vaddr, size);
 }
 EXPORT_SYMBOL_NS_GPL(ipu6_dma_sync_single, "INTEL_IPU6");
@@ -215,7 +219,8 @@ void *ipu6_dma_alloc(struct ipu6_bus_device *sys, size_t size,
 	info->pages = pages;
 	info->ipu6_iova = *dma_handle;
 	info->size = size;
-	list_add(&info->list, &mmu->vma_list);
+	scoped_guard(mutex, &mmu->vma_lock)
+		list_add(&info->list, &mmu->vma_list);
 
 	return info->vaddr;
 
@@ -255,22 +260,23 @@ void ipu6_dma_free(struct ipu6_bus_device *sys, size_t size, void *vaddr,
 	if (WARN_ON(!iova))
 		return;
 
-	info = get_vm_info(mmu, dma_handle);
-	if (WARN_ON(!info))
-		return;
+	scoped_guard(mutex, &mmu->vma_lock) {
+		info = get_vm_info(mmu, dma_handle);
+		if (WARN_ON(!info))
+			return;
 
-	if (WARN_ON(!info->vaddr))
-		return;
+		if (WARN_ON(!info->vaddr))
+			return;
 
-	if (WARN_ON(!info->pages))
-		return;
+		if (WARN_ON(!info->pages))
+			return;
 
-	list_del(&info->list);
+		list_del(&info->list);
+		pages = info->pages;
+	}
 
 	size = PAGE_ALIGN(size);
 
-	pages = info->pages;
-
 	vunmap(vaddr);
 
 	for (i = 0; i < PHYS_PFN(size); i++) {
@@ -304,6 +310,8 @@ int ipu6_dma_mmap(struct ipu6_bus_device *sys, struct vm_area_struct *vma,
 	size_t i;
 	int ret;
 
+	guard(mutex)(&mmu->vma_lock);
+
 	info = get_vm_info(mmu, iova);
 	if (!info)
 		return -EFAULT;
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.c b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
index f21f3a1e5356..c1c1bd3079dd 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
@@ -689,6 +689,7 @@ struct ipu6_mmu *ipu6_mmu_init(struct device *dev,
 	mmu->mmid = mmid;
 	mmu->ready = false;
 	INIT_LIST_HEAD(&mmu->vma_list);
+	mutex_init(&mmu->vma_lock);
 	spin_lock_init(&mmu->ready_lock);
 
 	ret = mmu->ops->init_hw_data(mmu, dev, base);
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.h b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
index ff113384c126..1db67f131fba 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
@@ -5,6 +5,7 @@
 #define IPU6_MMU_H
 
 #include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/spinlock_types.h>
 #include <linux/types.h>
 
@@ -186,6 +187,7 @@ struct ipu6_mmu {
 
 	struct ipu6_dma_mapping *dmap;
 	struct list_head vma_list;
+	struct mutex vma_lock; /* Serialize vma_list add/del/lookup */
 
 	struct page *trash_page;
 	dma_addr_t pci_trash_page; /* IOVA from PCI DMA services (parent) */

base-commit: 04b69b3a8acc04460cebf03820e2ee1ec77b549b
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] media: intel/ipu6: serialize vma_list accesses in the DMA ops
  2026-12-04 12:21 [PATCH v2] media: intel/ipu6: serialize vma_list accesses in the DMA ops manik.bajpai
@ 2026-12-04 12:49 ` Sakari Ailus
  2026-12-04 13:41   ` [PATCH v3] " Manik Bajpai
  0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2026-12-04 12:49 UTC (permalink / raw)
  To: manik.bajpai
  Cc: Antti Laakso, Sarang Sapre, Divyamani Tripathi, Bingbu Cao,
	Hans Verkuil, linux-media, linux-kernel

Hi Manik,

On Fri, Dec 04, 2026 at 05:51:09PM +0530, manik.bajpai@intel.com wrote:
> From: Manik Bajpai <manik.bajpai@intel.com>
> 
> Serialise access to vma_list in struct ipu6_mmu.
> 
> Fixes: 9163d83573e4 ("media: intel/ipu6: add IPU6 DMA mapping API and MMU table")
> Cc: stable@vger.kernel.org
> Signed-off-by: Manik Bajpai <manik.bajpai@intel.com>

You shouldn't cc the patch to stable@vger unless it is explicitly intended
for stable series only.

One more thing. I missed there's no mutex_destroy() for this mutex. Can you
add it to ipu6_mmu_cleanup()?

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3] media: intel/ipu6: serialize vma_list accesses in the DMA ops
  2026-12-04 12:49 ` Sakari Ailus
@ 2026-12-04 13:41   ` Manik Bajpai
  0 siblings, 0 replies; 3+ messages in thread
From: Manik Bajpai @ 2026-12-04 13:41 UTC (permalink / raw)
  To: Sakari Ailus, Antti Laakso
  Cc: Sarang Sapre, Divyamani Tripathi, Bingbu Cao, Hans Verkuil,
	linux-media, linux-kernel, ribalda

Serialise access to vma_list in struct ipu6_mmu.

Fixes: 9163d83573e4 ("media: intel/ipu6: add IPU6 DMA mapping API and MMU table")
Cc: stable@vger.kernel.org
Signed-off-by: Manik Bajpai <manik.bajpai@intel.com>
---
Changes since v2:
- Call mutex_destroy() on vma_lock in ipu6_mmu_cleanup().
- stable@vger.kernel.org is no longer on the mail Cc; the Cc: stable tag stays in the commit message.

Changes since v1:
- Simplify the commit message.
- Drop the Assisted-by: tag and add Cc: stable.
- Unlock vma_lock before the cache flush in ipu6_dma_sync_single().
- Use guard() and scoped_guard() instead of explicit mutex_lock()/mutex_unlock().

 drivers/media/pci/intel/ipu6/ipu6-dma.c | 44 +++++++++++++++----------
 drivers/media/pci/intel/ipu6/ipu6-mmu.c |  2 ++
 drivers/media/pci/intel/ipu6/ipu6-mmu.h |  2 ++
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
index 91c3c978387c..e45fd5e10f18 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/cacheflush.h>
+#include <linux/cleanup.h>
 #include <linux/dma-mapping.h>
 #include <linux/iova.h>
 #include <linux/list.h>
@@ -119,15 +120,18 @@ void ipu6_dma_sync_single(struct ipu6_bus_device *sys, dma_addr_t dma_handle,
 	struct vm_info *info;
 	struct ipu6_mmu *mmu = sys->mmu;
 
-	info = get_vm_info(mmu, dma_handle);
-	if (WARN_ON(!info))
-		return;
+	scoped_guard(mutex, &mmu->vma_lock) {
+		info = get_vm_info(mmu, dma_handle);
+		if (WARN_ON(!info))
+			return;
 
-	offset = dma_handle - info->ipu6_iova;
-	if (WARN_ON(size > (info->size - offset)))
-		return;
+		offset = dma_handle - info->ipu6_iova;
+		if (WARN_ON(size > (info->size - offset)))
+			return;
+
+		vaddr = info->vaddr + offset;
+	}
 
-	vaddr = info->vaddr + offset;
 	clflush_cache_range(vaddr, size);
 }
 EXPORT_SYMBOL_NS_GPL(ipu6_dma_sync_single, "INTEL_IPU6");
@@ -215,7 +219,8 @@ void *ipu6_dma_alloc(struct ipu6_bus_device *sys, size_t size,
 	info->pages = pages;
 	info->ipu6_iova = *dma_handle;
 	info->size = size;
-	list_add(&info->list, &mmu->vma_list);
+	scoped_guard(mutex, &mmu->vma_lock)
+		list_add(&info->list, &mmu->vma_list);
 
 	return info->vaddr;
 
@@ -255,22 +260,23 @@ void ipu6_dma_free(struct ipu6_bus_device *sys, size_t size, void *vaddr,
 	if (WARN_ON(!iova))
 		return;
 
-	info = get_vm_info(mmu, dma_handle);
-	if (WARN_ON(!info))
-		return;
+	scoped_guard(mutex, &mmu->vma_lock) {
+		info = get_vm_info(mmu, dma_handle);
+		if (WARN_ON(!info))
+			return;
 
-	if (WARN_ON(!info->vaddr))
-		return;
+		if (WARN_ON(!info->vaddr))
+			return;
 
-	if (WARN_ON(!info->pages))
-		return;
+		if (WARN_ON(!info->pages))
+			return;
 
-	list_del(&info->list);
+		list_del(&info->list);
+		pages = info->pages;
+	}
 
 	size = PAGE_ALIGN(size);
 
-	pages = info->pages;
-
 	vunmap(vaddr);
 
 	for (i = 0; i < PHYS_PFN(size); i++) {
@@ -304,6 +310,8 @@ int ipu6_dma_mmap(struct ipu6_bus_device *sys, struct vm_area_struct *vma,
 	size_t i;
 	int ret;
 
+	guard(mutex)(&mmu->vma_lock);
+
 	info = get_vm_info(mmu, iova);
 	if (!info)
 		return -EFAULT;
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.c b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
index f21f3a1e5356..6dec9e3874c5 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
@@ -689,6 +689,7 @@ struct ipu6_mmu *ipu6_mmu_init(struct device *dev,
 	mmu->mmid = mmid;
 	mmu->ready = false;
 	INIT_LIST_HEAD(&mmu->vma_list);
+	mutex_init(&mmu->vma_lock);
 	spin_lock_init(&mmu->ready_lock);
 
 	ret = mmu->ops->init_hw_data(mmu, dev, base);
@@ -713,4 +714,5 @@ void ipu6_mmu_cleanup(struct ipu6_mmu *mmu)
 	iova_cache_put();
 	put_iova_domain(&dmap->iovad);
 	kfree(dmap);
+	mutex_destroy(&mmu->vma_lock);
 }
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.h b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
index ff113384c126..1db67f131fba 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
@@ -5,6 +5,7 @@
 #define IPU6_MMU_H
 
 #include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/spinlock_types.h>
 #include <linux/types.h>
 
@@ -186,6 +187,7 @@ struct ipu6_mmu {
 
 	struct ipu6_dma_mapping *dmap;
 	struct list_head vma_list;
+	struct mutex vma_lock; /* Serialize vma_list add/del/lookup */
 
 	struct page *trash_page;
 	dma_addr_t pci_trash_page; /* IOVA from PCI DMA services (parent) */

base-commit: 04b69b3a8acc04460cebf03820e2ee1ec77b549b
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 13:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 12:21 [PATCH v2] media: intel/ipu6: serialize vma_list accesses in the DMA ops manik.bajpai
2026-12-04 12:49 ` Sakari Ailus
2026-12-04 13:41   ` [PATCH v3] " Manik Bajpai

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®