Commit c1b3fed3 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Daniel Borkmann

bpf: Factor out bpf_spin_lock into helpers.

Move ____bpf_spin_lock/unlock into helpers to make it more clear
that quadruple underscore bpf_spin_lock/unlock are irqsave/restore variants.
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210715005417.78572-3-alexei.starovoitov@gmail.com
parent d809e134
...@@ -289,13 +289,18 @@ static inline void __bpf_spin_unlock(struct bpf_spin_lock *lock) ...@@ -289,13 +289,18 @@ static inline void __bpf_spin_unlock(struct bpf_spin_lock *lock)
static DEFINE_PER_CPU(unsigned long, irqsave_flags); static DEFINE_PER_CPU(unsigned long, irqsave_flags);
notrace BPF_CALL_1(bpf_spin_lock, struct bpf_spin_lock *, lock) static inline void __bpf_spin_lock_irqsave(struct bpf_spin_lock *lock)
{ {
unsigned long flags; unsigned long flags;
local_irq_save(flags); local_irq_save(flags);
__bpf_spin_lock(lock); __bpf_spin_lock(lock);
__this_cpu_write(irqsave_flags, flags); __this_cpu_write(irqsave_flags, flags);
}
notrace BPF_CALL_1(bpf_spin_lock, struct bpf_spin_lock *, lock)
{
__bpf_spin_lock_irqsave(lock);
return 0; return 0;
} }
...@@ -306,13 +311,18 @@ const struct bpf_func_proto bpf_spin_lock_proto = { ...@@ -306,13 +311,18 @@ const struct bpf_func_proto bpf_spin_lock_proto = {
.arg1_type = ARG_PTR_TO_SPIN_LOCK, .arg1_type = ARG_PTR_TO_SPIN_LOCK,
}; };
notrace BPF_CALL_1(bpf_spin_unlock, struct bpf_spin_lock *, lock) static inline void __bpf_spin_unlock_irqrestore(struct bpf_spin_lock *lock)
{ {
unsigned long flags; unsigned long flags;
flags = __this_cpu_read(irqsave_flags); flags = __this_cpu_read(irqsave_flags);
__bpf_spin_unlock(lock); __bpf_spin_unlock(lock);
local_irq_restore(flags); local_irq_restore(flags);
}
notrace BPF_CALL_1(bpf_spin_unlock, struct bpf_spin_lock *, lock)
{
__bpf_spin_unlock_irqrestore(lock);
return 0; return 0;
} }
...@@ -333,9 +343,9 @@ void copy_map_value_locked(struct bpf_map *map, void *dst, void *src, ...@@ -333,9 +343,9 @@ void copy_map_value_locked(struct bpf_map *map, void *dst, void *src,
else else
lock = dst + map->spin_lock_off; lock = dst + map->spin_lock_off;
preempt_disable(); preempt_disable();
____bpf_spin_lock(lock); __bpf_spin_lock_irqsave(lock);
copy_map_value(map, dst, src); copy_map_value(map, dst, src);
____bpf_spin_unlock(lock); __bpf_spin_unlock_irqrestore(lock);
preempt_enable(); preempt_enable();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment