BUILD_BUG_ON() breaks sparse gfp_t checks
Subsystems (3)
Running sparse on page_alloc.c today, it errors out:
mm/page_alloc.c:96:5: warning: symbol 'percpu_pagelist_fraction' was not declared. Should it be static? mm/page_alloc.c:175:5: warning: symbol 'min_free_kbytes' was not declared. Should it be static? include/linux/gfp.h:254:17: error: bad constant expression include/linux/gfp.h:254:17: error: cannot size expression
which is a line in gfp_zone():
BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);
That's really unfortunate, because it ends up hiding all of the other legitimate sparse messages (like I introduced with the appended patch):
mm/page_alloc.c:96:5: warning: symbol 'percpu_pagelist_fraction' was not declared. Should it be static? mm/page_alloc.c:175:5: warning: symbol 'min_free_kbytes' was not declared. Should it be static? mm/page_alloc.c:3692:15: warning: symbol '__early_pfn_to_nid' was not declared. Should it be static? mm/page_alloc.c:5315:59: warning: incorrect type in argument 1 (different base types)
mm/page_alloc.c:5315:59: expected unsigned long [unsigned] [usertype] size
mm/page_alloc.c:5315:59: got restricted gfp_t [usertype] <noident>
...
Is sparse broken, or is that ? Even if it is, should we be working around this somehow? It looks like we've basically crippled sparse in some spots.
---
linux-2.6.git-dave/include/linux/gfp.h | 3 ++- linux-2.6.git-dave/mm/page_alloc.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/gfp.h renamed from include/linux/gfp.h~fix-gfp_h-sparse +2 -1
@@ -249,7 +249,7 @@ static inline enum zone_type gfp_zone(gf z = (GFP_ZONE_TABLE >> (bit *ZONES_SHIFT )) & ((1 <<ZONES_SHIFT ) -1 ); - +/* if (__builtin_constant_p(bit)) BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1); else {
@@ -257,6 +257,7 @@ static inline enum zone_type gfp_zone(gfBUG_ON((GFP_ZONE_BAD >> bit) & 1); #endif } +*/ return z; }
mm/page_alloc.c renamed from mm/page_alloc.c~fix-gfp_h-sparse +1 -0
@@ -5312,6 +5312,7 @@ void *__init alloc_large_system_hash(con*/ if (get_order (size) <MAX_ORDER ) { table =alloc_pages_exact (size,GFP_ATOMIC ); + table =alloc_pages_exact (GFP_ATOMIC , size);kmemleak_alloc (table, size,1 ,GFP_ATOMIC ); } }
_
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 22 lines · On Thu, 14 Apr 2011 08:41:35 -0700 Dave Hansen <[email protected]> wrote:
Running sparse on
page_alloc.ctoday, it errors out:
mm/page_alloc.c:96:5: warning: symbol 'percpu_pagelist_fraction' was not declared. Should it be static?mm/page_alloc.c:175:5: warning: symbol 'min_free_kbytes' was not declared. Should it be static?include/linux/gfp.h:254:17: error: bad constant expressioninclude/linux/gfp.h:254:17: error: cannot size expressionwhich is a line in
gfp_zone():BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1);That's really unfortunate, because it ends up hiding all of the other legitimate sparse messages (like I introduced with the appended patch):
mm/page_alloc.c:96:5: warning: symbol 'percpu_pagelist_fraction' was not declared. Should it be static?mm/page_alloc.c:175:5: warning: symbol 'min_free_kbytes' was not declared. Should it be static?mm/page_alloc.c:3692:15: warning: symbol '__early_pfn_to_nid' was not declared. Should it be static?mm/page_alloc.c:5315:59: warning: incorrect type in argument 1 (different base types)
mm/page_alloc.c:5315:59: expected unsigned long [unsigned] [usertype] size
mm/page_alloc.c:5315:59: got restrictedgfp_t[usertype] <noident>
...
Quoted 3 lines
Is sparse broken, or is that ? Even if it is, should we be working around this somehow? It looks like we've basically crippled sparse in some spots.
Is sparse having conniptions over that monster expression for GFP_ZONE_BAD?
The kernel calls gfp_zone() with a constant arg in very few places. This?
include/linux/gfp.h renamed from include/linux/gfp.h~a +1 -6
@@ -249,14 +249,9 @@ static inline enum zone_type gfp_zone(gf z = (GFP_ZONE_TABLE >> (bit *ZONES_SHIFT )) & ((1 <<ZONES_SHIFT ) -1 ); - -if (__builtin_constant_p (bit)) -BUILD_BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); -else {#ifdef CONFIG_DEBUG_VM -BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); +BUG_ON ((GFP_ZONE_BAD >> bit) &1 );#endif - }return z; }
_
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Andrew Morton
The kernel calls
gfp_zone()with a constant arg in very few places. This?include/linux/gfp.h renamed from include/linux/gfp.h~a +0
-1@@ -249,14 +249,9 @@ static inline enum zone_type gfp_zone(gf z = (GFP_ZONE_TABLE >> (bit *ZONES_SHIFT )) & ((1 <<ZONES_SHIFT ) -1 ); -
include/linux/gfp.h static inline enum zone_type gfp_zone(gf · line 256
Quoted 10 lines
include/linux/gfp.h renamed from include/linux/gfp.h~a +1
-5-if (__builtin_constant_p (bit)) -BUILD_BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); -else {#ifdef CONFIG_DEBUG_VM -BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); +BUG_ON ((GFP_ZONE_BAD >> bit) &1 );#endif - }return z; }
That definitely makes sparse happier. I hope the folks on cc will chime in if they wanted something special at build time.
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Dave Hansen
Quoted 7 lines · Andrew Morton
The kernel calls
gfp_zone()with a constant arg in very few places. This?include/linux/gfp.h renamed from include/linux/gfp.h~a +0
-0@@ -249,14 +249,9 @@ static inline enum zone_type gfp_zone(gf
Quoted 16 lines
include/linux/gfp.h static inline enum zone_type gfp_zone(gf · line 256
Quoted 13 lines
include/linux/gfp.h renamed from include/linux/gfp.h~a +1
-6z = (GFP_ZONE_TABLE >> (bit *ZONES_SHIFT )) & ((1 <<ZONES_SHIFT ) -1 ); - -if (__builtin_constant_p (bit)) -BUILD_BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); -else {#ifdef CONFIG_DEBUG_VM -BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); +BUG_ON ((GFP_ZONE_BAD >> bit) &1 );#endif - }return z; }That definitely makes sparse happier. I hope the folks on cc will chime in if they wanted something special at build time.
You can also remove the #ifdef. Use VM_BUG_ON.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/1 make new gfp.h BUG_ON() in to VM_BUG_ON()
Quoted 1 line · Christoph Lameter
You can also remove the #ifdef. Use
VM_BUG_ON.
Gotcha.
--
This goes on top of
include-linux-gfph-work-around-apparent-sparse-confusion.patch
already in the -mm tree.
VM_BUG_ON() if effectively a BUG_ON() undef #ifdef CONFIG_DEBUG_VM. That is exactly what we have here now, and two different folks have suggested doing it this way.
---
linux-2.6.git-dave/include/linux/gfp.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
include/linux/gfp.h renamed from include/linux/gfp.h~make-gfp_h-BUG_ON-in-too-VM_BUG_ON +1 -3
@@ -249,9 +249,7 @@ static inline enum zone_type gfp_zone(gf z = (GFP_ZONE_TABLE >> (bit *ZONES_SHIFT )) & ((1 <<ZONES_SHIFT ) -1 ); -#ifdef CONFIG_DEBUG_VM -BUG_ON ((GFP_ZONE_BAD >> bit) &1 ); -#endif +VM_BUG_ON ((GFP_ZONE_BAD >> bit) &1 );return z; }
_
-- Dave
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>