BPF List
 help / color / mirror / Atom feed
From: Philo Lu <lulie@linux.alibaba.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	john.fastabend@gmail.com, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	rostedt@goodmis.org, mhiramat@kernel.org,
	mathieu.desnoyers@efficios.com,
	linux-trace-kernel@vger.kernel.org, xuanzhuo@linux.alibaba.com,
	dust.li@linux.alibaba.com, alibuda@linux.alibaba.com,
	guwen@linux.alibaba.com, hengqi@linux.alibaba.com,
	shung-hsi.yu@suse.com
Subject: Re: [PATCH bpf-next 3/3] bpf: introduce bpf_relay_output helper
Date: Sat, 23 Dec 2023 10:56:40 +0800	[thread overview]
Message-ID: <d26c3522-6042-4ebd-980e-8c21166a19e6@linux.alibaba.com> (raw)
In-Reply-To: <ZYWhOP9og5P0W6Bl@krava>



On 2023/12/22 22:46, Jiri Olsa wrote:
> On Fri, Dec 22, 2023 at 08:21:46PM +0800, Philo Lu wrote:
>> Like perfbuf/ringbuf, a helper is needed to write into the buffer, named
>> bpf_relay_output, whose usage is same as ringbuf. Note that it works only
>> after relay files are set, i.e., after calling map_update_elem for the
>> created relay map.
> 
> we can't add helpers anymore, this will need to be kfunc
> check functions marked with __bpf_kfunc as examples
> 

Got it, I will change it to kfunc in the next version.

Thanks.

