Skip to contentSkip to conversation

mm: Change count_mm_mlocked_page_nr return type

PATCH In review Weikang shi 2 participants 2 messages May 13, 2019

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

PATCH 1/1 mm: Change count_mm_mlocked_page_nr return type

From: swkhack <[email protected]>

In 64-bit machine,the value of "vma->vm_end - vma->vm_start" maybe negative in 32bit int and the "count >> PAGE_SHIFT"'s result will be wrong.So change the local variable and return value to unsigned long will fix the problem.

---
 mm/mlock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mlock.c +2 -2
index 080f3b364..d614163f5 100644
@@ -636,11 +636,11 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
  * is also counted.
  * Return value: previously mlocked page counts
  */
-static int count_mm_mlocked_page_nr(struct mm_struct *mm,
+static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
 		unsigned long start, size_t len)
 {
 	struct vm_area_struct *vma;
-	int count = 0;
+	unsigned long count = 0;
 
 	if (mm == NULL)
 		mm = current->mm;
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Weikang shi

From: swkhack <[email protected]>

In 64-bit machine,the value of "vma->vm_end - vma->vm_start" maybe negative in 32bit int and the "count >> PAGE_SHIFT"'s result will be wrong.So change the local variable and return value to unsigned long will fix the problem.

Fixes 0cf2f6f6dc60 ("mm: mlock: check against vma for actual mlock() size")

Most users probably never noticed because large mlocked areas are not allowed by default. So I am not really sure this is worth backporting to stable trees.

Quoted 24 lines
---
 mm/mlock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mlock.c +2 -2
index 080f3b364..d614163f5 100644
@@ -636,11 +636,11 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
  * is also counted.
  * Return value: previously mlocked page counts
  */
-static int count_mm_mlocked_page_nr(struct mm_struct *mm,
+static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
 		unsigned long start, size_t len)
 {
 	struct vm_area_struct *vma;
-	int count = 0;
+	unsigned long count = 0;
 
 	if (mm == NULL)
 		mm = current->mm;
Signature · 1 line
2.17.1
Signature · 2 lines
Michal Hocko
SUSE Labs