From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 590C829A9D2 for ; Thu, 15 May 2025 13:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747314027; cv=none; b=iou3Bfdrm4Pmncafb0iDVREi3BKEsn54XusnkRoiA9PZllT0Qy0t8eyD0Ra7twH7eegKi+aEK87X0skh7dMGYwOhcjxpsuK9MEi3C1n1IGOGU7ft92Ut3B3CYzkQT2CpoQKPb8IxPV93PUgUXo8z5bxcG3AI44gvk3nDioaKm7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747314027; c=relaxed/simple; bh=069WWNaBNOdGxapm5+teX/2X7XGRTzvIlToc1CqrwN0=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=Yn72XVs7tq7EDsxW6PgYfAsAswr13WGPpa+ffsNe8+qAbJAurZvORm4s+Qi1u35mt60dIIuFhJ1d44CphVqNPLdhZGJrhBz7ZBxzZsv7D7HV9gb+3P8RYiNwwB9Ir9+Ip2fdmfzzwQR4xooNoliOhWH7Z9lg+3TtMYHKMjb0bpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=YQ0YEZrS; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="YQ0YEZrS" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1747314013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PdiS0ZXJtT9OI5f7vo+jFOFjHxyJbWuYbPxzzpD0umM=; b=YQ0YEZrSUMFiSnJJCYJFIPNGVsN9kQ0ZJ3iWRmm5ROi+oe0Z9KWLeyiKksBoTOP+W3W35c KT60cUqHELFpF+dC5y82hMj3vvMgoUn0cFLAT/P7jSPImvaaQ5+N5nyd9JTn0ujdMRvDE5 UfmSsFQ69m7WgaME8eOHTbS/V/rGXgE= Date: Thu, 15 May 2025 13:00:07 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Jiayuan Chen" Message-ID: <6a0524f8edd81f3bfafe8e139951b7ac78dd1fc0@linux.dev> TLS-Required: No Subject: Re: [PATCH bpf-next v2] bpftool: Add support for custom BTF path in prog load/loadall To: "Quentin Monnet" , bpf@vger.kernel.org Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Martin KaFai Lau" , "Eduard Zingerman" , "Song Liu" , "Yonghong Song" , "John Fastabend" , "KP Singh" , "Stanislav Fomichev" , "Hao Luo" , "Jiri Olsa" , "Daniel Xu" , "Mykyta Yatsenko" , "Tao Chen" , linux-kernel@vger.kernel.org In-Reply-To: References: <20250515065018.240188-1-jiayuan.chen@linux.dev> X-Migadu-Flow: FLOW_OUT May 15, 2025 at 17:17, "Quentin Monnet" wrote: >=20 >=202025-05-15 14:50 UTC+0800 ~ Jiayuan Chen >=20 >=20>=20 >=20> This patch exposes the btf_custom_path feature to bpftool, allowing= users > >=20 >=20> to specify a custom BTF file when loading BPF programs using prog = load or > >=20 >=20> prog loadall commands. > >=20 >=20>=20=20 >=20>=20 >=20> The argument 'btf_custom_path' in libbpf is used for those kernes = that > >=20 >=20 > Typo: "kernes" >=20 >=20>=20 >=20> don't have CONFIG_DEBUG_INFO_BTF enabled but still want to perform = CO-RE > >=20 >=20> relocations. > >=20 >=20>=20=20 >=20>=20 >=20> Signed-off-by: Jiayuan Chen > >=20 >=20> --- > >=20 >=20> tools/bpf/bpftool/Documentation/bpftool-prog.rst | 7 ++++++- > >=20 >=20> tools/bpf/bpftool/bash-completion/bpftool | 2 +- > >=20 >=20> tools/bpf/bpftool/prog.c | 12 +++++++++++- > >=20 >=20> 3 files changed, 18 insertions(+), 3 deletions(-) > >=20 >=20>=20=20 >=20>=20 >=20> diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/to= ols/bpf/bpftool/Documentation/bpftool-prog.rst > >=20 >=20> index d6304e01afe0..e60a829ab8d0 100644 > >=20 >=20> --- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst > >=20 >=20> +++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst > >=20 >=20> @@ -127,7 +127,7 @@ bpftool prog pin *PROG* *FILE* > >=20 >=20> Note: *FILE* must be located in *bpffs* mount. It must not contain= a dot > >=20 >=20> character ('.'), which is reserved for future extensions of *bpffs= *. > >=20 >=20>=20=20 >=20>=20 >=20> -bpftool prog { load | loadall } *OBJ* *PATH* [type *TYPE*] [map {= idx *IDX* | name *NAME* } *MAP*] [{ offload_dev | xdpmeta_dev } *NAME*] = [pinmaps *MAP_DIR*] [autoattach] > >=20 >=20> +bpftool prog { load | loadall } *OBJ* *PATH* [type *TYPE*] [map {= idx *IDX* | name *NAME* } *MAP*] [{ offload_dev | xdpmeta_dev } *NAME*] = [pinmaps *MAP_DIR*] [autoattach] [kernel_btf *BTF_DIR*] > >=20 >=20> Load bpf program(s) from binary *OBJ* and pin as *PATH*. **bpftool= prog > >=20 >=20> load** pins only the first program from the *OBJ* as *PATH*. **bpf= tool prog > >=20 >=20> loadall** pins all programs from the *OBJ* under *PATH* directory.= **type** > >=20 >=20> @@ -153,6 +153,11 @@ bpftool prog { load | loadall } *OBJ* *PATH* = [type *TYPE*] [map { idx *IDX* | na > >=20 >=20> program does not support autoattach, bpftool falls back to regular= pinning > >=20 >=20> for that program instead. > >=20 >=20>=20=20 >=20>=20 >=20> + The **kernel_btf** option allows specifying an external BTF file= to replace > >=20 >=20> + the system's own vmlinux BTF file for CO-RE relocations. NOTE th= at any > >=20 >=20> + other feature (e.g., fentry/fexit programs, struct_ops, etc) wil= l require > >=20 >=20 > Nit: No need for both "e.g." and "etc", they're redundant. >=20 >=20>=20 >=20> + actual kernel BTF like /sys/kernel/btf/vmlinux. > >=20 >=20> + > >=20 >=20 > Can we rephrase the second part of the paragraph a little bit please? >=20 >=20=E2=80=9CAny other feature=E2=80=9D could be clearer, how about: >=20 >=20 Note that any other feature relying on BTF (such as fentry/fexit >=20 >=20 programs, struct_ops) requires the BTF file for the actual >=20 >=20 kernel running on the host, often exposed at >=20 >=20 /sys/kernel/btf/vmlinux. >=20 >=20>=20 >=20> Note: *PATH* must be located in *bpffs* mount. It must not contain = a dot > >=20 >=20> character ('.'), which is reserved for future extensions of *bpffs= *. > >=20 >=20>=20=20 >=20>=20 >=20> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf= /bpftool/bash-completion/bpftool > >=20 >=20> index 1ce409a6cbd9..609938c287b7 100644 > >=20 >=20> --- a/tools/bpf/bpftool/bash-completion/bpftool > >=20 >=20> +++ b/tools/bpf/bpftool/bash-completion/bpftool > >=20 >=20> @@ -511,7 +511,7 @@ _bpftool() > >=20 >=20> ;; > >=20 >=20> *) > >=20 >=20> COMPREPLY=3D( $( compgen -W "map" -- "$cur" ) ) > >=20 >=20> - _bpftool_once_attr 'type pinmaps autoattach' > >=20 >=20> + _bpftool_once_attr 'type pinmaps autoattach kernel_btf' > >=20 >=20> _bpftool_one_of_list 'offload_dev xdpmeta_dev' > >=20 >=20> return 0 > >=20 >=20> ;; > >=20 >=20 > Correct, but right before this could you also add the following, please= : >=20 >=20 @@ -505,13 +505,13 @@ _bpftool() >=20 >=20 _bpftool_get_map_names >=20 >=20 return 0 >=20 >=20 ;; >=20 >=20 - pinned|pinmaps) >=20 >=20 + pinned|pinmaps|kernel_btf) >=20 >=20 _filedir >=20 >=20 return 0 >=20 >=20 ;; >=20 >=20 *) >=20 >=20This will make the completion offer file names after the user has typ= ed >=20 >=20"kernel_btf". >=20 >=20>=20 >=20> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c > >=20 >=20> index f010295350be..3b6a361dd0f8 100644 > >=20 >=20> --- a/tools/bpf/bpftool/prog.c > >=20 >=20> +++ b/tools/bpf/bpftool/prog.c > >=20 >=20> @@ -1681,8 +1681,17 @@ static int load_with_options(int argc, char= **argv, bool first_prog_only) > >=20 >=20> } else if (is_prefix(*argv, "autoattach")) { > >=20 >=20> auto_attach =3D true; > >=20 >=20> NEXT_ARG(); > >=20 >=20> + } else if (is_prefix(*argv, "kernel_btf")) { > >=20 >=20> + NEXT_ARG(); > >=20 >=20> + > >=20 >=20> + if (!REQ_ARGS(1)) > >=20 >=20> + goto err_free_reuse_maps; > >=20 >=20> + > >=20 >=20> + open_opts.btf_custom_path =3D GET_ARG(); > >=20 >=20> } else { > >=20 >=20> - p_err("expected no more arguments, 'type', 'map' or 'dev', got: = '%s'?", > >=20 >=20> + p_err("expected no more arguments, " > >=20 >=20> + "'type', 'map', 'dev', 'offload_dev', 'xdpmeta_dev', 'pinmaps', = " > >=20 >=20> + "'autoattach', or 'kernel_btf', got: '%s'?", > >=20 >=20 > Some of them were missing, thanks for this! Can you remove "dev" from >=20 >=20the list, please? It's been deprecated in favour of "offload_dev", to >=20 >=20avoid confusion with "xdpmeta_dev". >=20 >=20pw-bot: cr >=20 >=20>=20 >=20> *argv); > >=20 >=20> goto err_free_reuse_maps; > >=20 >=20> } > >=20 >=20> @@ -2474,6 +2483,7 @@ static int do_help(int argc, char **argv) > >=20 >=20> " [map { idx IDX | name NAME } MAP]\\\n" > >=20 >=20> " [pinmaps MAP_DIR]\n" > >=20 >=20> " [autoattach]\n" > >=20 >=20> + " [kernel_btf BTF_DIR]\n" > >=20 >=20> " %1$s %2$s attach PROG ATTACH_TYPE [MAP]\n" > >=20 >=20> " %1$s %2$s detach PROG ATTACH_TYPE [MAP]\n" > >=20 >=20> " %1$s %2$s run PROG \\\n" > >=20 >=20 > Thanks, >=20 >=20Quentin > Thank you, Quentin. Your suggestions are all very valuable; I will make t= he updates.