Skip to contentSkip to conversation

mm: Fix compile warning of mmotm-2012-09-06-16-46

PATCH In review Minchan Kim 3 participants 7 messages Sep 7, 2012 – Sep 11, 2012

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

PATCH 1/1 mm: Fix compile warning of mmotm-2012-09-06-16-46

When I compiled today, I met following warning.
Correct it.

mm/memory.c: In function a??copy_page_rangea??:
include/linux/mmu_notifier.h:235:38: warning: a??mmun_enda?? may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1043:16: note: a??mmun_enda?? was declared here
include/linux/mmu_notifier.h:235:38: warning: a??mmun_starta?? may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1042:16: note: a??mmun_starta?? was declared here
LD mm/built-in.o

Cc Sagi Grimberg <[email protected]>
Cc Haggai Eran <[email protected]>
---
 mm/memory.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +2 -2
index 10e9b38..d000449 100644
@@ -1039,8 +1039,8 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long next;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
-	unsigned long mmun_start;	/* For mmu_notifiers */
-	unsigned long mmun_end;		/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_start);	/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_end);	/* For mmu_notifiers */
 	int ret;
 
 	/*
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 22 lines · On Fri, 7 Sep 2012 09:57:10 +0900 Minchan Kim <[email protected]> wrote:

When I compiled today, I met following warning.
Correct it.

mm/memory.c: In function ___copy_page_range___:
include/linux/mmu_notifier.h:235:38: warning: ___mmun_end___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1043:16: note: ___mmun_end___ was declared here
include/linux/mmu_notifier.h:235:38: warning: ___mmun_start___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1042:16: note: ___mmun_start___ was declared here
LD mm/built-in.o

Cc Sagi Grimberg <[email protected]>
Cc Haggai Eran <[email protected]>
---
 mm/memory.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +0 -0
index 10e9b38..d000449 100644

mm/memory.c int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, · line 1045

Quoted 9 lines
mm/memory.c +2 -2
@@ -1039,8 +1039,8 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long next;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
-	unsigned long mmun_start;	/* For mmu_notifiers */
-	unsigned long mmun_end;		/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_start);	/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_end);	/* For mmu_notifiers */
 	int ret;
 

Well yes, but a) uninitialized_var is a bit ugly and has some potential to hide real bugs and b) it's not completely obvious that is_cow_mapping() is stable across those two calls.

I think a better approach is this:

