1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2016 Facebook
5 #include <linux/jhash.h>
6 #include <linux/filter.h>
7 #include <linux/kernel.h>
8 #include <linux/stacktrace.h>
9 #include <linux/perf_event.h>
10 #include <linux/elf.h>
11 #include <linux/pagemap.h>
12 #include <linux/irq_work.h>
13 #include <linux/btf_ids.h>
14 #include "percpu_freelist.h"
16 #define STACK_CREATE_FLAG_MASK \
17 (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY | \
20 struct stack_map_bucket {
21 struct pcpu_freelist_node fnode;
27 struct bpf_stack_map {
30 struct pcpu_freelist freelist;
32 struct stack_map_bucket *buckets[];
35 /* irq_work to run up_read() for build_id lookup in nmi context */
36 struct stack_map_irq_work {
37 struct irq_work irq_work;
41 static void do_up_read(struct irq_work *entry)
43 struct stack_map_irq_work *work;
45 if (WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_RT)))
48 work = container_of(entry, struct stack_map_irq_work, irq_work);
49 mmap_read_unlock_non_owner(work->mm);
52 static DEFINE_PER_CPU(struct stack_map_irq_work, up_read_work);
54 static inline bool stack_map_use_build_id(struct bpf_map *map)
56 return (map->map_flags & BPF_F_STACK_BUILD_ID);
59 static inline int stack_map_data_size(struct bpf_map *map)
61 return stack_map_use_build_id(map) ?
62 sizeof(struct bpf_stack_build_id) : sizeof(u64);
65 static int prealloc_elems_and_freelist(struct bpf_stack_map *smap)
67 u32 elem_size = sizeof(struct stack_map_bucket) + smap->map.value_size;
70 smap->elems = bpf_map_area_alloc(elem_size * smap->map.max_entries,
75 err = pcpu_freelist_init(&smap->freelist);
79 pcpu_freelist_populate(&smap->freelist, smap->elems, elem_size,
80 smap->map.max_entries);
84 bpf_map_area_free(smap->elems);
88 /* Called from syscall */
89 static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
91 u32 value_size = attr->value_size;
92 struct bpf_stack_map *smap;
97 return ERR_PTR(-EPERM);
99 if (attr->map_flags & ~STACK_CREATE_FLAG_MASK)
100 return ERR_PTR(-EINVAL);
102 /* check sanity of attributes */
103 if (attr->max_entries == 0 || attr->key_size != 4 ||
104 value_size < 8 || value_size % 8)
105 return ERR_PTR(-EINVAL);
107 BUILD_BUG_ON(sizeof(struct bpf_stack_build_id) % sizeof(u64));
108 if (attr->map_flags & BPF_F_STACK_BUILD_ID) {
109 if (value_size % sizeof(struct bpf_stack_build_id) ||
110 value_size / sizeof(struct bpf_stack_build_id)
111 > sysctl_perf_event_max_stack)
112 return ERR_PTR(-EINVAL);
113 } else if (value_size / 8 > sysctl_perf_event_max_stack)
114 return ERR_PTR(-EINVAL);
116 /* hash table size must be power of 2 */
117 n_buckets = roundup_pow_of_two(attr->max_entries);
119 return ERR_PTR(-E2BIG);
121 cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
122 cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));
123 smap = bpf_map_area_alloc(cost, bpf_map_attr_numa_node(attr));
125 return ERR_PTR(-ENOMEM);
127 bpf_map_init_from_attr(&smap->map, attr);
128 smap->map.value_size = value_size;
129 smap->n_buckets = n_buckets;
131 err = get_callchain_buffers(sysctl_perf_event_max_stack);
135 err = prealloc_elems_and_freelist(smap);
142 put_callchain_buffers();
144 bpf_map_area_free(smap);
148 #define BPF_BUILD_ID 3
150 * Parse build id from the note segment. This logic can be shared between
151 * 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
154 static inline int stack_map_parse_build_id(void *page_addr,
155 unsigned char *build_id,
157 Elf32_Word note_size)
159 Elf32_Word note_offs = 0, new_offs;
161 /* check for overflow */
162 if (note_start < page_addr || note_start + note_size < note_start)
165 /* only supports note that fits in the first page */
166 if (note_start + note_size > page_addr + PAGE_SIZE)
169 while (note_offs + sizeof(Elf32_Nhdr) < note_size) {
170 Elf32_Nhdr *nhdr = (Elf32_Nhdr *)(note_start + note_offs);
172 if (nhdr->n_type == BPF_BUILD_ID &&
173 nhdr->n_namesz == sizeof("GNU") &&
174 nhdr->n_descsz > 0 &&
175 nhdr->n_descsz <= BPF_BUILD_ID_SIZE) {
177 note_start + note_offs +
178 ALIGN(sizeof("GNU"), 4) + sizeof(Elf32_Nhdr),
180 memset(build_id + nhdr->n_descsz, 0,
181 BPF_BUILD_ID_SIZE - nhdr->n_descsz);
184 new_offs = note_offs + sizeof(Elf32_Nhdr) +
185 ALIGN(nhdr->n_namesz, 4) + ALIGN(nhdr->n_descsz, 4);
186 if (new_offs <= note_offs) /* overflow */
188 note_offs = new_offs;
193 /* Parse build ID from 32-bit ELF */
194 static int stack_map_get_build_id_32(void *page_addr,
195 unsigned char *build_id)
197 Elf32_Ehdr *ehdr = (Elf32_Ehdr *)page_addr;
201 /* only supports phdr that fits in one page */
203 (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
206 phdr = (Elf32_Phdr *)(page_addr + sizeof(Elf32_Ehdr));
208 for (i = 0; i < ehdr->e_phnum; ++i) {
209 if (phdr[i].p_type == PT_NOTE &&
210 !stack_map_parse_build_id(page_addr, build_id,
211 page_addr + phdr[i].p_offset,
218 /* Parse build ID from 64-bit ELF */
219 static int stack_map_get_build_id_64(void *page_addr,
220 unsigned char *build_id)
222 Elf64_Ehdr *ehdr = (Elf64_Ehdr *)page_addr;
226 /* only supports phdr that fits in one page */
228 (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
231 phdr = (Elf64_Phdr *)(page_addr + sizeof(Elf64_Ehdr));
233 for (i = 0; i < ehdr->e_phnum; ++i) {
234 if (phdr[i].p_type == PT_NOTE &&
235 !stack_map_parse_build_id(page_addr, build_id,
236 page_addr + phdr[i].p_offset,
243 /* Parse build ID of ELF file mapped to vma */
244 static int stack_map_get_build_id(struct vm_area_struct *vma,
245 unsigned char *build_id)
252 /* only works for page backed storage */
256 page = find_get_page(vma->vm_file->f_mapping, 0);
258 return -EFAULT; /* page not mapped */
261 page_addr = kmap_atomic(page);
262 ehdr = (Elf32_Ehdr *)page_addr;
264 /* compare magic x7f "ELF" */
265 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
268 /* only support executable file and shared object file */
269 if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN)
272 if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
273 ret = stack_map_get_build_id_32(page_addr, build_id);
274 else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
275 ret = stack_map_get_build_id_64(page_addr, build_id);
277 kunmap_atomic(page_addr);
282 static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
283 u64 *ips, u32 trace_nr, bool user)
286 struct vm_area_struct *vma;
287 bool irq_work_busy = false;
288 struct stack_map_irq_work *work = NULL;
290 if (irqs_disabled()) {
291 if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
292 work = this_cpu_ptr(&up_read_work);
293 if (irq_work_is_busy(&work->irq_work)) {
294 /* cannot queue more up_read, fallback */
295 irq_work_busy = true;
299 * PREEMPT_RT does not allow to trylock mmap sem in
300 * interrupt disabled context. Force the fallback code.
302 irq_work_busy = true;
307 * We cannot do up_read() when the irq is disabled, because of
308 * risk to deadlock with rq_lock. To do build_id lookup when the
309 * irqs are disabled, we need to run up_read() in irq_work. We use
310 * a percpu variable to do the irq_work. If the irq_work is
311 * already used by another lookup, we fall back to report ips.
313 * Same fallback is used for kernel stack (!user) on a stackmap
316 if (!user || !current || !current->mm || irq_work_busy ||
317 !mmap_read_trylock_non_owner(current->mm)) {
318 /* cannot access current->mm, fall back to ips */
319 for (i = 0; i < trace_nr; i++) {
320 id_offs[i].status = BPF_STACK_BUILD_ID_IP;
321 id_offs[i].ip = ips[i];
322 memset(id_offs[i].build_id, 0, BPF_BUILD_ID_SIZE);
327 for (i = 0; i < trace_nr; i++) {
328 vma = find_vma(current->mm, ips[i]);
329 if (!vma || stack_map_get_build_id(vma, id_offs[i].build_id)) {
330 /* per entry fall back to ips */
331 id_offs[i].status = BPF_STACK_BUILD_ID_IP;
332 id_offs[i].ip = ips[i];
333 memset(id_offs[i].build_id, 0, BPF_BUILD_ID_SIZE);
336 id_offs[i].offset = (vma->vm_pgoff << PAGE_SHIFT) + ips[i]
338 id_offs[i].status = BPF_STACK_BUILD_ID_VALID;
342 mmap_read_unlock_non_owner(current->mm);
344 work->mm = current->mm;
345 irq_work_queue(&work->irq_work);
349 static struct perf_callchain_entry *
350 get_callchain_entry_for_task(struct task_struct *task, u32 init_nr)
352 #ifdef CONFIG_STACKTRACE
353 struct perf_callchain_entry *entry;
356 entry = get_callchain_entry(&rctx);
361 entry->nr = init_nr +
362 stack_trace_save_tsk(task, (unsigned long *)(entry->ip + init_nr),
363 sysctl_perf_event_max_stack - init_nr, 0);
365 /* stack_trace_save_tsk() works on unsigned long array, while
366 * perf_callchain_entry uses u64 array. For 32-bit systems, it is
367 * necessary to fix this mismatch.
369 if (__BITS_PER_LONG != 64) {
370 unsigned long *from = (unsigned long *) entry->ip;
374 /* copy data from the end to avoid using extra buffer */
375 for (i = entry->nr - 1; i >= (int)init_nr; i--)
376 to[i] = (u64)(from[i]);
379 put_callchain_entry(rctx);
382 #else /* CONFIG_STACKTRACE */
387 static long __bpf_get_stackid(struct bpf_map *map,
388 struct perf_callchain_entry *trace, u64 flags)
390 struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
391 struct stack_map_bucket *bucket, *new_bucket, *old_bucket;
392 u32 max_depth = map->value_size / stack_map_data_size(map);
393 /* stack_map_alloc() checks that max_depth <= sysctl_perf_event_max_stack */
394 u32 init_nr = sysctl_perf_event_max_stack - max_depth;
395 u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
396 u32 hash, id, trace_nr, trace_len;
397 bool user = flags & BPF_F_USER_STACK;
401 /* get_perf_callchain() guarantees that trace->nr >= init_nr
402 * and trace-nr <= sysctl_perf_event_max_stack, so trace_nr <= max_depth
404 trace_nr = trace->nr - init_nr;
406 if (trace_nr <= skip)
407 /* skipping more than usable stack trace */
411 trace_len = trace_nr * sizeof(u64);
412 ips = trace->ip + skip + init_nr;
413 hash = jhash2((u32 *)ips, trace_len / sizeof(u32), 0);
414 id = hash & (smap->n_buckets - 1);
415 bucket = READ_ONCE(smap->buckets[id]);
417 hash_matches = bucket && bucket->hash == hash;
419 if (hash_matches && flags & BPF_F_FAST_STACK_CMP)
422 if (stack_map_use_build_id(map)) {
423 /* for build_id+offset, pop a bucket before slow cmp */
424 new_bucket = (struct stack_map_bucket *)
425 pcpu_freelist_pop(&smap->freelist);
426 if (unlikely(!new_bucket))
428 new_bucket->nr = trace_nr;
429 stack_map_get_build_id_offset(
430 (struct bpf_stack_build_id *)new_bucket->data,
431 ips, trace_nr, user);
432 trace_len = trace_nr * sizeof(struct bpf_stack_build_id);
433 if (hash_matches && bucket->nr == trace_nr &&
434 memcmp(bucket->data, new_bucket->data, trace_len) == 0) {
435 pcpu_freelist_push(&smap->freelist, &new_bucket->fnode);
438 if (bucket && !(flags & BPF_F_REUSE_STACKID)) {
439 pcpu_freelist_push(&smap->freelist, &new_bucket->fnode);
443 if (hash_matches && bucket->nr == trace_nr &&
444 memcmp(bucket->data, ips, trace_len) == 0)
446 if (bucket && !(flags & BPF_F_REUSE_STACKID))
449 new_bucket = (struct stack_map_bucket *)
450 pcpu_freelist_pop(&smap->freelist);
451 if (unlikely(!new_bucket))
453 memcpy(new_bucket->data, ips, trace_len);
456 new_bucket->hash = hash;
457 new_bucket->nr = trace_nr;
459 old_bucket = xchg(&smap->buckets[id], new_bucket);
461 pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
465 BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map,
468 u32 max_depth = map->value_size / stack_map_data_size(map);
469 /* stack_map_alloc() checks that max_depth <= sysctl_perf_event_max_stack */
470 u32 init_nr = sysctl_perf_event_max_stack - max_depth;
471 bool user = flags & BPF_F_USER_STACK;
472 struct perf_callchain_entry *trace;
475 if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
476 BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID)))
479 trace = get_perf_callchain(regs, init_nr, kernel, user,
480 sysctl_perf_event_max_stack, false, false);
482 if (unlikely(!trace))
483 /* couldn't fetch the stack trace */
486 return __bpf_get_stackid(map, trace, flags);
489 const struct bpf_func_proto bpf_get_stackid_proto = {
490 .func = bpf_get_stackid,
492 .ret_type = RET_INTEGER,
493 .arg1_type = ARG_PTR_TO_CTX,
494 .arg2_type = ARG_CONST_MAP_PTR,
495 .arg3_type = ARG_ANYTHING,
498 static __u64 count_kernel_ip(struct perf_callchain_entry *trace)
502 while (nr_kernel < trace->nr) {
503 if (trace->ip[nr_kernel] == PERF_CONTEXT_USER)
510 BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
511 struct bpf_map *, map, u64, flags)
513 struct perf_event *event = ctx->event;
514 struct perf_callchain_entry *trace;
519 /* perf_sample_data doesn't have callchain, use bpf_get_stackid */
520 if (!(event->attr.sample_type & __PERF_SAMPLE_CALLCHAIN_EARLY))
521 return bpf_get_stackid((unsigned long)(ctx->regs),
522 (unsigned long) map, flags, 0, 0);
524 if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
525 BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID)))
528 user = flags & BPF_F_USER_STACK;
531 trace = ctx->data->callchain;
532 if (unlikely(!trace))
535 nr_kernel = count_kernel_ip(trace);
538 __u64 nr = trace->nr;
540 trace->nr = nr_kernel;
541 ret = __bpf_get_stackid(map, trace, flags);
546 u64 skip = flags & BPF_F_SKIP_FIELD_MASK;
549 if (skip > BPF_F_SKIP_FIELD_MASK)
552 flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
553 ret = __bpf_get_stackid(map, trace, flags);
558 const struct bpf_func_proto bpf_get_stackid_proto_pe = {
559 .func = bpf_get_stackid_pe,
561 .ret_type = RET_INTEGER,
562 .arg1_type = ARG_PTR_TO_CTX,
563 .arg2_type = ARG_CONST_MAP_PTR,
564 .arg3_type = ARG_ANYTHING,
567 static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
568 struct perf_callchain_entry *trace_in,
569 void *buf, u32 size, u64 flags)
571 u32 init_nr, trace_nr, copy_len, elem_size, num_elem;
572 bool user_build_id = flags & BPF_F_USER_BUILD_ID;
573 u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
574 bool user = flags & BPF_F_USER_STACK;
575 struct perf_callchain_entry *trace;
580 if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
581 BPF_F_USER_BUILD_ID)))
583 if (kernel && user_build_id)
586 elem_size = (user && user_build_id) ? sizeof(struct bpf_stack_build_id)
588 if (unlikely(size % elem_size))
591 /* cannot get valid user stack for task without user_mode regs */
592 if (task && user && !user_mode(regs))
595 num_elem = size / elem_size;
596 if (sysctl_perf_event_max_stack < num_elem)
599 init_nr = sysctl_perf_event_max_stack - num_elem;
603 else if (kernel && task)
604 trace = get_callchain_entry_for_task(task, init_nr);
606 trace = get_perf_callchain(regs, init_nr, kernel, user,
607 sysctl_perf_event_max_stack,
609 if (unlikely(!trace))
612 trace_nr = trace->nr - init_nr;
617 trace_nr = (trace_nr <= num_elem) ? trace_nr : num_elem;
618 copy_len = trace_nr * elem_size;
619 ips = trace->ip + skip + init_nr;
620 if (user && user_build_id)
621 stack_map_get_build_id_offset(buf, ips, trace_nr, user);
623 memcpy(buf, ips, copy_len);
626 memset(buf + copy_len, 0, size - copy_len);
632 memset(buf, 0, size);
636 BPF_CALL_4(bpf_get_stack, struct pt_regs *, regs, void *, buf, u32, size,
639 return __bpf_get_stack(regs, NULL, NULL, buf, size, flags);
642 const struct bpf_func_proto bpf_get_stack_proto = {
643 .func = bpf_get_stack,
645 .ret_type = RET_INTEGER,
646 .arg1_type = ARG_PTR_TO_CTX,
647 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
648 .arg3_type = ARG_CONST_SIZE_OR_ZERO,
649 .arg4_type = ARG_ANYTHING,
652 BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
653 u32, size, u64, flags)
655 struct pt_regs *regs = task_pt_regs(task);
657 return __bpf_get_stack(regs, task, NULL, buf, size, flags);
660 BTF_ID_LIST_SINGLE(bpf_get_task_stack_btf_ids, struct, task_struct)
662 const struct bpf_func_proto bpf_get_task_stack_proto = {
663 .func = bpf_get_task_stack,
665 .ret_type = RET_INTEGER,
666 .arg1_type = ARG_PTR_TO_BTF_ID,
667 .arg1_btf_id = &bpf_get_task_stack_btf_ids[0],
668 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
669 .arg3_type = ARG_CONST_SIZE_OR_ZERO,
670 .arg4_type = ARG_ANYTHING,
673 BPF_CALL_4(bpf_get_stack_pe, struct bpf_perf_event_data_kern *, ctx,
674 void *, buf, u32, size, u64, flags)
676 struct pt_regs *regs = (struct pt_regs *)(ctx->regs);
677 struct perf_event *event = ctx->event;
678 struct perf_callchain_entry *trace;
683 if (!(event->attr.sample_type & __PERF_SAMPLE_CALLCHAIN_EARLY))
684 return __bpf_get_stack(regs, NULL, NULL, buf, size, flags);
686 if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
687 BPF_F_USER_BUILD_ID)))
690 user = flags & BPF_F_USER_STACK;
694 trace = ctx->data->callchain;
695 if (unlikely(!trace))
698 nr_kernel = count_kernel_ip(trace);
701 __u64 nr = trace->nr;
703 trace->nr = nr_kernel;
704 err = __bpf_get_stack(regs, NULL, trace, buf, size, flags);
709 u64 skip = flags & BPF_F_SKIP_FIELD_MASK;
712 if (skip > BPF_F_SKIP_FIELD_MASK)
715 flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
716 err = __bpf_get_stack(regs, NULL, trace, buf, size, flags);
721 memset(buf, 0, size);
726 const struct bpf_func_proto bpf_get_stack_proto_pe = {
727 .func = bpf_get_stack_pe,
729 .ret_type = RET_INTEGER,
730 .arg1_type = ARG_PTR_TO_CTX,
731 .arg2_type = ARG_PTR_TO_UNINIT_MEM,
732 .arg3_type = ARG_CONST_SIZE_OR_ZERO,
733 .arg4_type = ARG_ANYTHING,
736 /* Called from eBPF program */
737 static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
739 return ERR_PTR(-EOPNOTSUPP);
742 /* Called from syscall */
743 int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
745 struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
746 struct stack_map_bucket *bucket, *old_bucket;
747 u32 id = *(u32 *)key, trace_len;
749 if (unlikely(id >= smap->n_buckets))
752 bucket = xchg(&smap->buckets[id], NULL);
756 trace_len = bucket->nr * stack_map_data_size(map);
757 memcpy(value, bucket->data, trace_len);
758 memset(value + trace_len, 0, map->value_size - trace_len);
760 old_bucket = xchg(&smap->buckets[id], bucket);
762 pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
766 static int stack_map_get_next_key(struct bpf_map *map, void *key,
769 struct bpf_stack_map *smap = container_of(map,
770 struct bpf_stack_map, map);
773 WARN_ON_ONCE(!rcu_read_lock_held());
779 if (id >= smap->n_buckets || !smap->buckets[id])
785 while (id < smap->n_buckets && !smap->buckets[id])
788 if (id >= smap->n_buckets)
791 *(u32 *)next_key = id;
795 static int stack_map_update_elem(struct bpf_map *map, void *key, void *value,
801 /* Called from syscall or from eBPF program */
802 static int stack_map_delete_elem(struct bpf_map *map, void *key)
804 struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
805 struct stack_map_bucket *old_bucket;
806 u32 id = *(u32 *)key;
808 if (unlikely(id >= smap->n_buckets))
811 old_bucket = xchg(&smap->buckets[id], NULL);
813 pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
820 /* Called when map->refcnt goes to zero, either from workqueue or from syscall */
821 static void stack_map_free(struct bpf_map *map)
823 struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
825 bpf_map_area_free(smap->elems);
826 pcpu_freelist_destroy(&smap->freelist);
827 bpf_map_area_free(smap);
828 put_callchain_buffers();
831 static int stack_trace_map_btf_id;
832 const struct bpf_map_ops stack_trace_map_ops = {
833 .map_meta_equal = bpf_map_meta_equal,
834 .map_alloc = stack_map_alloc,
835 .map_free = stack_map_free,
836 .map_get_next_key = stack_map_get_next_key,
837 .map_lookup_elem = stack_map_lookup_elem,
838 .map_update_elem = stack_map_update_elem,
839 .map_delete_elem = stack_map_delete_elem,
840 .map_check_btf = map_check_no_btf,
841 .map_btf_name = "bpf_stack_map",
842 .map_btf_id = &stack_trace_map_btf_id,
845 static int __init stack_map_init(void)
848 struct stack_map_irq_work *work;
850 for_each_possible_cpu(cpu) {
851 work = per_cpu_ptr(&up_read_work, cpu);
852 init_irq_work(&work->irq_work, do_up_read);
856 subsys_initcall(stack_map_init);