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 53CFDCFC5E2 for ; Thu, 10 Oct 2024 16:46:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C90376B0082; Thu, 10 Oct 2024 12:46:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C19126B0083; Thu, 10 Oct 2024 12:46:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABA026B0085; Thu, 10 Oct 2024 12:46:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 89D876B0082 for ; Thu, 10 Oct 2024 12:46:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DB6201209C4 for ; Thu, 10 Oct 2024 16:46:04 +0000 (UTC) X-FDA: 82658270016.15.38BBEF1 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id E79151C0014 for ; Thu, 10 Oct 2024 16:46:05 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u6Ix0bf3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of namhyung@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=namhyung@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728578665; a=rsa-sha256; cv=none; b=bp3ydqZM5dGix51TsHz8ZfqsnjW/NTBomwZST3O0NteUAlVm5VyzOr8LMc3Zh7I9wKOcK4 f4LDJxjsw+2zSrHvAy3uCDGg/Uy58maNOFlRtfCQqTtcfQN2XR0v4Ia+dJLFTJAxNds5fq 3e5txUrSimbpLXkrE32VfktCf+Ox0Uw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=u6Ix0bf3; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of namhyung@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=namhyung@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728578665; 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=C1ZqtMx6XWaMAHJlWFjHQeGiwzELoGVM/cR4F48doS8=; b=3hhVRy0k5NV5A+Tqmco+9B/p/1VG8uEM2K8xwKpHrgMdUMZ30McOftWuHKWqtg54iPBSB0 8dED6WjJilyZo9i4qSy4C01Ump4L8LVTKWpOJX6PrtZ0EDFrXlaNjxDNF2l1LnErKZtbxA TPAz0+STfmGi4QDCLJFVBA3SjqOYXZY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 093E25C5FEF; Thu, 10 Oct 2024 16:46:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C578C4CEC5; Thu, 10 Oct 2024 16:46:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728578765; bh=08oJ1Ty/lrHxJqMnlNGf1Ch3DicmHiyZz4nCpw21uTY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u6Ix0bf3cc4FRzmp91azgETmOFuE1wfVYXinRRyp/GD+FEuglq4TSdz9649GSdcug 0SYmCsewJ/UiaKzoy9ydisL4moKN3CEBN2+blXvMpwfEJkE+N9G+GGLGgDu2kAUQQ7 GbIEOhxWfoQmkdZaloxwfgYsdCdfcdKI3l9c8rlRClxSNqJxVPvZJ3m9Ld5lmnQKFl 4eguRKzkJpu5ZhMzDRvgm/SoBWRz33hySRLia5MnJpQ5q62NT0FVOP0DGZbXm7QO1y Hlf3uE9SKbY6T/2PeGYHYsWHacXMGWVSUVEuKEF7Tbdb6IMv9M7epOv6zWu8rOn+om Nmzi5alsOz6RQ== Date: Thu, 10 Oct 2024 09:46:02 -0700 From: Namhyung Kim To: Vlastimil Babka Cc: Roman Gushchin , Song Liu , 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 , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Arnaldo Carvalho de Melo , Kees Cook Subject: Re: [PATCH v4 bpf-next 2/3] mm/bpf: Add bpf_get_kmem_cache() kfunc Message-ID: References: <20241002180956.1781008-1-namhyung@kernel.org> <20241002180956.1781008-3-namhyung@kernel.org> <37ca3072-4a0b-470f-b5b2-9828a2b708e5@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: E79151C0014 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: b3ieon8ifii3thyroero89d8nwci6dpb X-HE-Tag: 1728578765-854409 X-HE-Meta: U2FsdGVkX1/XpMBxbyKjjgOXMyAsai+erWlQ9gOtlwIrk+BW3mhPnsxHgLhy8VoTE3C26a6xRNagMNZYpmRwiUKcnElchWeT6LXBBRQraQRZPcXSmfenKjcaYbI8q6ruasWfSBi3raN9P4e8c/fE6b4W0x2+k02eTjAHzq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ccmZEEgmyCQen/vr+q95qzeaZInq4NLSlYgIoid+/7wf/LxrWUWy2awEQa1xf5ZrBkhuGXtyCvPTUJmAwXOgKVGxrVb7ciaN7+agl7oeF4F5JqpP1R4X+5Gy0VRqCasxhkaRASQrDtoOIz8+HFChCDDjFYPNe3VbFTNDD/7sLimlfaakGGGmIQCEjdGefQaJP4HPf/mio1u1Noa0ghc= 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 Wed, Oct 09, 2024 at 12:17:12AM -0700, Namhyung Kim wrote: > On Mon, Oct 07, 2024 at 02:57:08PM +0200, Vlastimil Babka wrote: > > On 10/4/24 11:25 PM, Roman Gushchin wrote: > > > On Fri, Oct 04, 2024 at 01:10:58PM -0700, Song Liu wrote: > > >> On Wed, Oct 2, 2024 at 11:10 AM Namhyung Kim wrote: > > >>> > > >>> The bpf_get_kmem_cache() is to get a slab cache information from a > > >>> virtual address like virt_to_cache(). If the address is a pointer > > >>> to a slab object, it'd return a valid kmem_cache pointer, otherwise > > >>> NULL is returned. > > >>> > > >>> It doesn't grab a reference count of the kmem_cache so the caller is > > >>> responsible to manage the access. The intended use case for now is to > > >>> symbolize locks in slab objects from the lock contention tracepoints. > > >>> > > >>> Suggested-by: Vlastimil Babka > > >>> Acked-by: Roman Gushchin (mm/*) > > >>> Acked-by: Vlastimil Babka #mm/slab > > >>> Signed-off-by: Namhyung Kim > > > > > > So IIRC from our discussions with Namhyung and Arnaldo at LSF/MM I > > thought the perf use case was: > > > > - at the beginning it iterates the kmem caches and stores anything of > > possible interest in bpf maps or somewhere - hence we have the iterator > > - during profiling, from object it gets to a cache, but doesn't need to > > access the cache - just store the kmem_cache address in the perf record > > - after profiling itself, use the information in the maps from the first > > step together with cache pointers from the second step to calculate > > whatever is necessary > > Correct. > > > > > So at no point it should be necessary to take refcount to a kmem_cache? > > > > But maybe "bpf_get_kmem_cache()" is implemented here as too generic > > given the above use case and it should be implemented in a way that the > > pointer it returns cannot be used to access anything (which could be > > unsafe), but only as a bpf map key - so it should return e.g. an > > unsigned long instead? > > Yep, this should work for my use case. Maybe we don't need the > iterator when bpf_get_kmem_cache() kfunc returns the valid pointer as > we can get the necessary info at the moment. But I think it'd be less > efficient as more work need to be done at the event (lock contention). > It'd better setting up necessary info in a map before monitoring (using > the iterator), and just looking up the map with the kfunc while > monitoring the lock contention. Maybe it's still better to return a non-refcounted pointer for future use. I'll leave it for v5. Thanks, Namhyung