From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31D6DCF885B for ; Fri, 4 Oct 2024 21:42:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE4F56B00D2; Fri, 4 Oct 2024 17:42:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A6CD66B012A; Fri, 4 Oct 2024 17:42:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90CE56B0126; Fri, 4 Oct 2024 17:42:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6C6256B00C8 for ; Fri, 4 Oct 2024 17:42:19 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2EF071A0171 for ; Fri, 4 Oct 2024 21:42:19 +0000 (UTC) X-FDA: 82637243598.13.08825E7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 863D118000D for ; Fri, 4 Oct 2024 21:42:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ajnja5FB; spf=pass (imf06.hostedemail.com: domain of namhyung@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=namhyung@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728078071; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=x2d9X6w4asMtoFysiefi1Wgw2uAwtD2Q9aLTT9O+0TM=; b=Keivz9ejYIaK3vhlCazGFL3G6lk9BT7w4vIAi1mcVu8v3CEn1JCSglqbL6GHEtCH+qsWtX bFbQ1tkpHLlJcs539Qy6xLtpktnZu1I+ycS1e/U02Aa7HNqpAfkVIciZGYVaeeL0M1NR2u t7sQ3rHUjfZYP2DL8cwXyjHXX8Fup3s= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ajnja5FB; spf=pass (imf06.hostedemail.com: domain of namhyung@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=namhyung@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728078071; a=rsa-sha256; cv=none; b=6lEJv2ieodlDXUtzLhlTuakAvTbdTcJCTAIs0cE2HlmnLFod6yFNUYFvx04t1UV+Tu/vTz Qfwuft+fYPHIanpZBZgPHjSkWJ0Xi3IHP3EsyXNz5oLB6c3eQSoXvjv4P3Un7EvCI6VuJb oPEXBvfoebSZ5NIzaMmM6Kgcr13nXbE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 38BB2A42610; Fri, 4 Oct 2024 21:42:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7596AC4CEC6; Fri, 4 Oct 2024 21:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728078136; bh=T6ND5IS9IVDBJQXIdIciM8H0/qv1eAB0bim1yDiTA6Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ajnja5FBPNJcg+31yWLZiDkKdwWDDk/OSBrGkuPtPdj5rQPT7fL6Htv44QDMQ9roS CgxDWl0cZh/jvIWxGSLDIDvqY4mHEur6XVMUPTbBCxslgMUzZuPMY9+WlLj3rWisX7 26QpbIXOw3Mt1J1FyNRFWnbfVRFHYdPbJb/szlcVW6N0qRPYxYBNX662XOvkRCZzr1 nIbPvBDRGYodqM/ZC2pQtimKIPbtEgjVqTvQWsUxDA+o0s/cEvR5P1ARrRgNbG5KbQ Lp6ljSvqBAiAC+Fx0Q3xs1ByEsxuUBq4gk37eE8AJ0g+GcIx4UqmfqSbW81xeqnesu BHis6NzgGscPA== Date: Fri, 4 Oct 2024 14:42:14 -0700 From: Namhyung Kim To: Song Liu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , LKML , bpf@vger.kernel.org, Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Arnaldo Carvalho de Melo , Kees Cook Subject: Re: [PATCH v4 bpf-next 1/3] bpf: Add kmem_cache iterator Message-ID: References: <20241002180956.1781008-1-namhyung@kernel.org> <20241002180956.1781008-2-namhyung@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 863D118000D X-Stat-Signature: tp8cxb4stzjfynafuzrsqbp1qwg7nomq X-HE-Tag: 1728078137-251049 X-HE-Meta: U2FsdGVkX19BKrBsRQTXGMY82ijjkXWr/vHggOGyRJZsA7e/xZ+S95gAog7/wcT96ggbZAN+DKHRZE5xNDruEuhIHYIasUC/F7zKdDtbjY38i5pRFFXKH330EY+odKVUOa+XampgMmhDB1VPksRdljNNNs9I4KBFaKagnBXM8LDoPzdqZ4IqUO6DURtNL+olv/hFnQXr8b9OerEtOKR5lS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JJzgvJKXHSCv44Vpee54ZBMKe8Urywjdr2Cxu6nXhlAMHeyGfWCoCVH9RsUwcOo0kp3MrOhNt5zYbQKjPmlF9SP/Mfy65Q7Jje75W9beqxNNqMAS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Oct 04, 2024 at 01:45:09PM -0700, Song Liu wrote: > On Wed, Oct 2, 2024 at 11:09 AM Namhyung Kim 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; Oh, I thought there's check for seq->count after the seq->op->show() for the ->start(). I need to check this logic again, thanks for pointing this out. Thanks, Namhyung > > > + return s; > > +} > > + > > +static void kmem_cache_iter_seq_stop(struct seq_file *seq, void *v) > [...]