mm/memory.c renamed from mm/memory.c~mm-move-all-mmu-notifier-invocations-to-be-done-outside-the-pt-lock-fix-fix +4 -2
@@ -1041,6 +1041,7 @@ int copy_page_range(struct mm_struct *ds
 	unsigned long end = vma->vm_end;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	bool is_cow;
 	int ret;
 
 	/*
@@ -1074,7 +1075,8 @@ int copy_page_range(struct mm_struct *ds
 	 * parent mm. And a permission downgrade will only happen if
 	 * is_cow_mapping() returns true.
 	 */
-	if (is_cow_mapping(vma->vm_flags)) {
+	is_cow = is_cow_mapping(vma->vm_flags);
+	if (is_cow) {
 		mmun_start = addr;
 		mmun_end   = end;
 		mmu_notifier_invalidate_range_start(src_mm, mmun_start,
@@ -1095,7 +1097,7 @@ int copy_page_range(struct mm_struct *ds
 		}
 	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
 
-	if (is_cow_mapping(vma->vm_flags))
+	if (is_cow)
 		mmu_notifier_invalidate_range_end(src_mm, mmun_start, mmun_end);
 	return ret;
 }

Unfortunately, my (old) versions of gcc are so stupid that they *still* generate the warning even when the code is as obviously correct as this :(

Can you please test it with your compiler?

We should use this patch anyway - it makes memory.o text 13 bytes smaller.

is_cow_mapping() should return bool.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Fri, 7 Sep 2012 09:57:10 +0900 Minchan Kim <[email protected]> wrote:

When I compiled today, I met following warning.
Correct it.

mm/memory.c: In function ___copy_page_range___:
include/linux/mmu_notifier.h:235:38: warning: ___mmun_end___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1043:16: note: ___mmun_end___ was declared here
include/linux/mmu_notifier.h:235:38: warning: ___mmun_start___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1042:16: note: ___mmun_start___ was declared here
LD mm/built-in.o

Cc Sagi Grimberg <[email protected]>
Cc Haggai Eran <[email protected]>
---
 mm/memory.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +0 -2
index 10e9b38..d000449 100644
@@ -1039,8 +1039,8 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long next;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
-	unsigned long mmun_start;	/* For mmu_notifiers */
-	unsigned long mmun_end;		/* For mmu_notifiers */
Quoted 8 lines

mm/memory.c int copy_page_range(struct mm_struct *ds · line 1046

Quoted 4 lines
mm/memory.c +2 -0
+	unsigned long uninitialized_var(mmun_start);	/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_end);	/* For mmu_notifiers */
 	int ret;
 

Well yes, but a) uninitialized_var is a bit ugly and has some potential to hide real bugs and b) it's not completely obvious that is_cow_mapping() is stable across those two calls.

I thought that code that changed the vm_flags would need mmap_sem locked exclusively, and copy_page_range is also called with the mmap_sem locked, so that would prevent is_cow_mapping() from changing, wouldn't it?

Quoted 33 lines

I think a better approach is this:

mm/memory.c renamed from mm/memory.c~mm-move-all-mmu-notifier-invocations-to-be-done-outside-the-pt-lock-fix-fix +4 -2
@@ -1041,6 +1041,7 @@ int copy_page_range(struct mm_struct *ds
 	unsigned long end = vma->vm_end;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	bool is_cow;
 	int ret;
 
 	/*
@@ -1074,7 +1075,8 @@ int copy_page_range(struct mm_struct *ds
 	 * parent mm. And a permission downgrade will only happen if
 	 * is_cow_mapping() returns true.
 	 */
-	if (is_cow_mapping(vma->vm_flags)) {
+	is_cow = is_cow_mapping(vma->vm_flags);
+	if (is_cow) {
 		mmun_start = addr;
 		mmun_end   = end;
 		mmu_notifier_invalidate_range_start(src_mm, mmun_start,
@@ -1095,7 +1097,7 @@ int copy_page_range(struct mm_struct *ds
 		}
 	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
 
-	if (is_cow_mapping(vma->vm_flags))
+	if (is_cow)
 		mmu_notifier_invalidate_range_end(src_mm, mmun_start, mmun_end);
 	return ret;
 }
Quoted 4 lines

Unfortunately, my (old) versions of gcc are so stupid that they *still* generate the warning even when the code is as obviously correct as this :(

Can you please test it with your compiler?

With GCC 4.4.4 I still get these warnings, even with the is_cow variable. Sorry I haven't noticed that before. Perhaps I can move the initialization of mmun_start/end before the if.

By the way, with GCC 4.4.4 I don't get the warning in do_wp_page.

Regards,
Haggai

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
In reply to Andrew Morton

Hi Andrew,

Quoted 71 lines · Andrew Morton
Quoted 22 lines · On Fri, 7 Sep 2012 09:57:10 +0900 Minchan Kim <[email protected]> wrote:

When I compiled today, I met following warning.
Correct it.

mm/memory.c: In function ___copy_page_range___:
include/linux/mmu_notifier.h:235:38: warning: ___mmun_end___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1043:16: note: ___mmun_end___ was declared here
include/linux/mmu_notifier.h:235:38: warning: ___mmun_start___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1042:16: note: ___mmun_start___ was declared here
LD mm/built-in.o

Cc Sagi Grimberg <[email protected]>
Cc Haggai Eran <[email protected]>
---
 mm/memory.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +0 -0
index 10e9b38..d000449 100644

mm/memory.c int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, · line 1045

Quoted 9 lines
mm/memory.c +2 -2
@@ -1039,8 +1039,8 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long next;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
-	unsigned long mmun_start;	/* For mmu_notifiers */
-	unsigned long mmun_end;		/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_start);	/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_end);	/* For mmu_notifiers */
 	int ret;
 

Well yes, but a) uninitialized_var is a bit ugly and has some potential to hide real bugs and b) it's not completely obvious that is_cow_mapping() is stable across those two calls.

I think a better approach is this:

mm/memory.c renamed from mm/memory.c~mm-move-all-mmu-notifier-invocations-to-be-done-outside-the-pt-lock-fix-fix +4 -2
@@ -1041,6 +1041,7 @@ int copy_page_range(struct mm_struct *ds
 	unsigned long end = vma->vm_end;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	bool is_cow;
 	int ret;
 
 	/*
@@ -1074,7 +1075,8 @@ int copy_page_range(struct mm_struct *ds
 	 * parent mm. And a permission downgrade will only happen if
 	 * is_cow_mapping() returns true.
 	 */
-	if (is_cow_mapping(vma->vm_flags)) {
+	is_cow = is_cow_mapping(vma->vm_flags);
+	if (is_cow) {
 		mmun_start = addr;
 		mmun_end   = end;
 		mmu_notifier_invalidate_range_start(src_mm, mmun_start,
@@ -1095,7 +1097,7 @@ int copy_page_range(struct mm_struct *ds
 		}
 	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
 
-	if (is_cow_mapping(vma->vm_flags))
+	if (is_cow)
 		mmu_notifier_invalidate_range_end(src_mm, mmun_start, mmun_end);
 	return ret;
 }
Quoted 4 lines

Unfortunately, my (old) versions of gcc are so stupid that they *still* generate the warning even when the code is as obviously correct as this :(

Can you please test it with your compiler?

My compiler is stupidl, too. It still emit the samw warning when I apply your patch. In addition, I can't see any benefit of text size.

barrios@bbox:~/linux-mmotm$ size mm/memory.o mm/memory.o.andrew 
   text    data     bss     dec     hex filename
  29147      54      40   29241    7239 mm/memory.o
  29147      54      40   29241    7239 mm/memory.o.andrew
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
Quoted 74 lines · Minchan Kim

Hi Andrew,

Quoted 71 lines · Andrew Morton
Quoted 22 lines · On Fri, 7 Sep 2012 09:57:10 +0900 Minchan Kim <[email protected]> wrote:

When I compiled today, I met following warning.
Correct it.

mm/memory.c: In function ___copy_page_range___:
include/linux/mmu_notifier.h:235:38: warning: ___mmun_end___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1043:16: note: ___mmun_end___ was declared here
include/linux/mmu_notifier.h:235:38: warning: ___mmun_start___ may be used uninitialized in this function [-Wuninitialized] mm/memory.c:1042:16: note: ___mmun_start___ was declared here
LD mm/built-in.o

Cc Sagi Grimberg <[email protected]>
Cc Haggai Eran <[email protected]>
---
 mm/memory.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory.c +0 -0
index 10e9b38..d000449 100644

mm/memory.c int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm, · line 1045

Quoted 9 lines
mm/memory.c +2 -2
@@ -1039,8 +1039,8 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long next;
 	unsigned long addr = vma->vm_start;
 	unsigned long end = vma->vm_end;
-	unsigned long mmun_start;	/* For mmu_notifiers */
-	unsigned long mmun_end;		/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_start);	/* For mmu_notifiers */
+	unsigned long uninitialized_var(mmun_end);	/* For mmu_notifiers */
 	int ret;
 

Well yes, but a) uninitialized_var is a bit ugly and has some potential to hide real bugs and b) it's not completely obvious that is_cow_mapping() is stable across those two calls.

I think a better approach is this:

mm/memory.c renamed from mm/memory.c~mm-move-all-mmu-notifier-invocations-to-be-done-outside-the-pt-lock-fix-fix +4 -2
@@ -1041,6 +1041,7 @@ int copy_page_range(struct mm_struct *ds
 	unsigned long end = vma->vm_end;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	bool is_cow;
 	int ret;
 
 	/*
@@ -1074,7 +1075,8 @@ int copy_page_range(struct mm_struct *ds
 	 * parent mm. And a permission downgrade will only happen if
 	 * is_cow_mapping() returns true.
 	 */
-	if (is_cow_mapping(vma->vm_flags)) {
+	is_cow = is_cow_mapping(vma->vm_flags);
+	if (is_cow) {
 		mmun_start = addr;
 		mmun_end   = end;
 		mmu_notifier_invalidate_range_start(src_mm, mmun_start,
@@ -1095,7 +1097,7 @@ int copy_page_range(struct mm_struct *ds
 		}
 	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
 
-	if (is_cow_mapping(vma->vm_flags))
+	if (is_cow)
 		mmu_notifier_invalidate_range_end(src_mm, mmun_start, mmun_end);
 	return ret;
 }
Quoted 7 lines
Quoted 4 lines

Unfortunately, my (old) versions of gcc are so stupid that they *still* generate the warning even when the code is as obviously correct as this :(

Can you please test it with your compiler?

My compiler is stupidl, too. It still emit the samw warning when I apply your patch. In addition, I can't see any benefit of text size.

barrios@bbox:~/linux-mmotm$ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

PATCH 1/1 mm: Fix compiler warning in copy_page_range

In reply to Haggai Eran

This patch fixes the warning about mmun_start/end used uninitialized in copy_page_range, by initializing them regardless of whether the notifiers are actually called. It also makes sure the vm_flags in copy_page_range are only read once.

---
 mm/memory.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
mm/memory.c +7 -6
index 3c88368..423d214 100644
@@ -712,7 +712,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
 	add_taint(TAINT_BAD_PAGE);
 }
 
-static inline int is_cow_mapping(vm_flags_t flags)
+static inline bool is_cow_mapping(vm_flags_t flags)
 {
 	return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
 }
@@ -1041,6 +1041,7 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	unsigned long end = vma->vm_end;
 	unsigned long mmun_start;	/* For mmu_notifiers */
 	unsigned long mmun_end;		/* For mmu_notifiers */
+	bool is_cow;
 	int ret;
 
 	/*
@@ -1073,12 +1074,12 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * parent mm. And a permission downgrade will only happen if
 	 * is_cow_mapping() returns true.
 	 */
-	if (is_cow_mapping(vma->vm_flags)) {
-		mmun_start = addr;
-		mmun_end   = end;
+	is_cow = is_cow_mapping(vma->vm_flags);
+	mmun_start = addr;
+	mmun_end   = end;
+	if (is_cow)
 		mmu_notifier_invalidate_range_start(src_mm, mmun_start,
 						    mmun_end);
-	}
 
 	ret = 0;
 	dst_pgd = pgd_offset(dst_mm, addr);
@@ -1094,7 +1095,7 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 		}
 	} while (dst_pgd++, src_pgd++, addr = next, addr != end);
 
-	if (is_cow_mapping(vma->vm_flags))
+	if (is_cow)
 		mmu_notifier_invalidate_range_end(src_mm, mmun_start,
 						  mmun_end);
 	return ret;
Signature · 7 lines
1.7.11.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author Reviewed-by on v1 1/1
#4 lore raw

Re: [PATCH] mm: Fix compiler warning in copy_page_range

Quoted 7 lines · Haggai Eran

This patch fixes the warning about mmun_start/end used uninitialized in copy_page_range, by initializing them regardless of whether the notifiers are actually called. It also makes sure the vm_flags in copy_page_range are only read once.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>