* [PATCH] mm, compaction: avoid uninitialized variable use
@ 2016-05-11 13:24 Arnd Bergmann
2016-05-11 14:44 ` Michal Hocko
2016-05-12 6:16 ` Michal Hocko
0 siblings, 2 replies; 8+ messages in thread
From: Arnd Bergmann @ 2016-05-11 13:24 UTC (permalink / raw)
To: Andrew Morton, Michal Hocko
Cc: Arnd Bergmann, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
A recent rework of the compaction code introduced a warning about
an uninitialized variable when CONFIG_COMPACTION is disabled and
__alloc_pages_direct_compact() does not set its 'compact_result'
output argument:
mm/page_alloc.c: In function '__alloc_pages_nodemask':
mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This adds another check for CONFIG_COMPACTION to ensure we never
evaluate the uninitialized variable in this configuration, which
is probably the simplest way to avoid the warning.
A more elaborate rework might make this more readable.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: 13cff7b81275 ("mm, compaction: simplify __alloc_pages_direct_compact feedback interface")
---
mm/page_alloc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 477d9382f70d..bedadc686a22 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3640,7 +3640,8 @@ retry:
goto got_pg;
/* Checks for THP-specific high-order allocations */
- if (is_thp_gfp_mask(gfp_mask)) {
+ if (IS_ENABLED(CONFIG_COMPACTION) &&
+ is_thp_gfp_mask(gfp_mask)) {
/*
* If compaction is deferred for high-order allocations, it is
* because sync compaction recently failed. If this is the case
--
2.7.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-11 13:24 [PATCH] mm, compaction: avoid uninitialized variable use Arnd Bergmann
@ 2016-05-11 14:44 ` Michal Hocko
2016-05-11 14:52 ` Arnd Bergmann
2016-05-11 14:53 ` Michal Hocko
2016-05-12 6:16 ` Michal Hocko
1 sibling, 2 replies; 8+ messages in thread
From: Michal Hocko @ 2016-05-11 14:44 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On Wed 11-05-16 15:24:44, Arnd Bergmann wrote:
> A recent rework of the compaction code introduced a warning about
> an uninitialized variable when CONFIG_COMPACTION is disabled and
> __alloc_pages_direct_compact() does not set its 'compact_result'
> output argument:
>
> mm/page_alloc.c: In function '__alloc_pages_nodemask':
> mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> This adds another check for CONFIG_COMPACTION to ensure we never
> evaluate the uninitialized variable in this configuration, which
> is probably the simplest way to avoid the warning.
I think that hiding this into __alloc_pages_direct_compact is a better
idea. See the diff below
>
> A more elaborate rework might make this more readable.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> Fixes: 13cff7b81275 ("mm, compaction: simplify __alloc_pages_direct_compact feedback interface")
Please do not use SHA for mmotm commits because they are unstable and
change each linux-next release.
---
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4950d01ff935..14e3b4d93adc 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
unsigned int alloc_flags, const struct alloc_context *ac,
enum migrate_mode mode, enum compact_result *compact_result)
{
+ *compact_result = COMPACT_DEFERRED;
return NULL;
}
--
Michal Hocko
SUSE Labs
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-11 14:44 ` Michal Hocko
@ 2016-05-11 14:52 ` Arnd Bergmann
2016-05-11 16:13 ` Michal Hocko
2016-05-11 14:53 ` Michal Hocko
1 sibling, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2016-05-11 14:52 UTC (permalink / raw)
To: Michal Hocko
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On Wednesday 11 May 2016 16:44:07 Michal Hocko wrote:
> On Wed 11-05-16 15:24:44, Arnd Bergmann wrote:
> > A recent rework of the compaction code introduced a warning about
> > an uninitialized variable when CONFIG_COMPACTION is disabled and
> > __alloc_pages_direct_compact() does not set its 'compact_result'
> > output argument:
> >
> > mm/page_alloc.c: In function '__alloc_pages_nodemask':
> > mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >
> > This adds another check for CONFIG_COMPACTION to ensure we never
> > evaluate the uninitialized variable in this configuration, which
> > is probably the simplest way to avoid the warning.
>
> I think that hiding this into __alloc_pages_direct_compact is a better
> idea. See the diff below
Ok, sounds good.
> ---
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4950d01ff935..14e3b4d93adc 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> unsigned int alloc_flags, const struct alloc_context *ac,
> enum migrate_mode mode, enum compact_result *compact_result)
> {
> + *compact_result = COMPACT_DEFERRED;
> return NULL;
> }
>
I thought about this but didn't know which COMPACT_* value was appropriate here.
The behavior then changes a bit with your approach compared to mine,
because
if (compact_result == COMPACT_DEFERRED)
goto nopage;
is true now. I assume this is what we want though.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-11 14:44 ` Michal Hocko
2016-05-11 14:52 ` Arnd Bergmann
@ 2016-05-11 14:53 ` Michal Hocko
1 sibling, 0 replies; 8+ messages in thread
From: Michal Hocko @ 2016-05-11 14:53 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On Wed 11-05-16 16:44:07, Michal Hocko wrote:
> On Wed 11-05-16 15:24:44, Arnd Bergmann wrote:
> > A recent rework of the compaction code introduced a warning about
> > an uninitialized variable when CONFIG_COMPACTION is disabled and
> > __alloc_pages_direct_compact() does not set its 'compact_result'
> > output argument:
> >
> > mm/page_alloc.c: In function '__alloc_pages_nodemask':
> > mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >
> > This adds another check for CONFIG_COMPACTION to ensure we never
> > evaluate the uninitialized variable in this configuration, which
> > is probably the simplest way to avoid the warning.
>
> I think that hiding this into __alloc_pages_direct_compact is a better
> idea. See the diff below
> >
> > A more elaborate rework might make this more readable.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > Fixes: 13cff7b81275 ("mm, compaction: simplify __alloc_pages_direct_compact feedback interface")
>
> Please do not use SHA for mmotm commits because they are unstable and
> change each linux-next release.
>
> ---
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4950d01ff935..14e3b4d93adc 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> unsigned int alloc_flags, const struct alloc_context *ac,
> enum migrate_mode mode, enum compact_result *compact_result)
> {
> + *compact_result = COMPACT_DEFERRED;
Sorry, this should have been COMPACT_SKIPPED.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-11 14:52 ` Arnd Bergmann
@ 2016-05-11 16:13 ` Michal Hocko
0 siblings, 0 replies; 8+ messages in thread
From: Michal Hocko @ 2016-05-11 16:13 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On Wed 11-05-16 16:52:41, Arnd Bergmann wrote:
> On Wednesday 11 May 2016 16:44:07 Michal Hocko wrote:
> > On Wed 11-05-16 15:24:44, Arnd Bergmann wrote:
> > > A recent rework of the compaction code introduced a warning about
> > > an uninitialized variable when CONFIG_COMPACTION is disabled and
> > > __alloc_pages_direct_compact() does not set its 'compact_result'
> > > output argument:
> > >
> > > mm/page_alloc.c: In function '__alloc_pages_nodemask':
> > > mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> > >
> > > This adds another check for CONFIG_COMPACTION to ensure we never
> > > evaluate the uninitialized variable in this configuration, which
> > > is probably the simplest way to avoid the warning.
> >
> > I think that hiding this into __alloc_pages_direct_compact is a better
> > idea. See the diff below
>
> Ok, sounds good.
>
> > ---
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 4950d01ff935..14e3b4d93adc 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> > unsigned int alloc_flags, const struct alloc_context *ac,
> > enum migrate_mode mode, enum compact_result *compact_result)
> > {
> > + *compact_result = COMPACT_DEFERRED;
> > return NULL;
> > }
> >
>
> I thought about this but didn't know which COMPACT_* value was appropriate here.
>
> The behavior then changes a bit with your approach compared to mine,
> because
>
> if (compact_result == COMPACT_DEFERRED)
> goto nopage;
>
> is true now. I assume this is what we want though.
No, we actually want to try to reclaim, that's why COMPACT_SKIPPED is
more appropriate. COMPACT_SKIPPED is even correct semantically because
the compaction wasn't invoked.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-11 13:24 [PATCH] mm, compaction: avoid uninitialized variable use Arnd Bergmann
2016-05-11 14:44 ` Michal Hocko
@ 2016-05-12 6:16 ` Michal Hocko
2016-05-12 12:00 ` Vlastimil Babka
2016-05-12 12:04 ` Arnd Bergmann
1 sibling, 2 replies; 8+ messages in thread
From: Michal Hocko @ 2016-05-12 6:16 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
I think this would be slightly better than your proposal. Andrew, could
you fold it into the original
mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch
patch?
---
>From 434bc8b6f3787724327499998c4fe651e8ce5d68 Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.com>
Date: Thu, 12 May 2016 08:10:33 +0200
Subject: [PATCH] mmotm:
mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface-fix
Arnd has reported the following compilation warning:
mm/page_alloc.c: In function '__alloc_pages_nodemask':
mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This should be a false positive TRANSPARENT_HUGEPAGE depends on COMPACTION
so is_thp_gfp_mask shouldn't be true. GFP_TRANSHUGE is a bit tricky
and somebody might be using this accidently. Make sure that compact_result
is defined also for !CONFIG_COMPACT and set it to COMPACT_SKIPPED because
the compaction was really withdrawn.
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
mm/page_alloc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4950d01ff935..0d9008042efa 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
unsigned int alloc_flags, const struct alloc_context *ac,
enum migrate_mode mode, enum compact_result *compact_result)
{
+ *compact_result = COMPACT_SKIPPED;
return NULL;
}
--
2.8.1
--
Michal Hocko
SUSE Labs
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-12 6:16 ` Michal Hocko
@ 2016-05-12 12:00 ` Vlastimil Babka
2016-05-12 12:04 ` Arnd Bergmann
1 sibling, 0 replies; 8+ messages in thread
From: Vlastimil Babka @ 2016-05-12 12:00 UTC (permalink / raw)
To: Michal Hocko, Arnd Bergmann
Cc: Andrew Morton, Mel Gorman, David Rientjes, Joonsoo Kim,
Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On 05/12/2016 08:16 AM, Michal Hocko wrote:
> I think this would be slightly better than your proposal. Andrew, could
> you fold it into the original
> mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch
> patch?
> ---
> From 434bc8b6f3787724327499998c4fe651e8ce5d68 Mon Sep 17 00:00:00 2001
> From: Michal Hocko <mhocko@suse.com>
> Date: Thu, 12 May 2016 08:10:33 +0200
> Subject: [PATCH] mmotm:
> mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface-fix
>
> Arnd has reported the following compilation warning:
> mm/page_alloc.c: In function '__alloc_pages_nodemask':
> mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> This should be a false positive TRANSPARENT_HUGEPAGE depends on COMPACTION
> so is_thp_gfp_mask shouldn't be true. GFP_TRANSHUGE is a bit tricky
> and somebody might be using this accidently. Make sure that compact_result
> is defined also for !CONFIG_COMPACT and set it to COMPACT_SKIPPED because
> the compaction was really withdrawn.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
Ack.
> ---
> mm/page_alloc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4950d01ff935..0d9008042efa 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -3300,6 +3300,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
> unsigned int alloc_flags, const struct alloc_context *ac,
> enum migrate_mode mode, enum compact_result *compact_result)
> {
> + *compact_result = COMPACT_SKIPPED;
> return NULL;
> }
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] mm, compaction: avoid uninitialized variable use
2016-05-12 6:16 ` Michal Hocko
2016-05-12 12:00 ` Vlastimil Babka
@ 2016-05-12 12:04 ` Arnd Bergmann
1 sibling, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2016-05-12 12:04 UTC (permalink / raw)
To: Michal Hocko
Cc: Andrew Morton, Mel Gorman, Vlastimil Babka, David Rientjes,
Joonsoo Kim, Taku Izumi, Johannes Weiner, linux-mm, linux-kernel
On Thursday 12 May 2016 08:16:36 Michal Hocko wrote:
> I think this would be slightly better than your proposal. Andrew, could
> you fold it into the original
> mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface.patch
> patch?
> ---
> From 434bc8b6f3787724327499998c4fe651e8ce5d68 Mon Sep 17 00:00:00 2001
> From: Michal Hocko <mhocko@suse.com>
> Date: Thu, 12 May 2016 08:10:33 +0200
> Subject: [PATCH] mmotm:
> mm-compaction-simplify-__alloc_pages_direct_compact-feedback-interface-fix
>
> Arnd has reported the following compilation warning:
> mm/page_alloc.c: In function '__alloc_pages_nodemask':
> mm/page_alloc.c:3651:6: error: 'compact_result' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
> This should be a false positive TRANSPARENT_HUGEPAGE depends on COMPACTION
> so is_thp_gfp_mask shouldn't be true. GFP_TRANSHUGE is a bit tricky
> and somebody might be using this accidently. Make sure that compact_result
> is defined also for !CONFIG_COMPACT and set it to COMPACT_SKIPPED because
> the compaction was really withdrawn.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Looks much nicer than my version.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-05-12 12:04 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 13:24 [PATCH] mm, compaction: avoid uninitialized variable use Arnd Bergmann
2016-05-11 14:44 ` Michal Hocko
2016-05-11 14:52 ` Arnd Bergmann
2016-05-11 16:13 ` Michal Hocko
2016-05-11 14:53 ` Michal Hocko
2016-05-12 6:16 ` Michal Hocko
2016-05-12 12:00 ` Vlastimil Babka
2016-05-12 12:04 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).