All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ziyang Men <ziyang.meme@gmail.com>
To: Tejun Heo <tj@kernel.org>
Cc: "Jens Axboe" <axboe@kernel.dk>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Shakeel Butt" <shakeel.butt@linux.dev>,
	"JP Kobryn" <inwardvessel@gmail.com>,
	"Mykola Lysenko" <mykolal@meta.com>,
	kernel-team@meta.com, linux-block@vger.kernel.org,
	bpf@vger.kernel.org, cgroups@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] block: add BPF kfuncs to read blkcg io.stat
Date: Mon, 10 Aug 2026 15:46:58 -0700	[thread overview]
Message-ID: <anpU4oV46MDVDixj@devvm16600.scu0.facebook.com> (raw)
In-Reply-To: <anot9w6mg9538RWm@slm.duckdns.org>

Hi Tejun,

Thanks for your review and suggestions!

On Mon, Aug 10, 2026 at 10:00:55AM -1000, Tejun Heo wrote:
>Hello,
>
>On Fri, Aug 07, 2026 at 12:37:31PM -0700, Ziyang Men wrote:
>> +__bpf_kfunc struct blkcg *bpf_get_root_blkcg(void)
>> +__bpf_kfunc struct blkcg *bpf_get_blkcg(struct cgroup_subsys_state *css)
>> +__bpf_kfunc void bpf_put_blkcg(struct blkcg *blkcg)
>> +__bpf_kfunc void bpf_blkcg_flush_stats(struct blkcg *blkcg)
>
>I wonder whether making the above deal with css's would make more sense so
>that we don't end up with per-subsystem iterators. If casting to per-subsys
>type is necessary, we can provide RCU protected cast kfucns.
>

Good idea! These do nothing block specific and we already have some common
helpers for it such as the bpf_get_root_blkcg(). What is missing is a way to get
one controller's css from a cgroup with a reference held, and the cast. So
I would add in kernel/cgroup/

   struct cgroup_subsys_state *bpf_cgroup_css(struct cgroup *cgrp, int ssid);
   void bpf_css_release(struct cgroup_subsys_state *css);

where the @ssid is an enum cgroup_subsys_id value. Afterwards, the only piece for
blkcg left is:
   struct blkcg *bpf_css_to_blkcg(struct cgroup_subsys_state *css);

Note the bpf_blkcg_flush_stats may keep its current shape as it mirrors the
blkcg_print_stat() which skips the root.

With these helpers we can also replace the existing ones in
mm/bpf_memcontrol.c as well:
	bpf_get_mem_cgroup()
	bpf_put_mem_cgroup()
	bpf_mem_cgroup_flush_stats()

they map onto bpf_cgroup_css() plus a bpf_css_to_memcg() cast the same way.

Hi Roman, JP, Shakeel: Do you think it is worth applying above changes for
the memory controller as well? If you are happy with the direction I am glad to
send the conversion as a follow-up once the generic kfuncs are in. Would you
take it?

>> +__bpf_kfunc u64 bpf_blkg_iostat_bytes(struct blkcg_gq *blkg,
>> +				      enum blkg_iostat_type rw)
>> +__bpf_kfunc u64 bpf_blkg_iostat_ios(struct blkcg_gq *blkg,
>> +				    enum blkg_iostat_type rw)
>> +__bpf_kfunc u64 bpf_blkg_dev(struct blkcg_gq *blkg)
>
>Ignoring 32bit split reads (do we really care for BPF accesses?), the above
>can easily be done with BPF_CORE_READ(), right?

Agree, these parts will be removed in the next version.

>
>Thanks.
>
>-- 
>tejun

Please let me know whether the above ideas works. Thanks very much!

Best,
Ziyang

  reply	other threads:[~2026-08-10 22:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 19:37 [PATCH 0/2] block: expose blkcg io.stat to BPF Ziyang Men
2026-08-07 19:37 ` [PATCH 1/2] block: add BPF kfuncs to read blkcg io.stat Ziyang Men
2026-08-07 20:00   ` sashiko-bot
2026-08-10 20:00   ` Tejun Heo
2026-08-10 22:46     ` Ziyang Men [this message]
2026-08-11  0:17       ` JP Kobryn
2026-08-07 19:37 ` [PATCH 2/2] selftests/bpf: add test for blkcg io.stat BPF kfuncs Ziyang Men
2026-08-07 19:51   ` sashiko-bot

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=anpU4oV46MDVDixj@devvm16600.scu0.facebook.com \
    --to=ziyang.meme@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=hannes@cmpxchg.org \
    --cc=inwardvessel@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@meta.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mkoutny@suse.com \
    --cc=mykolal@meta.com \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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 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.