[PATCH 2/2] platform/raspberrypi: vchiq: mark pinned pages dirty when unpinning them

Tal Zussman tz2294 at columbia.edu
Sat Oct 31 10:52:09 PDT 2026


free_pagelist() dirties the pages of a completed read with
set_page_dirty() before cleanup_pagelistinfo() unpins them. The pages
are pinned user memory that can be file backed, so they need to be
dirtied under the folio lock.

Pass a dirty flag to cleanup_pagelistinfo() and have it unpin with
unpin_user_pages_dirty_lock(), which marks each folio dirty once and
drops its pins in one go. The error paths in create_pagelist() pass
false.

This removes the last use of set_page_dirty() in vchiq.

Signed-off-by: Tal Zussman <tz2294 at columbia.edu>
---
 .../raspberrypi/vchiq-interface/vchiq_core.c       | 25 ++++++++--------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c b/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c
index 3ae4ee2973de..931feb54d6ea 100644
--- a/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c
+++ b/drivers/platform/raspberrypi/vchiq-interface/vchiq_core.c
@@ -1456,7 +1456,8 @@ poll_services(struct vchiq_state *state)
 }
 
 static void
-cleanup_pagelistinfo(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagelistinfo)
+cleanup_pagelistinfo(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagelistinfo,
+		     bool dirty)
 {
 	if (pagelistinfo->scatterlist_mapped) {
 		dma_unmap_sg(instance->state->dev, pagelistinfo->scatterlist,
@@ -1464,7 +1465,8 @@ cleanup_pagelistinfo(struct vchiq_instance *instance, struct vchiq_pagelist_info
 	}
 
 	if (pagelistinfo->pages_need_release)
-		unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
+		unpin_user_pages_dirty_lock(pagelistinfo->pages, pagelistinfo->num_pages,
+					    dirty);
 
 	dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_size,
 			  pagelistinfo->pagelist, pagelistinfo->dma_addr);
@@ -1578,7 +1580,7 @@ create_pagelist(struct vchiq_instance *instance, struct vchiq_bulk *bulk)
 			size_t bytes = PAGE_SIZE - off;
 
 			if (!pg) {
-				cleanup_pagelistinfo(instance, pagelistinfo);
+				cleanup_pagelistinfo(instance, pagelistinfo, false);
 				return NULL;
 			}
 
@@ -1601,7 +1603,7 @@ create_pagelist(struct vchiq_instance *instance, struct vchiq_bulk *bulk)
 			/* This is probably due to the process being killed */
 			if (actual_pages > 0)
 				unpin_user_pages(pages, actual_pages);
-			cleanup_pagelistinfo(instance, pagelistinfo);
+			cleanup_pagelistinfo(instance, pagelistinfo, false);
 			return NULL;
 		}
 		 /* release user pages */
@@ -1630,7 +1632,7 @@ create_pagelist(struct vchiq_instance *instance, struct vchiq_bulk *bulk)
 				 pagelistinfo->dma_dir);
 
 	if (dma_buffers == 0) {
-		cleanup_pagelistinfo(instance, pagelistinfo);
+		cleanup_pagelistinfo(instance, pagelistinfo, false);
 		return NULL;
 	}
 
@@ -1664,7 +1666,7 @@ create_pagelist(struct vchiq_instance *instance, struct vchiq_bulk *bulk)
 		char *fragments;
 
 		if (down_interruptible(&drv_mgmt->free_fragments_sema)) {
-			cleanup_pagelistinfo(instance, pagelistinfo);
+			cleanup_pagelistinfo(instance, pagelistinfo, false);
 			return NULL;
 		}
 
@@ -1739,16 +1741,7 @@ free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagel
 		up(&drv_mgmt->free_fragments_sema);
 	}
 
-	/* Need to mark all the pages dirty. */
-	if (pagelist->type != PAGELIST_WRITE &&
-	    pagelistinfo->pages_need_release) {
-		unsigned int i;
-
-		for (i = 0; i < num_pages; i++)
-			set_page_dirty(pages[i]);
-	}
-
-	cleanup_pagelistinfo(instance, pagelistinfo);
+	cleanup_pagelistinfo(instance, pagelistinfo, pagelist->type != PAGELIST_WRITE);
 }
 
 static int

-- 
2.39.5




More information about the linux-rpi-kernel mailing list