Skip to contentSkip to conversation

add API for flushing Anon pages

PATCH New James Bottomley 1 participant 1 message Mar 21, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 add API for flushing Anon pages

Currently, get_user_pages() returns fully coherent pages to the kernel for anything other than anonymous pages. This is a problem for things like fuse and the SCSI generic ioctl SG_IO which can potentially wish to do DMA to anonymous pages passed in by users.

The fix is to add a new memory management API: flush_anon_page() which is used in get_user_pages() to make anonymous pages coherent.

Documentation/cachetlb.txt +9 -0
Index: BUILD-2.6/Documentation/cachetlb.txt
===================================================================
@@ -362,6 +362,15 @@
 	likely that you will need to flush the instruction cache
 	for copy_to_user_page().
 
+  void flush_anon_page(struct page *page, unsigned long vmaddr)
+  	When the kernel needs to access the contents of an anonymous
+	page, it calls this function (currently only
+	get_user_pages()).  Note: flush_dcache_page() deliberately
+	doesn't work for an anonymous page.  The default
+	implementation is a nop (and should remain so for all coherent
+	architectures).  For incoherent architectures, it should flush
+	the cache of the page at vmaddr in the current user process.
+
   void flush_icache_range(unsigned long start, unsigned long end)
   	When the kernel stores into addresses that it will execute
 	out of (eg when loading modules), this function is called.
include/linux/highmem.h +6 -0
Index: BUILD-2.6/include/linux/highmem.h
===================================================================
@@ -7,6 +7,12 @@
 
 #include <asm/cacheflush.h>
 
+#ifndef ARCH_HAS_FLUSH_ANON_PAGE
+static inline void flush_anon_page(struct page *page, unsigned long vmaddr)
+{
+}
+#endif
+
 #ifdef CONFIG_HIGHMEM
 
 #include <asm/highmem.h>
mm/memory.c +2 -0
Index: BUILD-2.6/mm/memory.c
===================================================================
@@ -1074,6 +1074,8 @@
 			}
 			if (pages) {
 				pages[i] = page;
+
+				flush_anon_page(page, start);
 				flush_dcache_page(page);
 			}
 			if (vmas)