> jirka
> 
>>
>> Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
>> ---
>>   include/linux/bpf.h      |  1 +
>>   include/uapi/linux/bpf.h | 10 ++++++++++
>>   kernel/bpf/helpers.c     |  4 ++++
>>   kernel/bpf/relaymap.c    | 26 ++++++++++++++++++++++++++
>>   kernel/bpf/verifier.c    |  8 ++++++++
>>   kernel/trace/bpf_trace.c |  4 ++++
>>   6 files changed, 53 insertions(+)
>>
>> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>> index 7671530d6e4e..b177122369e6 100644
>> --- a/include/linux/bpf.h
>> +++ b/include/linux/bpf.h
>> @@ -3095,6 +3095,7 @@ extern const struct bpf_func_proto bpf_get_retval_proto;
>>   extern const struct bpf_func_proto bpf_user_ringbuf_drain_proto;
>>   extern const struct bpf_func_proto bpf_cgrp_storage_get_proto;
>>   extern const struct bpf_func_proto bpf_cgrp_storage_delete_proto;
>> +extern const struct bpf_func_proto bpf_relay_output_proto;
>>   
>>   const struct bpf_func_proto *tracing_prog_func_proto(
>>     enum bpf_func_id func_id, const struct bpf_prog *prog);
>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> index 143b75676bd3..03c0c1953ba1 100644
>> --- a/include/uapi/linux/bpf.h
>> +++ b/include/uapi/linux/bpf.h
>> @@ -5686,6 +5686,15 @@ union bpf_attr {
>>    *		0 on success.
>>    *
>>    *		**-ENOENT** if the bpf_local_storage cannot be found.
>> + *
>> + * long bpf_relay_output(void *map, void *data, u64 size, u64 flags)
>> + * 	Description
>> + * 		Copy *size* bytes from *data* into *map* of type BPF_MAP_TYPE_RELAY.
>> + * 		Currently, the *flags* must be 0.
>> + * 	Return
>> + * 		0 on success.
>> + *
>> + *		**-ENOENT** if the relay base_file in debugfs cannot be found.
>>    */
>>   #define ___BPF_FUNC_MAPPER(FN, ctx...)			\
>>   	FN(unspec, 0, ##ctx)				\
>> @@ -5900,6 +5909,7 @@ union bpf_attr {
>>   	FN(user_ringbuf_drain, 209, ##ctx)		\
>>   	FN(cgrp_storage_get, 210, ##ctx)		\
>>   	FN(cgrp_storage_delete, 211, ##ctx)		\
>> +	FN(relay_output, 212, ##ctx)		\
>>   	/* */
>>   
>>   /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
>> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
>> index be72824f32b2..0c26e87ce729 100644
>> --- a/kernel/bpf/helpers.c
>> +++ b/kernel/bpf/helpers.c
>> @@ -1720,6 +1720,10 @@ bpf_base_func_proto(enum bpf_func_id func_id)
>>   		return &bpf_ringbuf_discard_proto;
>>   	case BPF_FUNC_ringbuf_query:
>>   		return &bpf_ringbuf_query_proto;
>> +#ifdef CONFIG_RELAY
>> +	case BPF_FUNC_relay_output:
>> +		return &bpf_relay_output_proto;
>> +#endif
>>   	case BPF_FUNC_strncmp:
>>   		return &bpf_strncmp_proto;
>>   	case BPF_FUNC_strtol:
>> diff --git a/kernel/bpf/relaymap.c b/kernel/bpf/relaymap.c
>> index 588c8de0a4bd..f9e2e4a780df 100644
>> --- a/kernel/bpf/relaymap.c
>> +++ b/kernel/bpf/relaymap.c
>> @@ -173,6 +173,32 @@ static u64 relay_map_mem_usage(const struct bpf_map *map)
>>   	return usage;
>>   }
>>   
>> +BPF_CALL_4(bpf_relay_output, struct bpf_map *, map, void *, data, u64, size,
>> +	   u64, flags)
>> +{
>> +	struct bpf_relay_map *rmap;
>> +
>> +	/* not support any flag now */
>> +	if (unlikely(flags))
>> +		return -EINVAL;
>> +
>> +	rmap = container_of(map, struct bpf_relay_map, map);
>> +	if (!rmap->relay_chan->has_base_filename)
>> +		return -ENOENT;
>> +
>> +	relay_write(rmap->relay_chan, data, size);
>> +	return 0;
>> +}
>> +
>> +const struct bpf_func_proto bpf_relay_output_proto = {
>> +	.func		= bpf_relay_output,
>> +	.ret_type	= RET_INTEGER,
>> +	.arg1_type	= ARG_CONST_MAP_PTR,
>> +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
>> +	.arg3_type	= ARG_CONST_SIZE_OR_ZERO,
>> +	.arg4_type	= ARG_ANYTHING,
>> +};
>> +
>>   BTF_ID_LIST_SINGLE(relay_map_btf_ids, struct, bpf_relay_map)
>>   const struct bpf_map_ops relay_map_ops = {
>>   	.map_meta_equal = bpf_map_meta_equal,
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index f13008d27f35..8c8287d6ae18 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -8800,6 +8800,10 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
>>   		if (func_id != BPF_FUNC_user_ringbuf_drain)
>>   			goto error;
>>   		break;
>> +	case BPF_MAP_TYPE_RELAY:
>> +		if (func_id != BPF_FUNC_relay_output)
>> +			goto error;
>> +		break;
>>   	case BPF_MAP_TYPE_STACK_TRACE:
>>   		if (func_id != BPF_FUNC_get_stackid)
>>   			goto error;
>> @@ -8932,6 +8936,10 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
>>   		if (map->map_type != BPF_MAP_TYPE_USER_RINGBUF)
>>   			goto error;
>>   		break;
>> +	case BPF_FUNC_relay_output:
>> +		if (map->map_type != BPF_MAP_TYPE_RELAY)
>> +			goto error;
>> +		break;
>>   	case BPF_FUNC_get_stackid:
>>   		if (map->map_type != BPF_MAP_TYPE_STACK_TRACE)
>>   			goto error;
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 7ac6c52b25eb..5b13553c6232 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -1594,6 +1594,10 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>>   		return &bpf_ringbuf_discard_proto;
>>   	case BPF_FUNC_ringbuf_query:
>>   		return &bpf_ringbuf_query_proto;
>> +#ifdef CONFIG_RELAY
>> +	case BPF_FUNC_relay_output:
>> +		return &bpf_relay_output_proto;
>> +#endif
>>   	case BPF_FUNC_jiffies64:
>>   		return &bpf_jiffies64_proto;
>>   	case BPF_FUNC_get_task_stack:
>> -- 
>> 2.32.0.3.g01195cf9f
>>

  reply	other threads:[~2023-12-23  2:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22 12:21 [PATCH bpf-next 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Philo Lu
2023-12-22 12:21 ` [PATCH bpf-next 1/3] bpf: implement relay map basis Philo Lu
2023-12-22 14:45   ` Jiri Olsa
2023-12-23  2:54     ` Philo Lu
2023-12-22 23:07   ` kernel test robot
2023-12-23  0:11   ` kernel test robot
2023-12-23 11:22   ` Hou Tao
2023-12-23 13:02     ` Philo Lu
2023-12-25 11:36       ` Philo Lu
2023-12-25 13:06         ` Hou Tao
2023-12-22 12:21 ` [PATCH bpf-next 2/3] bpf: implement map_update_elem to init relay file Philo Lu
2023-12-22 14:45   ` Jiri Olsa
2023-12-23  2:55     ` Philo Lu
2023-12-23 11:28   ` Hou Tao
2023-12-23 13:19     ` Philo Lu
2023-12-22 12:21 ` [PATCH bpf-next 3/3] bpf: introduce bpf_relay_output helper Philo Lu
2023-12-22 14:46   ` Jiri Olsa
2023-12-23  2:56     ` Philo Lu [this message]
2023-12-22 14:45 ` [PATCH bpf-next 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Jiri Olsa
2023-12-23  2:57   ` Philo Lu

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=d26c3522-6042-4ebd-980e-8c21166a19e6@linux.alibaba.com \
    --to=lulie@linux.alibaba.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=guwen@linux.alibaba.com \
    --cc=haoluo@google.com \
    --cc=hengqi@linux.alibaba.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=olsajiri@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=sdf@google.com \
    --cc=shung-hsi.yu@suse.com \
    --cc=song@kernel.org \
    --cc=xuanzhuo@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox