All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	alexei.starovoitov@gmail.com, martin.lau@kernel.org,
	sinquersw@gmail.com, davemarchevsky@fb.com,
	Amery Hung <amery.hung@bytedance.com>
Subject: Re: [PATCH v1 bpf-next 3/4] bpf: Support bpf_kptr_xchg into local kptr
Date: Wed, 31 Jul 2024 16:38:42 -0700	[thread overview]
Message-ID: <fa767cc5-b330-4789-9a5e-e09e0f224c4e@linux.dev> (raw)
In-Reply-To: <20240728030115.3970543-4-amery.hung@bytedance.com>

On 7/27/24 8:01 PM, Amery Hung wrote:
> @@ -8399,7 +8408,12 @@ static const struct bpf_reg_types func_ptr_types = { .types = { PTR_TO_FUNC } };
>   static const struct bpf_reg_types stack_ptr_types = { .types = { PTR_TO_STACK } };
>   static const struct bpf_reg_types const_str_ptr_types = { .types = { PTR_TO_MAP_VALUE } };
>   static const struct bpf_reg_types timer_types = { .types = { PTR_TO_MAP_VALUE } };
> -static const struct bpf_reg_types kptr_xchg_dest_types = { .types = { PTR_TO_MAP_VALUE } };
> +static const struct bpf_reg_types kptr_xchg_dest_types = {
> +	.types = {
> +		PTR_TO_MAP_VALUE,
> +		PTR_TO_BTF_ID | MEM_ALLOC
> +	}
> +};
>   static const struct bpf_reg_types dynptr_types = {
>   	.types = {
>   		PTR_TO_STACK,
> @@ -8470,7 +8484,8 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
>   	if (base_type(arg_type) == ARG_PTR_TO_MEM)
>   		type &= ~DYNPTR_TYPE_FLAG_MASK;
>   
> -	if (meta->func_id == BPF_FUNC_kptr_xchg && type_is_alloc(type)) {
> +	/* local kptr types are allowed as the source argument of bpf_kptr_xchg */
> +	if (meta->func_id == BPF_FUNC_kptr_xchg && type_is_alloc(type) && regno == BPF_REG_2) {
>   		type &= ~MEM_ALLOC;
>   		type &= ~MEM_PERCPU;
>   	}
> @@ -8563,7 +8578,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
>   			verbose(env, "verifier internal error: unimplemented handling of MEM_ALLOC\n");
>   			return -EFAULT;
>   		}
> -		if (meta->func_id == BPF_FUNC_kptr_xchg) {
> +		if (meta->func_id == BPF_FUNC_kptr_xchg && regno == BPF_REG_2) {

I think this BPF_REG_2 check is because the dst (BPF_REG_1) can be MEM_ALLOC 
now. Just want to ensure I understand it correctly.

One nit. Please also update the document for bpf_kptr_xchg in uapi/linux/bpf.h:

==== >8888 ====
  * void *bpf_kptr_xchg(void *map_value, void *ptr)
  *      Description
  *              Exchange kptr at pointer *map_value* with *ptr*, and return the
==== 8888< ====


  reply	other threads:[~2024-07-31 23:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28  3:01 [PATCH v1 bpf-next 0/4] Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 1/4] bpf: Search for kptrs in prog BTF structs Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 2/4] bpf: Rename ARG_PTR_TO_KPTR -> ARG_KPTR_XCHG_DEST Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 3/4] bpf: Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-31 23:38   ` Martin KaFai Lau [this message]
2024-08-01  4:07     ` Amery Hung
2024-07-28  3:01 ` [PATCH v1 bpf-next 4/4] selftests/bpf: Test bpf_kptr_xchg stashing " Amery Hung
2024-08-01  0:11 ` [PATCH v1 bpf-next 0/4] Support bpf_kptr_xchg " Martin KaFai Lau

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=fa767cc5-b330-4789-9a5e-e09e0f224c4e@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=alexei.starovoitov@gmail.com \
    --cc=amery.hung@bytedance.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davemarchevsky@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=sinquersw@gmail.com \
    /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.