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 772E718C31; Mon, 30 Sep 2024 17:48:18 +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=1727718499; cv=none; b=JD3uEU90eNVZL3fDdaLWUZelUhM67CXJiHRaIf/PxHUdJJbWH03SytG05ncZu4pvJqM7S+NS8iOkp2Zz4nyiWeyhY924HNcK745pJGT6Vm/ng5okR8TzH8pOWimJ4fBecI9AldpB/d7oeC4mS7snCujwiX6f+7VB6GrHa76ofak= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727718499; c=relaxed/simple; bh=QtxA2Gn1aPRs/9qbO2VdoDhSsNonNYdVRLyEOTPcCrM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EFYB52nwaEawy0SREQJFL4GfEU1XA5PcPvrpMx84l/E0j7LYEkpVyRgk/s4CNPmGQ1iR9iGINX+X4TUg0ffD20TZor2IMsjqjFQPnAqwUa3K7SqgKlS7DLGqUu9+FAB8kGGUUja8cA+dBcUMjm1EFcCEWKe+HISuENfI16v+cw8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BjVQMSNb; 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="BjVQMSNb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23EEFC4CECE; Mon, 30 Sep 2024 17:48:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727718498; bh=QtxA2Gn1aPRs/9qbO2VdoDhSsNonNYdVRLyEOTPcCrM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BjVQMSNbjcfK0va4WqlUman7lD7aD6LhM6v5t1lWhSqmqwouwNKP/jb+xZKHV/WFG LFHyuWRgcsztTkv3ttZjUNi4VgVy/lsS9074kviNwyfinHyLqEv+wy/baKrKS374FN ebiGgGg6A5gdNIKvLWZb3Q2N8MfagY/WYAdCoPurnjbn+YMbQ4NBgbM+eQ9H1KDT2o yRFzuzHiVSxG0mg8wEg1uLT/bLIFxhghq1VpCyD78L7XB+AobiBumyvRmaUntxgcn7 gqOZ5ZUmAaymnj9gzwUrC3+ewiu91Ito5DK5Vl3GE9mDWmuK+xFBLLUdvowbRrdNjW hfy/lQ38GpD7A== Date: Mon, 30 Sep 2024 10:48:14 -0700 From: Namhyung Kim To: Hyeonggon Yoo <42.hyeyoo@gmail.com> 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@vger.kernel.org, Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , linux-mm@kvack.org, Arnaldo Carvalho de Melo Subject: Re: [RFC/PATCH bpf-next 3/3] selftests/bpf: Add a test for kmem_cache_iter Message-ID: References: <20240927184133.968283-1-namhyung@kernel.org> <20240927184133.968283-4-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 Sun, Sep 29, 2024 at 09:33:05PM -0700, Namhyung Kim wrote: > On Mon, Sep 30, 2024 at 12:24:52PM +0900, Hyeonggon Yoo wrote: > > On Mon, Sep 30, 2024 at 11:18 AM Namhyung Kim wrote: > > > > > > Hello Hyeonggon, > > > > > > On Sun, Sep 29, 2024 at 11:27:25PM +0900, Hyeonggon Yoo wrote: > > > > On Sun, Sep 29, 2024 at 3:13 PM Namhyung Kim wrote: > > > > > > +SEC("raw_tp/bpf_test_finish") > > > > > > +int BPF_PROG(check_task_struct) > > > > > > +{ > > > > > > + __u64 curr = bpf_get_current_task(); > > > > > > + struct kmem_cache *s; > > > > > > + char *name; > > > > > > + > > > > > > + s = bpf_get_kmem_cache(curr); > > > > > > + if (s == NULL) { > > > > > > + found = -1; > > > > > > + return 0; > > > > > > > > > > ... it cannot find a kmem_cache for the current task. This program is > > > > > run by bpf_prog_test_run_opts() with BPF_F_TEST_RUN_ON_CPU. So I think > > > > > the curr should point a task_struct in a slab cache. > > > > > > > > > > Am I missing something? > > > > > > > > Hi Namhyung, > > > > > > > > Out of curiosity I've been investigating this issue on my machine and > > > > running some experiments. > > > > > > Thanks a lot for looking at this! > > > > > > > > > > > When the test fails, calling dump_page() for the page the task_struct > > > > belongs to, > > > > shows that the page does not have the PGTY_slab flag set which is why > > > > virt_to_slab(current) returns NULL. > > > > > > > > Does the test always fails on your environment? On my machine, the > > > > test passed sometimes but failed some times. > > > > > > I'm using vmtest.sh but it succeeded mostly. I thought I couldn't > > > reproduce it locally, but I also see the failure sometimes. I'll take a > > > deeper look. > > > > > > > > > > > Maybe sometimes the value returned by 'current' macro belongs to a > > > > slab, but sometimes it does not. > > > > But that doesn't really make sense to me as IIUC task_struct > > > > descriptors are allocated from slab. > > > > > > AFAIK the notable exception is the init_task which lives in the kernel > > > data. I'm not sure the if the test is running by PID 1. > > > > I checked that the test is running under PID 0 (swapper) when it fails and > > non-0 PID when it succeeds. This makes sense as the task_struct for PID 0 > > should be in the kernel image area, not in a slab. > > > > Phew, fortunately, it's not a bug! :) > > Thanks for the test, I've seen the same now. > > > > > Any plans on how to adjust the test program? > > I thought the test runs in a separate task. I'll think about how to > test this more reliably. Oh, I think BPF_F_TEST_RUN_ON_CPU was the problem since it requires to run the test on the given CPU (cpu0 in this case). If the cpu0 was idle, it would fail like this. I think removing the flag will run the test on the current CPU so it won't get the swapper task anymore. Thanks, Namhyung