BPF List
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: Eduard Zingerman <eddyz87@gmail.com>, andrii@kernel.org
Cc: acme@redhat.com, ast@kernel.org, daniel@iogearbox.net,
	jolsa@kernel.org, martin.lau@linux.dev, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org,
	mykolal@fb.com, thinker.li@gmail.com, bentiss@kernel.org,
	tanggeliang@kylinos.cn, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 5/5] selftests/bpf: add kfunc_call test for simple dtor in bpf_testmod
Date: Wed, 19 Jun 2024 18:42:57 +0100	[thread overview]
Message-ID: <9359e765-c341-4164-90fd-78feafed89d5@oracle.com> (raw)
In-Reply-To: <3396181b67ff82ba8d25a620a72353989d733fc2.camel@gmail.com>

On 19/06/2024 17:54, Eduard Zingerman wrote:
> On Wed, 2024-06-19 at 17:45 +0100, Alan Maguire wrote:
> 
> [...]
> 
>> oops, missed a GFP_ATOMIC here to avoid possible sleeping. To use
>> existing kfunc call test structure it's simpler to do this than add a
>> sleepable test context I think, especially since the focus here is on
>> adding a basic test. More below..
> 
> Hi Alan,
> 
> And I agree, GFP_ATOMIC should probably help and it is simpler than
> adding a sleepable context.
> 
> [...]
> 
>> Yeah, my focus here was testing the registration to be honest and
>> thankfully as you noted it caught a case where I had forgotten to do id
>> relocation, so thanks for suggesting this!
>>
>> To trigger the dtor cleanup via a map, I came up with the following:
>>
>> - call bpf_testmod_ctx_create()
>> - do bpf_kptr_xchg(&ctx_val->ctx, ctx) to transfer the ctx kptr into the
>> map value;
>> - only release the reference if the kptr exchange fails
>> - and then it gets cleaned up on exit.
>>
>> I haven't used kptrs much so hopefully that's right.
>>
>> Tracing I confirmed cleanup happens via:
>>
>> $ sudo dtrace -n 'fbt::bpf_testmod_ctx_release:entry { stack(); }'
>> dtrace: description 'fbt::bpf_testmod_ctx_release:entry ' matched 1 probe
>> CPU     ID                    FUNCTION:NAME
>>   3 113779    bpf_testmod_ctx_release:entry
>>               vmlinux`array_map_free+0x69
>>               vmlinux`bpf_map_free_deferred+0x62
>>               vmlinux`process_one_work+0x192
>>               vmlinux`worker_thread+0x27a
>>               vmlinux`kthread+0xf7
>>               vmlinux`ret_from_fork+0x41
>>               vmlinux`ret_from_fork_asm+0x1a
>>
>> Does the above sound right? Thanks!
> 
> It does, might as well set some flag in the dtor kfunc and check it in
> the program (using another map?). Tbh, I thought we could get away w/o
> 

Sorry, I'm not following here. So I think what you'd like is a way to
verify that the dtor actually runs, is that right? The problem there is
that the map cleanup gets run when the skeleton gets destroyed, but then
it's too late then to collect a count value via that BPF object.

The only thing I can think of is to create an additional tracing object
that we separately load/attach to bpf_testmod_ctx_release() prior to
running kfunc call tests to verify that the destructor fires on cleanup
of the kfunc test skeletons. Is that what you have in mind? Thanks!

Alan

  reply	other threads:[~2024-06-19 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240618160454.801527-1-alan.maguire@oracle.com>
     [not found] ` <20240618160454.801527-6-alan.maguire@oracle.com>
     [not found]   ` <4321b99db5b362e278b1f37d6bd9b9a43d859d63.camel@gmail.com>
     [not found]     ` <76509fc5411e35a4820c333abca155b3fa4e5b84.camel@gmail.com>
2024-06-19 16:45       ` [PATCH bpf-next 5/5] selftests/bpf: add kfunc_call test for simple dtor in bpf_testmod Alan Maguire
2024-06-19 16:54         ` Eduard Zingerman
2024-06-19 17:42           ` Alan Maguire [this message]
2024-06-19 20:12             ` Eduard Zingerman
2024-06-20  9:17               ` Alan Maguire
2024-06-20 11:02                 ` Eduard Zingerman
2024-06-18 16:24 [PATCH bpf-next 0/5] bpf: resilient split BTF followups Alan Maguire
2024-06-18 16:24 ` [PATCH bpf-next 5/5] selftests/bpf: add kfunc_call test for simple dtor in bpf_testmod Alan Maguire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9359e765-c341-4164-90fd-78feafed89d5@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=acme@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=masahiroy@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mykolal@fb.com \
    --cc=nathan@kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=thinker.li@gmail.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox