Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1399248rdb; Fri, 1 Dec 2023 15:53:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHh0+WYPhG9qjS+orrgH83eB/nyW5EljkVK+Xh2wtCN6ZOWYmUKR4fnJmZfKP79LDP/hQX8 X-Received: by 2002:a05:6a20:138c:b0:18b:d99a:99bd with SMTP id hn12-20020a056a20138c00b0018bd99a99bdmr355422pzc.32.1701474787980; Fri, 01 Dec 2023 15:53:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701474787; cv=none; d=google.com; s=arc-20160816; b=wC/XQTJlLOr0vi9y6QnpJ9jT8vCBrSz7rulnUgs7SwVcZmB+LlVonR0wj3/v1lYZs1 WD1TihR7cHJbtpa2Lz0fZM8z5dXN7rbye3+MyNJ4Lol7OdusTefrC45aH+SqfdUvV+LN +CocHsA8X4WIjf1zOoSMM6j7J8Lx7jKyqwy/8SVTgCP3SOxIPbS1YrI28o9D2h/ICCU1 XZPuf1DWiSagfLvqa2FKMmPJ86zYZNm/gDz+lKF1cjKFAgvK0D9AHo3RVPtMQWnTOhRm vHDExXI7Iij7QD5U8FQqrCaHPPEzHNRuTvG1WvOsZAXizlg0G9HXMkusYPfSaKlONwOY vR/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BhIirItyGrM+IUEe5Xj2pk25VhtqsjDKJXNwWgIhPek=; fh=HxI5SR2WVd4xSrkMNLvu4ea8HmhoFcZlsBvm2gYxCQ8=; b=P+udMbCEcEzFx7ONh18lmLcBBbyFwxDlVi9aVfUUa1vyHl9DqA4UQKyqfRqOx678E7 H6BtDfAkkZEbzQu/vo3GwvamNAQ5BY5Zc9oxcwJok69SPd2ZC3kxbYxuu/Bsii6Xe61D USo22VVeN6rV8uKjE1SQ5Mo30rSkycywm72rxivOIzjfvDAN7IjMsBU+V0XeQsrbyjpr 9bFHo6/2BS5Q1aj1mNEhfc4q1db8qwOGvow4ueI0ovO02i106P3ZSSumnXxzAn+xiBBi 7NOfl7aF1/wWGaGL2ndtUs+UvZlIkVQh/uuK23VKrzxuX2TFo5cPgMKVGMQo2TKjCClW ItiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Tlw4zXl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e1-20020a656781000000b0058b8c72c5ddsi3874377pgr.607.2023.12.01.15.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 15:53:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Tlw4zXl4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F1D2984AA9DA; Fri, 1 Dec 2023 15:53:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbjLAXws (ORCPT + 99 others); Fri, 1 Dec 2023 18:52:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235345AbjLAXwf (ORCPT ); Fri, 1 Dec 2023 18:52:35 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E9D1730; Fri, 1 Dec 2023 15:52:38 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a00ac0101d9so393036166b.0; Fri, 01 Dec 2023 15:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701474757; x=1702079557; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BhIirItyGrM+IUEe5Xj2pk25VhtqsjDKJXNwWgIhPek=; b=Tlw4zXl44yxpcxH1XnAQRApMOyAIdD/lOn5823cNUnRS7QnRPH0C7pHmO1GndkXUwr sKxIYNpXtidbaNJSDyyhrs2RI4sXlb4Q+Z/MxOKlqhq2IcpEj4uO0BlVlo1At/pPpnzU A7bPva6PYM6nsRGcusAiYrIj0gq5l7YwodnWHqhjqdNU8kkGNOeSOvedj0KZKaAL1mPY ICznI7KopxKHws2ZFR4JR0z8ueyZptpnIO8QqA9VUCOL6ZHefuDtXgt/59PDdHd4vItO FqwPk5wExXbtGhGC723yDoesYLWZfmwkkbVKmx4sJYSsXDnuz4oeG5XiSzHlwFXkzuTZ W4zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701474757; x=1702079557; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BhIirItyGrM+IUEe5Xj2pk25VhtqsjDKJXNwWgIhPek=; b=KY1ug6VtVo40hwpCrEA9RWZh1Gxf0KEnVJeAO8sDKLqbNxUQAefgr5xQNP9EUUR7Wo 68nwhdliL/dBUuq9V2nld892oIgSUr4QFiwdQ4tBgdlfsclAqwCDPse8bMJQpP6BIi49 tRIVAI885s/l5GD/RzLDDyDw/DuqE7sGrTtM++/aqS3XR9QXZQ3qH+4Lks4uKYODcqxf PNIO0Ile1AZBRvTjeFVET5PlnQhcfIIVa+C5DuHc+uVggyKWXEMIzZKAsc3wTyFoNOXT jhCn2nmyz+ePs48d6oOsQCsHTZW50ZeYwPbcQFmmED/mtJK0BmW3LE7sqTqrTknAHZoM KuSQ== X-Gm-Message-State: AOJu0Yx5HSBwhCsot/4jlalrb/Tzx4633nJ76gfNkohuhzynjfTXZQB7 AUkR3v3CZe3sVuymGcktT/mmRy5r0h2y13ZI7Is= X-Received: by 2002:a17:906:1091:b0:a02:54fa:4f2f with SMTP id u17-20020a170906109100b00a0254fa4f2fmr1573374eju.53.1701474757149; Fri, 01 Dec 2023 15:52:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Fri, 1 Dec 2023 15:52:25 -0800 Message-ID: Subject: Re: [PATCH ipsec-next v3 5/9] libbpf: selftests: Add verifier tests for CO-RE bitfield writes To: Daniel Xu Cc: ast@kernel.org, daniel@iogearbox.net, shuah@kernel.org, andrii@kernel.org, steffen.klassert@secunet.com, antony.antony@secunet.com, alexei.starovoitov@gmail.com, yonghong.song@linux.dev, eddyz87@gmail.com, mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, devel@linux-ipsec.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 15:53:05 -0800 (PST) On Fri, Dec 1, 2023 at 12:24=E2=80=AFPM Daniel Xu wrote: > > Add some tests that exercise BPF_CORE_WRITE_BITFIELD() macro. Since some > non-trivial bit fiddling is going on, make sure various edge cases (such > as adjacent bitfields and bitfields at the edge of structs) are > exercised. > > Signed-off-by: Daniel Xu > --- > .../selftests/bpf/prog_tests/verifier.c | 2 + > .../bpf/progs/verifier_bitfield_write.c | 100 ++++++++++++++++++ > 2 files changed, 102 insertions(+) > create mode 100644 tools/testing/selftests/bpf/progs/verifier_bitfield_w= rite.c > LGTM, but I'm not sure why we need all those __failure_unpriv, see below. Regardless: Acked-by: Andrii Nakryiko > diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/te= sting/selftests/bpf/prog_tests/verifier.c > index 5cfa7a6316b6..67b4948865a3 100644 > --- a/tools/testing/selftests/bpf/prog_tests/verifier.c > +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c > @@ -6,6 +6,7 @@ > #include "verifier_and.skel.h" > #include "verifier_array_access.skel.h" > #include "verifier_basic_stack.skel.h" > +#include "verifier_bitfield_write.skel.h" > #include "verifier_bounds.skel.h" > #include "verifier_bounds_deduction.skel.h" > #include "verifier_bounds_deduction_non_const.skel.h" > @@ -115,6 +116,7 @@ static void run_tests_aux(const char *skel_name, > > void test_verifier_and(void) { RUN(verifier_and); } > void test_verifier_basic_stack(void) { RUN(verifier_basic_stack= ); } > +void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_wr= ite); } > void test_verifier_bounds(void) { RUN(verifier_bounds); } > void test_verifier_bounds_deduction(void) { RUN(verifier_bounds_dedu= ction); } > void test_verifier_bounds_deduction_non_const(void) { RUN(verifier_b= ounds_deduction_non_const); } > diff --git a/tools/testing/selftests/bpf/progs/verifier_bitfield_write.c = b/tools/testing/selftests/bpf/progs/verifier_bitfield_write.c > new file mode 100644 > index 000000000000..8fe355a19ba6 > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/verifier_bitfield_write.c > @@ -0,0 +1,100 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > + > +#include > +#include > + > +#include "bpf_misc.h" > + > +struct core_reloc_bitfields { > + /* unsigned bitfields */ > + uint8_t ub1: 1; > + uint8_t ub2: 2; > + uint32_t ub7: 7; > + /* signed bitfields */ > + int8_t sb4: 4; > + int32_t sb20: 20; > + /* non-bitfields */ > + uint32_t u32; > + int32_t s32; > +} __attribute__((preserve_access_index)); > + > +SEC("tc") > +__description("single CO-RE bitfield roundtrip") > +__btf_path("btf__core_reloc_bitfields.bpf.o") > +__success __failure_unpriv do we want __failure_unpriv at all? Is this failure related to *bitfield* logic at all? > +__retval(3) > +int single_field_roundtrip(struct __sk_buff *ctx) > +{ > + struct core_reloc_bitfields bitfields; > + > + __builtin_memset(&bitfields, 0, sizeof(bitfields)); > + BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 3); > + return BPF_CORE_READ_BITFIELD(&bitfields, ub2); > +} > + [...]