~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/bpf/prog_iter.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Copyright (c) 2020 Facebook */
  3 #include <linux/bpf.h>
  4 #include <linux/fs.h>
  5 #include <linux/filter.h>
  6 #include <linux/kernel.h>
  7 #include <linux/btf_ids.h>
  8 
  9 struct bpf_iter_seq_prog_info {
 10         u32 prog_id;
 11 };
 12 
 13 static void *bpf_prog_seq_start(struct seq_file *seq, loff_t *pos)
 14 {
 15         struct bpf_iter_seq_prog_info *info = seq->private;
 16         struct bpf_prog *prog;
 17 
 18         prog = bpf_prog_get_curr_or_next(&info->prog_id);
 19         if (!prog)
 20                 return NULL;
 21 
 22         if (*pos == 0)
 23                 ++*pos;
 24         return prog;
 25 }
 26 
 27 static void *bpf_prog_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 28 {
 29         struct bpf_iter_seq_prog_info *info = seq->private;
 30 
 31         ++*pos;
 32         ++info->prog_id;
 33         bpf_prog_put((struct bpf_prog *)v);
 34         return bpf_prog_get_curr_or_next(&info->prog_id);
 35 }
 36 
 37 struct bpf_iter__bpf_prog {
 38         __bpf_md_ptr(struct bpf_iter_meta *, meta);
 39         __bpf_md_ptr(struct bpf_prog *, prog);
 40 };
 41 
 42 DEFINE_BPF_ITER_FUNC(bpf_prog, struct bpf_iter_meta *meta, struct bpf_prog *prog)
 43 
 44 static int __bpf_prog_seq_show(struct seq_file *seq, void *v, bool in_stop)
 45 {
 46         struct bpf_iter__bpf_prog ctx;
 47         struct bpf_iter_meta meta;
 48         struct bpf_prog *prog;
 49         int ret = 0;
 50 
 51         ctx.meta = &meta;
 52         ctx.prog = v;
 53         meta.seq = seq;
 54         prog = bpf_iter_get_info(&meta, in_stop);
 55         if (prog)
 56                 ret = bpf_iter_run_prog(prog, &ctx);
 57 
 58         return ret;
 59 }
 60 
 61 static int bpf_prog_seq_show(struct seq_file *seq, void *v)
 62 {
 63         return __bpf_prog_seq_show(seq, v, false);
 64 }
 65 
 66 static void bpf_prog_seq_stop(struct seq_file *seq, void *v)
 67 {
 68         if (!v)
 69                 (void)__bpf_prog_seq_show(seq, v, true);
 70         else
 71                 bpf_prog_put((struct bpf_prog *)v);
 72 }
 73 
 74 static const struct seq_operations bpf_prog_seq_ops = {
 75         .start  = bpf_prog_seq_start,
 76         .next   = bpf_prog_seq_next,
 77         .stop   = bpf_prog_seq_stop,
 78         .show   = bpf_prog_seq_show,
 79 };
 80 
 81 BTF_ID_LIST(btf_bpf_prog_id)
 82 BTF_ID(struct, bpf_prog)
 83 
 84 static const struct bpf_iter_seq_info bpf_prog_seq_info = {
 85         .seq_ops                = &bpf_prog_seq_ops,
 86         .init_seq_private       = NULL,
 87         .fini_seq_private       = NULL,
 88         .seq_priv_size          = sizeof(struct bpf_iter_seq_prog_info),
 89 };
 90 
 91 static struct bpf_iter_reg bpf_prog_reg_info = {
 92         .target                 = "bpf_prog",
 93         .ctx_arg_info_size      = 1,
 94         .ctx_arg_info           = {
 95                 { offsetof(struct bpf_iter__bpf_prog, prog),
 96                   PTR_TO_BTF_ID_OR_NULL },
 97         },
 98         .seq_info               = &bpf_prog_seq_info,
 99 };
100 
101 static int __init bpf_prog_iter_init(void)
102 {
103         bpf_prog_reg_info.ctx_arg_info[0].btf_id = *btf_bpf_prog_id;
104         return bpf_iter_reg_target(&bpf_prog_reg_info);
105 }
106 
107 late_initcall(bpf_prog_iter_init);
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php