Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1232155ybt; Tue, 7 Jul 2020 10:33:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyORwZiRs7nTZa4clXIEI0TEcG5pPOAkMOAqqsKpAZInwzZKoLfgSeTO3NBqLzYa+O5/mO1 X-Received: by 2002:a50:fa0c:: with SMTP id b12mr63643258edq.226.1594143212288; Tue, 07 Jul 2020 10:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594143212; cv=none; d=google.com; s=arc-20160816; b=YBQLVQYQurQFXwUPytBkWFVShEAG+KDUF0HXoUu1WoZBveePUHIx8P5duWIKIl72Jq 6j+ntT3QFjyIC4yBo0fA4YHjhzcbrdxHN2oiE/CG2rlRRv01mHTar95hIXZ61LUisnpv dYUjGBnh0RoF9wzObPeRm5SvzxM3FmMA+EQ73bYmahBMOf5gj2gQBbpH5b5MGgNFvokZ ODNpVQGV5QjzqyxybSL2IdMH63gWnz/GWk/U+Rf/29nzEDLmF7l0x9acSM5iHQ1EmfYV 3mcegdWzF752pXbGIR0QwEFJz/GXZKkA2xgfCyBIau4PqMUGbrzdOl93Gw5e2AMsg9hd RVqQ== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=3fT7JHQzUuk2hN6+LXg4bH8jc1VGgXYeN1aqEYhz898=; b=pScYPd5p7aOTWOuYhYkx0VUgbo23+f87zE2v4fSIhr4/fPanyA00qHH/JeIv2s5Y14 fH2kyib9GIDAj+Obg/LSYgVuhPR3carVvAFpW+nquz8qQMd4tzatvSaxVA5rG4jwCIxd 54/PUUI2C6NjNYRh7yU9flWPEMc/4hDAOVp3LZTAB7loZJmJ1Ss4TvtbKw5qnloU+4mV VbdkaM9ELY4y5eET8Oo94XX9S5gZ31a5IEeyThFcAH4EPhGoMJw9mw5TrqnoRWe2SsPt W0vVMWseWzSiDby6leuTJwh63UHT/ggE03ohoxt8LaqmhStO+lLq5lF3eqfbWIXtZuBL 42aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vPwLy/dZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d25si14850729eja.521.2020.07.07.10.33.09; Tue, 07 Jul 2020 10:33:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vPwLy/dZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728484AbgGGRaP (ORCPT + 99 others); Tue, 7 Jul 2020 13:30:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:33158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgGGRaO (ORCPT ); Tue, 7 Jul 2020 13:30:14 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (unknown [163.114.132.1]) (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 A2E542075B; Tue, 7 Jul 2020 17:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594143014; bh=y/nx2A612UM8oaRHFRt0pVJEofy/MD08EpnGh5tjD2M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vPwLy/dZrsf2lKc6xY5QZhb/lBO3J7u2UOg6Z2mZZrHboN5O1gXQJch4ETtg93Thk PKaf7C8MJrbvEHq3g7RsJbQsdoIzLcGWhcKnBK+3YH/JpTgls0dA33TnIblRELXwPn TrJEP18+dbybB5rl0khvQJt0tNqdZ6h0juyVMOtk= Date: Tue, 7 Jul 2020 10:30:11 -0700 From: Jakub Kicinski To: Nick Desaulniers Cc: Sami Tolvanen , Masahiro Yamada , Will Deacon , Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , clang-built-linux , Kernel Hardening , linux-arch , linux-arm-kernel , Linux Kbuild mailing list , Linux Kernel Mailing List , linux-pci@vger.kernel.org, X86 ML Subject: Re: [PATCH 00/22] add support for Clang LTO Message-ID: <20200707103011.173d38c1@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: <20200624203200.78870-1-samitolvanen@google.com> <20200629232059.GA3787278@google.com> <20200707155107.GA3357035@google.com> <20200707160528.GA1300535@google.com> <20200707095651.422f0b22@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 7 Jul 2020 10:17:25 -0700 Nick Desaulniers wrote: > On Tue, Jul 7, 2020 at 9:56 AM Jakub Kicinski wrote: > > > > > On Tue, Jul 07, 2020 at 08:51:07AM -0700, Sami Tolvanen wrote: > > > > After spending some time debugging this with Nick, it looks like the > > > > error is caused by a recent optimization change in LLVM, which together > > > > with the inlining of ur_load_imm_any into jeq_imm, changes a runtime > > > > check in FIELD_FIT that would always fail, to a compile-time check that > > > > breaks the build. In jeq_imm, we have: > > > > > > > > /* struct bpf_insn: _s32 imm */ > > > > u64 imm = insn->imm; /* sign extend */ > > > > ... > > > > if (imm >> 32) { /* non-zero only if insn->imm is negative */ > > > > /* inlined from ur_load_imm_any */ > > > > u32 __imm = imm >> 32; /* therefore, always 0xffffffff */ > > > > > > > > /* > > > > * __imm has a value known at compile-time, which means > > > > * __builtin_constant_p(__imm) is true and we end up with > > > > * essentially this in __BF_FIELD_CHECK: > > > > */ > > > > if (__builtin_constant_p(__imm) && __imm > 255) > > > > I think FIELD_FIT() should not pass the value into __BF_FIELD_CHECK(). > > > > So: > > > > diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h > > index 48ea093ff04c..4e035aca6f7e 100644 > > --- a/include/linux/bitfield.h > > +++ b/include/linux/bitfield.h > > @@ -77,7 +77,7 @@ > > */ > > #define FIELD_FIT(_mask, _val) \ > > ({ \ > > - __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \ > > + __BF_FIELD_CHECK(_mask, 0ULL, 0ULL, "FIELD_FIT: "); \ > > !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ > > }) > > > > It's perfectly legal to pass a constant which does not fit, in which > > case FIELD_FIT() should just return false not break the build. > > > > Right? > > I see the value of the __builtin_constant_p check; this is just a very > interesting case where rather than an integer literal appearing in the > source, the compiler is able to deduce that the parameter can only > have one value in one case, and allows __builtin_constant_p to > evaluate to true for it. > > I had definitely asked Sami about the comment above FIELD_FIT: > """ > 76 * Return: true if @_val can fit inside @_mask, false if @_val is > too big. > """ > in which FIELD_FIT doesn't return false if @_val is too big and a > compile time constant. (Rather it breaks the build). > > Of the 14 expansion sites of FIELD_FIT I see in mainline, it doesn't > look like any integral literals are passed, so maybe the compile time > checks of _val are of little value for FIELD_FIT. Also I just double checked and all FIELD_FIT() uses check the return value. > So I think your suggested diff is the most concise fix. Feel free to submit that officially as a patch if it fixes the build for you, here's my sign-off: Signed-off-by: Jakub Kicinski