Re: [PATCH bpf-next v6 2/7] bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 10/9/25 07:07, Alexei Starovoitov wrote:
> On Tue, Sep 9, 2025 at 7:14 AM Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
>>
>> Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags and check them for
>> following APIs:
>>
>> * 'map_lookup_elem()'
>> * 'map_update_elem()'
>> * 'generic_map_lookup_batch()'
>> * 'generic_map_update_batch()'
>>
>> And, get the correct value size for these APIs.
>>
>> Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
>> ---
>>  include/linux/bpf.h            | 22 ++++++++++++++++++
>>  include/uapi/linux/bpf.h       |  2 ++
>>  kernel/bpf/syscall.c           | 42 ++++++++++++++++++++++------------
>>  tools/include/uapi/linux/bpf.h |  2 ++
>>  4 files changed, 54 insertions(+), 14 deletions(-)
>>
>> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
>> index 8f6e87f0f3a89..60c235836987d 100644
>> --- a/include/linux/bpf.h
>> +++ b/include/linux/bpf.h
>> @@ -3709,4 +3709,26 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
>>                            const char **linep, int *nump);
>>  struct bpf_prog *bpf_prog_find_from_stack(void);
>>
>> +static inline int bpf_map_check_cpu_flags(u64 flags, bool check_all_cpus_flag)
>> +{
> 
> This function is not used in this patch. Don't add it without users.
> 
> Also I really don't like 'bool' arguments.
> They make callsite hard to read.

Agreed. Using a bool argument here makes the call sites harder to
understand.

> Instead of bool use
> bpf_map_check_flags(u64 flags, u64 allowed_flags)
> 
> so the callsites will look like:
> bpf_map_check_flags(flags, BPF_F_CPU);
> and
> bpf_map_check_flags(flags, BPF_F_CPU | BPF_F_ALL_CPUS);
> 
> Also two functions that do very similar things look redundant.
> This bpf_map_check_flags() vs bpf_map_check_op_flags()...
> I think one should do it.
> 
Yes. It would be better to consolidate this logic into
bpf_map_check_op_flags(), rather than introducing a separate but
overlapping helper. That should keep the code simpler and avoid redundancy.

Thanks,
Leon

[...]




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux