BPF List
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
	Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH 1/4] bpf: Add pin_name into struct bpf_prog_aux
Date: Fri, 11 Feb 2022 12:11:42 +0000	[thread overview]
Message-ID: <20220211121145.35237-2-laoar.shao@gmail.com> (raw)
In-Reply-To: <20220211121145.35237-1-laoar.shao@gmail.com>

A new member pin_name is added into struct bpf_prog_aux, which will be
set when the prog is set and cleared when the pinned file is removed.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/linux/bpf.h      |  2 ++
 include/uapi/linux/bpf.h |  1 +
 kernel/bpf/inode.c       | 20 +++++++++++++++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 0ceb25b..9cf8055 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -933,6 +933,8 @@ struct bpf_prog_aux {
 		struct work_struct work;
 		struct rcu_head	rcu;
 	};
+
+	char pin_name[BPF_PIN_NAME_LEN];
 };
 
 struct bpf_array_aux {
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index c14fed8..bada5cc 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1217,6 +1217,7 @@ struct bpf_stack_build_id {
 };
 
 #define BPF_OBJ_NAME_LEN 16U
+#define BPF_PIN_NAME_LEN 64U
 
 union bpf_attr {
 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index 4477ca8..f1a8811 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -437,6 +437,8 @@ static int bpf_iter_link_pin_kernel(struct dentry *parent,
 static int bpf_obj_do_pin(const char __user *pathname, void *raw,
 			  enum bpf_type type)
 {
+	struct bpf_prog_aux *aux;
+	struct bpf_prog *prog;
 	struct dentry *dentry;
 	struct inode *dir;
 	struct path path;
@@ -461,6 +463,10 @@ static int bpf_obj_do_pin(const char __user *pathname, void *raw,
 
 	switch (type) {
 	case BPF_TYPE_PROG:
+		prog = raw;
+		aux = prog->aux;
+		(void) strncpy_from_user(aux->pin_name, pathname, BPF_PIN_NAME_LEN);
+		aux->pin_name[BPF_PIN_NAME_LEN - 1] = '\0';
 		ret = vfs_mkobj(dentry, mode, bpf_mkprog, raw);
 		break;
 	case BPF_TYPE_MAP:
@@ -611,12 +617,24 @@ static int bpf_show_options(struct seq_file *m, struct dentry *root)
 
 static void bpf_free_inode(struct inode *inode)
 {
+	struct bpf_prog_aux *aux;
+	struct bpf_prog *prog;
 	enum bpf_type type;
 
 	if (S_ISLNK(inode->i_mode))
 		kfree(inode->i_link);
-	if (!bpf_inode_type(inode, &type))
+	if (!bpf_inode_type(inode, &type)) {
+		switch (type) {
+		case BPF_TYPE_PROG:
+			prog = inode->i_private;
+			aux = prog->aux;
+			aux->pin_name[0] = '\0';
+			break;
+		default:
+			break;
+		}
 		bpf_any_put(inode->i_private, type);
+	}
 	free_inode_nonrcu(inode);
 }
 
-- 
1.8.3.1


  reply	other threads:[~2022-02-11 12:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 12:11 [PATCH 0/4] bpf: Add more information into bpffs Yafang Shao
2022-02-11 12:11 ` Yafang Shao [this message]
2022-02-11 12:43   ` [PATCH 1/4] bpf: Add pin_name into struct bpf_prog_aux Daniel Borkmann
2022-02-11 12:44     ` Daniel Borkmann
2022-02-13 11:28       ` Yafang Shao
2022-02-13 11:27     ` Yafang Shao
2022-02-11 17:58   ` kernel test robot
2022-02-13 11:29     ` Yafang Shao
2022-02-11 12:11 ` [PATCH 2/4] bpf: Add pin_name into struct bpf_map Yafang Shao
2022-02-11 12:11 ` [PATCH 3/4] bpf: Show pinned file name in {progs, maps}.debug Yafang Shao
2022-02-11 12:11 ` [PATCH 4/4] bpf: Show the used maps of each prog in progs.debug Yafang Shao

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=20220211121145.35237-2-laoar.shao@gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox