Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3868988ybi; Mon, 29 Jul 2019 14:16:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqz83aPppPFCHyM4wRAlZ06apAh33AFMseJz5Rfp5wkVUHweIC5wMjhMalRa24KCSfAz/eac X-Received: by 2002:a17:90a:19c2:: with SMTP id 2mr109843978pjj.13.1564434977091; Mon, 29 Jul 2019 14:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564434977; cv=none; d=google.com; s=arc-20160816; b=GIQTNYdUCSNOtDvMdFXUoUtKY/CU0M8MwEN9qftWswPqbp7XmHewvLgjW58I1l6lFL 7F2b9FwVpshGi5dKepoiQ/15cz6F8zvggwD22BXAZh9r6C1yXFR9wp+XmGcvSxanq56u en44Bp/YhMIITUnOSHhrjnLHNZnydiU2/peEozeB3qm+JCd72wskg+K9MK02dStPT++S HpCvx27BB98B3GehdJFHW/1PWF/zEZIeqfflP6anYL/MYVQ9gFjmZ56SKO8uPqbx9a30 UwTBOkmIM6fT6y9e+E3+Qx96+TMgsKRNJridLpmJM8KF56aa6sqvwLwzMBUELf3CLmNJ sE9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=A5FSwkiZuOd2qVcx76ksBBkSMhb0oMJooHYS8KoQW0U=; b=lfpApu7tdjxQ//OO1nIGTU336zIpvsLKHd77l1liNq8LAlpKF0WOHMwcHHT5GcmgzI clA5VYW1IGVfqr8w9WTtFf6zhr6VS5pQVSUUM7ZXqe1AnKvP6Ig/wBTpEWC5c8H9wiWq WbdclsbUMEzTxaIZFWRWbTgwk9QuwNKV0KgI26+mpse5g1alxQfVYPLd3NDUIvPtblQt kJb0bP242oPYDkW2jRLWgc5ecJqTIRdDwYcxbcpoTV7se4SCG9oYiV3MlcGLoGOVwROf 5z6hvJCLg9ULXDpg95VR3fK3RiU/N17sgtZloIrIVyEyr+ZACqzPifQ5Vjr45hXXYEti R+Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=APHVrMA7; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k186si27092555pgd.229.2019.07.29.14.16.02; Mon, 29 Jul 2019 14:16:17 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=APHVrMA7; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388627AbfG2VPR (ORCPT + 99 others); Mon, 29 Jul 2019 17:15:17 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41226 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388613AbfG2VPP (ORCPT ); Mon, 29 Jul 2019 17:15:15 -0400 Received: by mail-wr1-f68.google.com with SMTP id c2so60166214wrm.8; Mon, 29 Jul 2019 14:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=A5FSwkiZuOd2qVcx76ksBBkSMhb0oMJooHYS8KoQW0U=; b=APHVrMA7CyunmcDO/kR4Hlr4F3cviT/0NhU0qTv+4KhGVlwpuxy3XFaZqE9iVlmSfF Fgpy9d+Y0bRjOfNq1LzMtpWvrcjTFU2PnZukyWUykaBiznzt/B0B5kohs555aKXgvBfj slVRQBfzaJp0aAbGvpGcCVXW3cwNhnp+H57BLw45h8GvmSJcqmIKHKtCcgiIZtHuxbzm ECzpSZTKT8WW7SgMpf3DLAi9pVBoXe7Iu0rWZHEuhv60BvbApcIKxbE4fxJDKYEXyFd3 zUdd+vrY0NOUV0+S8eKwOYpS2QrNuzGjxC8ZKEuKEDPx5EAyKADZXkYknrJxao3PiHWr G0DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=A5FSwkiZuOd2qVcx76ksBBkSMhb0oMJooHYS8KoQW0U=; b=N0mELLQ3c41pjhmMOb2CzZN+w6GPrB7zqXgs9xa08kdYvv1gjfaZJ/BOsK5HxTsx35 i2fysjv0w9o4BQSy17hZkk55AjZ0/lV9Xrl/nnMtRD+BZ7fwxafa/MCxrL6WI4sSJK5X wFUPgUftYioGksB21GK71v2PF0sojQ31QGE5vAwZbieo4QyH2IPNsXp/fZp9TiykXEje 2BulhEdROIx8/aj/Gf1Jot3vwV5nJuIM731uPDFSt5vw4j04p1vPVSsXIm12aBvP01nt rkjlFT1P0FbTjeY9juoVLvDy2c7Y0qCY5ls+pyGvOqkSxcn7AFuHG1dN54Q6ZkOmuK/K SDCw== X-Gm-Message-State: APjAAAVLvEIEeSt0DwGoxj/2lYqbyV/nx91ZjQaftxMIP0PY/j+LJ/xN q38ISsUoOIYp71wWL03yiCk= X-Received: by 2002:adf:de8e:: with SMTP id w14mr2995656wrl.79.1564434914080; Mon, 29 Jul 2019 14:15:14 -0700 (PDT) Received: from archlinux-threadripper ([2a01:4f8:222:2f1b::2]) by smtp.gmail.com with ESMTPSA id j16sm4516071wrp.62.2019.07.29.14.15.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 14:15:13 -0700 (PDT) Date: Mon, 29 Jul 2019 14:15:11 -0700 From: Nathan Chancellor To: Nick Desaulniers Cc: ralf@linux-mips.org, paul.burton@mips.com, jhogan@kernel.org, Eli Friedman , "Maciej W. Rozycki" , 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 Message-ID: <20190729211511.GA74577@archlinux-threadripper> References: <20190729211014.39333-1-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190729211014.39333-1-ndesaulniers@google.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 29, 2019 at 02:10:12PM -0700, 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. > > 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. > > Link: https://github.com/ClangBuiltLinux/linux/issues/610 > Fixes: 966f4406d903 ("[MIPS] Work around bad code generation for .") > Reported-by: Nathan Chancellor > Debugged-by: Nathan Chancellor > Suggested-by: Eli Friedman > Signed-off-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor