Re: [PATCH v2 bpf-next 2/2] selftests/bpf: Add a test for open coded kmem_cache iter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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@xxxxxxxxxx>
> > > ---
[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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux