From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E88DD1C4A2C; Tue, 15 Oct 2024 18:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729016401; cv=none; b=q6l+VkvkXDv5peJGaUywnsQW0NyNnTI2wcgmx7cm1Pv5HL1yMdBrfhkP0ZXHHv5JbZTL/4JR8MH0GtwbUKBRFmxtfXivqwF3yoiFb0PukmH4aH/SalTTUWzqiEkVzQ63uz2A1XFAuCMMEwrLdP6jGCGX1Dod6dbAe8wKbdU2n98= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729016401; c=relaxed/simple; bh=/qveEz4oH0ioXwKnVP9i6T15T8fGe8hnk98Bruxgq4s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u3ZXnlrywASd7UfnGm7Ks4MJMkkSnuiMKGzWX1GRt3FRSTK1uMkW0bQjpYuQUXWjMpf0tTp0NmrUUPwacoxsnBG4zsTf68ulMNVN8oxTrgvj+gb+rItJuXucnTmFHJB0t3vxN4UDyehruNI+3C4JO3+iIC97OWGTm/Q6rAKqerM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lpkD4qeu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lpkD4qeu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C24CC4CEC6; Tue, 15 Oct 2024 18:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729016400; bh=/qveEz4oH0ioXwKnVP9i6T15T8fGe8hnk98Bruxgq4s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lpkD4qeucXLibc1EBuv+su9vyzVuPHT3FT9j0xnD5ovdbZ9wANxdqAJ6GTLeIpsnv X0ROdsgGwWCNTNErBIxQzNf06eLRV/6ns9fnfi0P4TxPboxsbIzNboGnkVcQ2TY5Lf uLKb1pLbPK4fgZkuqRhbjKHxjnqm8rBmRyupxqJ2d/ldoNPOdd0czT7aQSHLcqf2/h tcE5ht3pGEigGaWiAfvekuA5mkzbHoA+uMWgKk3LEBzGH07LSOKe6MTXXm3/u0zwMx VPEpBA00r40JIwBrcTzdXJWmKwVEOgJ8QVEVNvcU5dnkaMHEHsG03UeSpkFp8wGUEb toasnJB80NBbA== Date: Tue, 15 Oct 2024 11:19:58 -0700 From: Namhyung Kim To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , LKML , bpf , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm , Arnaldo Carvalho de Melo , Kees Cook , "Paul E. McKenney" Subject: Re: [PATCH v5 bpf-next 2/3] mm/bpf: Add bpf_get_kmem_cache() kfunc Message-ID: References: <20241010232505.1339892-1-namhyung@kernel.org> <20241010232505.1339892-3-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Oct 14, 2024 at 06:50:49PM -0700, Alexei Starovoitov wrote: > On Mon, Oct 14, 2024 at 11:13 AM Namhyung Kim wrote: > > > > Hi Alexei, > > > > On Fri, Oct 11, 2024 at 12:14:14PM -0700, Namhyung Kim wrote: > > > On Fri, Oct 11, 2024 at 11:35:27AM -0700, Alexei Starovoitov wrote: > > > > On Thu, Oct 10, 2024 at 4:25 PM 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 returned point is marked as > > > > > PTR_UNTRUSTED. And the kfunc has KF_RCU_PROTECTED as the slab object > > > > > might be protected by RCU. > > > > > > > > ... > > > > > +BTF_ID_FLAGS(func, bpf_get_kmem_cache, KF_RCU_PROTECTED) > > > > > > > > This flag is unnecessary. PTR_UNTRUSTED can point to absolutely any memory. > > > > In this case it likely points to a valid kmem_cache, but > > > > the verifier will guard all accesses with probe_read anyway. > > > > > > > > I can remove this flag while applying. > > > > > > Ok, I'd be happy if you would remove it. > > > > You will need to update the bpf_rcu_read_lock/unlock() in the test code > > (patch 3). I can send v6 with that and Vlastimil's Ack if you want. > > Fixed all that while applying. > > Could you please follow up with an open-coded iterator version > of the same slab iterator ? > So that progs can iterate slabs as a normal for/while loop ? I'm not sure I'm following. Do you want a new test program to iterate kmem_caches by reading list pointers manually? How can I grab the slab_mutex then? Thanks, Namhyung