@@ -113,7 +113,7 @@ struct dentry *kvm_debugfs_dir;
113
113
EXPORT_SYMBOL_GPL (kvm_debugfs_dir );
114
114
115
115
static int kvm_debugfs_num_entries ;
116
- static const struct file_operations * stat_fops_per_vm [] ;
116
+ static const struct file_operations stat_fops_per_vm ;
117
117
118
118
static long kvm_vcpu_ioctl (struct file * file , unsigned int ioctl ,
119
119
unsigned long arg );
@@ -650,11 +650,11 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
650
650
return - ENOMEM ;
651
651
652
652
stat_data -> kvm = kvm ;
653
- stat_data -> offset = p -> offset ;
654
- stat_data -> mode = p -> mode ? p -> mode : 0644 ;
653
+ stat_data -> dbgfs_item = p ;
655
654
kvm -> debugfs_stat_data [p - debugfs_entries ] = stat_data ;
656
- debugfs_create_file (p -> name , stat_data -> mode , kvm -> debugfs_dentry ,
657
- stat_data , stat_fops_per_vm [p -> kind ]);
655
+ debugfs_create_file (p -> name , KVM_DBGFS_GET_MODE (p ),
656
+ kvm -> debugfs_dentry , stat_data ,
657
+ & stat_fops_per_vm );
658
658
}
659
659
return 0 ;
660
660
}
@@ -4010,8 +4010,9 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file,
4010
4010
return - ENOENT ;
4011
4011
4012
4012
if (simple_attr_open (inode , file , get ,
4013
- stat_data -> mode & S_IWUGO ? set : NULL ,
4014
- fmt )) {
4013
+ KVM_DBGFS_GET_MODE (stat_data -> dbgfs_item ) & 0222
4014
+ ? set : NULL ,
4015
+ fmt )) {
4015
4016
kvm_put_kvm (stat_data -> kvm );
4016
4017
return - ENOMEM ;
4017
4018
}
@@ -4030,105 +4031,111 @@ static int kvm_debugfs_release(struct inode *inode, struct file *file)
4030
4031
return 0 ;
4031
4032
}
4032
4033
4033
- static int vm_stat_get_per_vm ( void * data , u64 * val )
4034
+ static int kvm_get_stat_per_vm ( struct kvm * kvm , size_t offset , u64 * val )
4034
4035
{
4035
- struct kvm_stat_data * stat_data = ( struct kvm_stat_data * )data ;
4036
+ * val = * ( ulong * )(( void * )kvm + offset ) ;
4036
4037
4037
- * val = * (ulong * )((void * )stat_data -> kvm + stat_data -> offset );
4038
+ return 0 ;
4039
+ }
4040
+
4041
+ static int kvm_clear_stat_per_vm (struct kvm * kvm , size_t offset )
4042
+ {
4043
+ * (ulong * )((void * )kvm + offset ) = 0 ;
4038
4044
4039
4045
return 0 ;
4040
4046
}
4041
4047
4042
- static int vm_stat_clear_per_vm ( void * data , u64 val )
4048
+ static int kvm_get_stat_per_vcpu ( struct kvm * kvm , size_t offset , u64 * val )
4043
4049
{
4044
- struct kvm_stat_data * stat_data = (struct kvm_stat_data * )data ;
4050
+ int i ;
4051
+ struct kvm_vcpu * vcpu ;
4045
4052
4046
- if (val )
4047
- return - EINVAL ;
4053
+ * val = 0 ;
4048
4054
4049
- * (ulong * )((void * )stat_data -> kvm + stat_data -> offset ) = 0 ;
4055
+ kvm_for_each_vcpu (i , vcpu , kvm )
4056
+ * val += * (u64 * )((void * )vcpu + offset );
4050
4057
4051
4058
return 0 ;
4052
4059
}
4053
4060
4054
- static int vm_stat_get_per_vm_open (struct inode * inode , struct file * file )
4061
+ static int kvm_clear_stat_per_vcpu (struct kvm * kvm , size_t offset )
4055
4062
{
4056
- __simple_attr_check_format ("%llu\n" , 0ull );
4057
- return kvm_debugfs_open (inode , file , vm_stat_get_per_vm ,
4058
- vm_stat_clear_per_vm , "%llu\n" );
4059
- }
4063
+ int i ;
4064
+ struct kvm_vcpu * vcpu ;
4060
4065
4061
- static const struct file_operations vm_stat_get_per_vm_fops = {
4062
- .owner = THIS_MODULE ,
4063
- .open = vm_stat_get_per_vm_open ,
4064
- .release = kvm_debugfs_release ,
4065
- .read = simple_attr_read ,
4066
- .write = simple_attr_write ,
4067
- .llseek = no_llseek ,
4068
- };
4066
+ kvm_for_each_vcpu (i , vcpu , kvm )
4067
+ * (u64 * )((void * )vcpu + offset ) = 0 ;
4068
+
4069
+ return 0 ;
4070
+ }
4069
4071
4070
- static int vcpu_stat_get_per_vm (void * data , u64 * val )
4072
+ static int kvm_stat_data_get (void * data , u64 * val )
4071
4073
{
4072
- int i ;
4074
+ int r = - EFAULT ;
4073
4075
struct kvm_stat_data * stat_data = (struct kvm_stat_data * )data ;
4074
- struct kvm_vcpu * vcpu ;
4075
-
4076
- * val = 0 ;
4077
4076
4078
- kvm_for_each_vcpu (i , vcpu , stat_data -> kvm )
4079
- * val += * (u64 * )((void * )vcpu + stat_data -> offset );
4077
+ switch (stat_data -> dbgfs_item -> kind ) {
4078
+ case KVM_STAT_VM :
4079
+ r = kvm_get_stat_per_vm (stat_data -> kvm ,
4080
+ stat_data -> dbgfs_item -> offset , val );
4081
+ break ;
4082
+ case KVM_STAT_VCPU :
4083
+ r = kvm_get_stat_per_vcpu (stat_data -> kvm ,
4084
+ stat_data -> dbgfs_item -> offset , val );
4085
+ break ;
4086
+ }
4080
4087
4081
- return 0 ;
4088
+ return r ;
4082
4089
}
4083
4090
4084
- static int vcpu_stat_clear_per_vm (void * data , u64 val )
4091
+ static int kvm_stat_data_clear (void * data , u64 val )
4085
4092
{
4086
- int i ;
4093
+ int r = - EFAULT ;
4087
4094
struct kvm_stat_data * stat_data = (struct kvm_stat_data * )data ;
4088
- struct kvm_vcpu * vcpu ;
4089
4095
4090
4096
if (val )
4091
4097
return - EINVAL ;
4092
4098
4093
- kvm_for_each_vcpu (i , vcpu , stat_data -> kvm )
4094
- * (u64 * )((void * )vcpu + stat_data -> offset ) = 0 ;
4099
+ switch (stat_data -> dbgfs_item -> kind ) {
4100
+ case KVM_STAT_VM :
4101
+ r = kvm_clear_stat_per_vm (stat_data -> kvm ,
4102
+ stat_data -> dbgfs_item -> offset );
4103
+ break ;
4104
+ case KVM_STAT_VCPU :
4105
+ r = kvm_clear_stat_per_vcpu (stat_data -> kvm ,
4106
+ stat_data -> dbgfs_item -> offset );
4107
+ break ;
4108
+ }
4095
4109
4096
- return 0 ;
4110
+ return r ;
4097
4111
}
4098
4112
4099
- static int vcpu_stat_get_per_vm_open (struct inode * inode , struct file * file )
4113
+ static int kvm_stat_data_open (struct inode * inode , struct file * file )
4100
4114
{
4101
4115
__simple_attr_check_format ("%llu\n" , 0ull );
4102
- return kvm_debugfs_open (inode , file , vcpu_stat_get_per_vm ,
4103
- vcpu_stat_clear_per_vm , "%llu\n" );
4116
+ return kvm_debugfs_open (inode , file , kvm_stat_data_get ,
4117
+ kvm_stat_data_clear , "%llu\n" );
4104
4118
}
4105
4119
4106
- static const struct file_operations vcpu_stat_get_per_vm_fops = {
4107
- .owner = THIS_MODULE ,
4108
- .open = vcpu_stat_get_per_vm_open ,
4120
+ static const struct file_operations stat_fops_per_vm = {
4121
+ .owner = THIS_MODULE ,
4122
+ .open = kvm_stat_data_open ,
4109
4123
.release = kvm_debugfs_release ,
4110
- .read = simple_attr_read ,
4111
- .write = simple_attr_write ,
4112
- .llseek = no_llseek ,
4113
- };
4114
-
4115
- static const struct file_operations * stat_fops_per_vm [] = {
4116
- [KVM_STAT_VCPU ] = & vcpu_stat_get_per_vm_fops ,
4117
- [KVM_STAT_VM ] = & vm_stat_get_per_vm_fops ,
4124
+ .read = simple_attr_read ,
4125
+ .write = simple_attr_write ,
4126
+ .llseek = no_llseek ,
4118
4127
};
4119
4128
4120
4129
static int vm_stat_get (void * _offset , u64 * val )
4121
4130
{
4122
4131
unsigned offset = (long )_offset ;
4123
4132
struct kvm * kvm ;
4124
- struct kvm_stat_data stat_tmp = {.offset = offset };
4125
4133
u64 tmp_val ;
4126
4134
4127
4135
* val = 0 ;
4128
4136
mutex_lock (& kvm_lock );
4129
4137
list_for_each_entry (kvm , & vm_list , vm_list ) {
4130
- stat_tmp .kvm = kvm ;
4131
- vm_stat_get_per_vm ((void * )& stat_tmp , & tmp_val );
4138
+ kvm_get_stat_per_vm (kvm , offset , & tmp_val );
4132
4139
* val += tmp_val ;
4133
4140
}
4134
4141
mutex_unlock (& kvm_lock );
@@ -4139,15 +4146,13 @@ static int vm_stat_clear(void *_offset, u64 val)
4139
4146
{
4140
4147
unsigned offset = (long )_offset ;
4141
4148
struct kvm * kvm ;
4142
- struct kvm_stat_data stat_tmp = {.offset = offset };
4143
4149
4144
4150
if (val )
4145
4151
return - EINVAL ;
4146
4152
4147
4153
mutex_lock (& kvm_lock );
4148
4154
list_for_each_entry (kvm , & vm_list , vm_list ) {
4149
- stat_tmp .kvm = kvm ;
4150
- vm_stat_clear_per_vm ((void * )& stat_tmp , 0 );
4155
+ kvm_clear_stat_per_vm (kvm , offset );
4151
4156
}
4152
4157
mutex_unlock (& kvm_lock );
4153
4158
@@ -4160,14 +4165,12 @@ static int vcpu_stat_get(void *_offset, u64 *val)
4160
4165
{
4161
4166
unsigned offset = (long )_offset ;
4162
4167
struct kvm * kvm ;
4163
- struct kvm_stat_data stat_tmp = {.offset = offset };
4164
4168
u64 tmp_val ;
4165
4169
4166
4170
* val = 0 ;
4167
4171
mutex_lock (& kvm_lock );
4168
4172
list_for_each_entry (kvm , & vm_list , vm_list ) {
4169
- stat_tmp .kvm = kvm ;
4170
- vcpu_stat_get_per_vm ((void * )& stat_tmp , & tmp_val );
4173
+ kvm_get_stat_per_vcpu (kvm , offset , & tmp_val );
4171
4174
* val += tmp_val ;
4172
4175
}
4173
4176
mutex_unlock (& kvm_lock );
@@ -4178,15 +4181,13 @@ static int vcpu_stat_clear(void *_offset, u64 val)
4178
4181
{
4179
4182
unsigned offset = (long )_offset ;
4180
4183
struct kvm * kvm ;
4181
- struct kvm_stat_data stat_tmp = {.offset = offset };
4182
4184
4183
4185
if (val )
4184
4186
return - EINVAL ;
4185
4187
4186
4188
mutex_lock (& kvm_lock );
4187
4189
list_for_each_entry (kvm , & vm_list , vm_list ) {
4188
- stat_tmp .kvm = kvm ;
4189
- vcpu_stat_clear_per_vm ((void * )& stat_tmp , 0 );
4190
+ kvm_clear_stat_per_vcpu (kvm , offset );
4190
4191
}
4191
4192
mutex_unlock (& kvm_lock );
4192
4193
@@ -4259,9 +4260,8 @@ static void kvm_init_debug(void)
4259
4260
4260
4261
kvm_debugfs_num_entries = 0 ;
4261
4262
for (p = debugfs_entries ; p -> name ; ++ p , kvm_debugfs_num_entries ++ ) {
4262
- int mode = p -> mode ? p -> mode : 0644 ;
4263
- debugfs_create_file (p -> name , mode , kvm_debugfs_dir ,
4264
- (void * )(long )p -> offset ,
4263
+ debugfs_create_file (p -> name , KVM_DBGFS_GET_MODE (p ),
4264
+ kvm_debugfs_dir , (void * )(long )p -> offset ,
4265
4265
stat_fops [p -> kind ]);
4266
4266
}
4267
4267
}
0 commit comments