Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1391521 > unrolled thread

[PATCH] mm: use unsigned long constant for page flags

Started byYu Zhao <yuzhao@google.com>
First post2016-04-30 01:20 +0200
Last post2016-04-30 01:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mm: use unsigned long constant for page flags Yu Zhao <yuzhao@google.com> - 2016-04-30 01:20 +0200
    Re: [PATCH] mm: use unsigned long constant for page flags Andrew Morton <akpm@linux-foundation.org> - 2016-04-30 01:30 +0200

#1391521 — [PATCH] mm: use unsigned long constant for page flags

FromYu Zhao <yuzhao@google.com>
Date2016-04-30 01:20 +0200
Subject[PATCH] mm: use unsigned long constant for page flags
Message-ID<rtpRw-69r-7@gated-at.bofh.it>
struct page->flags is unsigned long, so when shifting bits we should
use UL suffix to match it.

Found this problem after I added 64-bit CPU specific page flags and
failed to compile the kernel:
  mm/page_alloc.c: In function '__free_one_page':
  mm/page_alloc.c:672:2: error: integer overflow in expression [-Werror=overflow]

Signed-off-by: Yu Zhao <yuzhao@google.com>
---
 include/linux/page-flags.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index f4ed4f1b..3333a5c 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -474,7 +474,7 @@ static inline void ClearPageCompound(struct page *page)
 }
 #endif
 
-#define PG_head_mask ((1L << PG_head))
+#define PG_head_mask ((1UL << PG_head))
 
 #ifdef CONFIG_HUGETLB_PAGE
 int PageHuge(struct page *page);
@@ -643,7 +643,7 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)
 }
 
 #ifdef CONFIG_MMU
-#define __PG_MLOCKED		(1 << PG_mlocked)
+#define __PG_MLOCKED		(1UL << PG_mlocked)
 #else
 #define __PG_MLOCKED		0
 #endif
@@ -653,11 +653,11 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)
  * these flags set.  It they are, there is a problem.
  */
 #define PAGE_FLAGS_CHECK_AT_FREE \
-	(1 << PG_lru	 | 1 << PG_locked    | \
-	 1 << PG_private | 1 << PG_private_2 | \
-	 1 << PG_writeback | 1 << PG_reserved | \
-	 1 << PG_slab	 | 1 << PG_swapcache | 1 << PG_active | \
-	 1 << PG_unevictable | __PG_MLOCKED)
+	(1UL << PG_lru	 | 1UL << PG_locked    | \
+	 1UL << PG_private | 1UL << PG_private_2 | \
+	 1UL << PG_writeback | 1UL << PG_reserved | \
+	 1UL << PG_slab	 | 1UL << PG_swapcache | 1UL << PG_active | \
+	 1UL << PG_unevictable | __PG_MLOCKED)
 
 /*
  * Flags checked when a page is prepped for return by the page allocator.
@@ -668,10 +668,10 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)
  * alloc-free cycle to prevent from reusing the page.
  */
 #define PAGE_FLAGS_CHECK_AT_PREP	\
-	(((1 << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON)
+	(((1UL << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON)
 
 #define PAGE_FLAGS_PRIVATE				\
-	(1 << PG_private | 1 << PG_private_2)
+	(1UL << PG_private | 1UL << PG_private_2)
 /**
  * page_has_private - Determine if page has private stuff
  * @page: The page to be checked
-- 
2.8.0.rc3.226.g39d4020

[toc] | [next] | [standalone]


#1391524

FromAndrew Morton <akpm@linux-foundation.org>
Date2016-04-30 01:30 +0200
Message-ID<rtq1c-6eF-9@gated-at.bofh.it>
In reply to#1391521
On Fri, 29 Apr 2016 16:15:23 -0700 Yu Zhao <yuzhao@google.com> wrote:

> struct page->flags is unsigned long, so when shifting bits we should
> use UL suffix to match it.
> 
> Found this problem after I added 64-bit CPU specific page flags and
> failed to compile the kernel:
>   mm/page_alloc.c: In function '__free_one_page':
>   mm/page_alloc.c:672:2: error: integer overflow in expression [-Werror=overflow]
> 

Fair enough.

> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -474,7 +474,7 @@ static inline void ClearPageCompound(struct page *page)
>  }
>  #endif
>  
> -#define PG_head_mask ((1L << PG_head))
> +#define PG_head_mask ((1UL << PG_head))

We do have the BIT() macro.  I don't think it would add a lot of value
here; I'd be OK with it either way.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web