Skip to contentSkip to conversation

mm/msync: tweak tmpfs patch for syscall msync

PATCH In review Kang Kai 2 participants 3 messages Apr 26, 2012

Subsystems (2)
lore
Share & tools
lore

Kang Kai

author
#0 lore raw

PATCH v2 1/1 mm/msync: tweak tmpfs patch for syscall msync

Hi Bruce,

This Version 2 just update the commit header.

Regards,
Kai

author
#1 lore raw

PATCH v2 1/1 mm/msync: tweak tmpfs patch for syscall msync

Commit 1c3ae5441 "mm: msync: fix issues of sys_msync on tmpfs" fixes the problem that sys_msync fails with tmpfs on MIPS CPU which has feature "cache alias".

But it makes POSIX test cases mlockall/3-6 3-7 fail on MIPS. Case mlockall/3-6 creates a share memory, and maps it to memory.
fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); foo = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0);
Then calls mlockall to lock all of the virtual address space:
if (mlockall(MCL_CURRENT) == -1) {
At last tests whether the virtual address spaces are locked:
page_ptr = (void*) ((long)foo - ((long)foo % page_size)); result = msync(page_ptr, page_size, MS_SYNC|MS_INVALIDATE);
It espects msync returns -1 with EBUSY but returns 0. Case mlockall/3-7 creates a normal file to mmap, and it fails too.

Tweak the patch to:
1 Moved the CONFIG_TMPFS block down in the loop so that the normal
vma flag checking will perform.
2 There may be other VMAs in the list after this VMA which belongs
to tmpfs file, and we should sync them after the tmpfs one. So remove the break loop clauses.

---
 mm/msync.c |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)
mm/msync.c +13 -17
index ced6215..31cd311 100644
@@ -60,23 +60,6 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
 	down_read(&mm->mmap_sem);
 	vma = find_vma(mm, start);
 
-#ifdef CONFIG_TMPFS
-	/*
-	 * For tmpfs, no matter which flag(ASYNC or SYNC) gets from msync,
-	 * there is not so much thing to do for CPUs without cache alias,
-	 * But for some CPUs with cache alias, msync has to flush cache
-	 * explicitly, which makes sure the data coherency between memory
-	 * file and cache.
-	 */
-	file =  vma->vm_file;
-	if (file && (file->f_op == &shmem_file_operations)) {
-		if(CPU_HAS_CACHE_ALIAS)
-			flush_cache_range(vma, start, start+len);
-		error = 0;
-		goto out_unlock;
-	}
-#endif
-
 	for (;;) {
 
 		/* Still start < end. */
@@ -97,6 +80,19 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
 			goto out_unlock;
 		}
 		file = vma->vm_file;
+#ifdef CONFIG_TMPFS
+		/*
+		 * For tmpfs, no matter which flag(ASYNC or SYNC) gets from msync,
+		 * there is not so much thing to do for CPUs without cache alias,
+		 * But for some CPUs with cache alias, msync has to flush cache
+		 * explicitly, which makes sure the data coherency between memory
+		 * file and cache.
+		 */
+		if (file && (file->f_op == &shmem_file_operations)) {
+			if(CPU_HAS_CACHE_ALIAS)
+				flush_cache_range(vma, start, start+len);
+		}
+#endif
 		start = vma->vm_end;
 		if ((flags & MS_SYNC) && file &&
 				(vma->vm_flags & VM_SHARED)) {
Signature · 1 line
1.7.5.4
#2 lore raw
In reply to Kang Kai
Quoted 3 lines · Kang Kai

Hi Bruce,

This Version 2 just update the commit header.

Looks good. Merging to the routerstation pro branch.

Bruce

Quoted 4 lines

Regards,
Kai