bpf_trace.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com
  2. * Copyright (c) 2016 Facebook
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/slab.h>
  11. #include <linux/bpf.h>
  12. #include <linux/bpf_perf_event.h>
  13. #include <linux/filter.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/ctype.h>
  16. #include "trace.h"
  17. /**
  18. * trace_call_bpf - invoke BPF program
  19. * @prog: BPF program
  20. * @ctx: opaque context pointer
  21. *
  22. * kprobe handlers execute BPF programs via this helper.
  23. * Can be used from static tracepoints in the future.
  24. *
  25. * Return: BPF programs always return an integer which is interpreted by
  26. * kprobe handler as:
  27. * 0 - return from kprobe (event is filtered out)
  28. * 1 - store kprobe event into ring buffer
  29. * Other values are reserved and currently alias to 1
  30. */
  31. unsigned int trace_call_bpf(struct bpf_prog *prog, void *ctx)
  32. {
  33. unsigned int ret;
  34. if (in_nmi()) /* not supported yet */
  35. return 1;
  36. preempt_disable();
  37. if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
  38. /*
  39. * since some bpf program is already running on this cpu,
  40. * don't call into another bpf program (same or different)
  41. * and don't send kprobe event into ring-buffer,
  42. * so return zero here
  43. */
  44. ret = 0;
  45. goto out;
  46. }
  47. rcu_read_lock();
  48. ret = BPF_PROG_RUN(prog, ctx);
  49. rcu_read_unlock();
  50. out:
  51. __this_cpu_dec(bpf_prog_active);
  52. preempt_enable();
  53. return ret;
  54. }
  55. EXPORT_SYMBOL_GPL(trace_call_bpf);
  56. BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const void *, unsafe_ptr)
  57. {
  58. int ret;
  59. ret = probe_kernel_read(dst, unsafe_ptr, size);
  60. if (unlikely(ret < 0))
  61. memset(dst, 0, size);
  62. return ret;
  63. }
  64. static const struct bpf_func_proto bpf_probe_read_proto = {
  65. .func = bpf_probe_read,
  66. .gpl_only = true,
  67. .ret_type = RET_INTEGER,
  68. .arg1_type = ARG_PTR_TO_UNINIT_MEM,
  69. .arg2_type = ARG_CONST_SIZE,
  70. .arg3_type = ARG_ANYTHING,
  71. };
  72. BPF_CALL_3(bpf_probe_write_user, void *, unsafe_ptr, const void *, src,
  73. u32, size)
  74. {
  75. /*
  76. * Ensure we're in user context which is safe for the helper to
  77. * run. This helper has no business in a kthread.
  78. *
  79. * access_ok() should prevent writing to non-user memory, but in
  80. * some situations (nommu, temporary switch, etc) access_ok() does
  81. * not provide enough validation, hence the check on KERNEL_DS.
  82. */
  83. if (unlikely(in_interrupt() ||
  84. current->flags & (PF_KTHREAD | PF_EXITING)))
  85. return -EPERM;
  86. if (unlikely(uaccess_kernel()))
  87. return -EPERM;
  88. if (!access_ok(VERIFY_WRITE, unsafe_ptr, size))
  89. return -EPERM;
  90. return probe_kernel_write(unsafe_ptr, src, size);
  91. }
  92. static const struct bpf_func_proto bpf_probe_write_user_proto = {
  93. .func = bpf_probe_write_user,
  94. .gpl_only = true,
  95. .ret_type = RET_INTEGER,
  96. .arg1_type = ARG_ANYTHING,
  97. .arg2_type = ARG_PTR_TO_MEM,
  98. .arg3_type = ARG_CONST_SIZE,
  99. };
  100. static const struct bpf_func_proto *bpf_get_probe_write_proto(void)
  101. {
  102. pr_warn_ratelimited("%s[%d] is installing a program with bpf_probe_write_user helper that may corrupt user memory!",
  103. current->comm, task_pid_nr(current));
  104. return &bpf_probe_write_user_proto;
  105. }
  106. /*
  107. * limited trace_printk()
  108. * only %d %u %x %ld %lu %lx %lld %llu %llx %p %s conversion specifiers allowed
  109. */
  110. BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
  111. u64, arg2, u64, arg3)
  112. {
  113. bool str_seen = false;
  114. int mod[3] = {};
  115. int fmt_cnt = 0;
  116. u64 unsafe_addr;
  117. char buf[64];
  118. int i;
  119. /*
  120. * bpf_check()->check_func_arg()->check_stack_boundary()
  121. * guarantees that fmt points to bpf program stack,
  122. * fmt_size bytes of it were initialized and fmt_size > 0
  123. */
  124. if (fmt[--fmt_size] != 0)
  125. return -EINVAL;
  126. /* check format string for allowed specifiers */
  127. for (i = 0; i < fmt_size; i++) {
  128. if ((!isprint(fmt[i]) && !isspace(fmt[i])) || !isascii(fmt[i]))
  129. return -EINVAL;
  130. if (fmt[i] != '%')
  131. continue;
  132. if (fmt_cnt >= 3)
  133. return -EINVAL;
  134. /* fmt[i] != 0 && fmt[last] == 0, so we can access fmt[i + 1] */
  135. i++;
  136. if (fmt[i] == 'l') {
  137. mod[fmt_cnt]++;
  138. i++;
  139. } else if (fmt[i] == 'p' || fmt[i] == 's') {
  140. mod[fmt_cnt]++;
  141. i++;
  142. if (!isspace(fmt[i]) && !ispunct(fmt[i]) && fmt[i] != 0)
  143. return -EINVAL;
  144. fmt_cnt++;
  145. if (fmt[i - 1] == 's') {
  146. if (str_seen)
  147. /* allow only one '%s' per fmt string */
  148. return -EINVAL;
  149. str_seen = true;
  150. switch (fmt_cnt) {
  151. case 1:
  152. unsafe_addr = arg1;
  153. arg1 = (long) buf;
  154. break;
  155. case 2:
  156. unsafe_addr = arg2;
  157. arg2 = (long) buf;
  158. break;
  159. case 3:
  160. unsafe_addr = arg3;
  161. arg3 = (long) buf;
  162. break;
  163. }
  164. buf[0] = 0;
  165. strncpy_from_unsafe(buf,
  166. (void *) (long) unsafe_addr,
  167. sizeof(buf));
  168. }
  169. continue;
  170. }
  171. if (fmt[i] == 'l') {
  172. mod[fmt_cnt]++;
  173. i++;
  174. }
  175. if (fmt[i] != 'd' && fmt[i] != 'u' && fmt[i] != 'x')
  176. return -EINVAL;
  177. fmt_cnt++;
  178. }
  179. return __trace_printk(1/* fake ip will not be printed */, fmt,
  180. mod[0] == 2 ? arg1 : mod[0] == 1 ? (long) arg1 : (u32) arg1,
  181. mod[1] == 2 ? arg2 : mod[1] == 1 ? (long) arg2 : (u32) arg2,
  182. mod[2] == 2 ? arg3 : mod[2] == 1 ? (long) arg3 : (u32) arg3);
  183. }
  184. static const struct bpf_func_proto bpf_trace_printk_proto = {
  185. .func = bpf_trace_printk,
  186. .gpl_only = true,
  187. .ret_type = RET_INTEGER,
  188. .arg1_type = ARG_PTR_TO_MEM,
  189. .arg2_type = ARG_CONST_SIZE,
  190. };
  191. const struct bpf_func_proto *bpf_get_trace_printk_proto(void)
  192. {
  193. /*
  194. * this program might be calling bpf_trace_printk,
  195. * so allocate per-cpu printk buffers
  196. */
  197. trace_printk_init_buffers();
  198. return &bpf_trace_printk_proto;
  199. }
  200. BPF_CALL_2(bpf_perf_event_read, struct bpf_map *, map, u64, flags)
  201. {
  202. struct bpf_array *array = container_of(map, struct bpf_array, map);
  203. unsigned int cpu = smp_processor_id();
  204. u64 index = flags & BPF_F_INDEX_MASK;
  205. struct bpf_event_entry *ee;
  206. u64 value = 0;
  207. int err;
  208. if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
  209. return -EINVAL;
  210. if (index == BPF_F_CURRENT_CPU)
  211. index = cpu;
  212. if (unlikely(index >= array->map.max_entries))
  213. return -E2BIG;
  214. ee = READ_ONCE(array->ptrs[index]);
  215. if (!ee)
  216. return -ENOENT;
  217. err = perf_event_read_local(ee->event, &value);
  218. /*
  219. * this api is ugly since we miss [-22..-2] range of valid
  220. * counter values, but that's uapi
  221. */
  222. if (err)
  223. return err;
  224. return value;
  225. }
  226. static const struct bpf_func_proto bpf_perf_event_read_proto = {
  227. .func = bpf_perf_event_read,
  228. .gpl_only = true,
  229. .ret_type = RET_INTEGER,
  230. .arg1_type = ARG_CONST_MAP_PTR,
  231. .arg2_type = ARG_ANYTHING,
  232. };
  233. static __always_inline u64
  234. __bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map,
  235. u64 flags, struct perf_raw_record *raw)
  236. {
  237. struct bpf_array *array = container_of(map, struct bpf_array, map);
  238. unsigned int cpu = smp_processor_id();
  239. u64 index = flags & BPF_F_INDEX_MASK;
  240. struct perf_sample_data sample_data;
  241. struct bpf_event_entry *ee;
  242. struct perf_event *event;
  243. if (index == BPF_F_CURRENT_CPU)
  244. index = cpu;
  245. if (unlikely(index >= array->map.max_entries))
  246. return -E2BIG;
  247. ee = READ_ONCE(array->ptrs[index]);
  248. if (!ee)
  249. return -ENOENT;
  250. event = ee->event;
  251. if (unlikely(event->attr.type != PERF_TYPE_SOFTWARE ||
  252. event->attr.config != PERF_COUNT_SW_BPF_OUTPUT))
  253. return -EINVAL;
  254. if (unlikely(event->oncpu != cpu))
  255. return -EOPNOTSUPP;
  256. perf_sample_data_init(&sample_data, 0, 0);
  257. sample_data.raw = raw;
  258. perf_event_output(event, &sample_data, regs);
  259. return 0;
  260. }
  261. BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
  262. u64, flags, void *, data, u64, size)
  263. {
  264. struct perf_raw_record raw = {
  265. .frag = {
  266. .size = size,
  267. .data = data,
  268. },
  269. };
  270. if (unlikely(flags & ~(BPF_F_INDEX_MASK)))
  271. return -EINVAL;
  272. return __bpf_perf_event_output(regs, map, flags, &raw);
  273. }
  274. static const struct bpf_func_proto bpf_perf_event_output_proto = {
  275. .func = bpf_perf_event_output,
  276. .gpl_only = true,
  277. .ret_type = RET_INTEGER,
  278. .arg1_type = ARG_PTR_TO_CTX,
  279. .arg2_type = ARG_CONST_MAP_PTR,
  280. .arg3_type = ARG_ANYTHING,
  281. .arg4_type = ARG_PTR_TO_MEM,
  282. .arg5_type = ARG_CONST_SIZE,
  283. };
  284. static DEFINE_PER_CPU(struct pt_regs, bpf_pt_regs);
  285. u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
  286. void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy)
  287. {
  288. struct pt_regs *regs = this_cpu_ptr(&bpf_pt_regs);
  289. struct perf_raw_frag frag = {
  290. .copy = ctx_copy,
  291. .size = ctx_size,
  292. .data = ctx,
  293. };
  294. struct perf_raw_record raw = {
  295. .frag = {
  296. {
  297. .next = ctx_size ? &frag : NULL,
  298. },
  299. .size = meta_size,
  300. .data = meta,
  301. },
  302. };
  303. perf_fetch_caller_regs(regs);
  304. return __bpf_perf_event_output(regs, map, flags, &raw);
  305. }
  306. BPF_CALL_0(bpf_get_current_task)
  307. {
  308. return (long) current;
  309. }
  310. static const struct bpf_func_proto bpf_get_current_task_proto = {
  311. .func = bpf_get_current_task,
  312. .gpl_only = true,
  313. .ret_type = RET_INTEGER,
  314. };
  315. BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)
  316. {
  317. struct bpf_array *array = container_of(map, struct bpf_array, map);
  318. struct cgroup *cgrp;
  319. if (unlikely(in_interrupt()))
  320. return -EINVAL;
  321. if (unlikely(idx >= array->map.max_entries))
  322. return -E2BIG;
  323. cgrp = READ_ONCE(array->ptrs[idx]);
  324. if (unlikely(!cgrp))
  325. return -EAGAIN;
  326. return task_under_cgroup_hierarchy(current, cgrp);
  327. }
  328. static const struct bpf_func_proto bpf_current_task_under_cgroup_proto = {
  329. .func = bpf_current_task_under_cgroup,
  330. .gpl_only = false,
  331. .ret_type = RET_INTEGER,
  332. .arg1_type = ARG_CONST_MAP_PTR,
  333. .arg2_type = ARG_ANYTHING,
  334. };
  335. BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size,
  336. const void *, unsafe_ptr)
  337. {
  338. int ret;
  339. /*
  340. * The strncpy_from_unsafe() call will likely not fill the entire
  341. * buffer, but that's okay in this circumstance as we're probing
  342. * arbitrary memory anyway similar to bpf_probe_read() and might
  343. * as well probe the stack. Thus, memory is explicitly cleared
  344. * only in error case, so that improper users ignoring return
  345. * code altogether don't copy garbage; otherwise length of string
  346. * is returned that can be used for bpf_perf_event_output() et al.
  347. */
  348. ret = strncpy_from_unsafe(dst, unsafe_ptr, size);
  349. if (unlikely(ret < 0))
  350. memset(dst, 0, size);
  351. return ret;
  352. }
  353. static const struct bpf_func_proto bpf_probe_read_str_proto = {
  354. .func = bpf_probe_read_str,
  355. .gpl_only = true,
  356. .ret_type = RET_INTEGER,
  357. .arg1_type = ARG_PTR_TO_UNINIT_MEM,
  358. .arg2_type = ARG_CONST_SIZE,
  359. .arg3_type = ARG_ANYTHING,
  360. };
  361. static const struct bpf_func_proto *tracing_func_proto(enum bpf_func_id func_id)
  362. {
  363. switch (func_id) {
  364. case BPF_FUNC_map_lookup_elem:
  365. return &bpf_map_lookup_elem_proto;
  366. case BPF_FUNC_map_update_elem:
  367. return &bpf_map_update_elem_proto;
  368. case BPF_FUNC_map_delete_elem:
  369. return &bpf_map_delete_elem_proto;
  370. case BPF_FUNC_probe_read:
  371. return &bpf_probe_read_proto;
  372. case BPF_FUNC_ktime_get_ns:
  373. return &bpf_ktime_get_ns_proto;
  374. case BPF_FUNC_tail_call:
  375. return &bpf_tail_call_proto;
  376. case BPF_FUNC_get_current_pid_tgid:
  377. return &bpf_get_current_pid_tgid_proto;
  378. case BPF_FUNC_get_current_task:
  379. return &bpf_get_current_task_proto;
  380. case BPF_FUNC_get_current_uid_gid:
  381. return &bpf_get_current_uid_gid_proto;
  382. case BPF_FUNC_get_current_comm:
  383. return &bpf_get_current_comm_proto;
  384. case BPF_FUNC_trace_printk:
  385. return bpf_get_trace_printk_proto();
  386. case BPF_FUNC_get_smp_processor_id:
  387. return &bpf_get_smp_processor_id_proto;
  388. case BPF_FUNC_get_numa_node_id:
  389. return &bpf_get_numa_node_id_proto;
  390. case BPF_FUNC_perf_event_read:
  391. return &bpf_perf_event_read_proto;
  392. case BPF_FUNC_probe_write_user:
  393. return bpf_get_probe_write_proto();
  394. case BPF_FUNC_current_task_under_cgroup:
  395. return &bpf_current_task_under_cgroup_proto;
  396. case BPF_FUNC_get_prandom_u32:
  397. return &bpf_get_prandom_u32_proto;
  398. case BPF_FUNC_probe_read_str:
  399. return &bpf_probe_read_str_proto;
  400. default:
  401. return NULL;
  402. }
  403. }
  404. static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func_id)
  405. {
  406. switch (func_id) {
  407. case BPF_FUNC_perf_event_output:
  408. return &bpf_perf_event_output_proto;
  409. case BPF_FUNC_get_stackid:
  410. return &bpf_get_stackid_proto;
  411. default:
  412. return tracing_func_proto(func_id);
  413. }
  414. }
  415. /* bpf+kprobe programs can access fields of 'struct pt_regs' */
  416. static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
  417. enum bpf_reg_type *reg_type)
  418. {
  419. if (off < 0 || off >= sizeof(struct pt_regs))
  420. return false;
  421. if (type != BPF_READ)
  422. return false;
  423. if (off % size != 0)
  424. return false;
  425. /*
  426. * Assertion for 32 bit to make sure last 8 byte access
  427. * (BPF_DW) to the last 4 byte member is disallowed.
  428. */
  429. if (off + size > sizeof(struct pt_regs))
  430. return false;
  431. return true;
  432. }
  433. const struct bpf_verifier_ops kprobe_prog_ops = {
  434. .get_func_proto = kprobe_prog_func_proto,
  435. .is_valid_access = kprobe_prog_is_valid_access,
  436. };
  437. BPF_CALL_5(bpf_perf_event_output_tp, void *, tp_buff, struct bpf_map *, map,
  438. u64, flags, void *, data, u64, size)
  439. {
  440. struct pt_regs *regs = *(struct pt_regs **)tp_buff;
  441. /*
  442. * r1 points to perf tracepoint buffer where first 8 bytes are hidden
  443. * from bpf program and contain a pointer to 'struct pt_regs'. Fetch it
  444. * from there and call the same bpf_perf_event_output() helper inline.
  445. */
  446. return ____bpf_perf_event_output(regs, map, flags, data, size);
  447. }
  448. static const struct bpf_func_proto bpf_perf_event_output_proto_tp = {
  449. .func = bpf_perf_event_output_tp,
  450. .gpl_only = true,
  451. .ret_type = RET_INTEGER,
  452. .arg1_type = ARG_PTR_TO_CTX,
  453. .arg2_type = ARG_CONST_MAP_PTR,
  454. .arg3_type = ARG_ANYTHING,
  455. .arg4_type = ARG_PTR_TO_MEM,
  456. .arg5_type = ARG_CONST_SIZE,
  457. };
  458. BPF_CALL_3(bpf_get_stackid_tp, void *, tp_buff, struct bpf_map *, map,
  459. u64, flags)
  460. {
  461. struct pt_regs *regs = *(struct pt_regs **)tp_buff;
  462. /*
  463. * Same comment as in bpf_perf_event_output_tp(), only that this time
  464. * the other helper's function body cannot be inlined due to being
  465. * external, thus we need to call raw helper function.
  466. */
  467. return bpf_get_stackid((unsigned long) regs, (unsigned long) map,
  468. flags, 0, 0);
  469. }
  470. static const struct bpf_func_proto bpf_get_stackid_proto_tp = {
  471. .func = bpf_get_stackid_tp,
  472. .gpl_only = true,
  473. .ret_type = RET_INTEGER,
  474. .arg1_type = ARG_PTR_TO_CTX,
  475. .arg2_type = ARG_CONST_MAP_PTR,
  476. .arg3_type = ARG_ANYTHING,
  477. };
  478. static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)
  479. {
  480. switch (func_id) {
  481. case BPF_FUNC_perf_event_output:
  482. return &bpf_perf_event_output_proto_tp;
  483. case BPF_FUNC_get_stackid:
  484. return &bpf_get_stackid_proto_tp;
  485. default:
  486. return tracing_func_proto(func_id);
  487. }
  488. }
  489. static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
  490. enum bpf_reg_type *reg_type)
  491. {
  492. if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
  493. return false;
  494. if (type != BPF_READ)
  495. return false;
  496. if (off % size != 0)
  497. return false;
  498. BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(__u64));
  499. return true;
  500. }
  501. const struct bpf_verifier_ops tracepoint_prog_ops = {
  502. .get_func_proto = tp_prog_func_proto,
  503. .is_valid_access = tp_prog_is_valid_access,
  504. };
  505. static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
  506. enum bpf_reg_type *reg_type)
  507. {
  508. if (off < 0 || off >= sizeof(struct bpf_perf_event_data))
  509. return false;
  510. if (type != BPF_READ)
  511. return false;
  512. if (off % size != 0)
  513. return false;
  514. if (off == offsetof(struct bpf_perf_event_data, sample_period)) {
  515. if (size != sizeof(u64))
  516. return false;
  517. } else {
  518. if (size != sizeof(long))
  519. return false;
  520. }
  521. return true;
  522. }
  523. static u32 pe_prog_convert_ctx_access(enum bpf_access_type type,
  524. const struct bpf_insn *si,
  525. struct bpf_insn *insn_buf,
  526. struct bpf_prog *prog)
  527. {
  528. struct bpf_insn *insn = insn_buf;
  529. switch (si->off) {
  530. case offsetof(struct bpf_perf_event_data, sample_period):
  531. BUILD_BUG_ON(FIELD_SIZEOF(struct perf_sample_data, period) != sizeof(u64));
  532. *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
  533. data), si->dst_reg, si->src_reg,
  534. offsetof(struct bpf_perf_event_data_kern, data));
  535. *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg,
  536. offsetof(struct perf_sample_data, period));
  537. break;
  538. default:
  539. *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_perf_event_data_kern,
  540. regs), si->dst_reg, si->src_reg,
  541. offsetof(struct bpf_perf_event_data_kern, regs));
  542. *insn++ = BPF_LDX_MEM(BPF_SIZEOF(long), si->dst_reg, si->dst_reg,
  543. si->off);
  544. break;
  545. }
  546. return insn - insn_buf;
  547. }
  548. const struct bpf_verifier_ops perf_event_prog_ops = {
  549. .get_func_proto = tp_prog_func_proto,
  550. .is_valid_access = pe_prog_is_valid_access,
  551. .convert_ctx_access = pe_prog_convert_ctx_access,
  552. };