Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp830966oof; Tue, 25 Sep 2018 05:21:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV63QO6wUasTcsdYrR4SwCJeEnwF9zw0nW5f1xurls0H2J2ZP+9Lx6bOFt1XSUoo8mKwpDC+t X-Received: by 2002:a17:902:bf0c:: with SMTP id bi12-v6mr911124plb.219.1537878098997; Tue, 25 Sep 2018 05:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537878098; cv=none; d=google.com; s=arc-20160816; b=gEY2YYEs2XAsDTCjgU//3QgRDfu1Lsz1jPr+MH/+PFxeqNSaX1p7VT0dDJLhDujP9e wL6X0TpLV6j63VSVj5vrCS++RyqJHZiEVSMfcN7BzzP+hksAbPPCsB4bKc6zeMp2rOSY 2SMHGFTvPuV/hogeZfWnvvOiAlD8V+x91A7I/7/B15KaQA5PNX4zt8IUDmsXsv8M34+Z sSdidndaNOtqSG1k3NKtwGTk/JZelG1k0mDj73coy33wRL4Ds8JA5qiMS3MlysIvuVOg yU6W2EAuewUc9O37E6Eftn/TB4C3eCE/fQAgmdJTkbCejx7MGK9x6YobfVvti6L0hxEm DDLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=uPYLk6GOCCtoBhi7DSNYHbXcG0cbNWlpGuBf+mxCJI8=; b=AMUh/3o+4vl7L/SCtsvBLq8E60wC0/sxThm+JM80Vm44VLR3zETPE69i26C8kGzXA8 KpLYpgPeELLj62ycdNYPZk39qbfJZXb4hGtfZ8UXlucdlJxSEfPHKK1id7rIOexnQvkT GQ/Jk/pI0uxLKyMbEMCl4MQgl85ZkNLzwCCBC3hDQlTqmtoy0BXZIMjFz6JuvuiXsWHf GOfrQsPtnDf1ceRbGLsSUVH74Hg5jadCW1dlpA5VlDXUo67TJ8qXhPRYfhKZH9qpCurM W6vVCy8Jgd82ugR46Sg2IoOwkg7+IXl4vfAjLWVllXq0fYQ2kOiuuM00aSZwLmbOJRzC M5kA== 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 r20-v6si2281752pgk.207.2018.09.25.05.21.23; Tue, 25 Sep 2018 05:21:38 -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 S1729088AbeIYS21 (ORCPT + 99 others); Tue, 25 Sep 2018 14:28:27 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45683 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727617AbeIYS20 (ORCPT ); Tue, 25 Sep 2018 14:28:26 -0400 Received: by mail-lf1-f65.google.com with SMTP id m80-v6so9242110lfi.12; Tue, 25 Sep 2018 05:21:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uPYLk6GOCCtoBhi7DSNYHbXcG0cbNWlpGuBf+mxCJI8=; b=ObrKUJ2ZkFu3dKl0dU3JtRX9sEtoZY52S4bMJH0hqr1ZEYbgutx/ErB11OvLSVMz3c C8CuoaWP9FhZbS7Tg0i01VwGcH0fXv29ZQBxTrkZGqlzK0EfjvemKguHygBPD8CZ4rV1 e00f/4zhF4RbJEyd/nH5sSTFwVZb9T7jTQIepP4QTIxMXym/U0Qi7wek2BuL4tXUgdx7 bh1cYUWJFiLl7Mb+b+X5i+Thldys33Bie6NlgPbFJ9d/sWTBUkJK68PFICZPI7j91Rhz /0QCprDcapin3YOzrI8VJQJ+bg0893jWzV9AHqPx0Di8ODYyUKCzeShuCXRjxK2MGOzq /JcQ== X-Gm-Message-State: ABuFfoiRgLXdcFr9I1unrF0zX87lfdTT9BzemAvSB7wCG2ptOh9nZbP0 R18R9IcYLSPQmhXZHZzAvOnyvV/OkYd9d9LhABP39g== X-Received: by 2002:a19:a854:: with SMTP id r81-v6mr639031lfe.70.1537878066394; Tue, 25 Sep 2018 05:21:06 -0700 (PDT) MIME-Version: 1.0 References: <9516e4b3-f9f2-b150-f019-8b1ef465efb3@tu-dortmund.de> <649d3c5c-3d96-0ed3-cd4d-57641f0ee614@tu-dortmund.de> In-Reply-To: <649d3c5c-3d96-0ed3-cd4d-57641f0ee614@tu-dortmund.de> From: Arnd Bergmann Date: Tue, 25 Sep 2018 14:20:49 +0200 Message-ID: Subject: Re: [x86] BUG()/BUG_ON() macros cannot be disabled To: alexander.lochmann@tu-dortmund.de Cc: linux-arch , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 25, 2018 at 2:13 PM Alexander Lochmann wrote: > > > > Am 25.09.2018 um 14:06 schrieb Arnd Bergmann: > > On Tue, Sep 25, 2018 at 1:35 PM Alexander Lochmann > > wrote: > >> > >> Hi Arnd, > >> > >> I recently tried to disable the BUG macros on x86-32. I disabled the > >> config item in 'General Setup -> Configure standard kernel features > >> (expert users) -> BUG() support'. > >> However, BUG/BUG_ON is still defined. In the !CONFIG_BUG branch in > >> include/asm-generic/bug.h (line 181) the code checks for the existence > >> of architecture-specific variants of those macros. > >> Since x86 defines its own version of BUG(), line 182 is *not* used. > >> In the following, the x86 variant of BUG() is then used to define the > >> BUG_ON() macro. > >> > >> I propose a patch that really disables both macros if the developer > >> wants it. > >> It undefines the respective x86 variants, and defines both macros as > >> 'empty' macros. > > > > Maybe we should update the documentation instead. Note that the > > generic version is using 'while (1)' rather than 'while (0)', so this is > > not an empty macro but rather one that does more than the > > arch-specific one-instruction version does. > > > > We don't really want an empty macro any more, this was used in > > the past, but causes compile-time warnings and undefined behavior > > for no good reason > I see. So the documentation of the CONFIG_BUG option is wrong? > It currently states that 'Disabling this option eliminates support for > BUG and WARN'. > Is the current implemention (an endless loop) desired behavior? I think it's the most reasonable implementation, otherwise a function like int something(void) { if (x) return 0; else BUG(); } will return an uninitialized value. The arch specific implementations usually just contain a trapping instruction. With CONFIG_BUG() you get a nice console output that indicates where this happened, but without CONFIG_BUG(), this is just reported as an invalid instruction (if CONFIG_PRINTK is still enabled), killing the current process. Arnd