Skip to content
Permalink
Browse files
bpf: Add pin_name into struct bpf_prog_aux
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>
  • Loading branch information
laoar authored and intel-lab-lkp committed Feb 11, 2022
1 parent fe68195 commit 6cd35bc70f99caee380d84f5ba9256ac5fe03860
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
@@ -996,6 +996,8 @@ struct bpf_prog_aux {
struct work_struct work;
struct rcu_head rcu;
};

char pin_name[BPF_PIN_NAME_LEN];
};

struct bpf_array_aux {
@@ -1252,6 +1252,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 */
@@ -438,6 +438,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;
@@ -462,6 +464,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:
@@ -612,12 +618,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);
}

0 comments on commit 6cd35bc

Please sign in to comment.