linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	linux-mm <linux-mm@kvack.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Kees Cook <kees@kernel.org>
Subject: Re: [PATCH v2 bpf-next 2/2] selftests/bpf: Add a test for open coded kmem_cache iter
Date: Wed, 30 Oct 2024 14:35:38 -0700	[thread overview]
Message-ID: <ZyKmquDn3SNFzzgl@google.com> (raw)
In-Reply-To: <ZyGOng76IBUs8PtY@google.com>

On Tue, Oct 29, 2024 at 06:40:46PM -0700, Namhyung Kim wrote:
> Hello,
> 
> On Thu, Oct 24, 2024 at 11:08:00AM -0700, Alexei Starovoitov wrote:
> > On Thu, Oct 24, 2024 at 12:48 AM Namhyung Kim <namhyung@kernel.org> wrote:
> > >
> > > The new subtest is attached to sleepable fentry of syncfs() syscall.
> > > It iterates the kmem_cache using bpf_for_each loop and count the number
> > > of entries.  Finally it checks it with the number of entries from the
> > > regular iterator.
> > >
> > >   $ ./vmtest.sh -- ./test_progs -t kmem_cache_iter
> > >   ...
> > >   #130/1   kmem_cache_iter/check_task_struct:OK
> > >   #130/2   kmem_cache_iter/check_slabinfo:OK
> > >   #130/3   kmem_cache_iter/open_coded_iter:OK
> > >   #130     kmem_cache_iter:OK
> > >   Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
> > >
> > > Also simplify the code by using attach routine of the skeleton.
> > >
> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> > > ---
[SNIP]
> > > +SEC("fentry.s/" SYS_PREFIX "sys_syncfs")
> > > +int open_coded_iter(const void *ctx)
> > > +{
> > > +       struct kmem_cache *s;
> > > +
> > > +       if (tgid != bpf_get_current_pid_tgid() >> 32)
> > > +               return 0;
> > 
> > Pls use syscall prog type and prog_run() it.
> > No need to attach to exotic syscalls and filter by pid.
> 
> Sure, will update in v3.
> 
> > 
> > > +
> > > +       bpf_for_each(kmem_cache, s) {
> > > +               struct kmem_cache_result *r;
> > > +
> > > +               r = bpf_map_lookup_elem(&slab_result, &open_coded_seen);
> > > +               if (!r)
> > > +                       break;
> > > +
> > > +               open_coded_seen++;
> > > +
> > > +               if (r->obj_size != s->size)
> > > +                       break;
> > 
> > The order of 'if' and ++ should probably be changed ?
> > Otherwise the last object isn't sufficiently checked.
> 
> I don't think so.  The last element should be an actual slab cache and
> then the iterator will return NULL to break the loop.  I don't expect it
> will hit the if statement.

Oh, it seems you meant checking the obj_size.  Ok then, I can move the
increment after the check.

Thanks,
Namhyung



      reply	other threads:[~2024-10-30 21:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24  7:48 [PATCH v2 bpf-next 1/2] bpf: Add open coded version of kmem_cache iterator Namhyung Kim
2024-10-24  7:48 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add a test for open coded kmem_cache iter Namhyung Kim
2024-10-24 18:08   ` Alexei Starovoitov
2024-10-30  1:40     ` Namhyung Kim
2024-10-30 21:35       ` Namhyung Kim [this message]

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=ZyKmquDn3SNFzzgl@google.com \
    --to=namhyung@kernel.org \
    --cc=42.hyeyoo@gmail.com \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cl@linux.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kees@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=martin.lau@linux.dev \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=vbabka@suse.cz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox