bpf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Copyright (C) 2017 Netronome Systems, Inc.
  3. *
  4. * This software is licensed under the GNU General License Version 2,
  5. * June 1991 as shown in the file COPYING in the top-level directory of this
  6. * source tree.
  7. *
  8. * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS"
  9. * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  10. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  11. * FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
  12. * OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
  13. * THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  14. */
  15. #include <linux/bpf.h>
  16. #include <linux/bpf_verifier.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mutex.h>
  20. #include <linux/rtnetlink.h>
  21. #include <net/pkt_cls.h>
  22. #include "netdevsim.h"
  23. #define pr_vlog(env, fmt, ...) \
  24. bpf_verifier_log_write(env, "[netdevsim] " fmt, ##__VA_ARGS__)
  25. struct nsim_bpf_bound_prog {
  26. struct nsim_dev *nsim_dev;
  27. struct bpf_prog *prog;
  28. struct dentry *ddir;
  29. const char *state;
  30. bool is_loaded;
  31. struct list_head l;
  32. };
  33. #define NSIM_BPF_MAX_KEYS 2
  34. struct nsim_bpf_bound_map {
  35. struct netdevsim *ns;
  36. struct bpf_offloaded_map *map;
  37. struct mutex mutex;
  38. struct nsim_map_entry {
  39. void *key;
  40. void *value;
  41. } entry[NSIM_BPF_MAX_KEYS];
  42. struct list_head l;
  43. };
  44. static int nsim_bpf_string_show(struct seq_file *file, void *data)
  45. {
  46. const char **str = file->private;
  47. if (*str)
  48. seq_printf(file, "%s\n", *str);
  49. return 0;
  50. }
  51. DEFINE_SHOW_ATTRIBUTE(nsim_bpf_string);
  52. static int
  53. nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
  54. {
  55. struct nsim_bpf_bound_prog *state;
  56. state = env->prog->aux->offload->dev_priv;
  57. if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx)
  58. msleep(state->nsim_dev->bpf_bind_verifier_delay);
  59. if (insn_idx == env->prog->len - 1)
  60. pr_vlog(env, "Hello from netdevsim!\n");
  61. return 0;
  62. }
  63. static int nsim_bpf_finalize(struct bpf_verifier_env *env)
  64. {
  65. return 0;
  66. }
  67. static bool nsim_xdp_offload_active(struct netdevsim *ns)
  68. {
  69. return ns->xdp_hw.prog;
  70. }
  71. static void nsim_prog_set_loaded(struct bpf_prog *prog, bool loaded)
  72. {
  73. struct nsim_bpf_bound_prog *state;
  74. if (!prog || !prog->aux->offload)
  75. return;
  76. state = prog->aux->offload->dev_priv;
  77. state->is_loaded = loaded;
  78. }
  79. static int
  80. nsim_bpf_offload(struct netdevsim *ns, struct bpf_prog *prog, bool oldprog)
  81. {
  82. nsim_prog_set_loaded(ns->bpf_offloaded, false);
  83. WARN(!!ns->bpf_offloaded != oldprog,
  84. "bad offload state, expected offload %sto be active",
  85. oldprog ? "" : "not ");
  86. ns->bpf_offloaded = prog;
  87. ns->bpf_offloaded_id = prog ? prog->aux->id : 0;
  88. nsim_prog_set_loaded(prog, true);
  89. return 0;
  90. }
  91. int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type,
  92. void *type_data, void *cb_priv)
  93. {
  94. struct tc_cls_bpf_offload *cls_bpf = type_data;
  95. struct bpf_prog *prog = cls_bpf->prog;
  96. struct netdevsim *ns = cb_priv;
  97. struct bpf_prog *oldprog;
  98. if (type != TC_SETUP_CLSBPF) {
  99. NSIM_EA(cls_bpf->common.extack,
  100. "only offload of BPF classifiers supported");
  101. return -EOPNOTSUPP;
  102. }
  103. if (!tc_cls_can_offload_and_chain0(ns->netdev, &cls_bpf->common))
  104. return -EOPNOTSUPP;
  105. if (cls_bpf->common.protocol != htons(ETH_P_ALL)) {
  106. NSIM_EA(cls_bpf->common.extack,
  107. "only ETH_P_ALL supported as filter protocol");
  108. return -EOPNOTSUPP;
  109. }
  110. if (!ns->bpf_tc_accept) {
  111. NSIM_EA(cls_bpf->common.extack,
  112. "netdevsim configured to reject BPF TC offload");
  113. return -EOPNOTSUPP;
  114. }
  115. /* Note: progs without skip_sw will probably not be dev bound */
  116. if (prog && !prog->aux->offload && !ns->bpf_tc_non_bound_accept) {
  117. NSIM_EA(cls_bpf->common.extack,
  118. "netdevsim configured to reject unbound programs");
  119. return -EOPNOTSUPP;
  120. }
  121. if (cls_bpf->command != TC_CLSBPF_OFFLOAD)
  122. return -EOPNOTSUPP;
  123. oldprog = cls_bpf->oldprog;
  124. /* Don't remove if oldprog doesn't match driver's state */
  125. if (ns->bpf_offloaded != oldprog) {
  126. oldprog = NULL;
  127. if (!cls_bpf->prog)
  128. return 0;
  129. if (ns->bpf_offloaded) {
  130. NSIM_EA(cls_bpf->common.extack,
  131. "driver and netdev offload states mismatch");
  132. return -EBUSY;
  133. }
  134. }
  135. return nsim_bpf_offload(ns, cls_bpf->prog, oldprog);
  136. }
  137. int nsim_bpf_disable_tc(struct netdevsim *ns)
  138. {
  139. if (ns->bpf_offloaded && !nsim_xdp_offload_active(ns))
  140. return -EBUSY;
  141. return 0;
  142. }
  143. static int nsim_xdp_offload_prog(struct netdevsim *ns, struct netdev_bpf *bpf)
  144. {
  145. if (!nsim_xdp_offload_active(ns) && !bpf->prog)
  146. return 0;
  147. if (!nsim_xdp_offload_active(ns) && bpf->prog && ns->bpf_offloaded) {
  148. NSIM_EA(bpf->extack, "TC program is already loaded");
  149. return -EBUSY;
  150. }
  151. return nsim_bpf_offload(ns, bpf->prog, nsim_xdp_offload_active(ns));
  152. }
  153. static int
  154. nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf,
  155. struct xdp_attachment_info *xdp)
  156. {
  157. int err;
  158. if (!xdp_attachment_flags_ok(xdp, bpf))
  159. return -EBUSY;
  160. if (bpf->command == XDP_SETUP_PROG && !ns->bpf_xdpdrv_accept) {
  161. NSIM_EA(bpf->extack, "driver XDP disabled in DebugFS");
  162. return -EOPNOTSUPP;
  163. }
  164. if (bpf->command == XDP_SETUP_PROG_HW && !ns->bpf_xdpoffload_accept) {
  165. NSIM_EA(bpf->extack, "XDP offload disabled in DebugFS");
  166. return -EOPNOTSUPP;
  167. }
  168. if (bpf->command == XDP_SETUP_PROG_HW) {
  169. err = nsim_xdp_offload_prog(ns, bpf);
  170. if (err)
  171. return err;
  172. }
  173. xdp_attachment_setup(xdp, bpf);
  174. return 0;
  175. }
  176. static int nsim_bpf_create_prog(struct nsim_dev *nsim_dev,
  177. struct bpf_prog *prog)
  178. {
  179. struct nsim_bpf_bound_prog *state;
  180. char name[16];
  181. state = kzalloc(sizeof(*state), GFP_KERNEL);
  182. if (!state)
  183. return -ENOMEM;
  184. state->nsim_dev = nsim_dev;
  185. state->prog = prog;
  186. state->state = "verify";
  187. /* Program id is not populated yet when we create the state. */
  188. sprintf(name, "%u", nsim_dev->prog_id_gen++);
  189. state->ddir = debugfs_create_dir(name, nsim_dev->ddir_bpf_bound_progs);
  190. if (IS_ERR_OR_NULL(state->ddir)) {
  191. kfree(state);
  192. return -ENOMEM;
  193. }
  194. debugfs_create_u32("id", 0400, state->ddir, &prog->aux->id);
  195. debugfs_create_file("state", 0400, state->ddir,
  196. &state->state, &nsim_bpf_string_fops);
  197. debugfs_create_bool("loaded", 0400, state->ddir, &state->is_loaded);
  198. list_add_tail(&state->l, &nsim_dev->bpf_bound_progs);
  199. prog->aux->offload->dev_priv = state;
  200. return 0;
  201. }
  202. static int nsim_bpf_verifier_prep(struct bpf_prog *prog)
  203. {
  204. struct nsim_dev *nsim_dev =
  205. bpf_offload_dev_priv(prog->aux->offload->offdev);
  206. if (!nsim_dev->bpf_bind_accept)
  207. return -EOPNOTSUPP;
  208. return nsim_bpf_create_prog(nsim_dev, prog);
  209. }
  210. static int nsim_bpf_translate(struct bpf_prog *prog)
  211. {
  212. struct nsim_bpf_bound_prog *state = prog->aux->offload->dev_priv;
  213. state->state = "xlated";
  214. return 0;
  215. }
  216. static void nsim_bpf_destroy_prog(struct bpf_prog *prog)
  217. {
  218. struct nsim_bpf_bound_prog *state;
  219. state = prog->aux->offload->dev_priv;
  220. WARN(state->is_loaded,
  221. "offload state destroyed while program still bound");
  222. debugfs_remove_recursive(state->ddir);
  223. list_del(&state->l);
  224. kfree(state);
  225. }
  226. static const struct bpf_prog_offload_ops nsim_bpf_dev_ops = {
  227. .insn_hook = nsim_bpf_verify_insn,
  228. .finalize = nsim_bpf_finalize,
  229. .prepare = nsim_bpf_verifier_prep,
  230. .translate = nsim_bpf_translate,
  231. .destroy = nsim_bpf_destroy_prog,
  232. };
  233. static int nsim_setup_prog_checks(struct netdevsim *ns, struct netdev_bpf *bpf)
  234. {
  235. if (bpf->prog && bpf->prog->aux->offload) {
  236. NSIM_EA(bpf->extack, "attempt to load offloaded prog to drv");
  237. return -EINVAL;
  238. }
  239. if (ns->netdev->mtu > NSIM_XDP_MAX_MTU) {
  240. NSIM_EA(bpf->extack, "MTU too large w/ XDP enabled");
  241. return -EINVAL;
  242. }
  243. return 0;
  244. }
  245. static int
  246. nsim_setup_prog_hw_checks(struct netdevsim *ns, struct netdev_bpf *bpf)
  247. {
  248. struct nsim_bpf_bound_prog *state;
  249. if (!bpf->prog)
  250. return 0;
  251. if (!bpf->prog->aux->offload) {
  252. NSIM_EA(bpf->extack, "xdpoffload of non-bound program");
  253. return -EINVAL;
  254. }
  255. if (!bpf_offload_dev_match(bpf->prog, ns->netdev)) {
  256. NSIM_EA(bpf->extack, "program bound to different dev");
  257. return -EINVAL;
  258. }
  259. state = bpf->prog->aux->offload->dev_priv;
  260. if (WARN_ON(strcmp(state->state, "xlated"))) {
  261. NSIM_EA(bpf->extack, "offloading program in bad state");
  262. return -EINVAL;
  263. }
  264. return 0;
  265. }
  266. static bool
  267. nsim_map_key_match(struct bpf_map *map, struct nsim_map_entry *e, void *key)
  268. {
  269. return e->key && !memcmp(key, e->key, map->key_size);
  270. }
  271. static int nsim_map_key_find(struct bpf_offloaded_map *offmap, void *key)
  272. {
  273. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  274. unsigned int i;
  275. for (i = 0; i < ARRAY_SIZE(nmap->entry); i++)
  276. if (nsim_map_key_match(&offmap->map, &nmap->entry[i], key))
  277. return i;
  278. return -ENOENT;
  279. }
  280. static int
  281. nsim_map_alloc_elem(struct bpf_offloaded_map *offmap, unsigned int idx)
  282. {
  283. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  284. nmap->entry[idx].key = kmalloc(offmap->map.key_size, GFP_USER);
  285. if (!nmap->entry[idx].key)
  286. return -ENOMEM;
  287. nmap->entry[idx].value = kmalloc(offmap->map.value_size, GFP_USER);
  288. if (!nmap->entry[idx].value) {
  289. kfree(nmap->entry[idx].key);
  290. nmap->entry[idx].key = NULL;
  291. return -ENOMEM;
  292. }
  293. return 0;
  294. }
  295. static int
  296. nsim_map_get_next_key(struct bpf_offloaded_map *offmap,
  297. void *key, void *next_key)
  298. {
  299. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  300. int idx = -ENOENT;
  301. mutex_lock(&nmap->mutex);
  302. if (key)
  303. idx = nsim_map_key_find(offmap, key);
  304. if (idx == -ENOENT)
  305. idx = 0;
  306. else
  307. idx++;
  308. for (; idx < ARRAY_SIZE(nmap->entry); idx++) {
  309. if (nmap->entry[idx].key) {
  310. memcpy(next_key, nmap->entry[idx].key,
  311. offmap->map.key_size);
  312. break;
  313. }
  314. }
  315. mutex_unlock(&nmap->mutex);
  316. if (idx == ARRAY_SIZE(nmap->entry))
  317. return -ENOENT;
  318. return 0;
  319. }
  320. static int
  321. nsim_map_lookup_elem(struct bpf_offloaded_map *offmap, void *key, void *value)
  322. {
  323. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  324. int idx;
  325. mutex_lock(&nmap->mutex);
  326. idx = nsim_map_key_find(offmap, key);
  327. if (idx >= 0)
  328. memcpy(value, nmap->entry[idx].value, offmap->map.value_size);
  329. mutex_unlock(&nmap->mutex);
  330. return idx < 0 ? idx : 0;
  331. }
  332. static int
  333. nsim_map_update_elem(struct bpf_offloaded_map *offmap,
  334. void *key, void *value, u64 flags)
  335. {
  336. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  337. int idx, err = 0;
  338. mutex_lock(&nmap->mutex);
  339. idx = nsim_map_key_find(offmap, key);
  340. if (idx < 0 && flags == BPF_EXIST) {
  341. err = idx;
  342. goto exit_unlock;
  343. }
  344. if (idx >= 0 && flags == BPF_NOEXIST) {
  345. err = -EEXIST;
  346. goto exit_unlock;
  347. }
  348. if (idx < 0) {
  349. for (idx = 0; idx < ARRAY_SIZE(nmap->entry); idx++)
  350. if (!nmap->entry[idx].key)
  351. break;
  352. if (idx == ARRAY_SIZE(nmap->entry)) {
  353. err = -E2BIG;
  354. goto exit_unlock;
  355. }
  356. err = nsim_map_alloc_elem(offmap, idx);
  357. if (err)
  358. goto exit_unlock;
  359. }
  360. memcpy(nmap->entry[idx].key, key, offmap->map.key_size);
  361. memcpy(nmap->entry[idx].value, value, offmap->map.value_size);
  362. exit_unlock:
  363. mutex_unlock(&nmap->mutex);
  364. return err;
  365. }
  366. static int nsim_map_delete_elem(struct bpf_offloaded_map *offmap, void *key)
  367. {
  368. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  369. int idx;
  370. if (offmap->map.map_type == BPF_MAP_TYPE_ARRAY)
  371. return -EINVAL;
  372. mutex_lock(&nmap->mutex);
  373. idx = nsim_map_key_find(offmap, key);
  374. if (idx >= 0) {
  375. kfree(nmap->entry[idx].key);
  376. kfree(nmap->entry[idx].value);
  377. memset(&nmap->entry[idx], 0, sizeof(nmap->entry[idx]));
  378. }
  379. mutex_unlock(&nmap->mutex);
  380. return idx < 0 ? idx : 0;
  381. }
  382. static const struct bpf_map_dev_ops nsim_bpf_map_ops = {
  383. .map_get_next_key = nsim_map_get_next_key,
  384. .map_lookup_elem = nsim_map_lookup_elem,
  385. .map_update_elem = nsim_map_update_elem,
  386. .map_delete_elem = nsim_map_delete_elem,
  387. };
  388. static int
  389. nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
  390. {
  391. struct nsim_bpf_bound_map *nmap;
  392. int i, err;
  393. if (WARN_ON(offmap->map.map_type != BPF_MAP_TYPE_ARRAY &&
  394. offmap->map.map_type != BPF_MAP_TYPE_HASH))
  395. return -EINVAL;
  396. if (offmap->map.max_entries > NSIM_BPF_MAX_KEYS)
  397. return -ENOMEM;
  398. if (offmap->map.map_flags)
  399. return -EINVAL;
  400. nmap = kzalloc(sizeof(*nmap), GFP_USER);
  401. if (!nmap)
  402. return -ENOMEM;
  403. offmap->dev_priv = nmap;
  404. nmap->ns = ns;
  405. nmap->map = offmap;
  406. mutex_init(&nmap->mutex);
  407. if (offmap->map.map_type == BPF_MAP_TYPE_ARRAY) {
  408. for (i = 0; i < ARRAY_SIZE(nmap->entry); i++) {
  409. u32 *key;
  410. err = nsim_map_alloc_elem(offmap, i);
  411. if (err)
  412. goto err_free;
  413. key = nmap->entry[i].key;
  414. *key = i;
  415. }
  416. }
  417. offmap->dev_ops = &nsim_bpf_map_ops;
  418. list_add_tail(&nmap->l, &ns->nsim_dev->bpf_bound_maps);
  419. return 0;
  420. err_free:
  421. while (--i >= 0) {
  422. kfree(nmap->entry[i].key);
  423. kfree(nmap->entry[i].value);
  424. }
  425. kfree(nmap);
  426. return err;
  427. }
  428. static void nsim_bpf_map_free(struct bpf_offloaded_map *offmap)
  429. {
  430. struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
  431. unsigned int i;
  432. for (i = 0; i < ARRAY_SIZE(nmap->entry); i++) {
  433. kfree(nmap->entry[i].key);
  434. kfree(nmap->entry[i].value);
  435. }
  436. list_del_init(&nmap->l);
  437. mutex_destroy(&nmap->mutex);
  438. kfree(nmap);
  439. }
  440. int nsim_bpf(struct net_device *dev, struct netdev_bpf *bpf)
  441. {
  442. struct netdevsim *ns = netdev_priv(dev);
  443. int err;
  444. ASSERT_RTNL();
  445. switch (bpf->command) {
  446. case XDP_QUERY_PROG:
  447. return xdp_attachment_query(&ns->xdp, bpf);
  448. case XDP_QUERY_PROG_HW:
  449. return xdp_attachment_query(&ns->xdp_hw, bpf);
  450. case XDP_SETUP_PROG:
  451. err = nsim_setup_prog_checks(ns, bpf);
  452. if (err)
  453. return err;
  454. return nsim_xdp_set_prog(ns, bpf, &ns->xdp);
  455. case XDP_SETUP_PROG_HW:
  456. err = nsim_setup_prog_hw_checks(ns, bpf);
  457. if (err)
  458. return err;
  459. return nsim_xdp_set_prog(ns, bpf, &ns->xdp_hw);
  460. case BPF_OFFLOAD_MAP_ALLOC:
  461. if (!ns->bpf_map_accept)
  462. return -EOPNOTSUPP;
  463. return nsim_bpf_map_alloc(ns, bpf->offmap);
  464. case BPF_OFFLOAD_MAP_FREE:
  465. nsim_bpf_map_free(bpf->offmap);
  466. return 0;
  467. default:
  468. return -EINVAL;
  469. }
  470. }
  471. int nsim_bpf_dev_init(struct nsim_dev *nsim_dev)
  472. {
  473. int err;
  474. INIT_LIST_HEAD(&nsim_dev->bpf_bound_progs);
  475. INIT_LIST_HEAD(&nsim_dev->bpf_bound_maps);
  476. nsim_dev->ddir_bpf_bound_progs = debugfs_create_dir("bpf_bound_progs",
  477. nsim_dev->ddir);
  478. if (IS_ERR_OR_NULL(nsim_dev->ddir_bpf_bound_progs))
  479. return -ENOMEM;
  480. nsim_dev->bpf_dev = bpf_offload_dev_create(&nsim_bpf_dev_ops, nsim_dev);
  481. err = PTR_ERR_OR_ZERO(nsim_dev->bpf_dev);
  482. if (err)
  483. return err;
  484. nsim_dev->bpf_bind_accept = true;
  485. debugfs_create_bool("bpf_bind_accept", 0600, nsim_dev->ddir,
  486. &nsim_dev->bpf_bind_accept);
  487. debugfs_create_u32("bpf_bind_verifier_delay", 0600, nsim_dev->ddir,
  488. &nsim_dev->bpf_bind_verifier_delay);
  489. return 0;
  490. }
  491. void nsim_bpf_dev_exit(struct nsim_dev *nsim_dev)
  492. {
  493. WARN_ON(!list_empty(&nsim_dev->bpf_bound_progs));
  494. WARN_ON(!list_empty(&nsim_dev->bpf_bound_maps));
  495. bpf_offload_dev_destroy(nsim_dev->bpf_dev);
  496. }
  497. int nsim_bpf_init(struct netdevsim *ns)
  498. {
  499. struct dentry *ddir = ns->nsim_dev_port->ddir;
  500. int err;
  501. err = bpf_offload_dev_netdev_register(ns->nsim_dev->bpf_dev,
  502. ns->netdev);
  503. if (err)
  504. return err;
  505. debugfs_create_u32("bpf_offloaded_id", 0400, ddir,
  506. &ns->bpf_offloaded_id);
  507. ns->bpf_tc_accept = true;
  508. debugfs_create_bool("bpf_tc_accept", 0600, ddir,
  509. &ns->bpf_tc_accept);
  510. debugfs_create_bool("bpf_tc_non_bound_accept", 0600, ddir,
  511. &ns->bpf_tc_non_bound_accept);
  512. ns->bpf_xdpdrv_accept = true;
  513. debugfs_create_bool("bpf_xdpdrv_accept", 0600, ddir,
  514. &ns->bpf_xdpdrv_accept);
  515. ns->bpf_xdpoffload_accept = true;
  516. debugfs_create_bool("bpf_xdpoffload_accept", 0600, ddir,
  517. &ns->bpf_xdpoffload_accept);
  518. ns->bpf_map_accept = true;
  519. debugfs_create_bool("bpf_map_accept", 0600, ddir,
  520. &ns->bpf_map_accept);
  521. return 0;
  522. }
  523. void nsim_bpf_uninit(struct netdevsim *ns)
  524. {
  525. WARN_ON(ns->xdp.prog);
  526. WARN_ON(ns->xdp_hw.prog);
  527. WARN_ON(ns->bpf_offloaded);
  528. bpf_offload_dev_netdev_unregister(ns->nsim_dev->bpf_dev, ns->netdev);
  529. }