[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZyKmquDn3SNFzzgl@google.com>
Date: Wed, 30 Oct 2024 14:35:38 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
LKML <linux-kernel@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Christoph Lameter <cl@...ux.com>, Pekka Enberg <penberg@...nel.org>,
David Rientjes <rientjes@...gle.com>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Vlastimil Babka <vbabka@...e.cz>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Hyeonggon Yoo <42.hyeyoo@...il.com>, linux-mm <linux-mm@...ck.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Kees Cook <kees@...nel.org>
Subject: Re: [PATCH v2 bpf-next 2/2] selftests/bpf: Add a test for open coded
kmem_cache iter
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@...nel.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@...nel.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
Powered by blists - more mailing lists