From nobody Wed Dec 17 23:28:08 2025 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 2E9DBC77B72 for ; Mon, 17 Apr 2023 08:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjDQIIP (ORCPT ); Mon, 17 Apr 2023 04:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbjDQIIL (ORCPT ); Mon, 17 Apr 2023 04:08:11 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9924C21 for ; Mon, 17 Apr 2023 01:08:10 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id b2-20020a17090a6e0200b002470b249e59so14343099pjk.4 for ; Mon, 17 Apr 2023 01:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681718889; x=1684310889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hr7bhkX+Epn2YWYx/+oT337obKjgENzwcgRHzhBp9VI=; b=bJXY+7hDuLaSpYXxwM/yztjf06sBYybcq8xuD8cBmDItLAyd9PmLi0XpAUmOy6xHv+ dpbs4n5YrNyNLE6256NVjkOrdAV6ktoGBOmDZ9w7UHcKgAIC3bNX800RYlnF+U6pPF5d m21gfVGUIQGEEs5qowWSv8XTYGM8zmGWtv7OcI8aqDLWt1uQ5wboTfo0EHtda091FaMw 6iUnxdRbHa9aD3jdgBxyNYqLNz1cG0soqrHKFcaTf2LvRmOHyJ/96GhZ3Rzurl4r7P1p jipg6Ig8ym6ndYHYqs4TO55xszkUOh8WKQYAKfRyxwSrUHA7J+aT64DOXYKx+0vk10q/ DqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681718889; x=1684310889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hr7bhkX+Epn2YWYx/+oT337obKjgENzwcgRHzhBp9VI=; b=ZEICND6007Ybai55tJyxBDEjVGwl5Z4W6uTnxfuaDymvok8IW7Pt7AlS58gyT5dVD3 TjPwgzlH+d68JS9HXBsXk/9fUOmawgqBiKNHNbNoqBdu3z5CEq5jmq83lhAGClZoh49n IGQ49eatHZ7+tkToHBw+ChNPzKarJ1zFnpmeCOUKZknkdS3OgPAUWMcu2B/tgIuPXgOP k+GM2YttZsVc3aXs1bLZUR9idHEmLLa2ZzzOykzlvJW408cTBGMPdNBa9F81YtwkkCyn S++uzEiC7X0eXdA8III590+VilzLXfFTUaU1yG75QinYHtcXM44+QaAVgdyyLO4DvGoc i8Dg== X-Gm-Message-State: AAQBX9cxqgYKoWSKaDZTYE/L+QvdfgzS60c2t1zPdHcZv4bTXYmTv0Q7 kqohMv3eqBvuFP7rK1dyPiVgsUJh2mTlBb3pYGa+TA== X-Google-Smtp-Source: AKy350Y3sXXM1tDYSIZfPXRNb03tgaugGTrcsfNudlJlHZ3NSLoFefzqTDUv758I0MgQ0K4KVNT24g== X-Received: by 2002:a17:902:db09:b0:19e:6cb9:4c8f with SMTP id m9-20020a170902db0900b0019e6cb94c8fmr15803413plx.41.1681718889687; Mon, 17 Apr 2023 01:08:09 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id jc3-20020a17090325c300b0019a97a4324dsm7114135plb.5.2023.04.17.01.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 01:08:09 -0700 (PDT) From: Feng zhou To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH 1/2] bpf: support access variable length array of integer type Date: Mon, 17 Apr 2023 16:07:48 +0800 Message-Id: <20230417080749.39074-2-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230417080749.39074-1-zhoufeng.zf@bytedance.com> References: <20230417080749.39074-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Feng Zhou After this commit: bpf: Support variable length array in tracing programs (9c5f8a1008a1) Trace programs can access variable length array, but for structure type. This patch adds support for integer type. Example: Hook load_balance struct sched_domain { ... unsigned long span[]; } The access: sd->span[0]. Co-developed-by: Chengming Zhou Signed-off-by: Chengming Zhou Signed-off-by: Feng Zhou --- kernel/bpf/btf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 027f9f8a3551..a0887ee44e89 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6157,11 +6157,13 @@ static int btf_struct_walk(struct bpf_verifier_log = *log, const struct btf *btf, if (off < moff) goto error; =20 - /* Only allow structure for now, can be relaxed for - * other types later. - */ + /* allow structure and integer */ t =3D btf_type_skip_modifiers(btf, array_elem->type, NULL); + + if (btf_type_is_int(t)) + return WALK_SCALAR; + if (!btf_type_is_struct(t)) goto error; =20 --=20 2.20.1 From nobody Wed Dec 17 23:28:08 2025 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 A02B2C77B76 for ; Mon, 17 Apr 2023 08:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjDQIIu (ORCPT ); Mon, 17 Apr 2023 04:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbjDQIIs (ORCPT ); Mon, 17 Apr 2023 04:08:48 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244B34EC0 for ; Mon, 17 Apr 2023 01:08:19 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id s6-20020a17090a698600b00247a7794e78so873174pjj.0 for ; Mon, 17 Apr 2023 01:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681718898; x=1684310898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1pw86lkQMgAq2RDg8SbWVwn8vGT1h12ZQk1wvkYIReo=; b=hjF133/QONFZyitenmtjp0ZYeV3xbNysg6Km7omFX2WmTCji5Q0JNOY1YRay8T8RtG f+2xfP4i1GEDVWsEWu4nqWyEVKCAdlfn7LYHPQiiBeMnkYw5dlsobVnqFQzohR3zgpAA DSbF3zfJH6AqSwVO+gOARdL5BahZ5qhS+QLAugiTWX1UDaltFt9UFV3wcVPD464HDeY5 fgsbbVTnwHJlBBXd4yHWdEH7L4rwCi+fjhM7c4wahS7qWRM9l/7SdPeMZsToa+ortz0v cEh+gwpdv+tPlN2YtPzacZo54zM8pQhtc9X1omgDjbw3tq+bVUY+NCVyE5B+gi4HpHq4 kmzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681718898; x=1684310898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1pw86lkQMgAq2RDg8SbWVwn8vGT1h12ZQk1wvkYIReo=; b=YUw7v+joXD+p1e9UPMiSs7lNDjmKC97YxstKEACZXbeXryHEJ2TeRF4XFl2JsYV2aT opeyia/Iaa8y3CeBfOsomkFP2OGDtZc1dncc4zv2Y47xNBUPGl+SevAkH/rtPAoyvxTU ahlyOraKT+ZymaQbhsCol8AugZPOq7U5K786cBIpVXbtfj9AXqqq/DAGke/3BBUDKmFK hjs62MmnGOa5DpydNHjjizhYxw+opKHcjhxr5K2wwrmvcpONVoI4QwTA1bYIfKd6bS+J jVkwpQ1hkP67QNE7HhbhPu1BbGl/NOfWhzQxOBRlI1kvaxdFXsXbNtdo16sGITqPUpEz 0qCA== X-Gm-Message-State: AAQBX9cD3TLtGm9/EhIFWv8fdv5RFL0/pxYkrKWw3S/Eeq7uWN7zlFQP 4k8+fqXZ/PPnz5PC6A1KvL3yVQ== X-Google-Smtp-Source: AKy350Z8s7HBWoiUwUgBaoQgtBCq8ongGM5SOTp6XKSAx/VbvU1WfA8zD0I7T0xDwVZMO4CjZfb9tw== X-Received: by 2002:a17:902:e804:b0:1a6:b98b:eea9 with SMTP id u4-20020a170902e80400b001a6b98beea9mr8184873plg.20.1681718898555; Mon, 17 Apr 2023 01:08:18 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id jc3-20020a17090325c300b0019a97a4324dsm7114135plb.5.2023.04.17.01.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 01:08:18 -0700 (PDT) From: Feng zhou To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH 2/2] selftests/bpf: Add test to access integer type of variable array Date: Mon, 17 Apr 2023 16:07:49 +0800 Message-Id: <20230417080749.39074-3-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230417080749.39074-1-zhoufeng.zf@bytedance.com> References: <20230417080749.39074-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Feng Zhou Add prog test for accessing integer type of variable array in tracing program. Co-developed-by: Chengming Zhou Signed-off-by: Chengming Zhou Signed-off-by: Feng Zhou --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 20 +++++++++++++++++++ .../selftests/bpf/prog_tests/tracing_struct.c | 2 ++ .../selftests/bpf/progs/tracing_struct.c | 13 ++++++++++++ 3 files changed, 35 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/= testing/selftests/bpf/bpf_testmod/bpf_testmod.c index fe847ebfb731..52785ba671e6 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -28,6 +28,11 @@ struct bpf_testmod_struct_arg_2 { long b; }; =20 +struct bpf_testmod_struct_arg_3 { + int a; + int b[]; +}; + __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "Global functions as their definitions will be in bpf_testmod.ko BTF"); @@ -63,6 +68,12 @@ bpf_testmod_test_struct_arg_5(void) { return bpf_testmod_test_struct_arg_result; } =20 +noinline int +bpf_testmod_test_struct_arg_6(struct bpf_testmod_struct_arg_3 *a) { + bpf_testmod_test_struct_arg_result =3D a->b[0]; + return bpf_testmod_test_struct_arg_result; +} + __bpf_kfunc void bpf_testmod_test_mod_kfunc(int i) { @@ -195,6 +206,7 @@ bpf_testmod_test_read(struct file *file, struct kobject= *kobj, }; struct bpf_testmod_struct_arg_1 struct_arg1 =3D {10}; struct bpf_testmod_struct_arg_2 struct_arg2 =3D {2, 3}; + struct bpf_testmod_struct_arg_3 *struct_arg3; int i =3D 1; =20 while (bpf_testmod_return_ptr(i)) @@ -206,6 +218,14 @@ bpf_testmod_test_read(struct file *file, struct kobjec= t *kobj, (void)bpf_testmod_test_struct_arg_4(struct_arg1, 1, 2, 3, struct_arg2); (void)bpf_testmod_test_struct_arg_5(); =20 + struct_arg3 =3D kmalloc((sizeof(struct bpf_testmod_struct_arg_3) + + sizeof(int)), GFP_KERNEL); + if (struct_arg3 !=3D NULL) { + struct_arg3->b[0] =3D 1; + (void)bpf_testmod_test_struct_arg_6(struct_arg3); + kfree(struct_arg3); + } + /* This is always true. Use the check to make sure the compiler * doesn't remove bpf_testmod_loop_test. */ diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_struct.c b/tool= s/testing/selftests/bpf/prog_tests/tracing_struct.c index 48dc9472e160..1c75a32186d6 100644 --- a/tools/testing/selftests/bpf/prog_tests/tracing_struct.c +++ b/tools/testing/selftests/bpf/prog_tests/tracing_struct.c @@ -53,6 +53,8 @@ static void test_fentry(void) =20 ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret"); =20 + ASSERT_EQ(skel->bss->t6, 1, "t6 ret"); + tracing_struct__detach(skel); destroy_skel: tracing_struct__destroy(skel); diff --git a/tools/testing/selftests/bpf/progs/tracing_struct.c b/tools/tes= ting/selftests/bpf/progs/tracing_struct.c index e718f0ebee7d..c435a3a8328a 100644 --- a/tools/testing/selftests/bpf/progs/tracing_struct.c +++ b/tools/testing/selftests/bpf/progs/tracing_struct.c @@ -13,12 +13,18 @@ struct bpf_testmod_struct_arg_2 { long b; }; =20 +struct bpf_testmod_struct_arg_3 { + int a; + int b[]; +}; + long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs; __u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3; long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret; long t3_a, t3_b, t3_c_a, t3_c_b, t3_ret; long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret; long t5_ret; +int t6; =20 SEC("fentry/bpf_testmod_test_struct_arg_1") int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, = b, int, c) @@ -117,4 +123,11 @@ int BPF_PROG2(test_struct_arg_10, int, ret) return 0; } =20 +SEC("fentry/bpf_testmod_test_struct_arg_6") +int BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a) +{ + t6 =3D a->b[0]; + return 0; +} + char _license[] SEC("license") =3D "GPL"; --=20 2.20.1