All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info
@ 2018-12-12 17:37 Song Liu
  2018-12-12 17:37 ` [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h Song Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Song Liu @ 2018-12-12 17:37 UTC (permalink / raw)
  To: netdev; +Cc: Song Liu, ast, daniel, kernel-team

Changes v2 -> v3:
1. remove check for bpf_dump_raw_ok().

Changes v1 -> v2:
1. Fix error path as Martin suggested.

This patch adds nr_prog_tags and prog_tags to bpf_prog_info. This is a
reliable way for user space to get tags of all sub programs. Before this
patch, user space need to find sub program tags via kallsyms.

This feature will be used in BPF introspection, where user space queries
information about BPF programs via sys_bpf.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 include/uapi/linux/bpf.h |  2 ++
 kernel/bpf/syscall.c     | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index aa582cd5bfcf..e7d57e89f25f 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -2717,6 +2717,8 @@ struct bpf_prog_info {
 	__u32 nr_jited_line_info;
 	__u32 line_info_rec_size;
 	__u32 jited_line_info_rec_size;
+	__u32 nr_prog_tags;
+	__aligned_u64 prog_tags;
 } __attribute__((aligned(8)));

 struct bpf_map_info {
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 70fb11106fc2..894a2199ec40 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2323,6 +2323,28 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 		}
 	}

+	ulen = info.nr_prog_tags;
+	info.nr_prog_tags = prog->aux->func_cnt ? : 1;
+	if (ulen) {
+		__u8 __user (*user_prog_tags)[BPF_TAG_SIZE];
+		u32 i;
+
+		user_prog_tags = u64_to_user_ptr(info.prog_tags);
+		ulen = min_t(u32, info.nr_prog_tags, ulen);
+		if (prog->aux->func_cnt) {
+			for (i = 0; i < ulen; i++) {
+				if (copy_to_user(user_prog_tags[i],
+						 prog->aux->func[i]->tag,
+						 BPF_TAG_SIZE))
+					return -EFAULT;
+			}
+		} else {
+			if (copy_to_user(user_prog_tags[0],
+					 prog->tag, BPF_TAG_SIZE))
+				return -EFAULT;
+		}
+	}
+
 done:
 	if (copy_to_user(uinfo, &info, info_len) ||
 	    put_user(info_len, &uattr->info.info_len))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h
  2018-12-12 17:37 [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Song Liu
@ 2018-12-12 17:37 ` Song Liu
  2018-12-13  1:42   ` Martin Lau
  2018-12-13  1:39 ` [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Martin Lau
  2018-12-13 11:26 ` Daniel Borkmann
  2 siblings, 1 reply; 5+ messages in thread
From: Song Liu @ 2018-12-12 17:37 UTC (permalink / raw)
  To: netdev; +Cc: Song Liu, ast, daniel, kernel-team

Sync bpf.h for nr_prog_tags and prog_tags.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 tools/include/uapi/linux/bpf.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index aa582cd5bfcf..e7d57e89f25f 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -2717,6 +2717,8 @@ struct bpf_prog_info {
 	__u32 nr_jited_line_info;
 	__u32 line_info_rec_size;
 	__u32 jited_line_info_rec_size;
+	__u32 nr_prog_tags;
+	__aligned_u64 prog_tags;
 } __attribute__((aligned(8)));
 
 struct bpf_map_info {
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info
  2018-12-12 17:37 [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Song Liu
  2018-12-12 17:37 ` [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h Song Liu
@ 2018-12-13  1:39 ` Martin Lau
  2018-12-13 11:26 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: Martin Lau @ 2018-12-13  1:39 UTC (permalink / raw)
  To: Song Liu; +Cc: netdev, ast, daniel, Kernel Team

On Wed, Dec 12, 2018 at 09:37:46AM -0800, Song Liu wrote:
> Changes v2 -> v3:
> 1. remove check for bpf_dump_raw_ok().
> 
> Changes v1 -> v2:
> 1. Fix error path as Martin suggested.
> 
> This patch adds nr_prog_tags and prog_tags to bpf_prog_info. This is a
> reliable way for user space to get tags of all sub programs. Before this
> patch, user space need to find sub program tags via kallsyms.
Acked-by: Martin KaFai Lau <kafai@fb.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h
  2018-12-12 17:37 ` [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h Song Liu
@ 2018-12-13  1:42   ` Martin Lau
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Lau @ 2018-12-13  1:42 UTC (permalink / raw)
  To: Song Liu; +Cc: netdev, ast, daniel, Kernel Team

On Wed, Dec 12, 2018 at 09:37:47AM -0800, Song Liu wrote:
> Sync bpf.h for nr_prog_tags and prog_tags.
Acked-by: Martin KaFai Lau <kafai@fb.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info
  2018-12-12 17:37 [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Song Liu
  2018-12-12 17:37 ` [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h Song Liu
  2018-12-13  1:39 ` [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Martin Lau
@ 2018-12-13 11:26 ` Daniel Borkmann
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2018-12-13 11:26 UTC (permalink / raw)
  To: Song Liu, netdev; +Cc: ast, kernel-team

On 12/12/2018 06:37 PM, Song Liu wrote:
> Changes v2 -> v3:
> 1. remove check for bpf_dump_raw_ok().
> 
> Changes v1 -> v2:
> 1. Fix error path as Martin suggested.
> 
> This patch adds nr_prog_tags and prog_tags to bpf_prog_info. This is a
> reliable way for user space to get tags of all sub programs. Before this
> patch, user space need to find sub program tags via kallsyms.
> 
> This feature will be used in BPF introspection, where user space queries
> information about BPF programs via sys_bpf.
> 
> Signed-off-by: Song Liu <songliubraving@fb.com>

Looks better, applied, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-13 11:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 17:37 [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Song Liu
2018-12-12 17:37 ` [PATCH v3 bpf-next 2/2] bpf: sync tools/include/uapi/linux/bpf.h Song Liu
2018-12-13  1:42   ` Martin Lau
2018-12-13  1:39 ` [PATCH v3 bpf-next 1/2] bpf: include sub program tags in bpf_prog_info Martin Lau
2018-12-13 11:26 ` Daniel Borkmann

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.