From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1AB1C433E0 for ; Thu, 21 Jan 2021 21:28:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 340BE23A5B for ; Thu, 21 Jan 2021 21:28:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 340BE23A5B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 963466B0006; Thu, 21 Jan 2021 16:28:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EC8E6B0007; Thu, 21 Jan 2021 16:28:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 765656B0008; Thu, 21 Jan 2021 16:28:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 5CCE16B0006 for ; Thu, 21 Jan 2021 16:28:40 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0299E180ACF75 for ; Thu, 21 Jan 2021 21:28:40 +0000 (UTC) X-FDA: 77731071600.04.smell84_5b050a327566 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id C9D6E8019AA6 for ; Thu, 21 Jan 2021 21:28:39 +0000 (UTC) X-HE-Tag: smell84_5b050a327566 X-Filterd-Recvd-Size: 4584 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 21:28:39 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 0311623A53; Thu, 21 Jan 2021 21:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611264518; bh=Dd1W9bCeOuqQQTWgQKKjURvCvrcjupnyMPuQIYgLAi8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kwi1tgKNlVNM/FF/m5oTJAgGIXLi5xbGLLa/ACf5QQj8ztMOuzklYEmWRnE/74HJ7 LNn/REQ4/tO1id5izd309fpe+HOqBBdejgqiBZwtnTTUkIOlo/Zx45sGObLk4UjIMA C9Uaehs8Yi5cylTIwnpPo0NAw8mtqKDaCu6XaU1ncdu67byAoMPiirzfYToqSSckSX 8Z9InGZgbG37RHpkegkpqkdJ9KJBmA4F7c/pjSYvwNQGj6hDYRGqkjrOzY1Ecx1TdA uAeDhL6GEtaaoZ1UeHruQQxxMgiQ5lX89wDAwD7OPR8IeM3EmGYB9rEznjWR96T1a/ muxSRNkN6tNRQ== Date: Thu, 21 Jan 2021 21:28:32 +0000 From: Will Deacon To: Nick Desaulniers Cc: Linus Torvalds , Luc Van Oostenryck , LKML , Linux Memory Management List , Linux ARM , Catalin Marinas , Jan Kara , Minchan Kim , Andrew Morton , "Kirill A . Shutemov" , Vinayak Menon , Hugh Dickins , kernel-team Subject: Re: [PATCH v4 8/8] mm: Mark anonymous struct field of 'struct vm_fault' as 'const' Message-ID: <20210121212832.GA23234@willie-the-truck> References: <20210120173612.20913-1-will@kernel.org> <20210120173612.20913-9-will@kernel.org> <20210121131101.GD22123@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jan 21, 2021 at 11:24:36AM -0800, Nick Desaulniers wrote: > On Thu, Jan 21, 2021 at 5:11 AM Will Deacon wrote: > > > > On Wed, Jan 20, 2021 at 11:02:06AM -0800, Linus Torvalds wrote: > > > On Wed, Jan 20, 2021 at 10:27 AM Nick Desaulniers > > > wrote: > > > > > > > > Is there a difference between: [ const unnamed struct and individual const members ] > > > > > > Semantically? No. > > > > > > Syntactically the "group the const members together" is a lot cleaner, > > > imho. Not just from a "just a single const" standpoint, but from a > > > "code as documentation" standpoint. > > > > > > But I guess to avoid the clang issue, we could do the "mark individual > > > fields" thing. > > > > I'd prefer to wait until the bug against LLVM has been resolved before we > > try to work around anything. Although I couldn't find any other examples > > like this in the kernel, requiring all of the member fields to be marked as > > 'const' still feels pretty fragile to me; it's only a matter of time before > > new non-const fields get added, at which point the temptation for developers > > to remove 'const' from other fields when it gets in the way is pretty high. > > What's to stop a new non-const field from getting added outside the > const qualified anonymous struct? > What's to stop someone from removing const from the anonymous struct? > What's to stop a number of callers from manipulating the structure > temporarily before restoring it when returning by casting away the > const? > > Code review. Sure, but here we are cleaning up this stuff, so I think review only gets you so far. To me: const struct { int foo; long bar; }; clearly says "don't modify fields of this struct", whereas: struct { const int foo; const long bar; }; says "don't modify foo or bar, but add whatever you like on the end" and that's the slippery slope. So then we end up with the eye-sore of: const struct { const int foo; const long bar; }; and maybe that's the right answer, but I'm just saying we should wait for clang to make up its mind first. It's not like this is a functional problem, and there are enough GCC users around that we're not exactly in a hurry. Will