Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2692920rdh; Sun, 26 Nov 2023 16:06:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEss20+j5FICDptiorJTndEcxaU0AMAHvaiJVt7zekmPR144IX87LL7JLzWd/183PcK1VtH X-Received: by 2002:a05:6e02:152c:b0:35a:fa7f:36b with SMTP id i12-20020a056e02152c00b0035afa7f036bmr9843928ilu.9.1701043601965; Sun, 26 Nov 2023 16:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701043601; cv=none; d=google.com; s=arc-20160816; b=P7IFYOjF8johc8Cd53QOb7xGVwP4u2DaYE9IqMaklfDCE2OQCNvrcIhZqhfURMVfOh DCaaE3RIrwldoDGmjumI0926szpH9hV0RNpsriqigAkMvyz2275Vfifkol0wBr/HdOFN wMQQcWYAaYXW2jXvW/Z2IHll3FM22VoT9aMgDDabVrtiO20m0adIVfNlkA9YTUfawEOA 3Vgy62g0XfW/aazRlwHEu44EtkNxWol+CUV4QT/rjG4PFn9WGJQzOKhmuvTLiamB2iWS ssQhcet8cWQVJ5S1b+q78J5hprYMa7KKjYHGWdQkqrD1fI5Z8ZvGGa0cPfVWz3WSq2iA NtHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=UGNk44U4jmXOJ/AcIH3TlGvpqXW3QFjzprbde8gLJZU=; fh=V+groP5MQ9Pb4ZwNmjJ4Sbi1U5SG595WwXMCbuvm8RQ=; b=dg7p9z9u0AWTD1kCWEau9sYTubb5acwyv/nK0lY3IsCkbEh23E/B+ftAC9JCp+dc9l L05Q7BkbRWuaBRmTYTqfe/Pe2wKdvGAJgN1+E/QjNowbOUbn6mA6WgCfQR7MmSzyfk7W lryWKsmk3Bz93qkXNPjZgDIKdYw85p/5qPDpoKJzLjHUXADkUNDpixJBqCkMllcZhsZy obI7VSlQ7l+l3MfG2EeGbfUhkqAbAj1xnhB5w35P9KLsNjcDWtjH7YisOnLUC6uQMBru AatxdBdRSQZFFoMgRM1mXtlfbN2M/HPVNrCD7zYcAQ3H6gPYdyfHgfbLNDubZh0SNM8v 9Qag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=NaulhuTw; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=IddQoC+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z3-20020a63e103000000b005b16e351343si8624945pgh.241.2023.11.26.16.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 16:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=NaulhuTw; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=IddQoC+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 7D16E8069D56; Sun, 26 Nov 2023 16:05:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbjK0AFA (ORCPT + 99 others); Sun, 26 Nov 2023 19:05:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjK0AE7 (ORCPT ); Sun, 26 Nov 2023 19:04:59 -0500 Received: from new3-smtp.messagingengine.com (new3-smtp.messagingengine.com [66.111.4.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99351FB; Sun, 26 Nov 2023 16:04:57 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 8E18F5807BE; Sun, 26 Nov 2023 19:04:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 26 Nov 2023 19:04:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1701043493; x=1701050693; bh=UG Nk44U4jmXOJ/AcIH3TlGvpqXW3QFjzprbde8gLJZU=; b=NaulhuTwyiNqIMbSl8 cyVa+7RWp/OPWxg3O6P76LZYVLpu1kn9SSue+Gawi6CCJnxzv/34X+Dje+wkdcH1 f8LbXnkQwglIhjYZ5xLYDHHiXJejykMtIaKkvynrpBp806WZFNj1LAlKuObSyZhx yBXlqxjT6mkV+9AlVfDMXlXc+3pvahR790j3p7HWy4LXsLquJbbGhI0IBPPtvwkk m06RNfkcOqs46d46Op1KamrJp9AFX8G2XRjcSUZ6whvllI9SdGkV45OEdy7KStJb l7/BlGCzViVsjjzLmFhXKj5mc6sx1w8CCxCV1VAFj8d64QeWkPOwH/TUNcUN+cj4 Z4Fw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1701043493; x=1701050693; bh=UGNk44U4jmXOJ /AcIH3TlGvpqXW3QFjzprbde8gLJZU=; b=IddQoC+7h+piTRX4O77oxs63wgeJ/ qQnXeFocUrafGEluooWeaacpsCbDVfmdZuE4tsjVFdeVqbb5pBhzuOIjeP8npVRu rIveoi2kbsn9DsEuo98IuOaOda6yDqAHriusUOrL/l0e72i6Nn9UkmlHN6DPGKZZ lpopZKJC7so4PuhVBw0ANM3hoH3xpte6LkxKztaZTx+dPA496kw//3jrzxW8F6ZF mna5ObqhhpOf88uguLewL6PNO15mHOs8bpMYXVB6LfWRmRbKxnXzrRwau+yIvQ3W SAHtD0C6guqpxbuH+2NfaKPBFSUxLropKwdtGyEDIDPvaOgNbjzwy8XHA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeitddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdfstddt tddvnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqne cuggftrfgrthhtvghrnhepvdefkeetuddufeeigedtheefffekuedukeehudffudfffffg geeitdetgfdvhfdvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 26 Nov 2023 19:04:50 -0500 (EST) Date: Sun, 26 Nov 2023 18:04:49 -0600 From: Daniel Xu To: Eduard Zingerman Cc: Yonghong Song , Alexei Starovoitov , 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 Subject: Re: [PATCH ipsec-next v1 6/7] bpf: selftests: test_tunnel: Disable CO-RE relocations Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18e43cdf65e7ba0d8f6912364fbc5b08a6928b35.camel@gmail.com> 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 pete.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 (pete.vger.email [0.0.0.0]); Sun, 26 Nov 2023 16:05:48 -0800 (PST) Hi, On Sun, Nov 26, 2023 at 10:14:21PM +0200, 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 we should check if there are some clang knobs that prevent > generation of unaligned memory access. I'll take a look. Is there a reason to prefer fixing in compiler? I'm not opposed to it, but the downside to compiler fix is it takes years to propagate and sprinkles ifdefs into the code. Would it be possible to have an analogue of BPF_CORE_READ_BITFIELD()? Thanks, Daniel