bpf_jit_comp64.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. /*
  2. * bpf_jit_comp64.c: eBPF JIT compiler
  3. *
  4. * Copyright 2016 Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
  5. * IBM Corporation
  6. *
  7. * Based on the powerpc classic BPF JIT compiler by Matt Evans
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; version 2
  12. * of the License.
  13. */
  14. #include <linux/moduleloader.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/asm-compat.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/filter.h>
  19. #include <linux/if_vlan.h>
  20. #include <asm/kprobes.h>
  21. #include <linux/bpf.h>
  22. #include "bpf_jit64.h"
  23. static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
  24. {
  25. memset32(area, BREAKPOINT_INSTRUCTION, size/4);
  26. }
  27. static inline void bpf_flush_icache(void *start, void *end)
  28. {
  29. smp_wmb();
  30. flush_icache_range((unsigned long)start, (unsigned long)end);
  31. }
  32. static inline bool bpf_is_seen_register(struct codegen_context *ctx, int i)
  33. {
  34. return (ctx->seen & (1 << (31 - b2p[i])));
  35. }
  36. static inline void bpf_set_seen_register(struct codegen_context *ctx, int i)
  37. {
  38. ctx->seen |= (1 << (31 - b2p[i]));
  39. }
  40. static inline bool bpf_has_stack_frame(struct codegen_context *ctx)
  41. {
  42. /*
  43. * We only need a stack frame if:
  44. * - we call other functions (kernel helpers), or
  45. * - the bpf program uses its stack area
  46. * The latter condition is deduced from the usage of BPF_REG_FP
  47. */
  48. return ctx->seen & SEEN_FUNC || bpf_is_seen_register(ctx, BPF_REG_FP);
  49. }
  50. /*
  51. * When not setting up our own stackframe, the redzone usage is:
  52. *
  53. * [ prev sp ] <-------------
  54. * [ ... ] |
  55. * sp (r1) ---> [ stack pointer ] --------------
  56. * [ nv gpr save area ] 6*8
  57. * [ tail_call_cnt ] 8
  58. * [ local_tmp_var ] 8
  59. * [ unused red zone ] 208 bytes protected
  60. */
  61. static int bpf_jit_stack_local(struct codegen_context *ctx)
  62. {
  63. if (bpf_has_stack_frame(ctx))
  64. return STACK_FRAME_MIN_SIZE + ctx->stack_size;
  65. else
  66. return -(BPF_PPC_STACK_SAVE + 16);
  67. }
  68. static int bpf_jit_stack_tailcallcnt(struct codegen_context *ctx)
  69. {
  70. return bpf_jit_stack_local(ctx) + 8;
  71. }
  72. static int bpf_jit_stack_offsetof(struct codegen_context *ctx, int reg)
  73. {
  74. if (reg >= BPF_PPC_NVR_MIN && reg < 32)
  75. return (bpf_has_stack_frame(ctx) ?
  76. (BPF_PPC_STACKFRAME + ctx->stack_size) : 0)
  77. - (8 * (32 - reg));
  78. pr_err("BPF JIT is asking about unknown registers");
  79. BUG();
  80. }
  81. static void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx)
  82. {
  83. int i;
  84. /*
  85. * Initialize tail_call_cnt if we do tail calls.
  86. * Otherwise, put in NOPs so that it can be skipped when we are
  87. * invoked through a tail call.
  88. */
  89. if (ctx->seen & SEEN_TAILCALL) {
  90. PPC_LI(b2p[TMP_REG_1], 0);
  91. /* this goes in the redzone */
  92. PPC_BPF_STL(b2p[TMP_REG_1], 1, -(BPF_PPC_STACK_SAVE + 8));
  93. } else {
  94. PPC_NOP();
  95. PPC_NOP();
  96. }
  97. #define BPF_TAILCALL_PROLOGUE_SIZE 8
  98. if (bpf_has_stack_frame(ctx)) {
  99. /*
  100. * We need a stack frame, but we don't necessarily need to
  101. * save/restore LR unless we call other functions
  102. */
  103. if (ctx->seen & SEEN_FUNC) {
  104. EMIT(PPC_INST_MFLR | __PPC_RT(R0));
  105. PPC_BPF_STL(0, 1, PPC_LR_STKOFF);
  106. }
  107. PPC_BPF_STLU(1, 1, -(BPF_PPC_STACKFRAME + ctx->stack_size));
  108. }
  109. /*
  110. * Back up non-volatile regs -- BPF registers 6-10
  111. * If we haven't created our own stack frame, we save these
  112. * in the protected zone below the previous stack frame
  113. */
  114. for (i = BPF_REG_6; i <= BPF_REG_10; i++)
  115. if (bpf_is_seen_register(ctx, i))
  116. PPC_BPF_STL(b2p[i], 1, bpf_jit_stack_offsetof(ctx, b2p[i]));
  117. /* Setup frame pointer to point to the bpf stack area */
  118. if (bpf_is_seen_register(ctx, BPF_REG_FP))
  119. PPC_ADDI(b2p[BPF_REG_FP], 1,
  120. STACK_FRAME_MIN_SIZE + ctx->stack_size);
  121. }
  122. static void bpf_jit_emit_common_epilogue(u32 *image, struct codegen_context *ctx)
  123. {
  124. int i;
  125. /* Restore NVRs */
  126. for (i = BPF_REG_6; i <= BPF_REG_10; i++)
  127. if (bpf_is_seen_register(ctx, i))
  128. PPC_BPF_LL(b2p[i], 1, bpf_jit_stack_offsetof(ctx, b2p[i]));
  129. /* Tear down our stack frame */
  130. if (bpf_has_stack_frame(ctx)) {
  131. PPC_ADDI(1, 1, BPF_PPC_STACKFRAME + ctx->stack_size);
  132. if (ctx->seen & SEEN_FUNC) {
  133. PPC_BPF_LL(0, 1, PPC_LR_STKOFF);
  134. PPC_MTLR(0);
  135. }
  136. }
  137. }
  138. static void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx)
  139. {
  140. bpf_jit_emit_common_epilogue(image, ctx);
  141. /* Move result to r3 */
  142. PPC_MR(3, b2p[BPF_REG_0]);
  143. PPC_BLR();
  144. }
  145. static void bpf_jit_emit_func_call(u32 *image, struct codegen_context *ctx, u64 func)
  146. {
  147. unsigned int i, ctx_idx = ctx->idx;
  148. /* Load function address into r12 */
  149. PPC_LI64(12, func);
  150. /* For bpf-to-bpf function calls, the callee's address is unknown
  151. * until the last extra pass. As seen above, we use PPC_LI64() to
  152. * load the callee's address, but this may optimize the number of
  153. * instructions required based on the nature of the address.
  154. *
  155. * Since we don't want the number of instructions emitted to change,
  156. * we pad the optimized PPC_LI64() call with NOPs to guarantee that
  157. * we always have a five-instruction sequence, which is the maximum
  158. * that PPC_LI64() can emit.
  159. */
  160. for (i = ctx->idx - ctx_idx; i < 5; i++)
  161. PPC_NOP();
  162. #ifdef PPC64_ELF_ABI_v1
  163. /*
  164. * Load TOC from function descriptor at offset 8.
  165. * We can clobber r2 since we get called through a
  166. * function pointer (so caller will save/restore r2)
  167. * and since we don't use a TOC ourself.
  168. */
  169. PPC_BPF_LL(2, 12, 8);
  170. /* Load actual entry point from function descriptor */
  171. PPC_BPF_LL(12, 12, 0);
  172. #endif
  173. PPC_MTLR(12);
  174. PPC_BLRL();
  175. }
  176. static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 out)
  177. {
  178. /*
  179. * By now, the eBPF program has already setup parameters in r3, r4 and r5
  180. * r3/BPF_REG_1 - pointer to ctx -- passed as is to the next bpf program
  181. * r4/BPF_REG_2 - pointer to bpf_array
  182. * r5/BPF_REG_3 - index in bpf_array
  183. */
  184. int b2p_bpf_array = b2p[BPF_REG_2];
  185. int b2p_index = b2p[BPF_REG_3];
  186. /*
  187. * if (index >= array->map.max_entries)
  188. * goto out;
  189. */
  190. PPC_LWZ(b2p[TMP_REG_1], b2p_bpf_array, offsetof(struct bpf_array, map.max_entries));
  191. PPC_RLWINM(b2p_index, b2p_index, 0, 0, 31);
  192. PPC_CMPLW(b2p_index, b2p[TMP_REG_1]);
  193. PPC_BCC(COND_GE, out);
  194. /*
  195. * if (tail_call_cnt > MAX_TAIL_CALL_CNT)
  196. * goto out;
  197. */
  198. PPC_BPF_LL(b2p[TMP_REG_1], 1, bpf_jit_stack_tailcallcnt(ctx));
  199. PPC_CMPLWI(b2p[TMP_REG_1], MAX_TAIL_CALL_CNT);
  200. PPC_BCC(COND_GT, out);
  201. /*
  202. * tail_call_cnt++;
  203. */
  204. PPC_ADDI(b2p[TMP_REG_1], b2p[TMP_REG_1], 1);
  205. PPC_BPF_STL(b2p[TMP_REG_1], 1, bpf_jit_stack_tailcallcnt(ctx));
  206. /* prog = array->ptrs[index]; */
  207. PPC_MULI(b2p[TMP_REG_1], b2p_index, 8);
  208. PPC_ADD(b2p[TMP_REG_1], b2p[TMP_REG_1], b2p_bpf_array);
  209. PPC_BPF_LL(b2p[TMP_REG_1], b2p[TMP_REG_1], offsetof(struct bpf_array, ptrs));
  210. /*
  211. * if (prog == NULL)
  212. * goto out;
  213. */
  214. PPC_CMPLDI(b2p[TMP_REG_1], 0);
  215. PPC_BCC(COND_EQ, out);
  216. /* goto *(prog->bpf_func + prologue_size); */
  217. PPC_BPF_LL(b2p[TMP_REG_1], b2p[TMP_REG_1], offsetof(struct bpf_prog, bpf_func));
  218. #ifdef PPC64_ELF_ABI_v1
  219. /* skip past the function descriptor */
  220. PPC_ADDI(b2p[TMP_REG_1], b2p[TMP_REG_1],
  221. FUNCTION_DESCR_SIZE + BPF_TAILCALL_PROLOGUE_SIZE);
  222. #else
  223. PPC_ADDI(b2p[TMP_REG_1], b2p[TMP_REG_1], BPF_TAILCALL_PROLOGUE_SIZE);
  224. #endif
  225. PPC_MTCTR(b2p[TMP_REG_1]);
  226. /* tear down stack, restore NVRs, ... */
  227. bpf_jit_emit_common_epilogue(image, ctx);
  228. PPC_BCTR();
  229. /* out: */
  230. }
  231. /* Assemble the body code between the prologue & epilogue */
  232. static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
  233. struct codegen_context *ctx,
  234. u32 *addrs, bool extra_pass)
  235. {
  236. const struct bpf_insn *insn = fp->insnsi;
  237. int flen = fp->len;
  238. int i;
  239. /* Start of epilogue code - will only be valid 2nd pass onwards */
  240. u32 exit_addr = addrs[flen];
  241. for (i = 0; i < flen; i++) {
  242. u32 code = insn[i].code;
  243. u32 dst_reg = b2p[insn[i].dst_reg];
  244. u32 src_reg = b2p[insn[i].src_reg];
  245. s16 off = insn[i].off;
  246. s32 imm = insn[i].imm;
  247. u64 imm64;
  248. u8 *func;
  249. u32 true_cond;
  250. u32 tmp_idx;
  251. /*
  252. * addrs[] maps a BPF bytecode address into a real offset from
  253. * the start of the body code.
  254. */
  255. addrs[i] = ctx->idx * 4;
  256. /*
  257. * As an optimization, we note down which non-volatile registers
  258. * are used so that we can only save/restore those in our
  259. * prologue and epilogue. We do this here regardless of whether
  260. * the actual BPF instruction uses src/dst registers or not
  261. * (for instance, BPF_CALL does not use them). The expectation
  262. * is that those instructions will have src_reg/dst_reg set to
  263. * 0. Even otherwise, we just lose some prologue/epilogue
  264. * optimization but everything else should work without
  265. * any issues.
  266. */
  267. if (dst_reg >= BPF_PPC_NVR_MIN && dst_reg < 32)
  268. bpf_set_seen_register(ctx, insn[i].dst_reg);
  269. if (src_reg >= BPF_PPC_NVR_MIN && src_reg < 32)
  270. bpf_set_seen_register(ctx, insn[i].src_reg);
  271. switch (code) {
  272. /*
  273. * Arithmetic operations: ADD/SUB/MUL/DIV/MOD/NEG
  274. */
  275. case BPF_ALU | BPF_ADD | BPF_X: /* (u32) dst += (u32) src */
  276. case BPF_ALU64 | BPF_ADD | BPF_X: /* dst += src */
  277. PPC_ADD(dst_reg, dst_reg, src_reg);
  278. goto bpf_alu32_trunc;
  279. case BPF_ALU | BPF_SUB | BPF_X: /* (u32) dst -= (u32) src */
  280. case BPF_ALU64 | BPF_SUB | BPF_X: /* dst -= src */
  281. PPC_SUB(dst_reg, dst_reg, src_reg);
  282. goto bpf_alu32_trunc;
  283. case BPF_ALU | BPF_ADD | BPF_K: /* (u32) dst += (u32) imm */
  284. case BPF_ALU | BPF_SUB | BPF_K: /* (u32) dst -= (u32) imm */
  285. case BPF_ALU64 | BPF_ADD | BPF_K: /* dst += imm */
  286. case BPF_ALU64 | BPF_SUB | BPF_K: /* dst -= imm */
  287. if (BPF_OP(code) == BPF_SUB)
  288. imm = -imm;
  289. if (imm) {
  290. if (imm >= -32768 && imm < 32768)
  291. PPC_ADDI(dst_reg, dst_reg, IMM_L(imm));
  292. else {
  293. PPC_LI32(b2p[TMP_REG_1], imm);
  294. PPC_ADD(dst_reg, dst_reg, b2p[TMP_REG_1]);
  295. }
  296. }
  297. goto bpf_alu32_trunc;
  298. case BPF_ALU | BPF_MUL | BPF_X: /* (u32) dst *= (u32) src */
  299. case BPF_ALU64 | BPF_MUL | BPF_X: /* dst *= src */
  300. if (BPF_CLASS(code) == BPF_ALU)
  301. PPC_MULW(dst_reg, dst_reg, src_reg);
  302. else
  303. PPC_MULD(dst_reg, dst_reg, src_reg);
  304. goto bpf_alu32_trunc;
  305. case BPF_ALU | BPF_MUL | BPF_K: /* (u32) dst *= (u32) imm */
  306. case BPF_ALU64 | BPF_MUL | BPF_K: /* dst *= imm */
  307. if (imm >= -32768 && imm < 32768)
  308. PPC_MULI(dst_reg, dst_reg, IMM_L(imm));
  309. else {
  310. PPC_LI32(b2p[TMP_REG_1], imm);
  311. if (BPF_CLASS(code) == BPF_ALU)
  312. PPC_MULW(dst_reg, dst_reg,
  313. b2p[TMP_REG_1]);
  314. else
  315. PPC_MULD(dst_reg, dst_reg,
  316. b2p[TMP_REG_1]);
  317. }
  318. goto bpf_alu32_trunc;
  319. case BPF_ALU | BPF_DIV | BPF_X: /* (u32) dst /= (u32) src */
  320. case BPF_ALU | BPF_MOD | BPF_X: /* (u32) dst %= (u32) src */
  321. if (BPF_OP(code) == BPF_MOD) {
  322. PPC_DIVWU(b2p[TMP_REG_1], dst_reg, src_reg);
  323. PPC_MULW(b2p[TMP_REG_1], src_reg,
  324. b2p[TMP_REG_1]);
  325. PPC_SUB(dst_reg, dst_reg, b2p[TMP_REG_1]);
  326. } else
  327. PPC_DIVWU(dst_reg, dst_reg, src_reg);
  328. goto bpf_alu32_trunc;
  329. case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */
  330. case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */
  331. if (BPF_OP(code) == BPF_MOD) {
  332. PPC_DIVDU(b2p[TMP_REG_1], dst_reg, src_reg);
  333. PPC_MULD(b2p[TMP_REG_1], src_reg,
  334. b2p[TMP_REG_1]);
  335. PPC_SUB(dst_reg, dst_reg, b2p[TMP_REG_1]);
  336. } else
  337. PPC_DIVDU(dst_reg, dst_reg, src_reg);
  338. break;
  339. case BPF_ALU | BPF_MOD | BPF_K: /* (u32) dst %= (u32) imm */
  340. case BPF_ALU | BPF_DIV | BPF_K: /* (u32) dst /= (u32) imm */
  341. case BPF_ALU64 | BPF_MOD | BPF_K: /* dst %= imm */
  342. case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */
  343. if (imm == 0)
  344. return -EINVAL;
  345. else if (imm == 1)
  346. goto bpf_alu32_trunc;
  347. PPC_LI32(b2p[TMP_REG_1], imm);
  348. switch (BPF_CLASS(code)) {
  349. case BPF_ALU:
  350. if (BPF_OP(code) == BPF_MOD) {
  351. PPC_DIVWU(b2p[TMP_REG_2], dst_reg,
  352. b2p[TMP_REG_1]);
  353. PPC_MULW(b2p[TMP_REG_1],
  354. b2p[TMP_REG_1],
  355. b2p[TMP_REG_2]);
  356. PPC_SUB(dst_reg, dst_reg,
  357. b2p[TMP_REG_1]);
  358. } else
  359. PPC_DIVWU(dst_reg, dst_reg,
  360. b2p[TMP_REG_1]);
  361. break;
  362. case BPF_ALU64:
  363. if (BPF_OP(code) == BPF_MOD) {
  364. PPC_DIVDU(b2p[TMP_REG_2], dst_reg,
  365. b2p[TMP_REG_1]);
  366. PPC_MULD(b2p[TMP_REG_1],
  367. b2p[TMP_REG_1],
  368. b2p[TMP_REG_2]);
  369. PPC_SUB(dst_reg, dst_reg,
  370. b2p[TMP_REG_1]);
  371. } else
  372. PPC_DIVDU(dst_reg, dst_reg,
  373. b2p[TMP_REG_1]);
  374. break;
  375. }
  376. goto bpf_alu32_trunc;
  377. case BPF_ALU | BPF_NEG: /* (u32) dst = -dst */
  378. case BPF_ALU64 | BPF_NEG: /* dst = -dst */
  379. PPC_NEG(dst_reg, dst_reg);
  380. goto bpf_alu32_trunc;
  381. /*
  382. * Logical operations: AND/OR/XOR/[A]LSH/[A]RSH
  383. */
  384. case BPF_ALU | BPF_AND | BPF_X: /* (u32) dst = dst & src */
  385. case BPF_ALU64 | BPF_AND | BPF_X: /* dst = dst & src */
  386. PPC_AND(dst_reg, dst_reg, src_reg);
  387. goto bpf_alu32_trunc;
  388. case BPF_ALU | BPF_AND | BPF_K: /* (u32) dst = dst & imm */
  389. case BPF_ALU64 | BPF_AND | BPF_K: /* dst = dst & imm */
  390. if (!IMM_H(imm))
  391. PPC_ANDI(dst_reg, dst_reg, IMM_L(imm));
  392. else {
  393. /* Sign-extended */
  394. PPC_LI32(b2p[TMP_REG_1], imm);
  395. PPC_AND(dst_reg, dst_reg, b2p[TMP_REG_1]);
  396. }
  397. goto bpf_alu32_trunc;
  398. case BPF_ALU | BPF_OR | BPF_X: /* dst = (u32) dst | (u32) src */
  399. case BPF_ALU64 | BPF_OR | BPF_X: /* dst = dst | src */
  400. PPC_OR(dst_reg, dst_reg, src_reg);
  401. goto bpf_alu32_trunc;
  402. case BPF_ALU | BPF_OR | BPF_K:/* dst = (u32) dst | (u32) imm */
  403. case BPF_ALU64 | BPF_OR | BPF_K:/* dst = dst | imm */
  404. if (imm < 0 && BPF_CLASS(code) == BPF_ALU64) {
  405. /* Sign-extended */
  406. PPC_LI32(b2p[TMP_REG_1], imm);
  407. PPC_OR(dst_reg, dst_reg, b2p[TMP_REG_1]);
  408. } else {
  409. if (IMM_L(imm))
  410. PPC_ORI(dst_reg, dst_reg, IMM_L(imm));
  411. if (IMM_H(imm))
  412. PPC_ORIS(dst_reg, dst_reg, IMM_H(imm));
  413. }
  414. goto bpf_alu32_trunc;
  415. case BPF_ALU | BPF_XOR | BPF_X: /* (u32) dst ^= src */
  416. case BPF_ALU64 | BPF_XOR | BPF_X: /* dst ^= src */
  417. PPC_XOR(dst_reg, dst_reg, src_reg);
  418. goto bpf_alu32_trunc;
  419. case BPF_ALU | BPF_XOR | BPF_K: /* (u32) dst ^= (u32) imm */
  420. case BPF_ALU64 | BPF_XOR | BPF_K: /* dst ^= imm */
  421. if (imm < 0 && BPF_CLASS(code) == BPF_ALU64) {
  422. /* Sign-extended */
  423. PPC_LI32(b2p[TMP_REG_1], imm);
  424. PPC_XOR(dst_reg, dst_reg, b2p[TMP_REG_1]);
  425. } else {
  426. if (IMM_L(imm))
  427. PPC_XORI(dst_reg, dst_reg, IMM_L(imm));
  428. if (IMM_H(imm))
  429. PPC_XORIS(dst_reg, dst_reg, IMM_H(imm));
  430. }
  431. goto bpf_alu32_trunc;
  432. case BPF_ALU | BPF_LSH | BPF_X: /* (u32) dst <<= (u32) src */
  433. /* slw clears top 32 bits */
  434. PPC_SLW(dst_reg, dst_reg, src_reg);
  435. break;
  436. case BPF_ALU64 | BPF_LSH | BPF_X: /* dst <<= src; */
  437. PPC_SLD(dst_reg, dst_reg, src_reg);
  438. break;
  439. case BPF_ALU | BPF_LSH | BPF_K: /* (u32) dst <<== (u32) imm */
  440. /* with imm 0, we still need to clear top 32 bits */
  441. PPC_SLWI(dst_reg, dst_reg, imm);
  442. break;
  443. case BPF_ALU64 | BPF_LSH | BPF_K: /* dst <<== imm */
  444. if (imm != 0)
  445. PPC_SLDI(dst_reg, dst_reg, imm);
  446. break;
  447. case BPF_ALU | BPF_RSH | BPF_X: /* (u32) dst >>= (u32) src */
  448. PPC_SRW(dst_reg, dst_reg, src_reg);
  449. break;
  450. case BPF_ALU64 | BPF_RSH | BPF_X: /* dst >>= src */
  451. PPC_SRD(dst_reg, dst_reg, src_reg);
  452. break;
  453. case BPF_ALU | BPF_RSH | BPF_K: /* (u32) dst >>= (u32) imm */
  454. PPC_SRWI(dst_reg, dst_reg, imm);
  455. break;
  456. case BPF_ALU64 | BPF_RSH | BPF_K: /* dst >>= imm */
  457. if (imm != 0)
  458. PPC_SRDI(dst_reg, dst_reg, imm);
  459. break;
  460. case BPF_ALU64 | BPF_ARSH | BPF_X: /* (s64) dst >>= src */
  461. PPC_SRAD(dst_reg, dst_reg, src_reg);
  462. break;
  463. case BPF_ALU64 | BPF_ARSH | BPF_K: /* (s64) dst >>= imm */
  464. if (imm != 0)
  465. PPC_SRADI(dst_reg, dst_reg, imm);
  466. break;
  467. /*
  468. * MOV
  469. */
  470. case BPF_ALU | BPF_MOV | BPF_X: /* (u32) dst = src */
  471. case BPF_ALU64 | BPF_MOV | BPF_X: /* dst = src */
  472. PPC_MR(dst_reg, src_reg);
  473. goto bpf_alu32_trunc;
  474. case BPF_ALU | BPF_MOV | BPF_K: /* (u32) dst = imm */
  475. case BPF_ALU64 | BPF_MOV | BPF_K: /* dst = (s64) imm */
  476. PPC_LI32(dst_reg, imm);
  477. if (imm < 0)
  478. goto bpf_alu32_trunc;
  479. break;
  480. bpf_alu32_trunc:
  481. /* Truncate to 32-bits */
  482. if (BPF_CLASS(code) == BPF_ALU)
  483. PPC_RLWINM(dst_reg, dst_reg, 0, 0, 31);
  484. break;
  485. /*
  486. * BPF_FROM_BE/LE
  487. */
  488. case BPF_ALU | BPF_END | BPF_FROM_LE:
  489. case BPF_ALU | BPF_END | BPF_FROM_BE:
  490. #ifdef __BIG_ENDIAN__
  491. if (BPF_SRC(code) == BPF_FROM_BE)
  492. goto emit_clear;
  493. #else /* !__BIG_ENDIAN__ */
  494. if (BPF_SRC(code) == BPF_FROM_LE)
  495. goto emit_clear;
  496. #endif
  497. switch (imm) {
  498. case 16:
  499. /* Rotate 8 bits left & mask with 0x0000ff00 */
  500. PPC_RLWINM(b2p[TMP_REG_1], dst_reg, 8, 16, 23);
  501. /* Rotate 8 bits right & insert LSB to reg */
  502. PPC_RLWIMI(b2p[TMP_REG_1], dst_reg, 24, 24, 31);
  503. /* Move result back to dst_reg */
  504. PPC_MR(dst_reg, b2p[TMP_REG_1]);
  505. break;
  506. case 32:
  507. /*
  508. * Rotate word left by 8 bits:
  509. * 2 bytes are already in their final position
  510. * -- byte 2 and 4 (of bytes 1, 2, 3 and 4)
  511. */
  512. PPC_RLWINM(b2p[TMP_REG_1], dst_reg, 8, 0, 31);
  513. /* Rotate 24 bits and insert byte 1 */
  514. PPC_RLWIMI(b2p[TMP_REG_1], dst_reg, 24, 0, 7);
  515. /* Rotate 24 bits and insert byte 3 */
  516. PPC_RLWIMI(b2p[TMP_REG_1], dst_reg, 24, 16, 23);
  517. PPC_MR(dst_reg, b2p[TMP_REG_1]);
  518. break;
  519. case 64:
  520. /*
  521. * Way easier and faster(?) to store the value
  522. * into stack and then use ldbrx
  523. *
  524. * ctx->seen will be reliable in pass2, but
  525. * the instructions generated will remain the
  526. * same across all passes
  527. */
  528. PPC_BPF_STL(dst_reg, 1, bpf_jit_stack_local(ctx));
  529. PPC_ADDI(b2p[TMP_REG_1], 1, bpf_jit_stack_local(ctx));
  530. PPC_LDBRX(dst_reg, 0, b2p[TMP_REG_1]);
  531. break;
  532. }
  533. break;
  534. emit_clear:
  535. switch (imm) {
  536. case 16:
  537. /* zero-extend 16 bits into 64 bits */
  538. PPC_RLDICL(dst_reg, dst_reg, 0, 48);
  539. break;
  540. case 32:
  541. /* zero-extend 32 bits into 64 bits */
  542. PPC_RLDICL(dst_reg, dst_reg, 0, 32);
  543. break;
  544. case 64:
  545. /* nop */
  546. break;
  547. }
  548. break;
  549. /*
  550. * BPF_ST(X)
  551. */
  552. case BPF_STX | BPF_MEM | BPF_B: /* *(u8 *)(dst + off) = src */
  553. case BPF_ST | BPF_MEM | BPF_B: /* *(u8 *)(dst + off) = imm */
  554. if (BPF_CLASS(code) == BPF_ST) {
  555. PPC_LI(b2p[TMP_REG_1], imm);
  556. src_reg = b2p[TMP_REG_1];
  557. }
  558. PPC_STB(src_reg, dst_reg, off);
  559. break;
  560. case BPF_STX | BPF_MEM | BPF_H: /* (u16 *)(dst + off) = src */
  561. case BPF_ST | BPF_MEM | BPF_H: /* (u16 *)(dst + off) = imm */
  562. if (BPF_CLASS(code) == BPF_ST) {
  563. PPC_LI(b2p[TMP_REG_1], imm);
  564. src_reg = b2p[TMP_REG_1];
  565. }
  566. PPC_STH(src_reg, dst_reg, off);
  567. break;
  568. case BPF_STX | BPF_MEM | BPF_W: /* *(u32 *)(dst + off) = src */
  569. case BPF_ST | BPF_MEM | BPF_W: /* *(u32 *)(dst + off) = imm */
  570. if (BPF_CLASS(code) == BPF_ST) {
  571. PPC_LI32(b2p[TMP_REG_1], imm);
  572. src_reg = b2p[TMP_REG_1];
  573. }
  574. PPC_STW(src_reg, dst_reg, off);
  575. break;
  576. case BPF_STX | BPF_MEM | BPF_DW: /* (u64 *)(dst + off) = src */
  577. case BPF_ST | BPF_MEM | BPF_DW: /* *(u64 *)(dst + off) = imm */
  578. if (BPF_CLASS(code) == BPF_ST) {
  579. PPC_LI32(b2p[TMP_REG_1], imm);
  580. src_reg = b2p[TMP_REG_1];
  581. }
  582. PPC_BPF_STL(src_reg, dst_reg, off);
  583. break;
  584. /*
  585. * BPF_STX XADD (atomic_add)
  586. */
  587. /* *(u32 *)(dst + off) += src */
  588. case BPF_STX | BPF_XADD | BPF_W:
  589. /* Get EA into TMP_REG_1 */
  590. PPC_ADDI(b2p[TMP_REG_1], dst_reg, off);
  591. tmp_idx = ctx->idx * 4;
  592. /* load value from memory into TMP_REG_2 */
  593. PPC_BPF_LWARX(b2p[TMP_REG_2], 0, b2p[TMP_REG_1], 0);
  594. /* add value from src_reg into this */
  595. PPC_ADD(b2p[TMP_REG_2], b2p[TMP_REG_2], src_reg);
  596. /* store result back */
  597. PPC_BPF_STWCX(b2p[TMP_REG_2], 0, b2p[TMP_REG_1]);
  598. /* we're done if this succeeded */
  599. PPC_BCC_SHORT(COND_NE, tmp_idx);
  600. break;
  601. /* *(u64 *)(dst + off) += src */
  602. case BPF_STX | BPF_XADD | BPF_DW:
  603. PPC_ADDI(b2p[TMP_REG_1], dst_reg, off);
  604. tmp_idx = ctx->idx * 4;
  605. PPC_BPF_LDARX(b2p[TMP_REG_2], 0, b2p[TMP_REG_1], 0);
  606. PPC_ADD(b2p[TMP_REG_2], b2p[TMP_REG_2], src_reg);
  607. PPC_BPF_STDCX(b2p[TMP_REG_2], 0, b2p[TMP_REG_1]);
  608. PPC_BCC_SHORT(COND_NE, tmp_idx);
  609. break;
  610. /*
  611. * BPF_LDX
  612. */
  613. /* dst = *(u8 *)(ul) (src + off) */
  614. case BPF_LDX | BPF_MEM | BPF_B:
  615. PPC_LBZ(dst_reg, src_reg, off);
  616. break;
  617. /* dst = *(u16 *)(ul) (src + off) */
  618. case BPF_LDX | BPF_MEM | BPF_H:
  619. PPC_LHZ(dst_reg, src_reg, off);
  620. break;
  621. /* dst = *(u32 *)(ul) (src + off) */
  622. case BPF_LDX | BPF_MEM | BPF_W:
  623. PPC_LWZ(dst_reg, src_reg, off);
  624. break;
  625. /* dst = *(u64 *)(ul) (src + off) */
  626. case BPF_LDX | BPF_MEM | BPF_DW:
  627. PPC_BPF_LL(dst_reg, src_reg, off);
  628. break;
  629. /*
  630. * Doubleword load
  631. * 16 byte instruction that uses two 'struct bpf_insn'
  632. */
  633. case BPF_LD | BPF_IMM | BPF_DW: /* dst = (u64) imm */
  634. imm64 = ((u64)(u32) insn[i].imm) |
  635. (((u64)(u32) insn[i+1].imm) << 32);
  636. /* Adjust for two bpf instructions */
  637. addrs[++i] = ctx->idx * 4;
  638. PPC_LI64(dst_reg, imm64);
  639. break;
  640. /*
  641. * Return/Exit
  642. */
  643. case BPF_JMP | BPF_EXIT:
  644. /*
  645. * If this isn't the very last instruction, branch to
  646. * the epilogue. If we _are_ the last instruction,
  647. * we'll just fall through to the epilogue.
  648. */
  649. if (i != flen - 1)
  650. PPC_JMP(exit_addr);
  651. /* else fall through to the epilogue */
  652. break;
  653. /*
  654. * Call kernel helper or bpf function
  655. */
  656. case BPF_JMP | BPF_CALL:
  657. ctx->seen |= SEEN_FUNC;
  658. /* bpf function call */
  659. if (insn[i].src_reg == BPF_PSEUDO_CALL)
  660. if (!extra_pass)
  661. func = NULL;
  662. else if (fp->aux->func && off < fp->aux->func_cnt)
  663. /* use the subprog id from the off
  664. * field to lookup the callee address
  665. */
  666. func = (u8 *) fp->aux->func[off]->bpf_func;
  667. else
  668. return -EINVAL;
  669. /* kernel helper call */
  670. else
  671. func = (u8 *) __bpf_call_base + imm;
  672. bpf_jit_emit_func_call(image, ctx, (u64)func);
  673. /* move return value from r3 to BPF_REG_0 */
  674. PPC_MR(b2p[BPF_REG_0], 3);
  675. break;
  676. /*
  677. * Jumps and branches
  678. */
  679. case BPF_JMP | BPF_JA:
  680. PPC_JMP(addrs[i + 1 + off]);
  681. break;
  682. case BPF_JMP | BPF_JGT | BPF_K:
  683. case BPF_JMP | BPF_JGT | BPF_X:
  684. case BPF_JMP | BPF_JSGT | BPF_K:
  685. case BPF_JMP | BPF_JSGT | BPF_X:
  686. true_cond = COND_GT;
  687. goto cond_branch;
  688. case BPF_JMP | BPF_JLT | BPF_K:
  689. case BPF_JMP | BPF_JLT | BPF_X:
  690. case BPF_JMP | BPF_JSLT | BPF_K:
  691. case BPF_JMP | BPF_JSLT | BPF_X:
  692. true_cond = COND_LT;
  693. goto cond_branch;
  694. case BPF_JMP | BPF_JGE | BPF_K:
  695. case BPF_JMP | BPF_JGE | BPF_X:
  696. case BPF_JMP | BPF_JSGE | BPF_K:
  697. case BPF_JMP | BPF_JSGE | BPF_X:
  698. true_cond = COND_GE;
  699. goto cond_branch;
  700. case BPF_JMP | BPF_JLE | BPF_K:
  701. case BPF_JMP | BPF_JLE | BPF_X:
  702. case BPF_JMP | BPF_JSLE | BPF_K:
  703. case BPF_JMP | BPF_JSLE | BPF_X:
  704. true_cond = COND_LE;
  705. goto cond_branch;
  706. case BPF_JMP | BPF_JEQ | BPF_K:
  707. case BPF_JMP | BPF_JEQ | BPF_X:
  708. true_cond = COND_EQ;
  709. goto cond_branch;
  710. case BPF_JMP | BPF_JNE | BPF_K:
  711. case BPF_JMP | BPF_JNE | BPF_X:
  712. true_cond = COND_NE;
  713. goto cond_branch;
  714. case BPF_JMP | BPF_JSET | BPF_K:
  715. case BPF_JMP | BPF_JSET | BPF_X:
  716. true_cond = COND_NE;
  717. /* Fall through */
  718. cond_branch:
  719. switch (code) {
  720. case BPF_JMP | BPF_JGT | BPF_X:
  721. case BPF_JMP | BPF_JLT | BPF_X:
  722. case BPF_JMP | BPF_JGE | BPF_X:
  723. case BPF_JMP | BPF_JLE | BPF_X:
  724. case BPF_JMP | BPF_JEQ | BPF_X:
  725. case BPF_JMP | BPF_JNE | BPF_X:
  726. /* unsigned comparison */
  727. PPC_CMPLD(dst_reg, src_reg);
  728. break;
  729. case BPF_JMP | BPF_JSGT | BPF_X:
  730. case BPF_JMP | BPF_JSLT | BPF_X:
  731. case BPF_JMP | BPF_JSGE | BPF_X:
  732. case BPF_JMP | BPF_JSLE | BPF_X:
  733. /* signed comparison */
  734. PPC_CMPD(dst_reg, src_reg);
  735. break;
  736. case BPF_JMP | BPF_JSET | BPF_X:
  737. PPC_AND_DOT(b2p[TMP_REG_1], dst_reg, src_reg);
  738. break;
  739. case BPF_JMP | BPF_JNE | BPF_K:
  740. case BPF_JMP | BPF_JEQ | BPF_K:
  741. case BPF_JMP | BPF_JGT | BPF_K:
  742. case BPF_JMP | BPF_JLT | BPF_K:
  743. case BPF_JMP | BPF_JGE | BPF_K:
  744. case BPF_JMP | BPF_JLE | BPF_K:
  745. /*
  746. * Need sign-extended load, so only positive
  747. * values can be used as imm in cmpldi
  748. */
  749. if (imm >= 0 && imm < 32768)
  750. PPC_CMPLDI(dst_reg, imm);
  751. else {
  752. /* sign-extending load */
  753. PPC_LI32(b2p[TMP_REG_1], imm);
  754. /* ... but unsigned comparison */
  755. PPC_CMPLD(dst_reg, b2p[TMP_REG_1]);
  756. }
  757. break;
  758. case BPF_JMP | BPF_JSGT | BPF_K:
  759. case BPF_JMP | BPF_JSLT | BPF_K:
  760. case BPF_JMP | BPF_JSGE | BPF_K:
  761. case BPF_JMP | BPF_JSLE | BPF_K:
  762. /*
  763. * signed comparison, so any 16-bit value
  764. * can be used in cmpdi
  765. */
  766. if (imm >= -32768 && imm < 32768)
  767. PPC_CMPDI(dst_reg, imm);
  768. else {
  769. PPC_LI32(b2p[TMP_REG_1], imm);
  770. PPC_CMPD(dst_reg, b2p[TMP_REG_1]);
  771. }
  772. break;
  773. case BPF_JMP | BPF_JSET | BPF_K:
  774. /* andi does not sign-extend the immediate */
  775. if (imm >= 0 && imm < 32768)
  776. /* PPC_ANDI is _only/always_ dot-form */
  777. PPC_ANDI(b2p[TMP_REG_1], dst_reg, imm);
  778. else {
  779. PPC_LI32(b2p[TMP_REG_1], imm);
  780. PPC_AND_DOT(b2p[TMP_REG_1], dst_reg,
  781. b2p[TMP_REG_1]);
  782. }
  783. break;
  784. }
  785. PPC_BCC(true_cond, addrs[i + 1 + off]);
  786. break;
  787. /*
  788. * Tail call
  789. */
  790. case BPF_JMP | BPF_TAIL_CALL:
  791. ctx->seen |= SEEN_TAILCALL;
  792. bpf_jit_emit_tail_call(image, ctx, addrs[i + 1]);
  793. break;
  794. default:
  795. /*
  796. * The filter contains something cruel & unusual.
  797. * We don't handle it, but also there shouldn't be
  798. * anything missing from our list.
  799. */
  800. pr_err_ratelimited("eBPF filter opcode %04x (@%d) unsupported\n",
  801. code, i);
  802. return -ENOTSUPP;
  803. }
  804. }
  805. /* Set end-of-body-code address for exit. */
  806. addrs[i] = ctx->idx * 4;
  807. return 0;
  808. }
  809. struct powerpc64_jit_data {
  810. struct bpf_binary_header *header;
  811. u32 *addrs;
  812. u8 *image;
  813. u32 proglen;
  814. struct codegen_context ctx;
  815. };
  816. struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
  817. {
  818. u32 proglen;
  819. u32 alloclen;
  820. u8 *image = NULL;
  821. u32 *code_base;
  822. u32 *addrs;
  823. struct powerpc64_jit_data *jit_data;
  824. struct codegen_context cgctx;
  825. int pass;
  826. int flen;
  827. struct bpf_binary_header *bpf_hdr;
  828. struct bpf_prog *org_fp = fp;
  829. struct bpf_prog *tmp_fp;
  830. bool bpf_blinded = false;
  831. bool extra_pass = false;
  832. if (!fp->jit_requested)
  833. return org_fp;
  834. tmp_fp = bpf_jit_blind_constants(org_fp);
  835. if (IS_ERR(tmp_fp))
  836. return org_fp;
  837. if (tmp_fp != org_fp) {
  838. bpf_blinded = true;
  839. fp = tmp_fp;
  840. }
  841. jit_data = fp->aux->jit_data;
  842. if (!jit_data) {
  843. jit_data = kzalloc(sizeof(*jit_data), GFP_KERNEL);
  844. if (!jit_data) {
  845. fp = org_fp;
  846. goto out;
  847. }
  848. fp->aux->jit_data = jit_data;
  849. }
  850. flen = fp->len;
  851. addrs = jit_data->addrs;
  852. if (addrs) {
  853. cgctx = jit_data->ctx;
  854. image = jit_data->image;
  855. bpf_hdr = jit_data->header;
  856. proglen = jit_data->proglen;
  857. alloclen = proglen + FUNCTION_DESCR_SIZE;
  858. extra_pass = true;
  859. goto skip_init_ctx;
  860. }
  861. addrs = kcalloc(flen + 1, sizeof(*addrs), GFP_KERNEL);
  862. if (addrs == NULL) {
  863. fp = org_fp;
  864. goto out_addrs;
  865. }
  866. memset(&cgctx, 0, sizeof(struct codegen_context));
  867. /* Make sure that the stack is quadword aligned. */
  868. cgctx.stack_size = round_up(fp->aux->stack_depth, 16);
  869. /* Scouting faux-generate pass 0 */
  870. if (bpf_jit_build_body(fp, 0, &cgctx, addrs, false)) {
  871. /* We hit something illegal or unsupported. */
  872. fp = org_fp;
  873. goto out_addrs;
  874. }
  875. /*
  876. * If we have seen a tail call, we need a second pass.
  877. * This is because bpf_jit_emit_common_epilogue() is called
  878. * from bpf_jit_emit_tail_call() with a not yet stable ctx->seen.
  879. */
  880. if (cgctx.seen & SEEN_TAILCALL) {
  881. cgctx.idx = 0;
  882. if (bpf_jit_build_body(fp, 0, &cgctx, addrs, false)) {
  883. fp = org_fp;
  884. goto out_addrs;
  885. }
  886. }
  887. /*
  888. * Pretend to build prologue, given the features we've seen. This will
  889. * update ctgtx.idx as it pretends to output instructions, then we can
  890. * calculate total size from idx.
  891. */
  892. bpf_jit_build_prologue(0, &cgctx);
  893. bpf_jit_build_epilogue(0, &cgctx);
  894. proglen = cgctx.idx * 4;
  895. alloclen = proglen + FUNCTION_DESCR_SIZE;
  896. bpf_hdr = bpf_jit_binary_alloc(alloclen, &image, 4,
  897. bpf_jit_fill_ill_insns);
  898. if (!bpf_hdr) {
  899. fp = org_fp;
  900. goto out_addrs;
  901. }
  902. skip_init_ctx:
  903. code_base = (u32 *)(image + FUNCTION_DESCR_SIZE);
  904. /* Code generation passes 1-2 */
  905. for (pass = 1; pass < 3; pass++) {
  906. /* Now build the prologue, body code & epilogue for real. */
  907. cgctx.idx = 0;
  908. bpf_jit_build_prologue(code_base, &cgctx);
  909. bpf_jit_build_body(fp, code_base, &cgctx, addrs, extra_pass);
  910. bpf_jit_build_epilogue(code_base, &cgctx);
  911. if (bpf_jit_enable > 1)
  912. pr_info("Pass %d: shrink = %d, seen = 0x%x\n", pass,
  913. proglen - (cgctx.idx * 4), cgctx.seen);
  914. }
  915. if (bpf_jit_enable > 1)
  916. /*
  917. * Note that we output the base address of the code_base
  918. * rather than image, since opcodes are in code_base.
  919. */
  920. bpf_jit_dump(flen, proglen, pass, code_base);
  921. #ifdef PPC64_ELF_ABI_v1
  922. /* Function descriptor nastiness: Address + TOC */
  923. ((u64 *)image)[0] = (u64)code_base;
  924. ((u64 *)image)[1] = local_paca->kernel_toc;
  925. #endif
  926. fp->bpf_func = (void *)image;
  927. fp->jited = 1;
  928. fp->jited_len = alloclen;
  929. bpf_flush_icache(bpf_hdr, (u8 *)bpf_hdr + (bpf_hdr->pages * PAGE_SIZE));
  930. if (!fp->is_func || extra_pass) {
  931. out_addrs:
  932. kfree(addrs);
  933. kfree(jit_data);
  934. fp->aux->jit_data = NULL;
  935. } else {
  936. jit_data->addrs = addrs;
  937. jit_data->ctx = cgctx;
  938. jit_data->proglen = proglen;
  939. jit_data->image = image;
  940. jit_data->header = bpf_hdr;
  941. }
  942. out:
  943. if (bpf_blinded)
  944. bpf_jit_prog_release_other(fp, fp == org_fp ? tmp_fp : org_fp);
  945. return fp;
  946. }
  947. /* Overriding bpf_jit_free() as we don't set images read-only. */
  948. void bpf_jit_free(struct bpf_prog *fp)
  949. {
  950. unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
  951. struct bpf_binary_header *bpf_hdr = (void *)addr;
  952. if (fp->jited)
  953. bpf_jit_binary_free(bpf_hdr);
  954. bpf_prog_unlock_free(fp);
  955. }