[PATCH bpf] bpf: do not use kmalloc_nolock when !HAVE_CMPXCHG_DOUBLE

Levi Zim rsworktech at outlook.com
Sat Mar 14 08:17:49 PDT 2026


Hi,

On 3/14/26 7:09 PM, bot+bpf-ci at kernel.org wrote:
>> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
>> index 9c96a4477f81..8e4b0fe6d12a 100644
>> --- a/kernel/bpf/bpf_local_storage.c
>> +++ b/kernel/bpf/bpf_local_storage.c
>> @@ -894,7 +894,8 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
>>  	 * preemptible context. Thus, enforce all storages to use
>>  	 * kmalloc_nolock() when CONFIG_PREEMPT_RT is enabled.
>>  	 */
>> -	smap->use_kmalloc_nolock = IS_ENABLED(CONFIG_PREEMPT_RT) ? true : use_kmalloc_nolock;
>> +	smap->use_kmalloc_nolock = IS_ENABLED(CONFIG_PREEMPT_RT) &&
>> +		KMALLOC_NOLOCK_SUPPORTED ? true : use_kmalloc_nolock;
> 
> Should the comment above be updated to reflect the new behavior?
> It currently says "enforce all storages to use kmalloc_nolock()
> when CONFIG_PREEMPT_RT is enabled", but the code now only enforces
> kmalloc_nolock when both CONFIG_PREEMPT_RT and
> CONFIG_HAVE_CMPXCHG_DOUBLE are enabled. On PREEMPT_RT without
> HAVE_CMPXCHG_DOUBLE, the override is silently skipped and the
> caller's value is used instead.

I didn't give it too much thought initially. So the kmalloc_nolock() usage in PREEMPT_RT
context is necessary for correctness. I will remove "&& KMALLOC_NOLOCK_SUPPORTED" in v2
and add a comment to explain the current limitation when PREEMPT_RT is combined with
an architecture that doesn't HAVE_CMPXCHG_DOUBLE.

Best regards,
Levi

> 
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
> 
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/23086356774




More information about the linux-riscv mailing list