All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	David Vernet <void@manifault.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 05/14] bpf: Add support for custom exception callbacks
Date: Mon, 28 Aug 2023 15:11:54 -0700	[thread overview]
Message-ID: <9ca6f8c6-4296-a703-2413-a844275edb89@linux.dev> (raw)
In-Reply-To: <20230809114116.3216687-6-memxor@gmail.com>

On 8/9/23 4:41 AM, Kumar Kartikeya Dwivedi wrote:
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index d0f6c984272b..9d67d0633c59 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2457,6 +2457,73 @@ static int add_subprog(struct bpf_verifier_env *env, int off)
>   	return env->subprog_cnt - 1;
>   }
>   
> +static int bpf_find_exception_callback_insn_off(struct bpf_verifier_env *env)
> +{
> +	struct bpf_prog_aux *aux = env->prog->aux;
> +	struct btf *btf = aux->btf;
> +	const struct btf_type *t;
> +	const char *name;
> +	u32 main_btf_id;
> +	int ret, i, j;
> +
> +	/* Non-zero func_info_cnt implies valid btf */
> +	if (!aux->func_info_cnt)
> +		return 0;
> +	main_btf_id = aux->func_info[0].type_id;
> +
> +	t = btf_type_by_id(btf, main_btf_id);
> +	if (!t) {
> +		verbose(env, "invalid btf id for main subprog in func_info\n");
> +		return -EINVAL;
> +	}
> +
> +	name = btf_find_decl_tag_value(btf, t, -1, "exception_callback:");
> +	if (IS_ERR(name)) {
> +		ret = PTR_ERR(name);
> +		/* If there is no tag present, there is no exception callback */
> +		if (ret == -ENOENT)
> +			ret = 0;
> +		else if (ret == -EEXIST)
> +			verbose(env, "multiple exception callback tags for main subprog\n");
> +		return ret;
> +	}
> +
> +	ret = -ENOENT;
> +	for (i = 0; i < btf_nr_types(btf); i++) {
> +		t = btf_type_by_id(btf, i);
> +		if (!btf_type_is_func(t))
> +			continue;
> +		if (strcmp(name, btf_name_by_offset(btf, t->name_off)))
> +			continue;

nit. btf_find_by_name_kind() could be used here.


> +		if (btf_func_linkage(t) != BTF_FUNC_GLOBAL) {
> +			verbose(env, "exception callback '%s' must have global linkage\n", name);
> +			return -EINVAL;
> +		} > +
> +		ret = 0;
> +		for (j = 0; j < aux->func_info_cnt; j++) {
> +			if (aux->func_info[j].type_id != i)
> +				continue;
> +			ret = aux->func_info[j].insn_off;
> +			/* Further func_info and subprog checks will also happen
> +			 * later, so assume this is the right insn_off for now.
> +			 */
> +			if (!ret) {
> +				verbose(env, "invalid exception callback insn_off in func_info: 0\n");
> +				ret = -EINVAL;
> +			}
> +		}
> +		if (!ret) {
> +			verbose(env, "exception callback type id not found in func_info\n");
> +			ret = -EINVAL;
> +		}
> +		break;
> +	}
> +	if (ret == -ENOENT)
> +		verbose(env, "exception callback '%s' could not be found in BTF\n", name);
> +	return ret;
> +}


  reply	other threads:[~2023-08-28 22:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09 11:41 [PATCH bpf-next v2 00/14] Exceptions - 1/2 Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 01/14] arch/x86: Implement arch_bpf_stack_walk Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 02/14] bpf: Implement support for adding hidden subprogs Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 03/14] bpf: Implement BPF exceptions Kumar Kartikeya Dwivedi
2023-08-22  5:12   ` Alexei Starovoitov
2023-08-22 12:53     ` Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 04/14] bpf: Refactor check_btf_func and split into two phases Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 05/14] bpf: Add support for custom exception callbacks Kumar Kartikeya Dwivedi
2023-08-28 22:11   ` Martin KaFai Lau [this message]
2023-08-09 11:41 ` [PATCH bpf-next v2 06/14] bpf: Perform CFG walk for exception callback Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 07/14] bpf: Treat first argument as return value for bpf_throw Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 08/14] bpf: Prevent KASAN false positive with bpf_throw Kumar Kartikeya Dwivedi
2023-08-22 16:23   ` Alexei Starovoitov
2023-08-30 16:53   ` Andrey Konovalov
2023-08-09 11:41 ` [PATCH bpf-next v2 09/14] bpf: Detect IP == ksym.end as part of BPF program Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 10/14] bpf: Disallow extensions to exception callbacks Kumar Kartikeya Dwivedi
2023-08-22  5:09   ` Alexei Starovoitov
2023-08-22 12:53     ` Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 11/14] bpf: Fix kfunc callback register type handling Kumar Kartikeya Dwivedi
2023-08-10 21:12   ` David Marchevsky
2023-08-09 11:41 ` [PATCH bpf-next v2 12/14] libbpf: Add support for custom exception callbacks Kumar Kartikeya Dwivedi
2023-08-22 16:34   ` Alexei Starovoitov
2023-08-22 16:58     ` Kumar Kartikeya Dwivedi
2023-08-22 19:20       ` Alexei Starovoitov
2023-08-25 18:43   ` Andrii Nakryiko
2023-08-26 22:41     ` Kumar Kartikeya Dwivedi
2023-08-27 22:27       ` Alexei Starovoitov
2023-08-09 11:41 ` [PATCH bpf-next v2 13/14] selftests/bpf: Add BPF assertion macros Kumar Kartikeya Dwivedi
2023-08-09 11:41 ` [PATCH bpf-next v2 14/14] selftests/bpf: Add tests for BPF exceptions Kumar Kartikeya Dwivedi
2023-08-22 21:22 ` [PATCH bpf-next v2 00/14] Exceptions - 1/2 Kumar Kartikeya Dwivedi
2023-08-22 22:07   ` Jose E. Marchesi
2023-08-22 22:39     ` Yonghong Song
2023-08-22 22:53       ` Kumar Kartikeya Dwivedi
2023-08-22 23:06         ` Alexei Starovoitov
2023-08-25 18:55           ` Andrii Nakryiko
2023-08-26 22:42             ` Kumar Kartikeya Dwivedi
2023-08-22 22:54     ` Kumar Kartikeya Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ca6f8c6-4296-a703-2413-a844275edb89@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=memxor@gmail.com \
    --cc=void@manifault.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.