1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <linux/error-injection.h>
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/sysfs.h>
7 #include <linux/tracepoint.h>
8 #include "bpf_testmod.h"
10 #define CREATE_TRACE_POINTS
11 #include "bpf_testmod-events.h"
14 bpf_testmod_test_read(struct file
*file
, struct kobject
*kobj
,
15 struct bin_attribute
*bin_attr
,
16 char *buf
, loff_t off
, size_t len
)
18 struct bpf_testmod_test_read_ctx ctx
= {
24 trace_bpf_testmod_test_read(current
, &ctx
);
26 return -EIO
; /* always fail */
28 EXPORT_SYMBOL(bpf_testmod_test_read
);
29 ALLOW_ERROR_INJECTION(bpf_testmod_test_read
, ERRNO
);
31 static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init
= {
32 .attr
= { .name
= "bpf_testmod", .mode
= 0444, },
33 .read
= bpf_testmod_test_read
,
36 static int bpf_testmod_init(void)
38 return sysfs_create_bin_file(kernel_kobj
, &bin_attr_bpf_testmod_file
);
41 static void bpf_testmod_exit(void)
43 return sysfs_remove_bin_file(kernel_kobj
, &bin_attr_bpf_testmod_file
);
46 module_init(bpf_testmod_init
);
47 module_exit(bpf_testmod_exit
);
49 MODULE_AUTHOR("Andrii Nakryiko");
50 MODULE_DESCRIPTION("BPF selftests module");
51 MODULE_LICENSE("Dual BSD/GPL");