[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW5BKxZH2EA=fuQa_3man5_qcUt3euwtfwsqD4g36JngaA@mail.gmail.com>
Date: Fri, 4 Oct 2024 13:45:09 -0700
From: Song Liu <song@...nel.org>
To: Namhyung Kim <namhyung@...nel.org>
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>, 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@...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@...ck.org,
Arnaldo Carvalho de Melo <acme@...nel.org>, Kees Cook <kees@...nel.org>
Subject: Re: [PATCH v4 bpf-next 1/3] bpf: Add kmem_cache iterator
On Wed, Oct 2, 2024 at 11:09 AM Namhyung Kim <namhyung@...nel.org> wrote:
>
[...]
> +
> +static void *kmem_cache_iter_seq_start(struct seq_file *seq, loff_t *pos)
> +{
> + loff_t cnt = 0;
> + bool found = false;
> + struct kmem_cache *s;
> +
> + mutex_lock(&slab_mutex);
> +
> + /*
> + * Find an entry at the given position in the slab_caches list instead
> + * of keeping a reference (of the last visited entry, if any) out of
> + * slab_mutex. It might miss something if one is deleted in the middle
> + * while it releases the lock. But it should be rare and there's not
> + * much we can do about it.
> + */
> + list_for_each_entry(s, &slab_caches, list) {
> + if (cnt == *pos) {
> + /*
> + * Make sure this entry remains in the list by getting
> + * a new reference count. Note that boot_cache entries
> + * have a negative refcount, so don't touch them.
> + */
> + if (s->refcount > 0)
> + s->refcount++;
> + found = true;
> + break;
> + }
> + cnt++;
> + }
> + mutex_unlock(&slab_mutex);
> +
> + if (!found)
> + return NULL;
> +
> + ++*pos;
This should be
if (*pos == 0)
++*pos;
> + return s;
> +}
> +
> +static void kmem_cache_iter_seq_stop(struct seq_file *seq, void *v)
[...]
Powered by blists - more mailing lists