stackmap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* Copyright (c) 2016 Facebook
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of version 2 of the GNU General Public
  5. * License as published by the Free Software Foundation.
  6. */
  7. #include <linux/bpf.h>
  8. #include <linux/jhash.h>
  9. #include <linux/filter.h>
  10. #include <linux/stacktrace.h>
  11. #include <linux/perf_event.h>
  12. #include <linux/elf.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/irq_work.h>
  15. #include "percpu_freelist.h"
  16. #define STACK_CREATE_FLAG_MASK \
  17. (BPF_F_NUMA_NODE | BPF_F_RDONLY | BPF_F_WRONLY | \
  18. BPF_F_STACK_BUILD_ID)
  19. struct stack_map_bucket {
  20. struct pcpu_freelist_node fnode;
  21. u32 hash;
  22. u32 nr;
  23. u64 data[];
  24. };
  25. struct bpf_stack_map {
  26. struct bpf_map map;
  27. void *elems;
  28. struct pcpu_freelist freelist;
  29. u32 n_buckets;
  30. struct stack_map_bucket *buckets[];
  31. };
  32. /* irq_work to run up_read() for build_id lookup in nmi context */
  33. struct stack_map_irq_work {
  34. struct irq_work irq_work;
  35. struct rw_semaphore *sem;
  36. };
  37. static void do_up_read(struct irq_work *entry)
  38. {
  39. struct stack_map_irq_work *work;
  40. work = container_of(entry, struct stack_map_irq_work, irq_work);
  41. up_read(work->sem);
  42. work->sem = NULL;
  43. }
  44. static DEFINE_PER_CPU(struct stack_map_irq_work, up_read_work);
  45. static inline bool stack_map_use_build_id(struct bpf_map *map)
  46. {
  47. return (map->map_flags & BPF_F_STACK_BUILD_ID);
  48. }
  49. static inline int stack_map_data_size(struct bpf_map *map)
  50. {
  51. return stack_map_use_build_id(map) ?
  52. sizeof(struct bpf_stack_build_id) : sizeof(u64);
  53. }
  54. static int prealloc_elems_and_freelist(struct bpf_stack_map *smap)
  55. {
  56. u32 elem_size = sizeof(struct stack_map_bucket) + smap->map.value_size;
  57. int err;
  58. smap->elems = bpf_map_area_alloc(elem_size * smap->map.max_entries,
  59. smap->map.numa_node);
  60. if (!smap->elems)
  61. return -ENOMEM;
  62. err = pcpu_freelist_init(&smap->freelist);
  63. if (err)
  64. goto free_elems;
  65. pcpu_freelist_populate(&smap->freelist, smap->elems, elem_size,
  66. smap->map.max_entries);
  67. return 0;
  68. free_elems:
  69. bpf_map_area_free(smap->elems);
  70. return err;
  71. }
  72. /* Called from syscall */
  73. static struct bpf_map *stack_map_alloc(union bpf_attr *attr)
  74. {
  75. u32 value_size = attr->value_size;
  76. struct bpf_stack_map *smap;
  77. u64 cost, n_buckets;
  78. int err;
  79. if (!capable(CAP_SYS_ADMIN))
  80. return ERR_PTR(-EPERM);
  81. if (attr->map_flags & ~STACK_CREATE_FLAG_MASK)
  82. return ERR_PTR(-EINVAL);
  83. /* check sanity of attributes */
  84. if (attr->max_entries == 0 || attr->key_size != 4 ||
  85. value_size < 8 || value_size % 8)
  86. return ERR_PTR(-EINVAL);
  87. BUILD_BUG_ON(sizeof(struct bpf_stack_build_id) % sizeof(u64));
  88. if (attr->map_flags & BPF_F_STACK_BUILD_ID) {
  89. if (value_size % sizeof(struct bpf_stack_build_id) ||
  90. value_size / sizeof(struct bpf_stack_build_id)
  91. > sysctl_perf_event_max_stack)
  92. return ERR_PTR(-EINVAL);
  93. } else if (value_size / 8 > sysctl_perf_event_max_stack)
  94. return ERR_PTR(-EINVAL);
  95. /* hash table size must be power of 2 */
  96. n_buckets = roundup_pow_of_two(attr->max_entries);
  97. cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap);
  98. if (cost >= U32_MAX - PAGE_SIZE)
  99. return ERR_PTR(-E2BIG);
  100. smap = bpf_map_area_alloc(cost, bpf_map_attr_numa_node(attr));
  101. if (!smap)
  102. return ERR_PTR(-ENOMEM);
  103. err = -E2BIG;
  104. cost += n_buckets * (value_size + sizeof(struct stack_map_bucket));
  105. if (cost >= U32_MAX - PAGE_SIZE)
  106. goto free_smap;
  107. bpf_map_init_from_attr(&smap->map, attr);
  108. smap->map.value_size = value_size;
  109. smap->n_buckets = n_buckets;
  110. smap->map.pages = round_up(cost, PAGE_SIZE) >> PAGE_SHIFT;
  111. err = bpf_map_precharge_memlock(smap->map.pages);
  112. if (err)
  113. goto free_smap;
  114. err = get_callchain_buffers(sysctl_perf_event_max_stack);
  115. if (err)
  116. goto free_smap;
  117. err = prealloc_elems_and_freelist(smap);
  118. if (err)
  119. goto put_buffers;
  120. return &smap->map;
  121. put_buffers:
  122. put_callchain_buffers();
  123. free_smap:
  124. bpf_map_area_free(smap);
  125. return ERR_PTR(err);
  126. }
  127. #define BPF_BUILD_ID 3
  128. /*
  129. * Parse build id from the note segment. This logic can be shared between
  130. * 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
  131. * identical.
  132. */
  133. static inline int stack_map_parse_build_id(void *page_addr,
  134. unsigned char *build_id,
  135. void *note_start,
  136. Elf32_Word note_size)
  137. {
  138. Elf32_Word note_offs = 0, new_offs;
  139. /* check for overflow */
  140. if (note_start < page_addr || note_start + note_size < note_start)
  141. return -EINVAL;
  142. /* only supports note that fits in the first page */
  143. if (note_start + note_size > page_addr + PAGE_SIZE)
  144. return -EINVAL;
  145. while (note_offs + sizeof(Elf32_Nhdr) < note_size) {
  146. Elf32_Nhdr *nhdr = (Elf32_Nhdr *)(note_start + note_offs);
  147. if (nhdr->n_type == BPF_BUILD_ID &&
  148. nhdr->n_namesz == sizeof("GNU") &&
  149. nhdr->n_descsz == BPF_BUILD_ID_SIZE) {
  150. memcpy(build_id,
  151. note_start + note_offs +
  152. ALIGN(sizeof("GNU"), 4) + sizeof(Elf32_Nhdr),
  153. BPF_BUILD_ID_SIZE);
  154. return 0;
  155. }
  156. new_offs = note_offs + sizeof(Elf32_Nhdr) +
  157. ALIGN(nhdr->n_namesz, 4) + ALIGN(nhdr->n_descsz, 4);
  158. if (new_offs <= note_offs) /* overflow */
  159. break;
  160. note_offs = new_offs;
  161. }
  162. return -EINVAL;
  163. }
  164. /* Parse build ID from 32-bit ELF */
  165. static int stack_map_get_build_id_32(void *page_addr,
  166. unsigned char *build_id)
  167. {
  168. Elf32_Ehdr *ehdr = (Elf32_Ehdr *)page_addr;
  169. Elf32_Phdr *phdr;
  170. int i;
  171. /* only supports phdr that fits in one page */
  172. if (ehdr->e_phnum >
  173. (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
  174. return -EINVAL;
  175. phdr = (Elf32_Phdr *)(page_addr + sizeof(Elf32_Ehdr));
  176. for (i = 0; i < ehdr->e_phnum; ++i)
  177. if (phdr[i].p_type == PT_NOTE)
  178. return stack_map_parse_build_id(page_addr, build_id,
  179. page_addr + phdr[i].p_offset,
  180. phdr[i].p_filesz);
  181. return -EINVAL;
  182. }
  183. /* Parse build ID from 64-bit ELF */
  184. static int stack_map_get_build_id_64(void *page_addr,
  185. unsigned char *build_id)
  186. {
  187. Elf64_Ehdr *ehdr = (Elf64_Ehdr *)page_addr;
  188. Elf64_Phdr *phdr;
  189. int i;
  190. /* only supports phdr that fits in one page */
  191. if (ehdr->e_phnum >
  192. (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
  193. return -EINVAL;
  194. phdr = (Elf64_Phdr *)(page_addr + sizeof(Elf64_Ehdr));
  195. for (i = 0; i < ehdr->e_phnum; ++i)
  196. if (phdr[i].p_type == PT_NOTE)
  197. return stack_map_parse_build_id(page_addr, build_id,
  198. page_addr + phdr[i].p_offset,
  199. phdr[i].p_filesz);
  200. return -EINVAL;
  201. }
  202. /* Parse build ID of ELF file mapped to vma */
  203. static int stack_map_get_build_id(struct vm_area_struct *vma,
  204. unsigned char *build_id)
  205. {
  206. Elf32_Ehdr *ehdr;
  207. struct page *page;
  208. void *page_addr;
  209. int ret;
  210. /* only works for page backed storage */
  211. if (!vma->vm_file)
  212. return -EINVAL;
  213. page = find_get_page(vma->vm_file->f_mapping, 0);
  214. if (!page)
  215. return -EFAULT; /* page not mapped */
  216. ret = -EINVAL;
  217. page_addr = page_address(page);
  218. ehdr = (Elf32_Ehdr *)page_addr;
  219. /* compare magic x7f "ELF" */
  220. if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
  221. goto out;
  222. /* only support executable file and shared object file */
  223. if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN)
  224. goto out;
  225. if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
  226. ret = stack_map_get_build_id_32(page_addr, build_id);
  227. else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
  228. ret = stack_map_get_build_id_64(page_addr, build_id);
  229. out:
  230. put_page(page);
  231. return ret;
  232. }
  233. static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
  234. u64 *ips, u32 trace_nr, bool user)
  235. {
  236. int i;
  237. struct vm_area_struct *vma;
  238. bool irq_work_busy = false;
  239. struct stack_map_irq_work *work = NULL;
  240. if (in_nmi()) {
  241. work = this_cpu_ptr(&up_read_work);
  242. if (work->irq_work.flags & IRQ_WORK_BUSY)
  243. /* cannot queue more up_read, fallback */
  244. irq_work_busy = true;
  245. }
  246. /*
  247. * We cannot do up_read() in nmi context. To do build_id lookup
  248. * in nmi context, we need to run up_read() in irq_work. We use
  249. * a percpu variable to do the irq_work. If the irq_work is
  250. * already used by another lookup, we fall back to report ips.
  251. *
  252. * Same fallback is used for kernel stack (!user) on a stackmap
  253. * with build_id.
  254. */
  255. if (!user || !current || !current->mm || irq_work_busy ||
  256. down_read_trylock(&current->mm->mmap_sem) == 0) {
  257. /* cannot access current->mm, fall back to ips */
  258. for (i = 0; i < trace_nr; i++) {
  259. id_offs[i].status = BPF_STACK_BUILD_ID_IP;
  260. id_offs[i].ip = ips[i];
  261. }
  262. return;
  263. }
  264. for (i = 0; i < trace_nr; i++) {
  265. vma = find_vma(current->mm, ips[i]);
  266. if (!vma || stack_map_get_build_id(vma, id_offs[i].build_id)) {
  267. /* per entry fall back to ips */
  268. id_offs[i].status = BPF_STACK_BUILD_ID_IP;
  269. id_offs[i].ip = ips[i];
  270. continue;
  271. }
  272. id_offs[i].offset = (vma->vm_pgoff << PAGE_SHIFT) + ips[i]
  273. - vma->vm_start;
  274. id_offs[i].status = BPF_STACK_BUILD_ID_VALID;
  275. }
  276. if (!work) {
  277. up_read(&current->mm->mmap_sem);
  278. } else {
  279. work->sem = &current->mm->mmap_sem;
  280. irq_work_queue(&work->irq_work);
  281. }
  282. }
  283. BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map,
  284. u64, flags)
  285. {
  286. struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
  287. struct perf_callchain_entry *trace;
  288. struct stack_map_bucket *bucket, *new_bucket, *old_bucket;
  289. u32 max_depth = map->value_size / stack_map_data_size(map);
  290. /* stack_map_alloc() checks that max_depth <= sysctl_perf_event_max_stack */
  291. u32 init_nr = sysctl_perf_event_max_stack - max_depth;
  292. u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
  293. u32 hash, id, trace_nr, trace_len;
  294. bool user = flags & BPF_F_USER_STACK;
  295. bool kernel = !user;
  296. u64 *ips;
  297. bool hash_matches;
  298. if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
  299. BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID)))
  300. return -EINVAL;
  301. trace = get_perf_callchain(regs, init_nr, kernel, user,
  302. sysctl_perf_event_max_stack, false, false);
  303. if (unlikely(!trace))
  304. /* couldn't fetch the stack trace */
  305. return -EFAULT;
  306. /* get_perf_callchain() guarantees that trace->nr >= init_nr
  307. * and trace-nr <= sysctl_perf_event_max_stack, so trace_nr <= max_depth
  308. */
  309. trace_nr = trace->nr - init_nr;
  310. if (trace_nr <= skip)
  311. /* skipping more than usable stack trace */
  312. return -EFAULT;
  313. trace_nr -= skip;
  314. trace_len = trace_nr * sizeof(u64);
  315. ips = trace->ip + skip + init_nr;
  316. hash = jhash2((u32 *)ips, trace_len / sizeof(u32), 0);
  317. id = hash & (smap->n_buckets - 1);
  318. bucket = READ_ONCE(smap->buckets[id]);
  319. hash_matches = bucket && bucket->hash == hash;
  320. /* fast cmp */
  321. if (hash_matches && flags & BPF_F_FAST_STACK_CMP)
  322. return id;
  323. if (stack_map_use_build_id(map)) {
  324. /* for build_id+offset, pop a bucket before slow cmp */
  325. new_bucket = (struct stack_map_bucket *)
  326. pcpu_freelist_pop(&smap->freelist);
  327. if (unlikely(!new_bucket))
  328. return -ENOMEM;
  329. new_bucket->nr = trace_nr;
  330. stack_map_get_build_id_offset(
  331. (struct bpf_stack_build_id *)new_bucket->data,
  332. ips, trace_nr, user);
  333. trace_len = trace_nr * sizeof(struct bpf_stack_build_id);
  334. if (hash_matches && bucket->nr == trace_nr &&
  335. memcmp(bucket->data, new_bucket->data, trace_len) == 0) {
  336. pcpu_freelist_push(&smap->freelist, &new_bucket->fnode);
  337. return id;
  338. }
  339. if (bucket && !(flags & BPF_F_REUSE_STACKID)) {
  340. pcpu_freelist_push(&smap->freelist, &new_bucket->fnode);
  341. return -EEXIST;
  342. }
  343. } else {
  344. if (hash_matches && bucket->nr == trace_nr &&
  345. memcmp(bucket->data, ips, trace_len) == 0)
  346. return id;
  347. if (bucket && !(flags & BPF_F_REUSE_STACKID))
  348. return -EEXIST;
  349. new_bucket = (struct stack_map_bucket *)
  350. pcpu_freelist_pop(&smap->freelist);
  351. if (unlikely(!new_bucket))
  352. return -ENOMEM;
  353. memcpy(new_bucket->data, ips, trace_len);
  354. }
  355. new_bucket->hash = hash;
  356. new_bucket->nr = trace_nr;
  357. old_bucket = xchg(&smap->buckets[id], new_bucket);
  358. if (old_bucket)
  359. pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
  360. return id;
  361. }
  362. const struct bpf_func_proto bpf_get_stackid_proto = {
  363. .func = bpf_get_stackid,
  364. .gpl_only = true,
  365. .ret_type = RET_INTEGER,
  366. .arg1_type = ARG_PTR_TO_CTX,
  367. .arg2_type = ARG_CONST_MAP_PTR,
  368. .arg3_type = ARG_ANYTHING,
  369. };
  370. BPF_CALL_4(bpf_get_stack, struct pt_regs *, regs, void *, buf, u32, size,
  371. u64, flags)
  372. {
  373. u32 init_nr, trace_nr, copy_len, elem_size, num_elem;
  374. bool user_build_id = flags & BPF_F_USER_BUILD_ID;
  375. u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
  376. bool user = flags & BPF_F_USER_STACK;
  377. struct perf_callchain_entry *trace;
  378. bool kernel = !user;
  379. int err = -EINVAL;
  380. u64 *ips;
  381. if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
  382. BPF_F_USER_BUILD_ID)))
  383. goto clear;
  384. if (kernel && user_build_id)
  385. goto clear;
  386. elem_size = (user && user_build_id) ? sizeof(struct bpf_stack_build_id)
  387. : sizeof(u64);
  388. if (unlikely(size % elem_size))
  389. goto clear;
  390. num_elem = size / elem_size;
  391. if (sysctl_perf_event_max_stack < num_elem)
  392. init_nr = 0;
  393. else
  394. init_nr = sysctl_perf_event_max_stack - num_elem;
  395. trace = get_perf_callchain(regs, init_nr, kernel, user,
  396. sysctl_perf_event_max_stack, false, false);
  397. if (unlikely(!trace))
  398. goto err_fault;
  399. trace_nr = trace->nr - init_nr;
  400. if (trace_nr < skip)
  401. goto err_fault;
  402. trace_nr -= skip;
  403. trace_nr = (trace_nr <= num_elem) ? trace_nr : num_elem;
  404. copy_len = trace_nr * elem_size;
  405. ips = trace->ip + skip + init_nr;
  406. if (user && user_build_id)
  407. stack_map_get_build_id_offset(buf, ips, trace_nr, user);
  408. else
  409. memcpy(buf, ips, copy_len);
  410. if (size > copy_len)
  411. memset(buf + copy_len, 0, size - copy_len);
  412. return copy_len;
  413. err_fault:
  414. err = -EFAULT;
  415. clear:
  416. memset(buf, 0, size);
  417. return err;
  418. }
  419. const struct bpf_func_proto bpf_get_stack_proto = {
  420. .func = bpf_get_stack,
  421. .gpl_only = true,
  422. .ret_type = RET_INTEGER,
  423. .arg1_type = ARG_PTR_TO_CTX,
  424. .arg2_type = ARG_PTR_TO_UNINIT_MEM,
  425. .arg3_type = ARG_CONST_SIZE_OR_ZERO,
  426. .arg4_type = ARG_ANYTHING,
  427. };
  428. /* Called from eBPF program */
  429. static void *stack_map_lookup_elem(struct bpf_map *map, void *key)
  430. {
  431. return NULL;
  432. }
  433. /* Called from syscall */
  434. int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
  435. {
  436. struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
  437. struct stack_map_bucket *bucket, *old_bucket;
  438. u32 id = *(u32 *)key, trace_len;
  439. if (unlikely(id >= smap->n_buckets))
  440. return -ENOENT;
  441. bucket = xchg(&smap->buckets[id], NULL);
  442. if (!bucket)
  443. return -ENOENT;
  444. trace_len = bucket->nr * stack_map_data_size(map);
  445. memcpy(value, bucket->data, trace_len);
  446. memset(value + trace_len, 0, map->value_size - trace_len);
  447. old_bucket = xchg(&smap->buckets[id], bucket);
  448. if (old_bucket)
  449. pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
  450. return 0;
  451. }
  452. static int stack_map_get_next_key(struct bpf_map *map, void *key,
  453. void *next_key)
  454. {
  455. struct bpf_stack_map *smap = container_of(map,
  456. struct bpf_stack_map, map);
  457. u32 id;
  458. WARN_ON_ONCE(!rcu_read_lock_held());
  459. if (!key) {
  460. id = 0;
  461. } else {
  462. id = *(u32 *)key;
  463. if (id >= smap->n_buckets || !smap->buckets[id])
  464. id = 0;
  465. else
  466. id++;
  467. }
  468. while (id < smap->n_buckets && !smap->buckets[id])
  469. id++;
  470. if (id >= smap->n_buckets)
  471. return -ENOENT;
  472. *(u32 *)next_key = id;
  473. return 0;
  474. }
  475. static int stack_map_update_elem(struct bpf_map *map, void *key, void *value,
  476. u64 map_flags)
  477. {
  478. return -EINVAL;
  479. }
  480. /* Called from syscall or from eBPF program */
  481. static int stack_map_delete_elem(struct bpf_map *map, void *key)
  482. {
  483. struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
  484. struct stack_map_bucket *old_bucket;
  485. u32 id = *(u32 *)key;
  486. if (unlikely(id >= smap->n_buckets))
  487. return -E2BIG;
  488. old_bucket = xchg(&smap->buckets[id], NULL);
  489. if (old_bucket) {
  490. pcpu_freelist_push(&smap->freelist, &old_bucket->fnode);
  491. return 0;
  492. } else {
  493. return -ENOENT;
  494. }
  495. }
  496. /* Called when map->refcnt goes to zero, either from workqueue or from syscall */
  497. static void stack_map_free(struct bpf_map *map)
  498. {
  499. struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
  500. /* wait for bpf programs to complete before freeing stack map */
  501. synchronize_rcu();
  502. bpf_map_area_free(smap->elems);
  503. pcpu_freelist_destroy(&smap->freelist);
  504. bpf_map_area_free(smap);
  505. put_callchain_buffers();
  506. }
  507. const struct bpf_map_ops stack_map_ops = {
  508. .map_alloc = stack_map_alloc,
  509. .map_free = stack_map_free,
  510. .map_get_next_key = stack_map_get_next_key,
  511. .map_lookup_elem = stack_map_lookup_elem,
  512. .map_update_elem = stack_map_update_elem,
  513. .map_delete_elem = stack_map_delete_elem,
  514. .map_check_btf = map_check_no_btf,
  515. };
  516. static int __init stack_map_init(void)
  517. {
  518. int cpu;
  519. struct stack_map_irq_work *work;
  520. for_each_possible_cpu(cpu) {
  521. work = per_cpu_ptr(&up_read_work, cpu);
  522. init_irq_work(&work->irq_work, do_up_read);
  523. }
  524. return 0;
  525. }
  526. subsys_initcall(stack_map_init);