Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp465550ybl; Tue, 28 Jan 2020 06:23:59 -0800 (PST) X-Google-Smtp-Source: APXvYqx5r43Xzq4xojMetagwepFFYY383p7hla87eMcwJ/6kerOB0GCcsFBb1KlUTWez5JEhKIMw X-Received: by 2002:a05:6808:907:: with SMTP id w7mr2971544oih.137.1580221439367; Tue, 28 Jan 2020 06:23:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221439; cv=none; d=google.com; s=arc-20160816; b=iCQ4emOrNM2fI6seAv2fpTAsVzoEwyBKuyQ3stH9FgCzYEN5NQD2uA3Qxic7EhBtob s2XTo/F/uOgqHO3UJB6ppAq3x8ySFuZO8LQ66bBXEBEqA1TOp90aHxtdT2Fe48rPGiwP zD8IgRUll51wF0dRVMFUHQYgIIF6eqD3OiQQzLNQD8cFywhT6bUm1EdedhqmKCdWDPW2 XXgqdG6k3WyiwR9rMvg9dEhRKGNuahARnGocGP2mUpI0vvhQsZzdUImBM22kV8rg41yR oRAZNr3OvfErVKbPtk343JyNYe7u1Cxxr8tTZUjssEmEz8H8DoAgB6fOVHBE3db4Cd3k ViuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FmPyGCw24mfbAt0RCwDqFY9hL1iM74rAyanynR9MV3E=; b=BS1xVwelpvbRrbC0HD/z89iPqZgAQhHRo/l85BePKa6XR4OwPJDu34F22NIWCJXQyY vxt1vk4vM71URsbZKTHxRJs9vHI9SmtwHxV8iMb8An5+Ngvosq74mur8cShyECyHd9Y3 Q1X+XowwtaeNbGksFvI6MsktWtoVxkHo1gzf0FZlTBivq+zyQ05r2jY6hnQj37xbT/q6 d66Ya0S5MZCs6jNscq+chLX0jF3YsO1K2GRBcNAV42WQDkdUzR+tO51OsVqA+pcvE8bL NIL4e/l1zo+QH7ujqg2zcISksdRppv8UxrpU0S3JCjz0ME/RATAFR5BjG7PcBif44y0z QLpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lfySTc3X; 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 e73si5279441oib.145.2020.01.28.06.23.47; Tue, 28 Jan 2020 06:23:59 -0800 (PST) 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=@kernel.org header.s=default header.b=lfySTc3X; 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 S1731386AbgA1OWu (ORCPT + 99 others); Tue, 28 Jan 2020 09:22:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:48596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731673AbgA1OWo (ORCPT ); Tue, 28 Jan 2020 09:22:44 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D16B524681; Tue, 28 Jan 2020 14:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221363; bh=qwTLXXni0laGzArkawsT8uWneqmS22Y3RwOerASELaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lfySTc3XWZP+4SRtnncSHtmoXcbIz+PwLpM95p+i6d7Fvd/A6OajJJQXAJStreCnD lHJyKIED6zXDdjDngJZkKCFShs80ckMpIlZsutdq9BdYkyTjoUr0fwzOD3d9t+k9jS eIF214q+Fr9Hw9cMOFEpbrvKtdKxs2dz7lxNPeaI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Eli Friedman , Nick Desaulniers , Paul Burton , ralf@linux-mips.org, jhogan@kernel.org, "Maciej W. Rozycki" , Hassan Naveed , Stephen Kitt , Serge Semin , Mike Rapoport , Andrew Morton , Michal Hocko , linux-mips@vger.kernel.org, clang-built-linux@googlegroups.com, Sasha Levin Subject: [PATCH 4.9 187/271] mips: avoid explicit UB in assignment of mips_io_port_base Date: Tue, 28 Jan 2020 15:05:36 +0100 Message-Id: <20200128135906.492399637@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Desaulniers [ Upstream commit 12051b318bc3ce5b42d6d786191008284b067d83 ] 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 Signed-off-by: Paul Burton Cc: ralf@linux-mips.org Cc: jhogan@kernel.org Cc: Maciej W. Rozycki Cc: Hassan Naveed Cc: Stephen Kitt Cc: Serge Semin Cc: Mike Rapoport Cc: Andrew Morton Cc: Michal Hocko Cc: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: clang-built-linux@googlegroups.com Signed-off-by: Sasha Levin --- arch/mips/include/asm/io.h | 14 ++------------ arch/mips/kernel/setup.c | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h index 06049b6b3dddb..5dfae80264b9b 100644 --- a/arch/mips/include/asm/io.h +++ b/arch/mips/include/asm/io.h @@ -60,21 +60,11 @@ * instruction, so the lower 16 bits must be zero. Should be true on * on any sane architecture; generic code does not use this assumption. */ -extern const unsigned long mips_io_port_base; +extern unsigned long mips_io_port_base; -/* - * Gcc will generate code to load the value of mips_io_port_base after each - * function call which may be fairly wasteful in some cases. So we don't - * play quite by the book. We tell gcc mips_io_port_base is a long variable - * which solves the code generation issue. Now we need to violate the - * aliasing rules a little to make initialization possible and finally we - * will need the barrier() to fight side effects of the aliasing chat. - * This trickery will eventually collapse under gcc's optimizer. Oh well. - */ static inline void set_io_port_base(unsigned long base) { - * (unsigned long *) &mips_io_port_base = base; - barrier(); + mips_io_port_base = base; } /* diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 695950361d2a7..7cc1d29334ee1 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -74,7 +74,7 @@ static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; * mips_io_port_base is the begin of the address space to which x86 style * I/O ports are mapped. */ -const unsigned long mips_io_port_base = -1; +unsigned long mips_io_port_base = -1; EXPORT_SYMBOL(mips_io_port_base); static struct resource code_resource = { .name = "Kernel code", }; -- 2.20.1