From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753199AbcHWSm0 (ORCPT ); Tue, 23 Aug 2016 14:42:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41404 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751187AbcHWSmY (ORCPT ); Tue, 23 Aug 2016 14:42:24 -0400 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: paulmck@linux.vnet.ibm.com Date: Tue, 23 Aug 2016 07:23:26 -0700 From: "Paul E. McKenney" To: Geert Uytterhoeven Cc: Steven Rostedt , Peter Zijlstra , Eric Dumazet , LKML , Ingo Molnar , jiangshanlai@gmail.com, dipankar@in.ibm.com, Andrew Morton , Mathieu Desnoyers , Josh Triplett , Thomas Gleixner , David Howells , Darren Hart , =?iso-8859-1?Q?Fr=E9d=E9ric?= Weisbecker , Oleg Nesterov , pranith kumar , Greg Ungerer Subject: Re: [PATCH tip/core/rcu 2/2] documentation: Record reason for rcu_head two-byte alignment Reply-To: paulmck@linux.vnet.ibm.com References: <20160822173453.GF3482@linux.vnet.ibm.com> <20160822185609.GK10153@twins.programming.kicks-ass.net> <20160822151854.175dfea8@grimm.local.home> <20160822195445.GO3482@linux.vnet.ibm.com> <20160822211606.GU3482@linux.vnet.ibm.com> <20160823134314.GE3482@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16082314-0024-0000-0000-000014638421 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005634; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000183; SDB=6.00748575; UDB=6.00353310; IPR=6.00521240; BA=6.00004672; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012435; XFM=3.00000011; UTC=2016-08-23 14:23:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16082314-0025-0000-0000-000043CF58A8 Message-Id: <20160823142326.GF3482@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-08-23_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608230144 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 23, 2016 at 03:45:51PM +0200, Geert Uytterhoeven wrote: > Hi Paul, > > On Tue, Aug 23, 2016 at 3:43 PM, Paul E. McKenney > wrote: > > On Tue, Aug 23, 2016 at 08:39:18AM +0200, Geert Uytterhoeven wrote: > >> On Mon, Aug 22, 2016 at 11:16 PM, Paul E. McKenney > >> wrote: > >> > On Mon, Aug 22, 2016 at 10:48:57PM +0200, Geert Uytterhoeven wrote: > >> >> On Mon, Aug 22, 2016 at 9:54 PM, Paul E. McKenney > >> >> wrote: > >> >> > On Mon, Aug 22, 2016 at 03:18:54PM -0400, Steven Rostedt wrote: > >> >> >> On Mon, 22 Aug 2016 20:56:09 +0200 > >> >> >> Peter Zijlstra wrote: > >> >> >> > >> >> >> > > Don't we have __alignof__(void *) to avoid #ifdef CONFIG_M68K and > >> >> >> > > other new macros ? > >> >> > > >> >> > Hmmm... Does __alignof__(void *) give two-byte alignment on m68k, > >> >> > allowing something like this? Heh!!! It is already there. ;-) > >> >> > > >> >> > struct callback_head { > >> >> > struct callback_head *next; > >> >> > void (*func)(struct callback_head *head); > >> >> > } __attribute__((aligned(sizeof(void *)))); > >> >> > >> >> No, it's aligning to sizeof(void *) (4 on m68k), not __alignof__(void *). > >> > > >> > Right you are. Commit 720abae3d68ae from Kirill A. Shutemov in November > >> > 2015. > >> > > >> > Given that you haven't complained, I am guessing that this works for you. > >> > If so, I can make the __call_rcu() WARN_ON() more strict. > >> > Again, does the current state work for you? > > >> Yes it does. See also your commit 1146edcbef378922 ("rcu: Loosen __call_rcu()'s > >> rcu_head alignment constraint"). > > > > Understood! > > > > But given that all architectures now provide at least four-byte alignment > > for the rcu_head structure, isn't it now OK for me to tighten up __call_rcu()'s > > check, for example, to this? > > > > WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1)); > > Yes, I agree with that. Very good, I have queued the following patch. Thanx, Paul ------------------------------------------------------------------------ commit 89d39c83d193733ed5fff1c480cd42c9de1da404 Author: Paul E. McKenney Date: Tue Aug 23 06:51:47 2016 -0700 rcu: Tighted up __call_rcu() rcu_head alignment check Commit 720abae3d68ae ("rcu: force alignment on struct callback_head/rcu_head") forced the rcu_head (AKA callback_head) structure's alignment to pointer size, that is, to 4-byte boundaries on 32-bit systems and to 8-byte boundaries on 64-bit systems. This commit therefore checks for this same alignment in __call_rcu(), which used to check for two-byte alignment. Signed-off-by: Paul E. McKenney Cc: Geert Uytterhoeven Cc: Kirill A. Shutemov diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 3a8eec3ba1bd..673bcb3934a3 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3122,7 +3122,9 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func, unsigned long flags; struct rcu_data *rdp; - WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */ + /* Misaligned rcu_head! */ + WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1)); + if (debug_rcu_head_queue(head)) { /* Probable double call_rcu(), so leak the callback. */ WRITE_ONCE(head->func, rcu_leak_callback);