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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,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 6D746C433DB for ; Thu, 7 Jan 2021 17:28:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFEB7233FB for ; Thu, 7 Jan 2021 17:28:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFEB7233FB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D0A9A8D013C; Thu, 7 Jan 2021 12:28:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB9A08D013A; Thu, 7 Jan 2021 12:28:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCF658D013C; Thu, 7 Jan 2021 12:28:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id A5C1F8D013A for ; Thu, 7 Jan 2021 12:28:32 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5ADC9180AD811 for ; Thu, 7 Jan 2021 17:28:32 +0000 (UTC) X-FDA: 77679663264.25.duck90_080f0a1274ec Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 31D821804E3A8 for ; Thu, 7 Jan 2021 17:28:32 +0000 (UTC) X-HE-Tag: duck90_080f0a1274ec X-Filterd-Recvd-Size: 3182 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Jan 2021 17:28:31 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 37078AD26; Thu, 7 Jan 2021 17:28:30 +0000 (UTC) To: Hugh Dickins , Andrea Arcangeli Cc: Andrew Morton , Alex Shi , Minchan Kim , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1607743586-80303-1-git-send-email-alex.shi@linux.alibaba.com> <1607743586-80303-2-git-send-email-alex.shi@linux.alibaba.com> <20210106114620.5c221690f3a9cad7afcc3077@linux-foundation.org> From: Vlastimil Babka Subject: Re: [PATCH] mm/mmap: replace if (cond) BUG() with BUG_ON() Message-ID: Date: Thu, 7 Jan 2021 18:28:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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 1/6/21 9:18 PM, Hugh Dickins wrote: > On Wed, 6 Jan 2021, Andrea Arcangeli wrote: >>=20 >> I'd be surprised if the kernel can boot with BUG_ON() defined as "do >> {}while(0)" so I guess it doesn't make any difference. >=20 > I had been afraid of that too, when CONFIG_BUG is not set: > but I think it's actually "if (cond) do {} while (0)". It's a maze of configs and arch-specific vs generic headers, but I do see= this in include/asm-generic/bug.h: #else /* !CONFIG_BUG */ #ifndef HAVE_ARCH_BUG #define BUG() do {} while (1) #endif So seems to me there *are* configurations possible where side-effects are= indeed thrown away, right? WARN_ON is different as the result of the "inner" condition should be fur= ther usable for constructing "outer" conditions: (still in !CONFIG_BUG section) #ifndef HAVE_ARCH_WARN_ON #define WARN_ON(condition) ({ int __ret_warn_on =3D !!(condition); unlikely(__ret_warn_on); }) #endif For completeness let's look at our own extensions when VM_DEBUG is disabl= ed, which is quite analogical to disabling CONFIG_BUG and thus it should bett= er be consistent with the generic stuff. #define VM_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond) where BUILD_BUG_ON_INVALID generates no code, so it's consistent with BUG= _ON() and !CONFIG_BUG. #define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond) ... well that's not consistent with WARN_ON. Hmm if you have asked me bef= ore I checked, I would have said that it is, that I checked it already in the p= ast and/or there was some discussion already about it. Memory is failing me i= t seems. We should better fix this?