Commit 780c6983 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'Access variable length array relaxed for integer type'



Feng zhou says:

====================

From: Feng Zhou <zhoufeng.zf@bytedance.com>

Add support for integer type of accessing variable length array.
Add a selftest to check it.
====================

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 2ddade32 5ff54ded
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -6157,11 +6157,13 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,
		if (off < moff)
			goto error;

		/* Only allow structure for now, can be relaxed for
		 * other types later.
		 */
		/* allow structure and integer */
		t = 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 −0
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@ struct bpf_testmod_struct_arg_2 {
	long b;
};

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;
}

noinline int
bpf_testmod_test_struct_arg_6(struct bpf_testmod_struct_arg_3 *a) {
	bpf_testmod_test_struct_arg_result = 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 = {10};
	struct bpf_testmod_struct_arg_2 struct_arg2 = {2, 3};
	struct bpf_testmod_struct_arg_3 *struct_arg3;
	int i = 1;

	while (bpf_testmod_return_ptr(i))
@@ -206,6 +218,14 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
	(void)bpf_testmod_test_struct_arg_4(struct_arg1, 1, 2, 3, struct_arg2);
	(void)bpf_testmod_test_struct_arg_5();

	struct_arg3 = kmalloc((sizeof(struct bpf_testmod_struct_arg_3) +
				sizeof(int)), GFP_KERNEL);
	if (struct_arg3 != NULL) {
		struct_arg3->b[0] = 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.
	 */
+16 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Bytedance */

#include <test_progs.h>
#include "test_access_variable_array.skel.h"

void test_access_variable_array(void)
{
	struct test_access_variable_array *skel;

	skel = test_access_variable_array__open_and_load();
	if (!ASSERT_OK_PTR(skel, "test_access_variable_array__open_and_load"))
		return;

	test_access_variable_array__destroy(skel);
}
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ static void test_fentry(void)

	ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret");

	ASSERT_EQ(skel->bss->t6, 1, "t6 ret");

	tracing_struct__detach(skel);
destroy_skel:
	tracing_struct__destroy(skel);
+19 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Bytedance */

#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

unsigned long span = 0;

SEC("fentry/load_balance")
int BPF_PROG(fentry_fentry, int this_cpu, struct rq *this_rq,
		struct sched_domain *sd)
{
	span = sd->span[0];

	return 0;
}

char _license[] SEC("license") = "GPL";
Loading