bcma: claim only 14e4:4365 PCI Dell card with SoftMAC BCM43142
[linux/fpc-iii.git] / tools / perf / util / bpf-loader.c
blob540a7efa657ea8668eeddf1b476bbcb3c0490bbc
1 /*
2 * bpf-loader.c
4 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
5 * Copyright (C) 2015 Huawei Inc.
6 */
8 #include <linux/bpf.h>
9 #include <bpf/libbpf.h>
10 #include <linux/err.h>
11 #include <linux/string.h>
12 #include "perf.h"
13 #include "debug.h"
14 #include "bpf-loader.h"
15 #include "bpf-prologue.h"
16 #include "llvm-utils.h"
17 #include "probe-event.h"
18 #include "probe-finder.h" // for MAX_PROBES
19 #include "llvm-utils.h"
21 #define DEFINE_PRINT_FN(name, level) \
22 static int libbpf_##name(const char *fmt, ...) \
23 { \
24 va_list args; \
25 int ret; \
27 va_start(args, fmt); \
28 ret = veprintf(level, verbose, pr_fmt(fmt), args);\
29 va_end(args); \
30 return ret; \
33 DEFINE_PRINT_FN(warning, 1)
34 DEFINE_PRINT_FN(info, 1)
35 DEFINE_PRINT_FN(debug, 1)
37 struct bpf_prog_priv {
38 struct perf_probe_event pev;
39 bool need_prologue;
40 struct bpf_insn *insns_buf;
41 int nr_types;
42 int *type_mapping;
45 static bool libbpf_initialized;
47 struct bpf_object *
48 bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
50 struct bpf_object *obj;
52 if (!libbpf_initialized) {
53 libbpf_set_print(libbpf_warning,
54 libbpf_info,
55 libbpf_debug);
56 libbpf_initialized = true;
59 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
60 if (IS_ERR(obj)) {
61 pr_debug("bpf: failed to load buffer\n");
62 return ERR_PTR(-EINVAL);
65 return obj;
68 struct bpf_object *bpf__prepare_load(const char *filename, bool source)
70 struct bpf_object *obj;
72 if (!libbpf_initialized) {
73 libbpf_set_print(libbpf_warning,
74 libbpf_info,
75 libbpf_debug);
76 libbpf_initialized = true;
79 if (source) {
80 int err;
81 void *obj_buf;
82 size_t obj_buf_sz;
84 err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
85 if (err)
86 return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
87 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
88 free(obj_buf);
89 } else
90 obj = bpf_object__open(filename);
92 if (IS_ERR(obj)) {
93 pr_debug("bpf: failed to load %s\n", filename);
94 return obj;
97 return obj;
100 void bpf__clear(void)
102 struct bpf_object *obj, *tmp;
104 bpf_object__for_each_safe(obj, tmp) {
105 bpf__unprobe(obj);
106 bpf_object__close(obj);
110 static void
111 bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused,
112 void *_priv)
114 struct bpf_prog_priv *priv = _priv;
116 cleanup_perf_probe_events(&priv->pev, 1);
117 zfree(&priv->insns_buf);
118 zfree(&priv->type_mapping);
119 free(priv);
122 static int
123 prog_config__exec(const char *value, struct perf_probe_event *pev)
125 pev->uprobes = true;
126 pev->target = strdup(value);
127 if (!pev->target)
128 return -ENOMEM;
129 return 0;
132 static int
133 prog_config__module(const char *value, struct perf_probe_event *pev)
135 pev->uprobes = false;
136 pev->target = strdup(value);
137 if (!pev->target)
138 return -ENOMEM;
139 return 0;
142 static int
143 prog_config__bool(const char *value, bool *pbool, bool invert)
145 int err;
146 bool bool_value;
148 if (!pbool)
149 return -EINVAL;
151 err = strtobool(value, &bool_value);
152 if (err)
153 return err;
155 *pbool = invert ? !bool_value : bool_value;
156 return 0;
159 static int
160 prog_config__inlines(const char *value,
161 struct perf_probe_event *pev __maybe_unused)
163 return prog_config__bool(value, &probe_conf.no_inlines, true);
166 static int
167 prog_config__force(const char *value,
168 struct perf_probe_event *pev __maybe_unused)
170 return prog_config__bool(value, &probe_conf.force_add, false);
173 static struct {
174 const char *key;
175 const char *usage;
176 const char *desc;
177 int (*func)(const char *, struct perf_probe_event *);
178 } bpf_prog_config_terms[] = {
180 .key = "exec",
181 .usage = "exec=<full path of file>",
182 .desc = "Set uprobe target",
183 .func = prog_config__exec,
186 .key = "module",
187 .usage = "module=<module name> ",
188 .desc = "Set kprobe module",
189 .func = prog_config__module,
192 .key = "inlines",
193 .usage = "inlines=[yes|no] ",
194 .desc = "Probe at inline symbol",
195 .func = prog_config__inlines,
198 .key = "force",
199 .usage = "force=[yes|no] ",
200 .desc = "Forcibly add events with existing name",
201 .func = prog_config__force,
205 static int
206 do_prog_config(const char *key, const char *value,
207 struct perf_probe_event *pev)
209 unsigned int i;
211 pr_debug("config bpf program: %s=%s\n", key, value);
212 for (i = 0; i < ARRAY_SIZE(bpf_prog_config_terms); i++)
213 if (strcmp(key, bpf_prog_config_terms[i].key) == 0)
214 return bpf_prog_config_terms[i].func(value, pev);
216 pr_debug("BPF: ERROR: invalid program config option: %s=%s\n",
217 key, value);
219 pr_debug("\nHint: Valid options are:\n");
220 for (i = 0; i < ARRAY_SIZE(bpf_prog_config_terms); i++)
221 pr_debug("\t%s:\t%s\n", bpf_prog_config_terms[i].usage,
222 bpf_prog_config_terms[i].desc);
223 pr_debug("\n");
225 return -BPF_LOADER_ERRNO__PROGCONF_TERM;
228 static const char *
229 parse_prog_config_kvpair(const char *config_str, struct perf_probe_event *pev)
231 char *text = strdup(config_str);
232 char *sep, *line;
233 const char *main_str = NULL;
234 int err = 0;
236 if (!text) {
237 pr_debug("No enough memory: dup config_str failed\n");
238 return ERR_PTR(-ENOMEM);
241 line = text;
242 while ((sep = strchr(line, ';'))) {
243 char *equ;
245 *sep = '\0';
246 equ = strchr(line, '=');
247 if (!equ) {
248 pr_warning("WARNING: invalid config in BPF object: %s\n",
249 line);
250 pr_warning("\tShould be 'key=value'.\n");
251 goto nextline;
253 *equ = '\0';
255 err = do_prog_config(line, equ + 1, pev);
256 if (err)
257 break;
258 nextline:
259 line = sep + 1;
262 if (!err)
263 main_str = config_str + (line - text);
264 free(text);
266 return err ? ERR_PTR(err) : main_str;
269 static int
270 parse_prog_config(const char *config_str, struct perf_probe_event *pev)
272 int err;
273 const char *main_str = parse_prog_config_kvpair(config_str, pev);
275 if (IS_ERR(main_str))
276 return PTR_ERR(main_str);
278 err = parse_perf_probe_command(main_str, pev);
279 if (err < 0) {
280 pr_debug("bpf: '%s' is not a valid config string\n",
281 config_str);
282 /* parse failed, don't need clear pev. */
283 return -BPF_LOADER_ERRNO__CONFIG;
285 return 0;
288 static int
289 config_bpf_program(struct bpf_program *prog)
291 struct perf_probe_event *pev = NULL;
292 struct bpf_prog_priv *priv = NULL;
293 const char *config_str;
294 int err;
296 /* Initialize per-program probing setting */
297 probe_conf.no_inlines = false;
298 probe_conf.force_add = false;
300 config_str = bpf_program__title(prog, false);
301 if (IS_ERR(config_str)) {
302 pr_debug("bpf: unable to get title for program\n");
303 return PTR_ERR(config_str);
306 priv = calloc(sizeof(*priv), 1);
307 if (!priv) {
308 pr_debug("bpf: failed to alloc priv\n");
309 return -ENOMEM;
311 pev = &priv->pev;
313 pr_debug("bpf: config program '%s'\n", config_str);
314 err = parse_prog_config(config_str, pev);
315 if (err)
316 goto errout;
318 if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) {
319 pr_debug("bpf: '%s': group for event is set and not '%s'.\n",
320 config_str, PERF_BPF_PROBE_GROUP);
321 err = -BPF_LOADER_ERRNO__GROUP;
322 goto errout;
323 } else if (!pev->group)
324 pev->group = strdup(PERF_BPF_PROBE_GROUP);
326 if (!pev->group) {
327 pr_debug("bpf: strdup failed\n");
328 err = -ENOMEM;
329 goto errout;
332 if (!pev->event) {
333 pr_debug("bpf: '%s': event name is missing. Section name should be 'key=value'\n",
334 config_str);
335 err = -BPF_LOADER_ERRNO__EVENTNAME;
336 goto errout;
338 pr_debug("bpf: config '%s' is ok\n", config_str);
340 err = bpf_program__set_private(prog, priv, bpf_prog_priv__clear);
341 if (err) {
342 pr_debug("Failed to set priv for program '%s'\n", config_str);
343 goto errout;
346 return 0;
348 errout:
349 if (pev)
350 clear_perf_probe_event(pev);
351 free(priv);
352 return err;
355 static int bpf__prepare_probe(void)
357 static int err = 0;
358 static bool initialized = false;
361 * Make err static, so if init failed the first, bpf__prepare_probe()
362 * fails each time without calling init_probe_symbol_maps multiple
363 * times.
365 if (initialized)
366 return err;
368 initialized = true;
369 err = init_probe_symbol_maps(false);
370 if (err < 0)
371 pr_debug("Failed to init_probe_symbol_maps\n");
372 probe_conf.max_probes = MAX_PROBES;
373 return err;
376 static int
377 preproc_gen_prologue(struct bpf_program *prog, int n,
378 struct bpf_insn *orig_insns, int orig_insns_cnt,
379 struct bpf_prog_prep_result *res)
381 struct probe_trace_event *tev;
382 struct perf_probe_event *pev;
383 struct bpf_prog_priv *priv;
384 struct bpf_insn *buf;
385 size_t prologue_cnt = 0;
386 int i, err;
388 err = bpf_program__get_private(prog, (void **)&priv);
389 if (err || !priv)
390 goto errout;
392 pev = &priv->pev;
394 if (n < 0 || n >= priv->nr_types)
395 goto errout;
397 /* Find a tev belongs to that type */
398 for (i = 0; i < pev->ntevs; i++) {
399 if (priv->type_mapping[i] == n)
400 break;
403 if (i >= pev->ntevs) {
404 pr_debug("Internal error: prologue type %d not found\n", n);
405 return -BPF_LOADER_ERRNO__PROLOGUE;
408 tev = &pev->tevs[i];
410 buf = priv->insns_buf;
411 err = bpf__gen_prologue(tev->args, tev->nargs,
412 buf, &prologue_cnt,
413 BPF_MAXINSNS - orig_insns_cnt);
414 if (err) {
415 const char *title;
417 title = bpf_program__title(prog, false);
418 if (!title)
419 title = "[unknown]";
421 pr_debug("Failed to generate prologue for program %s\n",
422 title);
423 return err;
426 memcpy(&buf[prologue_cnt], orig_insns,
427 sizeof(struct bpf_insn) * orig_insns_cnt);
429 res->new_insn_ptr = buf;
430 res->new_insn_cnt = prologue_cnt + orig_insns_cnt;
431 res->pfd = NULL;
432 return 0;
434 errout:
435 pr_debug("Internal error in preproc_gen_prologue\n");
436 return -BPF_LOADER_ERRNO__PROLOGUE;
440 * compare_tev_args is reflexive, transitive and antisymmetric.
441 * I can proof it but this margin is too narrow to contain.
443 static int compare_tev_args(const void *ptev1, const void *ptev2)
445 int i, ret;
446 const struct probe_trace_event *tev1 =
447 *(const struct probe_trace_event **)ptev1;
448 const struct probe_trace_event *tev2 =
449 *(const struct probe_trace_event **)ptev2;
451 ret = tev2->nargs - tev1->nargs;
452 if (ret)
453 return ret;
455 for (i = 0; i < tev1->nargs; i++) {
456 struct probe_trace_arg *arg1, *arg2;
457 struct probe_trace_arg_ref *ref1, *ref2;
459 arg1 = &tev1->args[i];
460 arg2 = &tev2->args[i];
462 ret = strcmp(arg1->value, arg2->value);
463 if (ret)
464 return ret;
466 ref1 = arg1->ref;
467 ref2 = arg2->ref;
469 while (ref1 && ref2) {
470 ret = ref2->offset - ref1->offset;
471 if (ret)
472 return ret;
474 ref1 = ref1->next;
475 ref2 = ref2->next;
478 if (ref1 || ref2)
479 return ref2 ? 1 : -1;
482 return 0;
486 * Assign a type number to each tevs in a pev.
487 * mapping is an array with same slots as tevs in that pev.
488 * nr_types will be set to number of types.
490 static int map_prologue(struct perf_probe_event *pev, int *mapping,
491 int *nr_types)
493 int i, type = 0;
494 struct probe_trace_event **ptevs;
496 size_t array_sz = sizeof(*ptevs) * pev->ntevs;
498 ptevs = malloc(array_sz);
499 if (!ptevs) {
500 pr_debug("No ehough memory: alloc ptevs failed\n");
501 return -ENOMEM;
504 pr_debug("In map_prologue, ntevs=%d\n", pev->ntevs);
505 for (i = 0; i < pev->ntevs; i++)
506 ptevs[i] = &pev->tevs[i];
508 qsort(ptevs, pev->ntevs, sizeof(*ptevs),
509 compare_tev_args);
511 for (i = 0; i < pev->ntevs; i++) {
512 int n;
514 n = ptevs[i] - pev->tevs;
515 if (i == 0) {
516 mapping[n] = type;
517 pr_debug("mapping[%d]=%d\n", n, type);
518 continue;
521 if (compare_tev_args(ptevs + i, ptevs + i - 1) == 0)
522 mapping[n] = type;
523 else
524 mapping[n] = ++type;
526 pr_debug("mapping[%d]=%d\n", n, mapping[n]);
528 free(ptevs);
529 *nr_types = type + 1;
531 return 0;
534 static int hook_load_preprocessor(struct bpf_program *prog)
536 struct perf_probe_event *pev;
537 struct bpf_prog_priv *priv;
538 bool need_prologue = false;
539 int err, i;
541 err = bpf_program__get_private(prog, (void **)&priv);
542 if (err || !priv) {
543 pr_debug("Internal error when hook preprocessor\n");
544 return -BPF_LOADER_ERRNO__INTERNAL;
547 pev = &priv->pev;
548 for (i = 0; i < pev->ntevs; i++) {
549 struct probe_trace_event *tev = &pev->tevs[i];
551 if (tev->nargs > 0) {
552 need_prologue = true;
553 break;
558 * Since all tevs don't have argument, we don't need generate
559 * prologue.
561 if (!need_prologue) {
562 priv->need_prologue = false;
563 return 0;
566 priv->need_prologue = true;
567 priv->insns_buf = malloc(sizeof(struct bpf_insn) * BPF_MAXINSNS);
568 if (!priv->insns_buf) {
569 pr_debug("No enough memory: alloc insns_buf failed\n");
570 return -ENOMEM;
573 priv->type_mapping = malloc(sizeof(int) * pev->ntevs);
574 if (!priv->type_mapping) {
575 pr_debug("No enough memory: alloc type_mapping failed\n");
576 return -ENOMEM;
578 memset(priv->type_mapping, -1,
579 sizeof(int) * pev->ntevs);
581 err = map_prologue(pev, priv->type_mapping, &priv->nr_types);
582 if (err)
583 return err;
585 err = bpf_program__set_prep(prog, priv->nr_types,
586 preproc_gen_prologue);
587 return err;
590 int bpf__probe(struct bpf_object *obj)
592 int err = 0;
593 struct bpf_program *prog;
594 struct bpf_prog_priv *priv;
595 struct perf_probe_event *pev;
597 err = bpf__prepare_probe();
598 if (err) {
599 pr_debug("bpf__prepare_probe failed\n");
600 return err;
603 bpf_object__for_each_program(prog, obj) {
604 err = config_bpf_program(prog);
605 if (err)
606 goto out;
608 err = bpf_program__get_private(prog, (void **)&priv);
609 if (err || !priv)
610 goto out;
611 pev = &priv->pev;
613 err = convert_perf_probe_events(pev, 1);
614 if (err < 0) {
615 pr_debug("bpf_probe: failed to convert perf probe events");
616 goto out;
619 err = apply_perf_probe_events(pev, 1);
620 if (err < 0) {
621 pr_debug("bpf_probe: failed to apply perf probe events");
622 goto out;
626 * After probing, let's consider prologue, which
627 * adds program fetcher to BPF programs.
629 * hook_load_preprocessorr() hooks pre-processor
630 * to bpf_program, let it generate prologue
631 * dynamically during loading.
633 err = hook_load_preprocessor(prog);
634 if (err)
635 goto out;
637 out:
638 return err < 0 ? err : 0;
641 #define EVENTS_WRITE_BUFSIZE 4096
642 int bpf__unprobe(struct bpf_object *obj)
644 int err, ret = 0;
645 struct bpf_program *prog;
646 struct bpf_prog_priv *priv;
648 bpf_object__for_each_program(prog, obj) {
649 int i;
651 err = bpf_program__get_private(prog, (void **)&priv);
652 if (err || !priv)
653 continue;
655 for (i = 0; i < priv->pev.ntevs; i++) {
656 struct probe_trace_event *tev = &priv->pev.tevs[i];
657 char name_buf[EVENTS_WRITE_BUFSIZE];
658 struct strfilter *delfilter;
660 snprintf(name_buf, EVENTS_WRITE_BUFSIZE,
661 "%s:%s", tev->group, tev->event);
662 name_buf[EVENTS_WRITE_BUFSIZE - 1] = '\0';
664 delfilter = strfilter__new(name_buf, NULL);
665 if (!delfilter) {
666 pr_debug("Failed to create filter for unprobing\n");
667 ret = -ENOMEM;
668 continue;
671 err = del_perf_probe_events(delfilter);
672 strfilter__delete(delfilter);
673 if (err) {
674 pr_debug("Failed to delete %s\n", name_buf);
675 ret = err;
676 continue;
680 return ret;
683 int bpf__load(struct bpf_object *obj)
685 int err;
687 err = bpf_object__load(obj);
688 if (err) {
689 pr_debug("bpf: load objects failed\n");
690 return err;
692 return 0;
695 int bpf__foreach_tev(struct bpf_object *obj,
696 bpf_prog_iter_callback_t func,
697 void *arg)
699 struct bpf_program *prog;
700 int err;
702 bpf_object__for_each_program(prog, obj) {
703 struct probe_trace_event *tev;
704 struct perf_probe_event *pev;
705 struct bpf_prog_priv *priv;
706 int i, fd;
708 err = bpf_program__get_private(prog,
709 (void **)&priv);
710 if (err || !priv) {
711 pr_debug("bpf: failed to get private field\n");
712 return -BPF_LOADER_ERRNO__INTERNAL;
715 pev = &priv->pev;
716 for (i = 0; i < pev->ntevs; i++) {
717 tev = &pev->tevs[i];
719 if (priv->need_prologue) {
720 int type = priv->type_mapping[i];
722 fd = bpf_program__nth_fd(prog, type);
723 } else {
724 fd = bpf_program__fd(prog);
727 if (fd < 0) {
728 pr_debug("bpf: failed to get file descriptor\n");
729 return fd;
732 err = (*func)(tev, fd, arg);
733 if (err) {
734 pr_debug("bpf: call back failed, stop iterate\n");
735 return err;
739 return 0;
742 #define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START)
743 #define ERRCODE_OFFSET(c) ERRNO_OFFSET(BPF_LOADER_ERRNO__##c)
744 #define NR_ERRNO (__BPF_LOADER_ERRNO__END - __BPF_LOADER_ERRNO__START)
746 static const char *bpf_loader_strerror_table[NR_ERRNO] = {
747 [ERRCODE_OFFSET(CONFIG)] = "Invalid config string",
748 [ERRCODE_OFFSET(GROUP)] = "Invalid group name",
749 [ERRCODE_OFFSET(EVENTNAME)] = "No event name found in config string",
750 [ERRCODE_OFFSET(INTERNAL)] = "BPF loader internal error",
751 [ERRCODE_OFFSET(COMPILE)] = "Error when compiling BPF scriptlet",
752 [ERRCODE_OFFSET(PROGCONF_TERM)] = "Invalid program config term in config string",
753 [ERRCODE_OFFSET(PROLOGUE)] = "Failed to generate prologue",
754 [ERRCODE_OFFSET(PROLOGUE2BIG)] = "Prologue too big for program",
755 [ERRCODE_OFFSET(PROLOGUEOOB)] = "Offset out of bound for prologue",
758 static int
759 bpf_loader_strerror(int err, char *buf, size_t size)
761 char sbuf[STRERR_BUFSIZE];
762 const char *msg;
764 if (!buf || !size)
765 return -1;
767 err = err > 0 ? err : -err;
769 if (err >= __LIBBPF_ERRNO__START)
770 return libbpf_strerror(err, buf, size);
772 if (err >= __BPF_LOADER_ERRNO__START && err < __BPF_LOADER_ERRNO__END) {
773 msg = bpf_loader_strerror_table[ERRNO_OFFSET(err)];
774 snprintf(buf, size, "%s", msg);
775 buf[size - 1] = '\0';
776 return 0;
779 if (err >= __BPF_LOADER_ERRNO__END)
780 snprintf(buf, size, "Unknown bpf loader error %d", err);
781 else
782 snprintf(buf, size, "%s",
783 strerror_r(err, sbuf, sizeof(sbuf)));
785 buf[size - 1] = '\0';
786 return -1;
789 #define bpf__strerror_head(err, buf, size) \
790 char sbuf[STRERR_BUFSIZE], *emsg;\
791 if (!size)\
792 return 0;\
793 if (err < 0)\
794 err = -err;\
795 bpf_loader_strerror(err, sbuf, sizeof(sbuf));\
796 emsg = sbuf;\
797 switch (err) {\
798 default:\
799 scnprintf(buf, size, "%s", emsg);\
800 break;
802 #define bpf__strerror_entry(val, fmt...)\
803 case val: {\
804 scnprintf(buf, size, fmt);\
805 break;\
808 #define bpf__strerror_end(buf, size)\
810 buf[size - 1] = '\0';
812 int bpf__strerror_prepare_load(const char *filename, bool source,
813 int err, char *buf, size_t size)
815 size_t n;
816 int ret;
818 n = snprintf(buf, size, "Failed to load %s%s: ",
819 filename, source ? " from source" : "");
820 if (n >= size) {
821 buf[size - 1] = '\0';
822 return 0;
824 buf += n;
825 size -= n;
827 ret = bpf_loader_strerror(err, buf, size);
828 buf[size - 1] = '\0';
829 return ret;
832 int bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
833 int err, char *buf, size_t size)
835 bpf__strerror_head(err, buf, size);
836 case BPF_LOADER_ERRNO__PROGCONF_TERM: {
837 scnprintf(buf, size, "%s (add -v to see detail)", emsg);
838 break;
840 bpf__strerror_entry(EEXIST, "Probe point exist. Try 'perf probe -d \"*\"' and set 'force=yes'");
841 bpf__strerror_entry(EACCES, "You need to be root");
842 bpf__strerror_entry(EPERM, "You need to be root, and /proc/sys/kernel/kptr_restrict should be 0");
843 bpf__strerror_entry(ENOENT, "You need to check probing points in BPF file");
844 bpf__strerror_end(buf, size);
845 return 0;
848 int bpf__strerror_load(struct bpf_object *obj,
849 int err, char *buf, size_t size)
851 bpf__strerror_head(err, buf, size);
852 case LIBBPF_ERRNO__KVER: {
853 unsigned int obj_kver = bpf_object__get_kversion(obj);
854 unsigned int real_kver;
856 if (fetch_kernel_version(&real_kver, NULL, 0)) {
857 scnprintf(buf, size, "Unable to fetch kernel version");
858 break;
861 if (obj_kver != real_kver) {
862 scnprintf(buf, size,
863 "'version' ("KVER_FMT") doesn't match running kernel ("KVER_FMT")",
864 KVER_PARAM(obj_kver),
865 KVER_PARAM(real_kver));
866 break;
869 scnprintf(buf, size, "Failed to load program for unknown reason");
870 break;
872 bpf__strerror_end(buf, size);
873 return 0;