netdev.vger.kernel.org archive mirror
 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 RFC 2/3] bpf: set attached cgroup name in attach_name
Date: Fri, 18 Feb 2022 09:56:11 +0000	[thread overview]
Message-ID: <20220218095612.52082-3-laoar.shao@gmail.com> (raw)
In-Reply-To: <20220218095612.52082-1-laoar.shao@gmail.com>

Set the cgroup path when a bpf prog is attached to a cgroup, and unset
it when the bpf prog is detached.

Below is the result after this change,
$ cat progs.debug
  id name             attached
   5 dump_bpf_map     bpf_iter_bpf_map
   7 dump_bpf_prog    bpf_iter_bpf_prog
  17 bpf_sockmap      cgroup:/
  19 bpf_redir_proxy

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 kernel/bpf/cgroup.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 43eb3501721b..ebd87e54f2d0 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -440,6 +440,7 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
 	struct bpf_cgroup_storage *storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
 	struct bpf_cgroup_storage *new_storage[MAX_BPF_CGROUP_STORAGE_TYPE] = {};
 	enum cgroup_bpf_attach_type atype;
+	char cgrp_path[64] = "cgroup:";
 	struct bpf_prog_list *pl;
 	struct list_head *progs;
 	int err;
@@ -508,6 +509,11 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
 	else
 		static_branch_inc(&cgroup_bpf_enabled_key[atype]);
 	bpf_cgroup_storages_link(new_storage, cgrp, type);
+
+	cgroup_name(cgrp, cgrp_path + strlen("cgroup:"), 64);
+	cgrp_path[63] = '\0';
+	prog->aux->attach_name = kstrdup(cgrp_path, GFP_KERNEL);
+
 	return 0;
 
 cleanup:
@@ -735,6 +741,8 @@ static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,
 	if (old_prog)
 		bpf_prog_put(old_prog);
 	static_branch_dec(&cgroup_bpf_enabled_key[atype]);
+	kfree(prog->aux->attach_name);
+
 	return 0;
 
 cleanup:
-- 
2.17.1


  parent reply	other threads:[~2022-02-18  9:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18  9:56 [PATCH RFC 0/3] bpf: show attached name for progs without btf name Yafang Shao
2022-02-18  9:56 ` [PATCH RFC 1/3] bpf: rename attach_func_name to attach_name Yafang Shao
2022-02-18  9:56 ` Yafang Shao [this message]
2022-02-19 18:27   ` [PATCH RFC 2/3] bpf: set attached cgroup name in attach_name Alexei Starovoitov
2022-02-20 14:17     ` Yafang Shao
2022-02-20 20:59       ` Alexei Starovoitov
2022-02-21  2:33         ` Yafang Shao
2022-02-21 14:26         ` Yafang Shao
2022-02-22  4:30           ` Alexei Starovoitov
2022-02-22  8:34             ` Yafang Shao
2022-02-18  9:56 ` [PATCH RFC 3/3] bpf: set attached sockmap id " 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=20220218095612.52082-3-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;
as well as URLs for NNTP newsgroup(s).