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" 9 10 #define CREATE_TRACE_POINTS 11 #include "bpf_testmod-events.h" 12 13 noinline ssize_t 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) 17 { 18 struct bpf_testmod_test_read_ctx ctx = { 19 .buf = buf, 20 .off = off, 21 .len = len, 22 }; 23 24 trace_bpf_testmod_test_read(current, &ctx); 25 26 return -EIO; /* always fail */ 27 } 28 EXPORT_SYMBOL(bpf_testmod_test_read); 29 ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO); 30 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, 34 }; 35 36 static int bpf_testmod_init(void) 37 { 38 return sysfs_create_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file); 39 } 40 41 static void bpf_testmod_exit(void) 42 { 43 return sysfs_remove_bin_file(kernel_kobj, &bin_attr_bpf_testmod_file); 44 } 45 46 module_init(bpf_testmod_init); 47 module_exit(bpf_testmod_exit); 48 49 MODULE_AUTHOR("Andrii Nakryiko"); 50 MODULE_DESCRIPTION("BPF selftests module"); 51 MODULE_LICENSE("Dual BSD/GPL"); 52 53