
From: Hugh Dickins <hugh@veritas.com>

Stas Sergeev <stsp@aknet.ru> wrote:

   mprotect() fails to merge VMAs because one VMA can end up with
   VM_ACCOUNT flag set, and another without that flag.  That makes several
   apps of mine to malfuncate.


Great find!  Someone has got their test the wrong way round.  Since that
VM_MAYACCT macro is being used in one place only, and just hiding what it's
actually about, fold it into its callsite.


---

 25-akpm/include/linux/mm.h |    3 ---
 25-akpm/mm/mprotect.c      |    3 +--
 2 files changed, 1 insertion(+), 5 deletions(-)

diff -puN include/linux/mm.h~vm-accounting-fix include/linux/mm.h
--- 25/include/linux/mm.h~vm-accounting-fix	Tue May 11 14:01:21 2004
+++ 25-akpm/include/linux/mm.h	Tue May 11 14:01:21 2004
@@ -112,9 +112,6 @@ struct vm_area_struct {
 #define VM_HUGETLB	0x00400000	/* Huge TLB Page VM */
 #define VM_NONLINEAR	0x00800000	/* Is non-linear (remap_file_pages) */
 
-/* It makes sense to apply VM_ACCOUNT to this vma. */
-#define VM_MAYACCT(vma) (!!((vma)->vm_flags & VM_HUGETLB))
-
 #ifndef VM_STACK_DEFAULT_FLAGS		/* arch can override this */
 #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
 #endif
diff -puN mm/mprotect.c~vm-accounting-fix mm/mprotect.c
--- 25/mm/mprotect.c~vm-accounting-fix	Tue May 11 14:01:21 2004
+++ 25-akpm/mm/mprotect.c	Tue May 11 14:01:21 2004
@@ -174,8 +174,7 @@ mprotect_fixup(struct vm_area_struct *vm
 	 * a MAP_NORESERVE private mapping to writable will now reserve.
 	 */
 	if (newflags & VM_WRITE) {
-		if (!(vma->vm_flags & (VM_ACCOUNT|VM_WRITE|VM_SHARED))
-				&& VM_MAYACCT(vma)) {
+		if (!(vma->vm_flags & (VM_ACCOUNT|VM_WRITE|VM_SHARED|VM_HUGETLB))) {
 			charged = (end - start) >> PAGE_SHIFT;
 			if (security_vm_enough_memory(charged))
 				return -ENOMEM;

_
