Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp682788rdb; Tue, 16 Jan 2024 12:28:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPE7mdRuKHDkvr2zdEbr/zzg1XlQQhgCo4s7K1x049uMk34mlpEHkLqTSJIlCk3AJzH3zX X-Received: by 2002:a25:86ca:0:b0:dbd:4594:51a2 with SMTP id y10-20020a2586ca000000b00dbd459451a2mr4036569ybm.23.1705436931563; Tue, 16 Jan 2024 12:28:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705436931; cv=pass; d=google.com; s=arc-20160816; b=wEkBOoCVDVYR2bVJVS33hM7esvNm5VStpk8xqMzNfWwwOQv5oIhCNVVw6fUbI06G/2 vRsEN9YDhTJCSsovKMVRuqgiA3GT1B8th8RqX4qfbFoMtU0e4DrNs6vnIylZi3OremHy CsFL5DXSnvXprEkxUP3Doz5oWIC429Dh8hId/nk+uLk/O2ISSrmYgSt0HoDh4fIG7DFU EVMfaMtSwa20HJO5cShnV492DXoXMPOWMH9x7QsJQhXAWfLgqtNNJ/msh+21Imy/rt+f 6cEKNoTG8s0JrBczcAJdUTHPXcNb4NGO7dYQJw/bunWCAoo09dkjA9MLHkzbeDoGPspC JBHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ojp+x1MogCVuMz44QqiLp9SbRLJmAX3yuWoJUzrUh70=; fh=hir9R1IRhxjGjkm0kpSnb1aHy4tOwnJ5Ku56Zjl/rBc=; b=ukCHR3BGGdUYSmzKw1PMp683lxbhAqtw5Ey9PM9UFOD+AEmNL9GafYj0eCQJBrGp8P oRaIt2OmRn8sa1+gQetnsXSZHTyLYhXWA1vrlXJyjmzzMUxku9lr9XS6fWB9iq42MnN/ c5l5POmyN+DmEzIYlH/NkBPVp+rOue6X8kV8bVbJPajmzQ8z/IkIo5F4yHSKF7zDJHeu 6b7Gfx8YQ6x0CsheEBMybD7g2pKOfbPtNAYstWUMJg31h0Wf/dwl/E2xBwob70XPM7d+ rCGcGOSk0aKRcCNgRlNASk3Jn6esbRFU1KMDLWbif1v/7yWw3Fqta7zx30GMObJQQOLp AwTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHcHfCj9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-27913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g5-20020ac87d05000000b00429fee31f32si2550987qtb.138.2024.01.16.12.28.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 12:28:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHcHfCj9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-27913-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27913-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4DCE81C24B31 for ; Tue, 16 Jan 2024 20:28:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57B2886141; Tue, 16 Jan 2024 19:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jHcHfCj9" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FE7750A94; Tue, 16 Jan 2024 19:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434573; cv=none; b=Z1pP2G1C4yhK/hTVhQDQOkzbxmBNDUxqFV2oVswk3jnCNYDhOHH1P2LwCQnxvivSZAhw4K09rohnqXC9Pp2QH7oKvw1Zxs8L42M6osZXbCcmIP5BRItr8kG+egj2ht/cujou3778afTu6mK4w3PUu5z4vA0tsZOJPQueJ578S6E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705434573; c=relaxed/simple; bh=hORw/LjtmLslIhMW3hB1p5s4EeH7XhY/u0cxo++nrUU=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:X-stable: X-Patchwork-Hint:X-stable-base:Content-Transfer-Encoding; b=fAYKe4COdJPWnO0hrNww+RNmDSAhqvuh+tjE9et+w2e5PnUjM9fKsmvNHUfogh7Qg/wI2frbR6I0H+2m5SJUoWsPfh6zU7sBRcmXk8A9sTMpx8A51rhu4gZaD7lmOj+u/M0B/c0Dvcif+j/vxgUxqfA58aL9ML3lwB/hqur8jA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jHcHfCj9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E560FC433F1; Tue, 16 Jan 2024 19:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705434573; bh=hORw/LjtmLslIhMW3hB1p5s4EeH7XhY/u0cxo++nrUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHcHfCj9e7G2Bzq9mdRRsVG6GRNCinmpln4/RZKVxAiLaEoqGlftf7tc04ICMBR7p JWcAY11bQiDs0WdEOXyH5sVKOCnwxyncC+FhWXyr/0CYOFIkUWXBO8CxusF7a9S7Pc ZvRLdLhhLetV4n3+8GExBRCtc/JCc59FvY1YAQyP3qAh3ffjyqmdCMoS5lae9Khr8N 3ZfzIhh+WFE50MjCkb/F6szULlOWaw+oouxRlpBD65iyUcBj+lBBd6ywvLrLnSgfUY gtDez+Ti4ZEMSWlA1Fnp8oIxfN/9fDYxFk50PktxZ/Cqijb0JjUW/YqlSGyyzhHtLU +YNjckrrAxpqg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yonghong Song , Andrii Nakryiko , Alan Maguire , Sasha Levin , ast@kernel.org, daniel@iogearbox.net, shuah@kernel.org, nathan@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.6 006/104] selftests/bpf: Fix pyperf180 compilation failure with clang18 Date: Tue, 16 Jan 2024 14:45:32 -0500 Message-ID: <20240116194908.253437-6-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116194908.253437-1-sashal@kernel.org> References: <20240116194908.253437-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.12 Content-Transfer-Encoding: 8bit From: Yonghong Song [ Upstream commit 100888fb6d8a185866b1520031ee7e3182b173de ] With latest clang18 (main branch of llvm-project repo), when building bpf selftests, [~/work/bpf-next (master)]$ make -C tools/testing/selftests/bpf LLVM=1 -j The following compilation error happens: fatal error: error in backend: Branch target out of insn range ... Stack dump: 0. Program arguments: clang -g -Wall -Werror -D__TARGET_ARCH_x86 -mlittle-endian -I/home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/include -I/home/yhs/work/bpf-next/tools/testing/selftests/bpf -I/home/yhs/work/bpf-next/tools/include/uapi -I/home/yhs/work/bpf-next/tools/testing/selftests/usr/include -idirafter /home/yhs/work/llvm-project/llvm/build.18/install/lib/clang/18/include -idirafter /usr/local/include -idirafter /usr/include -Wno-compare-distinct-pointer-types -DENABLE_ATOMICS_TESTS -O2 --target=bpf -c progs/pyperf180.c -mcpu=v3 -o /home/yhs/work/bpf-next/tools/testing/selftests/bpf/pyperf180.bpf.o 1. parser at end of file 2. Code generation ... The compilation failure only happens to cpu=v2 and cpu=v3. cpu=v4 is okay since cpu=v4 supports 32-bit branch target offset. The above failure is due to upstream llvm patch [1] where some inlining behavior are changed in clang18. To workaround the issue, previously all 180 loop iterations are fully unrolled. The bpf macro __BPF_CPU_VERSION__ (implemented in clang18 recently) is used to avoid unrolling changes if cpu=v4. If __BPF_CPU_VERSION__ is not available and the compiler is clang18, the unrollng amount is unconditionally reduced. [1] https://github.com/llvm/llvm-project/commit/1a2e77cf9e11dbf56b5720c607313a566eebb16e Signed-off-by: Yonghong Song Signed-off-by: Andrii Nakryiko Tested-by: Alan Maguire Link: https://lore.kernel.org/bpf/20231110193644.3130906-1-yonghong.song@linux.dev Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/progs/pyperf180.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/pyperf180.c b/tools/testing/selftests/bpf/progs/pyperf180.c index c39f559d3100..42c4a8b62e36 100644 --- a/tools/testing/selftests/bpf/progs/pyperf180.c +++ b/tools/testing/selftests/bpf/progs/pyperf180.c @@ -1,4 +1,26 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2019 Facebook #define STACK_MAX_LEN 180 + +/* llvm upstream commit at clang18 + * https://github.com/llvm/llvm-project/commit/1a2e77cf9e11dbf56b5720c607313a566eebb16e + * changed inlining behavior and caused compilation failure as some branch + * target distance exceeded 16bit representation which is the maximum for + * cpu v1/v2/v3. Macro __BPF_CPU_VERSION__ is later implemented in clang18 + * to specify which cpu version is used for compilation. So a smaller + * unroll_count can be set if __BPF_CPU_VERSION__ is less than 4, which + * reduced some branch target distances and resolved the compilation failure. + * + * To capture the case where a developer/ci uses clang18 but the corresponding + * repo checkpoint does not have __BPF_CPU_VERSION__, a smaller unroll_count + * will be set as well to prevent potential compilation failures. + */ +#ifdef __BPF_CPU_VERSION__ +#if __BPF_CPU_VERSION__ < 4 +#define UNROLL_COUNT 90 +#endif +#elif __clang_major__ == 18 +#define UNROLL_COUNT 90 +#endif + #include "pyperf.h" -- 2.43.0