Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1407901 > unrolled thread
| Started by | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| First post | 2016-05-27 10:10 +0200 |
| Last post | 2016-05-30 08:50 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] oom_reaper: don't call mmput_async() on uninitialized mm Arnd Bergmann <arnd@arndb.de> - 2016-05-27 10:10 +0200
Re: [PATCH] oom_reaper: don't call mmput_async() on uninitialized mm Michal Hocko <mhocko@kernel.org> - 2016-05-27 10:20 +0200
Re: [PATCH] oom_reaper: don't call mmput_async() on uninitialized mm Andrew Morton <akpm@linux-foundation.org> - 2016-05-27 22:00 +0200
Re: [PATCH] oom_reaper: don't call mmput_async() on uninitialized mm Michal Hocko <mhocko@kernel.org> - 2016-05-30 08:50 +0200
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2016-05-27 10:10 +0200 |
| Subject | [PATCH] oom_reaper: don't call mmput_async() on uninitialized mm |
| Message-ID | <rDl0e-Ub-33@gated-at.bofh.it> |
The change to the oom_reaper to hold a mutex inside __oom_reap_task()
accidentally started calling mmput_async() on the local
mm before that variable got initialized, as reported by gcc
in linux-next:
mm/oom_kill.c: In function '__oom_reap_task':
mm/oom_kill.c:537:2: error: 'mm' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This rearranges the code slightly back to the state before patch
but leaves the lock in place. The error handling in the function
still looks a bit confusing and could probably be improved
but I could not come up with a solution that made me happy
for now.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: mmotm ("oom_reaper: close race with exiting task")
---
mm/oom_kill.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1685890d424e..255cb5f48019 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -447,7 +447,7 @@ static bool __oom_reap_task(struct task_struct *tsk)
struct task_struct *p;
struct zap_details details = {.check_swap_entries = true,
.ignore_dirty = true};
- bool ret = true;
+ bool ret;
/*
* We have to make sure to not race with the victim exit path
@@ -472,13 +472,16 @@ static bool __oom_reap_task(struct task_struct *tsk)
* is no mm.
*/
p = find_lock_task_mm(tsk);
- if (!p)
- goto unlock_oom;
+ if (!p) {
+ mutex_unlock(&oom_lock);
+ return true;
+ }
mm = p->mm;
if (!atomic_inc_not_zero(&mm->mm_users)) {
task_unlock(p);
- goto unlock_oom;
+ mutex_unlock(&oom_lock);
+ return true;
}
task_unlock(p);
@@ -527,6 +530,7 @@ static bool __oom_reap_task(struct task_struct *tsk)
* to release its memory.
*/
set_bit(MMF_OOM_REAPED, &mm->flags);
+ ret = true;
unlock_oom:
mutex_unlock(&oom_lock);
/*
--
2.7.0
[toc] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2016-05-27 10:20 +0200 |
| Message-ID | <rDl9U-XC-5@gated-at.bofh.it> |
| In reply to | #1407901 |
On Fri 27-05-16 10:00:48, Arnd Bergmann wrote:
> The change to the oom_reaper to hold a mutex inside __oom_reap_task()
> accidentally started calling mmput_async() on the local
> mm before that variable got initialized, as reported by gcc
> in linux-next:
>
> mm/oom_kill.c: In function '__oom_reap_task':
> mm/oom_kill.c:537:2: error: 'mm' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> This rearranges the code slightly back to the state before patch
> but leaves the lock in place. The error handling in the function
> still looks a bit confusing and could probably be improved
> but I could not come up with a solution that made me happy
> for now.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: mmotm ("oom_reaper: close race with exiting task")
Thanks for catching that Arnd?
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> mm/oom_kill.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 1685890d424e..255cb5f48019 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -447,7 +447,7 @@ static bool __oom_reap_task(struct task_struct *tsk)
> struct task_struct *p;
> struct zap_details details = {.check_swap_entries = true,
> .ignore_dirty = true};
> - bool ret = true;
> + bool ret;
>
> /*
> * We have to make sure to not race with the victim exit path
> @@ -472,13 +472,16 @@ static bool __oom_reap_task(struct task_struct *tsk)
> * is no mm.
> */
> p = find_lock_task_mm(tsk);
> - if (!p)
> - goto unlock_oom;
> + if (!p) {
> + mutex_unlock(&oom_lock);
> + return true;
> + }
>
> mm = p->mm;
> if (!atomic_inc_not_zero(&mm->mm_users)) {
> task_unlock(p);
> - goto unlock_oom;
> + mutex_unlock(&oom_lock);
> + return true;
> }
>
> task_unlock(p);
> @@ -527,6 +530,7 @@ static bool __oom_reap_task(struct task_struct *tsk)
> * to release its memory.
> */
> set_bit(MMF_OOM_REAPED, &mm->flags);
> + ret = true;
> unlock_oom:
> mutex_unlock(&oom_lock);
> /*
> --
> 2.7.0
>
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Date | 2016-05-27 22:00 +0200 |
| Subject | Re: [PATCH] oom_reaper: don't call mmput_async() on uninitialized mm |
| Message-ID | <rDw5k-7Db-29@gated-at.bofh.it> |
| In reply to | #1407905 |
On Fri, 27 May 2016 10:10:59 +0200 Michal Hocko <mhocko@kernel.org> wrote:
> On Fri 27-05-16 10:00:48, Arnd Bergmann wrote:
> > The change to the oom_reaper to hold a mutex inside __oom_reap_task()
> > accidentally started calling mmput_async() on the local
> > mm before that variable got initialized, as reported by gcc
> > in linux-next:
> >
> > mm/oom_kill.c: In function '__oom_reap_task':
> > mm/oom_kill.c:537:2: error: 'mm' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >
> > This rearranges the code slightly back to the state before patch
> > but leaves the lock in place. The error handling in the function
> > still looks a bit confusing and could probably be improved
> > but I could not come up with a solution that made me happy
> > for now.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > Fixes: mmotm ("oom_reaper: close race with exiting task")
>
> Thanks for catching that Arnd?
>
> Acked-by: Michal Hocko <mhocko@suse.com>
I think I preferred my version - all those unwinding return statements
can cause problems..
--- a/mm/oom_kill.c~oom_reaper-close-race-with-exiting-task-fix
+++ a/mm/oom_kill.c
@@ -443,7 +443,7 @@ static bool __oom_reap_task(struct task_
{
struct mmu_gather tlb;
struct vm_area_struct *vma;
- struct mm_struct *mm;
+ struct mm_struct *mm = NULL;
struct task_struct *p;
struct zap_details details = {.check_swap_entries = true,
.ignore_dirty = true};
@@ -534,7 +534,8 @@ unlock_oom:
* different context because we shouldn't risk we get stuck there and
* put the oom_reaper out of the way.
*/
- mmput_async(mm);
+ if (mm)
+ mmput_async(mm);
return ret;
}
_
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2016-05-30 08:50 +0200 |
| Message-ID | <rEpbs-B4-25@gated-at.bofh.it> |
| In reply to | #1408268 |
On Fri 27-05-16 12:55:34, Andrew Morton wrote:
> On Fri, 27 May 2016 10:10:59 +0200 Michal Hocko <mhocko@kernel.org> wrote:
>
> > On Fri 27-05-16 10:00:48, Arnd Bergmann wrote:
> > > The change to the oom_reaper to hold a mutex inside __oom_reap_task()
> > > accidentally started calling mmput_async() on the local
> > > mm before that variable got initialized, as reported by gcc
> > > in linux-next:
> > >
> > > mm/oom_kill.c: In function '__oom_reap_task':
> > > mm/oom_kill.c:537:2: error: 'mm' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> > >
> > > This rearranges the code slightly back to the state before patch
> > > but leaves the lock in place. The error handling in the function
> > > still looks a bit confusing and could probably be improved
> > > but I could not come up with a solution that made me happy
> > > for now.
> > >
> > > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > > Fixes: mmotm ("oom_reaper: close race with exiting task")
> >
> > Thanks for catching that Arnd?
> >
> > Acked-by: Michal Hocko <mhocko@suse.com>
>
> I think I preferred my version - all those unwinding return statements
> can cause problems..
looks good to me as well.
Thanks!
> --- a/mm/oom_kill.c~oom_reaper-close-race-with-exiting-task-fix
> +++ a/mm/oom_kill.c
> @@ -443,7 +443,7 @@ static bool __oom_reap_task(struct task_
> {
> struct mmu_gather tlb;
> struct vm_area_struct *vma;
> - struct mm_struct *mm;
> + struct mm_struct *mm = NULL;
> struct task_struct *p;
> struct zap_details details = {.check_swap_entries = true,
> .ignore_dirty = true};
> @@ -534,7 +534,8 @@ unlock_oom:
> * different context because we shouldn't risk we get stuck there and
> * put the oom_reaper out of the way.
> */
> - mmput_async(mm);
> + if (mm)
> + mmput_async(mm);
> return ret;
> }
>
> _
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web