Re: [PATCH bpf-next v8 5/7] bpf: Implement bpf_local_storage for inodes

From: KP Singh
Date: Tue Aug 18 2020 - 11:33:45 EST




On 8/18/20 5:23 PM, Martin KaFai Lau wrote:
> On Tue, Aug 18, 2020 at 05:10:34PM +0200, KP Singh wrote:
>>
>>
>> On 8/18/20 3:27 AM, Martin KaFai Lau wrote:>>> On Mon, Aug 03, 2020 at 06:46:53PM +0200, KP Singh wrote:

[...]

a get_file
>> rather fcheck followed by get_file_rcu:
>>
>> #define get_file_rcu_many(x, cnt) \
>> atomic_long_add_unless(&(x)->f_count, (cnt), 0)
>> #define get_file_rcu(x) get_file_rcu_many((x), 1)
>> #define file_count(x) atomic_long_read(&(x)->f_count)
>>
>> But there is an easier way than all of this and this is to use
>> fget_raw which also calls get_file_rcu_many
>> and ensures a non-zero count before getting a reference.
> ic. Make sense.
>
> There are fdget() and fdput() also which are used in bpf/syscall.c.

Yeah we could use fdget_raw but we don't really need the struct fd but just the
struct file.

he non-raw versions masks away FMODE_PATH (O_PATH) files, we should still be able to
access blobs on the O_PATH files, thus the _raw version here.

- KP

>