lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fdeda8c6ec282fae793799bf5546d7e3b0578e1a.camel@gmail.com>
Date: Thu, 20 Nov 2025 15:39:55 -0800
From: Eduard Zingerman <eddyz87@...il.com>
To: Donglin Peng <dolinux.peng@...il.com>, ast@...nel.org, 
	andrii.nakryiko@...il.com
Cc: zhangxiaoqin@...omi.com, linux-kernel@...r.kernel.org,
 bpf@...r.kernel.org,  Donglin Peng <pengdonglin@...omi.com>, Alan Maguire
 <alan.maguire@...cle.com>, Song Liu <song@...nel.org>
Subject: Re: [RFC PATCH v7 2/7] selftests/bpf: Add test cases for
 btf__permute functionality

On Wed, 2025-11-19 at 11:15 +0800, Donglin Peng wrote:

[...]

> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_permute.c b/tools/testing/selftests/bpf/prog_tests/btf_permute.c
> new file mode 100644
> index 000000000000..f67bf89519b3
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_permute.c
> @@ -0,0 +1,608 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 Xiaomi */
> +
> +#include <test_progs.h>
> +#include <bpf/btf.h>
> +#include "btf_helpers.h"
> +
> +/* Ensure btf__permute work as expected with base BTF */
> +static void test_permute_base(void)
> +{
> +	struct btf *btf;
> +	__u32 permute_ids[6];
> +	int start_id = 1;
> +	int err;
> +
> +	btf = btf__new_empty();
> +	if (!ASSERT_OK_PTR(btf, "empty_main_btf"))
> +		return;
> +
> +	btf__add_int(btf, "int", 4, BTF_INT_SIGNED);	/* [1] int */
> +	btf__add_ptr(btf, 1);				/* [2] ptr to int */
> +	btf__add_struct(btf, "s1", 4);			/* [3] struct s1 { */
> +	btf__add_field(btf, "m", 1, 0, 0);		/*       int m; */
> +							/* } */
> +	btf__add_struct(btf, "s2", 4);			/* [4] struct s2 { */
> +	btf__add_field(btf, "m", 1, 0, 0);		/*       int m; */
> +							/* } */
> +	btf__add_func_proto(btf, 1);			/* [5] int (*)(int *p); */
> +	btf__add_func_param(btf, "p", 2);
> +	btf__add_func(btf, "f", BTF_FUNC_STATIC, 5);	/* [6] int f(int *p); */
> +
> +	VALIDATE_RAW_BTF(
> +		btf,
> +		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[2] PTR '(anon)' type_id=1",
> +		"[3] STRUCT 's1' size=4 vlen=1\n"
> +		"\t'm' type_id=1 bits_offset=0",
> +		"[4] STRUCT 's2' size=4 vlen=1\n"
> +		"\t'm' type_id=1 bits_offset=0",
> +		"[5] FUNC_PROTO '(anon)' ret_type_id=1 vlen=1\n"
> +		"\t'p' type_id=2",
> +		"[6] FUNC 'f' type_id=5 linkage=static");
> +
> +	permute_ids[1 - start_id] = 4; /* [1] -> [4] */
> +	permute_ids[2 - start_id] = 3; /* [2] -> [3] */
> +	permute_ids[3 - start_id] = 5; /* [3] -> [5] */
> +	permute_ids[4 - start_id] = 1; /* [4] -> [1] */
> +	permute_ids[5 - start_id] = 6; /* [5] -> [6] */
> +	permute_ids[6 - start_id] = 2; /* [6] -> [2] */
> +	err = btf__permute(btf, permute_ids, ARRAY_SIZE(permute_ids), NULL);
> +	if (!ASSERT_OK(err, "btf__permute_base"))
> +		goto done;
> +
> +	VALIDATE_RAW_BTF(
> +		btf,
> +		"[1] STRUCT 's2' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[2] FUNC 'f' type_id=6 linkage=static",
> +		"[3] PTR '(anon)' type_id=4",
> +		"[4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[5] STRUCT 's1' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[6] FUNC_PROTO '(anon)' ret_type_id=4 vlen=1\n"
> +		"\t'p' type_id=3");
> +
> +	/*
> +	 * For base BTF, id_map_cnt must equal to the number of types
> +	 * include VOID type
> +	 */
> +	permute_ids[1 - start_id] = 4; /* [1] -> [4] */
> +	permute_ids[2 - start_id] = 3; /* [2] -> [3] */
> +	permute_ids[3 - start_id] = 5; /* [3] -> [5] */
> +	permute_ids[4 - start_id] = 1; /* [4] -> [1] */
> +	permute_ids[5 - start_id] = 6; /* [5] -> [6] */
> +	permute_ids[6 - start_id] = 2; /* [6] -> [2] */
> +	err = btf__permute(btf, permute_ids, ARRAY_SIZE(permute_ids) - 1, NULL);
> +	if (!ASSERT_ERR(err, "btf__permute_base"))
> +		goto done;
> +
> +	VALIDATE_RAW_BTF(
> +		btf,
> +		"[1] STRUCT 's2' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[2] FUNC 'f' type_id=6 linkage=static",
> +		"[3] PTR '(anon)' type_id=4",
> +		"[4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[5] STRUCT 's1' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[6] FUNC_PROTO '(anon)' ret_type_id=4 vlen=1\n"
> +		"\t'p' type_id=3");
> +
> +	/* Multiple types can not be mapped to the same ID */
> +	permute_ids[1 - start_id] = 4;
> +	permute_ids[2 - start_id] = 4;
> +	permute_ids[3 - start_id] = 5;
> +	permute_ids[4 - start_id] = 1;
> +	permute_ids[5 - start_id] = 6;
> +	permute_ids[6 - start_id] = 2;
> +	err = btf__permute(btf, permute_ids, ARRAY_SIZE(permute_ids), NULL);
> +	if (!ASSERT_ERR(err, "btf__permute_base"))
> +		goto done;

Nit: Maybe extract the VALIDATE_RAW_BTF as a function, so that it is
     not repeated? Otherwise it is a bit harder to tell that you are
     checking for BTF to be intact if error is returned.
     Same for the test_permute_split() case.

> +
> +	VALIDATE_RAW_BTF(
> +		btf,
> +		"[1] STRUCT 's2' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[2] FUNC 'f' type_id=6 linkage=static",
> +		"[3] PTR '(anon)' type_id=4",
> +		"[4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[5] STRUCT 's1' size=4 vlen=1\n"
> +		"\t'm' type_id=4 bits_offset=0",
> +		"[6] FUNC_PROTO '(anon)' ret_type_id=4 vlen=1\n"
> +		"\t'p' type_id=3");

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