From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1587BC4167B for ; Sun, 26 Nov 2023 04:25:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230319AbjKZEW1 (ORCPT ); Sat, 25 Nov 2023 23:22:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjKZEWY (ORCPT ); Sat, 25 Nov 2023 23:22:24 -0500 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51EB11D for ; Sat, 25 Nov 2023 20:22:27 -0800 (PST) Message-ID: <3ec6c068-7f95-419a-a0ae-a901f95e4838@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700972545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YPqbGwvoWuhH3MNinMuIoCbVuSs6v7gO8I55MtBSoJU=; b=iFZ1kHr0JZmtTSmpiAQW0kJwEZwA2ZDUGadFJNdN4Xb6zgg5w0HO3U4tT+Wh1oK/6dJq9a jZGPr5LjmCSgn6KBRW+H6QBHPiXz3RDDaf02BawHtOiX78jLogyZ7gDFWhyXgHgYowGOdE nEsGPUjAhKOBmOaFutn/Y8xbp9F5Lqo= Date: Sat, 25 Nov 2023 20:22:14 -0800 MIME-Version: 1.0 Subject: Re: [PATCH ipsec-next v1 6/7] bpf: selftests: test_tunnel: Disable CO-RE relocations Content-Language: en-GB To: Alexei Starovoitov Cc: Daniel Xu , Shuah Khan , Daniel Borkmann , Andrii Nakryiko , Alexei Starovoitov , Steffen Klassert , antony.antony@secunet.com, Eddy Z , Mykola Lysenko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , devel@linux-ipsec.org, Network Development References: <391d524c496acc97a8801d8bea80976f58485810.1700676682.git.dxu@dxuuu.xyz> <0f210cef-c6e9-41c1-9ba8-225f046435e5@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/25/23 7:54 PM, Alexei Starovoitov wrote: > On Sat, Nov 25, 2023 at 4:52 PM Yonghong Song wrote: >>> diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c >>> index 3065a716544d..ec7e04e012ae 100644 >>> --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c >>> +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c >>> @@ -6,6 +6,7 @@ >>> * modify it under the terms of version 2 of the GNU General Public >>> * License as published by the Free Software Foundation. >>> */ >>> +#define BPF_NO_PRESERVE_ACCESS_INDEX >> This is a temporary workaround and hopefully we can lift it in the >> near future. Please add a comment here with prefix 'Workaround' to >> explain why this is needed and later on we can earliy search the >> keyword and remember to tackle this. > I suspect we will forget to remove this "workaround" and people > will start copy pasting it. > Let's change the test instead to avoid bitfield access. Agree. Avoiding bitfield access is definitely a solution. I just checked llvm preserve_static_offset (not merged yet), it seems to be able to fix the issue as well. Applying patch https://reviews.llvm.org/D133361 to latest llvm-project, and with the following patch on top of patch 6, ===== diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c index ec7e04e012ae..11cbb12b4029 100644 --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c @@ -6,7 +6,10 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ -#define BPF_NO_PRESERVE_ACCESS_INDEX +#if __has_attribute(preserve_static_offset) +struct __attribute__((preserve_static_offset)) erspan_md2; +struct __attribute__((preserve_static_offset)) erspan_metadata; +#endif #include "vmlinux.h" #include #include @@ -25,12 +28,12 @@ * 172.16.1.200 */ #define ASSIGNED_ADDR_VETH1 0xac1001c8 struct vxlanhdr { __be32 vx_flags; __be32 vx_vni; } __attribute__((packed)); int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __ksym; int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, @@ -174,9 +177,13 @@ int erspan_set_tunnel(struct __sk_buff *skb) __u8 hwid = 7; md.version = 2; +#if __has_attribute(preserve_static_offset) md.u.md2.dir = direction; md.u.md2.hwid = hwid & 0xf; md.u.md2.hwid_upper = (hwid >> 4) & 0x3; +#else + /* Change bit-field store to byte(s)-level stores. */ +#endif #endif ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md)); ==== Eduard, could you double check whether this is a valid use case to solve this kind of issue with preserve_static_offset attribute?