Lines Matching refs:rcpu
125 static void get_cpu_map_entry(struct bpf_cpu_map_entry *rcpu) in get_cpu_map_entry() argument
127 atomic_inc(&rcpu->refcnt); in get_cpu_map_entry()
133 struct bpf_cpu_map_entry *rcpu; in cpu_map_kthread_stop() local
135 rcpu = container_of(work, struct bpf_cpu_map_entry, kthread_stop_wq); in cpu_map_kthread_stop()
143 kthread_stop(rcpu->kthread); in cpu_map_kthread_stop()
160 static void put_cpu_map_entry(struct bpf_cpu_map_entry *rcpu) in put_cpu_map_entry() argument
162 if (atomic_dec_and_test(&rcpu->refcnt)) { in put_cpu_map_entry()
163 if (rcpu->prog) in put_cpu_map_entry()
164 bpf_prog_put(rcpu->prog); in put_cpu_map_entry()
166 __cpu_map_ring_cleanup(rcpu->queue); in put_cpu_map_entry()
167 ptr_ring_cleanup(rcpu->queue, NULL); in put_cpu_map_entry()
168 kfree(rcpu->queue); in put_cpu_map_entry()
169 kfree(rcpu); in put_cpu_map_entry()
173 static void cpu_map_bpf_prog_run_skb(struct bpf_cpu_map_entry *rcpu, in cpu_map_bpf_prog_run_skb() argument
183 act = bpf_prog_run_generic_xdp(skb, &xdp, rcpu->prog); in cpu_map_bpf_prog_run_skb()
190 rcpu->prog); in cpu_map_bpf_prog_run_skb()
199 bpf_warn_invalid_xdp_action(NULL, rcpu->prog, act); in cpu_map_bpf_prog_run_skb()
202 trace_xdp_exception(skb->dev, rcpu->prog, act); in cpu_map_bpf_prog_run_skb()
213 static int cpu_map_bpf_prog_run_xdp(struct bpf_cpu_map_entry *rcpu, in cpu_map_bpf_prog_run_xdp() argument
235 act = bpf_prog_run_xdp(rcpu->prog, &xdp); in cpu_map_bpf_prog_run_xdp()
249 rcpu->prog); in cpu_map_bpf_prog_run_xdp()
258 bpf_warn_invalid_xdp_action(NULL, rcpu->prog, act); in cpu_map_bpf_prog_run_xdp()
274 static int cpu_map_bpf_prog_run(struct bpf_cpu_map_entry *rcpu, void **frames, in cpu_map_bpf_prog_run() argument
280 if (!rcpu->prog) in cpu_map_bpf_prog_run()
285 nframes = cpu_map_bpf_prog_run_xdp(rcpu, frames, xdp_n, stats); in cpu_map_bpf_prog_run()
291 cpu_map_bpf_prog_run_skb(rcpu, list, stats); in cpu_map_bpf_prog_run()
301 struct bpf_cpu_map_entry *rcpu = data; in cpu_map_kthread_run() local
310 while (!kthread_should_stop() || !__ptr_ring_empty(rcpu->queue)) { in cpu_map_kthread_run()
320 if (__ptr_ring_empty(rcpu->queue)) { in cpu_map_kthread_run()
323 if (__ptr_ring_empty(rcpu->queue)) { in cpu_map_kthread_run()
338 n = __ptr_ring_consume_batched(rcpu->queue, frames, in cpu_map_kthread_run()
363 nframes = cpu_map_bpf_prog_run(rcpu, frames, xdp_n, &stats, &list); in cpu_map_kthread_run()
390 trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops, in cpu_map_kthread_run()
397 put_cpu_map_entry(rcpu); in cpu_map_kthread_run()
401 static int __cpu_map_load_bpf_program(struct bpf_cpu_map_entry *rcpu, in __cpu_map_load_bpf_program() argument
416 rcpu->value.bpf_prog.id = prog->aux->id; in __cpu_map_load_bpf_program()
417 rcpu->prog = prog; in __cpu_map_load_bpf_program()
428 struct bpf_cpu_map_entry *rcpu; in __cpu_map_entry_alloc() local
434 rcpu = bpf_map_kmalloc_node(map, sizeof(*rcpu), gfp | __GFP_ZERO, numa); in __cpu_map_entry_alloc()
435 if (!rcpu) in __cpu_map_entry_alloc()
439 rcpu->bulkq = bpf_map_alloc_percpu(map, sizeof(*rcpu->bulkq), in __cpu_map_entry_alloc()
441 if (!rcpu->bulkq) in __cpu_map_entry_alloc()
445 bq = per_cpu_ptr(rcpu->bulkq, i); in __cpu_map_entry_alloc()
446 bq->obj = rcpu; in __cpu_map_entry_alloc()
450 rcpu->queue = bpf_map_kmalloc_node(map, sizeof(*rcpu->queue), gfp, in __cpu_map_entry_alloc()
452 if (!rcpu->queue) in __cpu_map_entry_alloc()
455 err = ptr_ring_init(rcpu->queue, value->qsize, gfp); in __cpu_map_entry_alloc()
459 rcpu->cpu = cpu; in __cpu_map_entry_alloc()
460 rcpu->map_id = map->id; in __cpu_map_entry_alloc()
461 rcpu->value.qsize = value->qsize; in __cpu_map_entry_alloc()
463 if (fd > 0 && __cpu_map_load_bpf_program(rcpu, map, fd)) in __cpu_map_entry_alloc()
467 rcpu->kthread = kthread_create_on_node(cpu_map_kthread_run, rcpu, numa, in __cpu_map_entry_alloc()
470 if (IS_ERR(rcpu->kthread)) in __cpu_map_entry_alloc()
473 get_cpu_map_entry(rcpu); /* 1-refcnt for being in cmap->cpu_map[] */ in __cpu_map_entry_alloc()
474 get_cpu_map_entry(rcpu); /* 1-refcnt for kthread */ in __cpu_map_entry_alloc()
477 kthread_bind(rcpu->kthread, cpu); in __cpu_map_entry_alloc()
478 wake_up_process(rcpu->kthread); in __cpu_map_entry_alloc()
480 return rcpu; in __cpu_map_entry_alloc()
483 if (rcpu->prog) in __cpu_map_entry_alloc()
484 bpf_prog_put(rcpu->prog); in __cpu_map_entry_alloc()
486 ptr_ring_cleanup(rcpu->queue, NULL); in __cpu_map_entry_alloc()
488 kfree(rcpu->queue); in __cpu_map_entry_alloc()
490 free_percpu(rcpu->bulkq); in __cpu_map_entry_alloc()
492 kfree(rcpu); in __cpu_map_entry_alloc()
498 struct bpf_cpu_map_entry *rcpu; in __cpu_map_entry_free() local
505 rcpu = container_of(rcu, struct bpf_cpu_map_entry, rcu); in __cpu_map_entry_free()
507 free_percpu(rcpu->bulkq); in __cpu_map_entry_free()
509 put_cpu_map_entry(rcpu); in __cpu_map_entry_free()
532 u32 key_cpu, struct bpf_cpu_map_entry *rcpu) in __cpu_map_entry_replace() argument
536 old_rcpu = unrcu_pointer(xchg(&cmap->cpu_map[key_cpu], RCU_INITIALIZER(rcpu))); in __cpu_map_entry_replace()
562 struct bpf_cpu_map_entry *rcpu; in cpu_map_update_elem() local
582 rcpu = NULL; /* Same as deleting */ in cpu_map_update_elem()
585 rcpu = __cpu_map_entry_alloc(map, &cpumap_value, key_cpu); in cpu_map_update_elem()
586 if (!rcpu) in cpu_map_update_elem()
588 rcpu->cmap = cmap; in cpu_map_update_elem()
591 __cpu_map_entry_replace(cmap, key_cpu, rcpu); in cpu_map_update_elem()
616 struct bpf_cpu_map_entry *rcpu; in cpu_map_free() local
618 rcpu = rcu_dereference_raw(cmap->cpu_map[i]); in cpu_map_free()
619 if (!rcpu) in cpu_map_free()
636 struct bpf_cpu_map_entry *rcpu; in __cpu_map_lookup_elem() local
641 rcpu = rcu_dereference_check(cmap->cpu_map[key], in __cpu_map_lookup_elem()
643 return rcpu; in __cpu_map_lookup_elem()
648 struct bpf_cpu_map_entry *rcpu = in cpu_map_lookup_elem() local
651 return rcpu ? &rcpu->value : NULL; in cpu_map_lookup_elem()
693 struct bpf_cpu_map_entry *rcpu = bq->obj; in bq_flush_to_queue() local
695 const int to_cpu = rcpu->cpu; in bq_flush_to_queue()
702 q = rcpu->queue; in bq_flush_to_queue()
722 trace_xdp_cpumap_enqueue(rcpu->map_id, processed, drops, to_cpu); in bq_flush_to_queue()
728 static void bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf) in bq_enqueue() argument
731 struct xdp_bulk_queue *bq = this_cpu_ptr(rcpu->bulkq); in bq_enqueue()
751 int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *xdpf, in cpu_map_enqueue() argument
757 bq_enqueue(rcpu, xdpf); in cpu_map_enqueue()
761 int cpu_map_generic_redirect(struct bpf_cpu_map_entry *rcpu, in cpu_map_generic_redirect() argument
770 ret = ptr_ring_produce(rcpu->queue, skb); in cpu_map_generic_redirect()
774 wake_up_process(rcpu->kthread); in cpu_map_generic_redirect()
776 trace_xdp_cpumap_enqueue(rcpu->map_id, !ret, !!ret, rcpu->cpu); in cpu_map_generic_redirect()