mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Manik Bajpai <manik.bajpai@intel.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Antti Laakso <antti.laakso@linux.intel.com>
Cc: Sarang Sapre <sarang.sapre@intel.com>,
	Divyamani Tripathi <divyamani.tripathi@intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	ribalda@google.com
Subject: [PATCH v3] media: intel/ipu6: serialize vma_list accesses in the DMA ops
Date: Fri,  4 Dec 2026 19:11:35 +0530	[thread overview]
Message-ID: <20261204134135.1883533-1-manik.bajpai@intel.com> (raw)
In-Reply-To: <axK2yA6jQeV3dZeo@kekkonen.localdomain>

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


      reply	other threads:[~2026-12-04 13:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 12:21 [PATCH v2] " manik.bajpai
2026-12-04 12:49 ` Sakari Ailus
2026-12-04 13:41   ` Manik Bajpai [this message]

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=20261204134135.1883533-1-manik.bajpai@intel.com \
    --to=manik.bajpai@intel.com \
    --cc=antti.laakso@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=divyamani.tripathi@intel.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=ribalda@google.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sarang.sapre@intel.com \
    /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®