Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4144913ybi; Mon, 29 Jul 2019 20:14:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlo81NSJmP6ftxvsQy+mo6OaW5uDrbu0jU8NUg/eez/uoPi+DXvYLsy/7FnAFyTiVUDUel X-Received: by 2002:a63:b555:: with SMTP id u21mr108870601pgo.222.1564456454897; Mon, 29 Jul 2019 20:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564456454; cv=none; d=google.com; s=arc-20160816; b=Fb1DZfz1fTFZFpgScwujyVqlvzc1rUj9fhLb+7tRTYbw1TFTGjtBDcFaZ7e3DCIPom TconJhkTwEucaDZW82/D4e4qrh9Acgu5QKW+bs/xNhtn4Jipa0NcyLk+xvRE/hf8Uxgl sXR6oLE6nKmn9BcFmtIr8PqrJrXJ6jTjTUbjr7Te2jJ8pE/EvvMEu1rW+bdN+rqoz6xS dV5c+uiozyWJy0kIZrdX5J61pm1IrX43HiF/UjkQsw8AiO14Bp4QcP0HbupBWrXMNtq5 LTv2mHadKxLfR9rnt2e+OhK3r0/6c/PoMXL1TbdLqe87nul0QZ4+HCImXfIJ9ufPdKwF e5rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=4oV050ZrNhNijgFD5hLERQzypXWVcBOfEhocbjHaMPs=; b=JUYjY3iw3sRTx1OFVFcMV9wOlnpojP25alWrOH3JNP+m+D/cUFj5WwYY8qzyRENMwC Nq2hOoWMD8IiM1cis2CZjvjwLnKdwb1A0qBSrrRMqxgKKTE7G86VKSeXyp4SiCfesOnN 5Rt2x+oz2YQXNlCTKqm+YHBQm3h1j3shMs51nX+wUUgkAumfOxhhFxZhNKf5V0t8OK5J DnL5pGbVCJ2ArRwGJy/azgGuyBpXANHuGMWJH88I5xuu7Id1hV9xwaEBnI0/DPKUKWQ8 U3CIZredWAn6Mdjz6OVrJAQh3ctzSEqdijcowxZKiAflyDReHdy1f2cMHEJzyAzed432 sAVQ== 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 n61si25999279pjb.20.2019.07.29.20.13.59; Mon, 29 Jul 2019 20:14:14 -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 S1729220AbfG2WQt (ORCPT + 99 others); Mon, 29 Jul 2019 18:16:49 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:45984 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726869AbfG2WQs (ORCPT ); Mon, 29 Jul 2019 18:16:48 -0400 Received: (from localhost user: 'macro', uid#1010) by eddie.linux-mips.org with ESMTP id S23992779AbfG2WQpdRPci (ORCPT + 1 other); Tue, 30 Jul 2019 00:16:45 +0200 Date: Mon, 29 Jul 2019 23:16:45 +0100 (BST) From: "Maciej W. Rozycki" To: Nick Desaulniers cc: Ralf Baechle , Paul Burton , James Hogan , Nathan Chancellor , Eli Friedman , Hassan Naveed , Stephen Kitt , Serge Semin , Mike Rapoport , Andrew Morton , Michal Hocko , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] mips: avoid explicit UB in assignment of mips_io_port_base In-Reply-To: <20190729211014.39333-1-ndesaulniers@google.com> Message-ID: References: <20190729211014.39333-1-ndesaulniers@google.com> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 Jul 2019, Nick Desaulniers wrote: > The code in question is modifying a variable declared const through > pointer manipulation. Such code is explicitly undefined behavior, and > is the lone issue preventing malta_defconfig from booting when built > with Clang: > > If an attempt is made to modify an object defined with a const-qualified > type through use of an lvalue with non-const-qualified type, the > behavior is undefined. > > LLVM is removing such assignments. A simple fix is to not declare > variables const that you plan on modifying. Limiting the scope would be > a better method of preventing unwanted writes to such a variable. > > Further, the code in question mentions "compiler bugs" without any links > to bug reports, so it is difficult to know if the issue is resolved in > GCC. The patch was authored in 2006, which would have been GCC 4.0.3 or > 4.1.1. The minimal supported version of GCC in the Linux kernel is > currently 4.6. It's somewhat older than that. My investigation points to: commit c94e57dcd61d661749d53ee876ab265883b0a103 Author: Ralf Baechle Date: Sun Nov 25 09:25:53 2001 +0000 Cleanup of include/asm-mips/io.h. Now looks neat and harmless. However the purpose of the arrangement does not appear to me to be particularly specific to a compiler version. > For what its worth, there was UB before the commit in question, it just > added a barrier and got lucky IRT codegen. I don't think there's any > actual compiler bugs related, just runtime bugs due to UB. Does your solution preserves the original purpose of the hack though as documented in the comment you propose to be removed? Clearly it was defined enough to work for almost 18 years, so it would be good to keep the optimisation functionally by using different means that do not rely on UB. This variable is assigned at most once throughout the life of the kernel and then early on, so considering it r/w with all the consequences for all accesses does not appear to me to be a good use of it. Maybe a piece of inline asm to hide the initialisation or suchlike then? Maciej