Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2798488rdh; Sun, 26 Nov 2023 21:20:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNkMTw53Jxw4sT+AqnMq7Db2rqZXp/RQepVvhPIHGg1bOiFOwmr62IBjlhKl49jI/0sT9K X-Received: by 2002:a05:6871:438b:b0:1f9:9980:93bb with SMTP id lv11-20020a056871438b00b001f9998093bbmr14869933oab.52.1701062459268; Sun, 26 Nov 2023 21:20:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701062459; cv=none; d=google.com; s=arc-20160816; b=x811SQ+/kf1hQHwEbSC3M7FQbCYDF40OIa5ZN7/i9Bec6YLU08Vvj9q1zxZ/udQNJ1 x/Om3S7XLKrDa2elm7JaW81dDnRvwT5mXUIz4mCMfqFA8Rvm+Kt2/LdNkBTnOHxdL8fg mwM2Oez1B4wwtpVBjAbKVqUuDxVKWZ0c96N8X2dsRMj+/BXwamZl2L06ATFsMReN5At1 tar/M8s3BDpBWp3foZhCSQNKiH8wFTF89Nm49/lY25zVH6m946ZCAFRLkygTrjJnNFJs eclI4z0KF7+x1EIj/fIii80Veu2aTNdWoEZQ/3VjPWtQ07xf0etKPkdzt/QhoV7SUlvA Piew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=UUrbG3HjhihcDSzvkRm1feo5g3W6/H0iCiMp+spttWg=; fh=rq7w7yHb3lqk908lIfluGmk5t3dWvGgzTYEF2sP0oIY=; b=RFRPizbtkXJZZZ2FtEUNsxqlDonY1UsJnoDIA7uO+nOoX1jd6r5f/GsJ/j2KC5LF+J yRGuCHGhuuayQsydTaocCCzkn2E7NXHkEvDxa+GBhEg0sGUe440qfL285HfzgQaOqqFL AfDgXi/9XbHUPjXVuj6xzn6/iNq+oT10udlrimmi9RqhpBD1/++8vn+q8wy6vLxPBh3x T+FzzABjoGvfxiJZfckGUqdrodw+1zQh/noNbZ1ue0zmR9td0jQQmOgu71GulVXUQemO QtGAFTumrDapywLDsv4I64ShZMx7dPBvMItYnTaYpIdgUyRgQrhV5f7tuNWgLTDT/j3v ISVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vT6C7U8X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cu8-20020a056a00448800b006cd904df7a2si1041745pfb.112.2023.11.26.21.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 21:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vT6C7U8X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id BD498803BEDA; Sun, 26 Nov 2023 21:20:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbjK0FUi (ORCPT + 99 others); Mon, 27 Nov 2023 00:20:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjK0FUh (ORCPT ); Mon, 27 Nov 2023 00:20:37 -0500 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [IPv6:2001:41d0:203:375::bd]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65515131 for ; Sun, 26 Nov 2023 21:20:42 -0800 (PST) Message-ID: <2b66d64c-3398-44e0-897e-39dce82a6935@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1701062440; 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=UUrbG3HjhihcDSzvkRm1feo5g3W6/H0iCiMp+spttWg=; b=vT6C7U8XfSqEqxK251ALqSEbpw2NDD0mseTiFA2A2SckDHBRTu0xVHHOlB3NwjOuxoTwBZ g7/8q7wltd1g8fGXkVu+yD19S5DzHtbR/Nbypxj3P8ziOyACIM6Lyeu12hjPyseqAweaLy PCUkvLoivcUD2xH9R/tawCRCkVFXO7k= Date: Sun, 26 Nov 2023 21:20:30 -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: Eduard Zingerman , Alexei Starovoitov Cc: Daniel Xu , Shuah Khan , Daniel Borkmann , Andrii Nakryiko , Alexei Starovoitov , Steffen Klassert , antony.antony@secunet.com, 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> <3ec6c068-7f95-419a-a0ae-a901f95e4838@linux.dev> <18e43cdf65e7ba0d8f6912364fbc5b08a6928b35.camel@gmail.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: <18e43cdf65e7ba0d8f6912364fbc5b08a6928b35.camel@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 26 Nov 2023 21:20:56 -0800 (PST) On 11/26/23 3:14 PM, Eduard Zingerman wrote: > On Sat, 2023-11-25 at 20:22 -0800, Yonghong Song wrote: > [...] >> --- 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" > [...] >> 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? > Tbh I'm not sure. This test passes with preserve_static_offset > because it suppresses preserve_access_index. In general clang > translates bitfield access to a set of IR statements like: > > C: > struct foo { > unsigned _; > unsigned a:1; > ... > }; > ... foo->a ... > > IR: > %a = getelementptr inbounds %struct.foo, ptr %0, i32 0, i32 1 > %bf.load = load i8, ptr %a, align 4 > %bf.clear = and i8 %bf.load, 1 > %bf.cast = zext i8 %bf.clear to i32 > > With preserve_static_offset the getelementptr+load are replaced by a > single statement which is preserved as-is till code generation, > thus load with align 4 is preserved. > > On the other hand, I'm not sure that clang guarantees that load or > stores used for bitfield access would be always aligned according to > verifier expectations. I think it should be true. The frontend does alignment analysis based on types and (packed vs. unpacked) and assign each load/store with proper alignment (like 'align 4' in the above). 'align 4' truely means the load itself is 4-byte aligned. Otherwise, it will be very confusing for arch's which do not support unaligned memory access (e.g. BPF). > > I think we should check if there are some clang knobs that prevent > generation of unaligned memory access. I'll take a look.