mm: thp: avoid uninitialized variable use
Subsystems (2)
PATCH 1/1 mm: thp: avoid uninitialized variable use
When the down_read_trylock() fails, 'vma' has not been initialized yet, which gcc now warns about:
mm/khugepaged.c: In function 'khugepaged':mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Presumable we are not supposed to call find_vma() without the mmap_sem either, so setting it to NULL for this case seems appropriate.
---
I'm not completely sure this patch is sufficient, it gets rid of the warning, but it would be good to have the code reviewed better to see if other problems remain that result from down_read_trylock() patch.
--- mm/khugepaged.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/khugepaged.c +2 -3
@@ -1677,11 +1677,10 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages,* Don't wait for semaphore (to avoid long wait times). Just move to * the next mm on the list. */ + vma =NULL ;if (unlikely (!down_read_trylock (&mm->mmap_sem))) goto breakouterloop_mmap_sem; -if (unlikely (khugepaged_test_exit (mm))) - vma =NULL ; -else +if (likely (!khugepaged_test_exit (mm))) vma =find_vma (mm, khugepaged_scan.address); progress++;
Signature · 7 lines
2.9.0 -- 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>
Quoted 5 lines · Arnd Bergmann
When the
down_read_trylock()fails, 'vma' has not been initialized yet, which gcc now warns about:
mm/khugepaged.c: In function 'khugepaged':mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized]
ups missed that
Quoted 3 lines
Presumable we are not supposed to call
find_vma()without themmap_semeither, so setting it to NULL for this case seems appropriate.
yes
Quoted 1 line
Fixes 0951b59acf3a ("mm: thp: use down_read_trylock() in khugepaged to avoid long block")
This sha is not stable because this is a mmotm tree. I assume Andrew will fold it to mm-thp-use-down_read_trylock-in-khugepaged-to-avoid-long-block.patch. The patch looks good to me. I would initialize the vma in the declaration, but that is a minor thing.
Quoted 1 line
Signed-off-by Arnd Bergmann <[email protected]>
Quoted 30 lines
---
I'm not completely sure this patch is sufficient, it gets rid of the warning, but it would be good to have the code reviewed better to see if other problems remain that result fromdown_read_trylock()patch.--- mm/khugepaged.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/khugepaged.c +2
-3@@ -1677,11 +1677,10 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages,* Don't wait for semaphore (to avoid long wait times). Just move to * the next mm on the list. */ + vma =NULL ;if (unlikely (!down_read_trylock (&mm->mmap_sem))) goto breakouterloop_mmap_sem; -if (unlikely (khugepaged_test_exit (mm))) - vma =NULL ; -else +if (likely (!khugepaged_test_exit (mm))) vma =find_vma (mm, khugepaged_scan.address); progress++;Signature · 1 line
2.9.0
Signature · 8 lines
Michal Hocko SUSE Labs -- 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>
Quoted 5 lines · Arnd Bergmann
When the
down_read_trylock()fails, 'vma' has not been initialized yet, which gcc now warns about:
mm/khugepaged.c: In function 'khugepaged':mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Arnd,
Thanks for catching this. I'm wondering why my test didn't catch it. It might be because my gcc is old. I'm using gcc 4.8.5 on centos 7.
Regards,
Yang
Quoted 24 lines
Presumable we are not supposed to call
find_vma()without themmap_semeither, so setting it to NULL for this case seems appropriate.Fixes 0951b59acf3a ("mm: thp: use down_read_trylock() in khugepaged to avoid long block")Signed-off-by Arnd Bergmann <[email protected]>---
I'm not completely sure this patch is sufficient, it gets rid of the warning, but it would be good to have the code reviewed better to see if other problems remain that result fromdown_read_trylock()patch.--- mm/khugepaged.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)mm/khugepaged.c +0
-0@@ -1677,11 +1677,10 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages,* Don't wait for semaphore (to avoid long wait times). Just move to * the next mm on the list. */
mm/khugepaged.c static unsigned int khugepaged_scan_mm_slot(unsigned int pages, · line 1686
Quoted 10 lines
mm/khugepaged.c +2
-3+ vma =NULL ;if (unlikely (!down_read_trylock (&mm->mmap_sem))) goto breakouterloop_mmap_sem; -if (unlikely (khugepaged_test_exit (mm))) - vma =NULL ; -else +if (likely (!khugepaged_test_exit (mm))) vma =find_vma (mm, khugepaged_scan.address); progress++;
--
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>
Quoted 12 lines · Yang Shi
Quoted 7 lines · Arnd Bergmann
When the
down_read_trylock()fails, 'vma' has not been initialized yet, which gcc now warns about:
mm/khugepaged.c: In function 'khugepaged':mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Quoted 4 lines
Arnd,
Thanks for catching this. I'm wondering why my test didn't catch it. It might be because my gcc is old. I'm using gcc 4.8.5 on centos 7.
Correct, gcc-4.8 and earlier have too many false-positive warnings with -Wmaybe-uninitialized, so we turn it off on those versions. 4.9 is much better here, but I'd recommend using gcc-6 or gcc-7 when you upgrade, they have a much better set of default warnings besides producing better binary code.
See http://git.infradead.org/users/segher/buildall.git for a simple way to build toolchains suitable for building kernels in varying architectures and versions.
Arnd
--
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>
Quoted 15 lines · Arnd Bergmann
Quoted 14 lines · Yang Shi
Quoted 7 lines · Arnd Bergmann
When the
down_read_trylock()fails, 'vma' has not been initialized yet, which gcc now warns about:
mm/khugepaged.c: In function 'khugepaged':mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized]Arnd,
Quoted 8 lines
Quoted 2 lines
Thanks for catching this. I'm wondering why my test didn't catch it. It might be because my gcc is old. I'm using gcc 4.8.5 on centos 7.
Correct, gcc-4.8 and earlier have too many false-positive warnings with -Wmaybe-uninitialized, so we turn it off on those versions. 4.9 is much better here, but I'd recommend using gcc-6 or gcc-7 when you upgrade, they have a much better set of default warnings besides producing better binary code.
Thanks, I just upgraded gcc to 6.4 on my cetnos 7 machine. But, I ran into a build error with 4.15-rc3 kernel, but 4.14 is fine. I bisected to a commit in Makefile. I will email my bug report to the mailing list.
Regards,
Yang
Quoted 7 lines
See http://git.infradead.org/users/segher/buildall.git for a simple way to build toolchains suitable for building kernels in varying architectures and versions.
Arnd
--
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>