diff mbox series

[bpf-next,3/5] bpf: add link_query support for newly added main_thread_only info

Message ID 20200827000621.2712111-1-yhs@fb.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: add main_thread_only customization for task/task_file iterators | expand

Commit Message

Yonghong Song Aug. 27, 2020, 12:06 a.m. UTC
Added support for link_query for main_thread_only information
with task/task_file iterators.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 include/uapi/linux/bpf.h       |  5 +++++
 kernel/bpf/task_iter.c         | 17 +++++++++++++++++
 tools/include/uapi/linux/bpf.h |  5 +++++
 3 files changed, 27 insertions(+)

Comments

Andrii Nakryiko Aug. 27, 2020, 5:14 a.m. UTC | #1
On Wed, Aug 26, 2020 at 5:07 PM Yonghong Song <yhs@fb.com> wrote:
>
> Added support for link_query for main_thread_only information
> with task/task_file iterators.
>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
>  include/uapi/linux/bpf.h       |  5 +++++
>  kernel/bpf/task_iter.c         | 17 +++++++++++++++++
>  tools/include/uapi/linux/bpf.h |  5 +++++
>  3 files changed, 27 insertions(+)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index af5c600bf673..595bdc4c9431 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -4259,6 +4259,11 @@ struct bpf_link_info {
>                                 struct {
>                                         __u32 map_id;
>                                 } map;
> +
> +                               struct {
> +                                       __u32 main_thread_only:1;
> +                                       __u32 :31;
> +                               } task;
>                         };
>                 } iter;
>                 struct  {
> diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
> index 362bf2dda63a..7636abe05f27 100644
> --- a/kernel/bpf/task_iter.c
> +++ b/kernel/bpf/task_iter.c
> @@ -329,6 +329,19 @@ static int bpf_iter_attach_task(struct bpf_prog *prog,
>         return 0;
>  }
>
> +static void bpf_iter_task_show_fdinfo(const struct bpf_iter_aux_info *aux,
> +                                     struct seq_file *seq)
> +{
> +       seq_printf(seq, "main_thread_only:\t%u\n", aux->main_thread_only);
> +}
> +
> +static int bpf_iter_task_fill_link_info(const struct bpf_iter_aux_info *aux,
> +                                       struct bpf_link_info *info)
> +{
> +       info->iter.task.main_thread_only = aux->main_thread_only;
> +       return 0;
> +}
> +
>  BTF_ID_LIST(btf_task_file_ids)
>  BTF_ID(struct, task_struct)
>  BTF_ID(struct, file)
> @@ -343,6 +356,8 @@ static const struct bpf_iter_seq_info task_seq_info = {
>  static struct bpf_iter_reg task_reg_info = {
>         .target                 = "task",
>         .attach_target          = bpf_iter_attach_task,
> +       .show_fdinfo            = bpf_iter_task_show_fdinfo,
> +       .fill_link_info         = bpf_iter_task_fill_link_info,
>         .ctx_arg_info_size      = 1,
>         .ctx_arg_info           = {
>                 { offsetof(struct bpf_iter__task, task),
> @@ -361,6 +376,8 @@ static const struct bpf_iter_seq_info task_file_seq_info = {
>  static struct bpf_iter_reg task_file_reg_info = {
>         .target                 = "task_file",
>         .attach_target          = bpf_iter_attach_task,
> +       .show_fdinfo            = bpf_iter_task_show_fdinfo,
> +       .fill_link_info         = bpf_iter_task_fill_link_info,
>         .ctx_arg_info_size      = 2,
>         .ctx_arg_info           = {
>                 { offsetof(struct bpf_iter__task_file, task),
> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> index af5c600bf673..595bdc4c9431 100644
> --- a/tools/include/uapi/linux/bpf.h
> +++ b/tools/include/uapi/linux/bpf.h
> @@ -4259,6 +4259,11 @@ struct bpf_link_info {
>                                 struct {
>                                         __u32 map_id;
>                                 } map;
> +
> +                               struct {
> +                                       __u32 main_thread_only:1;
> +                                       __u32 :31;

nit: unless we want to always re-calculate how many bits we have left
(and specify that in UAPI header), using `__u32: 0` would work here,
won't require updating it with every new flag, and won't accidentally
add an extra 32 bits to the task struct, if we forget to update the
size.

But nothing wrong with :31,  if explicitness was a goal here.

> +                               } task;
>                         };
>                 } iter;
>                 struct  {
> --
> 2.24.1
>
diff mbox series

Patch

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index af5c600bf673..595bdc4c9431 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -4259,6 +4259,11 @@  struct bpf_link_info {
 				struct {
 					__u32 map_id;
 				} map;
+
+				struct {
+					__u32 main_thread_only:1;
+					__u32 :31;
+				} task;
 			};
 		} iter;
 		struct  {
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index 362bf2dda63a..7636abe05f27 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -329,6 +329,19 @@  static int bpf_iter_attach_task(struct bpf_prog *prog,
 	return 0;
 }
 
+static void bpf_iter_task_show_fdinfo(const struct bpf_iter_aux_info *aux,
+				      struct seq_file *seq)
+{
+	seq_printf(seq, "main_thread_only:\t%u\n", aux->main_thread_only);
+}
+
+static int bpf_iter_task_fill_link_info(const struct bpf_iter_aux_info *aux,
+					struct bpf_link_info *info)
+{
+	info->iter.task.main_thread_only = aux->main_thread_only;
+	return 0;
+}
+
 BTF_ID_LIST(btf_task_file_ids)
 BTF_ID(struct, task_struct)
 BTF_ID(struct, file)
@@ -343,6 +356,8 @@  static const struct bpf_iter_seq_info task_seq_info = {
 static struct bpf_iter_reg task_reg_info = {
 	.target			= "task",
 	.attach_target		= bpf_iter_attach_task,
+	.show_fdinfo		= bpf_iter_task_show_fdinfo,
+	.fill_link_info		= bpf_iter_task_fill_link_info,
 	.ctx_arg_info_size	= 1,
 	.ctx_arg_info		= {
 		{ offsetof(struct bpf_iter__task, task),
@@ -361,6 +376,8 @@  static const struct bpf_iter_seq_info task_file_seq_info = {
 static struct bpf_iter_reg task_file_reg_info = {
 	.target			= "task_file",
 	.attach_target		= bpf_iter_attach_task,
+	.show_fdinfo		= bpf_iter_task_show_fdinfo,
+	.fill_link_info		= bpf_iter_task_fill_link_info,
 	.ctx_arg_info_size	= 2,
 	.ctx_arg_info		= {
 		{ offsetof(struct bpf_iter__task_file, task),
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index af5c600bf673..595bdc4c9431 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -4259,6 +4259,11 @@  struct bpf_link_info {
 				struct {
 					__u32 map_id;
 				} map;
+
+				struct {
+					__u32 main_thread_only:1;
+					__u32 :31;
+				} task;
 			};
 		} iter;
 		struct  {