lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110205090451.GA2315@cmpxchg.org>
Date:	Sat, 5 Feb 2011 10:04:51 +0100
From:	Johannes Weiner <hannes@...xchg.org>
To:	Randy Dunlap <randy.dunlap@...cle.com>
Cc:	linux-kernel@...r.kernel.org, akpm@...ux-foundation.org,
	linux-mm@...ck.org, linux-fsdevel@...r.kernel.org
Subject: [patch fixup] memcg: remove direct page_cgroup-to-page pointer fix

On Fri, Feb 04, 2011 at 06:38:10PM -0800, Randy Dunlap wrote:
> On Fri, 04 Feb 2011 15:15:17 -0800 akpm@...ux-foundation.org wrote:
> 
> > The mm-of-the-moment snapshot 2011-02-04-15-15 has been uploaded to
> > 
> >    http://userweb.kernel.org/~akpm/mmotm/
> > 
> > and will soon be available at
> > 
> >    git://zen-kernel.org/kernel/mmotm.git
> > 
> > It contains the following patches against 2.6.38-rc3:
> 
> 
> Lots of these warnings in some kernel configs:
> 
> mmotm-2011-0204-1515/include/linux/page_cgroup.h:144: warning: left shift count >= width of type
> mmotm-2011-0204-1515/include/linux/page_cgroup.h:145: warning: left shift count >= width of type
> mmotm-2011-0204-1515/include/linux/page_cgroup.h:150: warning: right shift count >= width of type

Thanks for the report, Randy, and sorry for the breakage.  Here is the
fixup:

---
Since the non-flags field for pc array ids in pc->flags is offset from
the end of the word, we end up with a shift count of BITS_PER_LONG in
case the field width is zero.

This results in a compiler warning as we shift in both directions a
long int by BITS_PER_LONG.

There is no real harm -- the mask is zero -- but fix up the compiler
warning by also making the shift count zero for a non-existant field.

Reported-by: Randy Dunlap <randy.dunlap@...cle.com>
Signed-off-by: Johannes Weiner <hannes@...xchg.org>
---

diff --git a/include/linux/page_cgroup.h b/include/linux/page_cgroup.h
index 05d8618..f5de21d 100644
--- a/include/linux/page_cgroup.h
+++ b/include/linux/page_cgroup.h
@@ -123,31 +123,36 @@ static inline void move_unlock_page_cgroup(struct page_cgroup *pc,
 }
 
 #ifdef CONFIG_SPARSEMEM
-#define PCG_ARRAYID_SHIFT	SECTIONS_SHIFT
+#define PCG_ARRAYID_WIDTH	SECTIONS_SHIFT
 #else
-#define PCG_ARRAYID_SHIFT	NODES_SHIFT
+#define PCG_ARRAYID_WIDTH	NODES_SHIFT
 #endif
 
-#if (PCG_ARRAYID_SHIFT > BITS_PER_LONG - NR_PCG_FLAGS)
+#if (PCG_ARRAYID_WIDTH > BITS_PER_LONG - NR_PCG_FLAGS)
 #error Not enough space left in pc->flags to store page_cgroup array IDs
 #endif
 
 /* pc->flags: ARRAY-ID | FLAGS */
 
-#define PCG_ARRAYID_MASK	((1UL << PCG_ARRAYID_SHIFT) - 1)
+#define PCG_ARRAYID_MASK	((1UL << PCG_ARRAYID_WIDTH) - 1)
 
-#define PCG_ARRAYID_OFFSET	(sizeof(unsigned long) * 8 - PCG_ARRAYID_SHIFT)
+#define PCG_ARRAYID_OFFSET	(BITS_PER_LONG - PCG_ARRAYID_WIDTH)
+/*
+ * Zero the shift count for non-existant fields, to prevent compiler
+ * warnings and ensure references are optimized away.
+ */
+#define PCG_ARRAYID_SHIFT	(PCG_ARRAYID_OFFSET * (PCG_ARRAYID_WIDTH != 0))
 
 static inline void set_page_cgroup_array_id(struct page_cgroup *pc,
 					    unsigned long id)
 {
-	pc->flags &= ~(PCG_ARRAYID_MASK << PCG_ARRAYID_OFFSET);
-	pc->flags |= (id & PCG_ARRAYID_MASK) << PCG_ARRAYID_OFFSET;
+	pc->flags &= ~(PCG_ARRAYID_MASK << PCG_ARRAYID_SHIFT);
+	pc->flags |= (id & PCG_ARRAYID_MASK) << PCG_ARRAYID_SHIFT;
 }
 
 static inline unsigned long page_cgroup_array_id(struct page_cgroup *pc)
 {
-	return (pc->flags >> PCG_ARRAYID_OFFSET) & PCG_ARRAYID_MASK;
+	return (pc->flags >> PCG_ARRAYID_SHIFT) & PCG_ARRAYID_MASK;
 }
 
 #else /* CONFIG_CGROUP_MEM_RES_CTLR */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