Received: by 10.192.165.156 with SMTP id m28csp942351imm; Wed, 11 Apr 2018 09:37:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx48kJ7F8hhPxx7XRxw/SdXWchz4ihsKZJ40svHcgKYledMm6FrRqKu+Op0ADRCCoByG0TakL X-Received: by 2002:a17:902:44c:: with SMTP id 70-v6mr5921353ple.354.1523464667932; Wed, 11 Apr 2018 09:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523464667; cv=none; d=google.com; s=arc-20160816; b=RfueBJMUscep8iCDZFY7GrjRYuvpr4nITNyDtSpXo2syDZq5EiESgLp3kK43P1nObk F1bEZ9V2c8rSkeAbxL2LcgTUNx9F7KunMjCO6O/OfxccEuZtLN7rCWre1fdjtmy3Az0T flc/lCPKlZNf2peuegy9pobdLXUrAZp3RieZediK1izka05DHVmlhqnHFPofLkB60gQ/ wztchCnmmIWgqdzN2C6cFce1+Bex61n0tsCYWMVhPf5QEuLxjXOXUr5gcoqu1xsY3aVX iL+Sx37Zx7oCHZp4a/R+JWvxPY58AXuRVN16VlUNO/Xnpu+x7tNDpucBFeUooboli7Nb UmKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=wW0Jvx3YGLvXBmLQdWB5Nj2PnzQ4UNVi40W/j3X0YPw=; b=Iv30Lnja0pPTZn8vmWbOvnv+eoF9sPvbc360KmxSVs114c3tro9XJjbmMVao4pmF+A yWmp4AQMjNZnHOff0iakZzC8pbmInGuGH69zsanE6WkM0IK5FM+Xm5VocR6bhyGcLlnN hTvMXIdWfMmoyhmDunw4HmpkIYAiTw84DqU+bTCsLUCRPxKR3HcS+0BFNU/57qt1Th5Y KYZTN1FdKhOqPkE0LgkuAxRd0GL6a1s0e8LJVDNL/0M63WsOzsEu+52ENBS7FGeMz6q2 Dba8aSe/dfzyFgmUBed4OlJgqlK1S7IiPodJun4BiXPGL+bY4Q/32IAFtNCtdtvUoOz/ Eh+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si1098394pff.301.2018.04.11.09.37.10; Wed, 11 Apr 2018 09:37:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754063AbeDKQaD (ORCPT + 99 others); Wed, 11 Apr 2018 12:30:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45996 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753090AbeDKQaB (ORCPT ); Wed, 11 Apr 2018 12:30:01 -0400 Received: from localhost.localdomain (c-24-4-125-7.hsd1.ca.comcast.net [24.4.125.7]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9F6DBD7C; Wed, 11 Apr 2018 16:30:00 +0000 (UTC) Date: Wed, 11 Apr 2018 09:29:59 -0700 From: Andrew Morton To: Peter Zijlstra Cc: Joe Perches , "Rafael J. Wysocki" , Andy Whitcroft , yuankuiz@codeaurora.org, Linux PM , "Rafael J. Wysocki" , Frederic Weisbecker , Thomas Gleixner , paulmck@linux.vnet.ibm.com, Ingo Molnar , Len Brown , Linux Kernel Mailing List Subject: Re: [PATCH] checkpatch: Add a --strict test for structs with bool member definitions Message-Id: <20180411092959.e666ec443e4d3bb6f43901d7@linux-foundation.org> In-Reply-To: <20180411081502.GJ4082@hirez.programming.kicks-ass.net> References: <891d4f632fbff5052e11f2d0b6fac35d@codeaurora.org> <20180410123305.GF4082@hirez.programming.kicks-ass.net> <95477c93db187bab6da8a8ba7c57836868446179.camel@perches.com> <20180410143950.4b8526073b4e3e34689f68cb@linux-foundation.org> <20180410150011.df9e036f57b5bcac7ac19686@linux-foundation.org> <20180411081502.GJ4082@hirez.programming.kicks-ass.net> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Apr 2018 10:15:02 +0200 Peter Zijlstra wrote: > On Tue, Apr 10, 2018 at 03:00:11PM -0700, Andrew Morton wrote: > > On Tue, 10 Apr 2018 14:53:51 -0700 Joe Perches wrote: > > > > > On Tue, 2018-04-10 at 14:39 -0700, Andrew Morton wrote: > > > > On Tue, 10 Apr 2018 11:19:54 -0700 Joe Perches wrote: > > > > > > > > > A struct with a bool member can have different sizes on various > > > > > architectures because neither bool size nor alignment is standardized. > > > > > > > > What's wrong with bools in structs? > > > > > > See above. > > > > Yeah, but so what? `long' has different sizes on different > > architectures too. > > Right, so we have ILP32/LP64 for all our 32/64 bit archs respectively. > So only 2 possible variations to consider, and if you know your bitness > you know your layout. > > (+- some really unfortunate alignment exceptions, the worst of which > Arnd recently removed, hooray!) > > But neither says anything about sizeof(_Bool), and the standard leaves > it undefined and only mandates it is large enough to store either 0 or > 1 (and I suspect this vagueness is because there are architectures that > either have no byte addressibility or it's more expensive than word > addressibility). > > Typically GCC chooses a single byte to represent _Bool, but there are no > guarantees. This means that when you care about structure layout (as we > all really should) things go wobbly when you use _Bool. > > If GCC were to guarantee a 1 byte _Bool for all Linux ABIs we could > reconsider. OK. I guess. But I'm not really seeing some snappy description which helps people understand why checkpatch is warning about this. We already have some 500 bools-in-structs and the owners of that code will be wondering whether they should change them, and whether they should apply those remove-bool-in-struct patches which someone sent them. So... can we please get some clarity here? ... (ooh, https://lkml.org/lkml/2017/11/21/384 is working this morning) hm, Linus suggests that instead of using bool mybool; we should use unsigned mybool:1; However that introduces the risk that alterations of mybool will use nonatomic rmw operations. unsigned myboolA:1; unsigned myboolB:1; so foo->myboolA = 1; could scribble on concurrent alterations of foo->myboolB. I think. I guess that risk is also present if myboolA and myboolB were `bool', too. The compiler could do any old thing with them including, perhaps, using a single-bit bitfield(?).