0001
0002
0003
0004
0005
0006
0007 #include <linux/hyperv.h>
0008 #include <linux/debugfs.h>
0009 #include <linux/delay.h>
0010 #include <linux/err.h>
0011
0012 #include "hyperv_vmbus.h"
0013
0014 static struct dentry *hv_debug_root;
0015
0016 static int hv_debugfs_delay_get(void *data, u64 *val)
0017 {
0018 *val = *(u32 *)data;
0019 return 0;
0020 }
0021
0022 static int hv_debugfs_delay_set(void *data, u64 val)
0023 {
0024 if (val > 1000)
0025 return -EINVAL;
0026 *(u32 *)data = val;
0027 return 0;
0028 }
0029
0030 DEFINE_DEBUGFS_ATTRIBUTE(hv_debugfs_delay_fops, hv_debugfs_delay_get,
0031 hv_debugfs_delay_set, "%llu\n");
0032
0033 static int hv_debugfs_state_get(void *data, u64 *val)
0034 {
0035 *val = *(bool *)data;
0036 return 0;
0037 }
0038
0039 static int hv_debugfs_state_set(void *data, u64 val)
0040 {
0041 if (val == 1)
0042 *(bool *)data = true;
0043 else if (val == 0)
0044 *(bool *)data = false;
0045 else
0046 return -EINVAL;
0047 return 0;
0048 }
0049
0050 DEFINE_DEBUGFS_ATTRIBUTE(hv_debugfs_state_fops, hv_debugfs_state_get,
0051 hv_debugfs_state_set, "%llu\n");
0052
0053
0054 static int hv_debug_delay_files(struct hv_device *dev, struct dentry *root)
0055 {
0056 struct vmbus_channel *channel = dev->channel;
0057 char *buffer = "fuzz_test_buffer_interrupt_delay";
0058 char *message = "fuzz_test_message_delay";
0059 int *buffer_val = &channel->fuzz_testing_interrupt_delay;
0060 int *message_val = &channel->fuzz_testing_message_delay;
0061 struct dentry *buffer_file, *message_file;
0062
0063 buffer_file = debugfs_create_file(buffer, 0644, root,
0064 buffer_val,
0065 &hv_debugfs_delay_fops);
0066 if (IS_ERR(buffer_file)) {
0067 pr_debug("debugfs_hyperv: file %s not created\n", buffer);
0068 return PTR_ERR(buffer_file);
0069 }
0070
0071 message_file = debugfs_create_file(message, 0644, root,
0072 message_val,
0073 &hv_debugfs_delay_fops);
0074 if (IS_ERR(message_file)) {
0075 pr_debug("debugfs_hyperv: file %s not created\n", message);
0076 return PTR_ERR(message_file);
0077 }
0078
0079 return 0;
0080 }
0081
0082
0083 static int hv_debug_set_test_state(struct hv_device *dev, struct dentry *root)
0084 {
0085 struct vmbus_channel *channel = dev->channel;
0086 bool *state = &channel->fuzz_testing_state;
0087 char *status = "fuzz_test_state";
0088 struct dentry *test_state;
0089
0090 test_state = debugfs_create_file(status, 0644, root,
0091 state,
0092 &hv_debugfs_state_fops);
0093 if (IS_ERR(test_state)) {
0094 pr_debug("debugfs_hyperv: file %s not created\n", status);
0095 return PTR_ERR(test_state);
0096 }
0097
0098 return 0;
0099 }
0100
0101
0102 static void hv_debug_set_dir_dentry(struct hv_device *dev, struct dentry *root)
0103 {
0104 if (hv_debug_root)
0105 dev->debug_dir = root;
0106 }
0107
0108
0109 int hv_debug_add_dev_dir(struct hv_device *dev)
0110 {
0111 const char *device = dev_name(&dev->device);
0112 char *delay_name = "delay";
0113 struct dentry *delay, *dev_root;
0114 int ret;
0115
0116 if (!IS_ERR(hv_debug_root)) {
0117 dev_root = debugfs_create_dir(device, hv_debug_root);
0118 if (IS_ERR(dev_root)) {
0119 pr_debug("debugfs_hyperv: hyperv/%s/ not created\n",
0120 device);
0121 return PTR_ERR(dev_root);
0122 }
0123 hv_debug_set_test_state(dev, dev_root);
0124 hv_debug_set_dir_dentry(dev, dev_root);
0125 delay = debugfs_create_dir(delay_name, dev_root);
0126
0127 if (IS_ERR(delay)) {
0128 pr_debug("debugfs_hyperv: hyperv/%s/%s/ not created\n",
0129 device, delay_name);
0130 return PTR_ERR(delay);
0131 }
0132 ret = hv_debug_delay_files(dev, delay);
0133
0134 return ret;
0135 }
0136 pr_debug("debugfs_hyperv: hyperv/ not in root debugfs path\n");
0137 return PTR_ERR(hv_debug_root);
0138 }
0139
0140
0141 void hv_debug_rm_dev_dir(struct hv_device *dev)
0142 {
0143 if (!IS_ERR(hv_debug_root))
0144 debugfs_remove_recursive(dev->debug_dir);
0145 }
0146
0147
0148 void hv_debug_rm_all_dir(void)
0149 {
0150 debugfs_remove_recursive(hv_debug_root);
0151 }
0152
0153
0154 void hv_debug_delay_test(struct vmbus_channel *channel, enum delay delay_type)
0155 {
0156 struct vmbus_channel *test_channel = channel->primary_channel ?
0157 channel->primary_channel :
0158 channel;
0159 bool state = test_channel->fuzz_testing_state;
0160
0161 if (state) {
0162 if (delay_type == 0)
0163 udelay(test_channel->fuzz_testing_interrupt_delay);
0164 else
0165 udelay(test_channel->fuzz_testing_message_delay);
0166 }
0167 }
0168
0169
0170 int hv_debug_init(void)
0171 {
0172 hv_debug_root = debugfs_create_dir("hyperv", NULL);
0173 if (IS_ERR(hv_debug_root)) {
0174 pr_debug("debugfs_hyperv: hyperv/ not created\n");
0175 return PTR_ERR(hv_debug_root);
0176 }
0177 return 0;
0178 }