@@ -595,7 +595,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
595
595
stat_data -> kvm = kvm ;
596
596
stat_data -> offset = p -> offset ;
597
597
kvm -> debugfs_stat_data [p - debugfs_entries ] = stat_data ;
598
- if (!debugfs_create_file (p -> name , 0444 ,
598
+ if (!debugfs_create_file (p -> name , 0644 ,
599
599
kvm -> debugfs_dentry ,
600
600
stat_data ,
601
601
stat_fops_per_vm [p -> kind ]))
@@ -3663,11 +3663,23 @@ static int vm_stat_get_per_vm(void *data, u64 *val)
3663
3663
return 0 ;
3664
3664
}
3665
3665
3666
+ static int vm_stat_clear_per_vm (void * data , u64 val )
3667
+ {
3668
+ struct kvm_stat_data * stat_data = (struct kvm_stat_data * )data ;
3669
+
3670
+ if (val )
3671
+ return - EINVAL ;
3672
+
3673
+ * (ulong * )((void * )stat_data -> kvm + stat_data -> offset ) = 0 ;
3674
+
3675
+ return 0 ;
3676
+ }
3677
+
3666
3678
static int vm_stat_get_per_vm_open (struct inode * inode , struct file * file )
3667
3679
{
3668
3680
__simple_attr_check_format ("%llu\n" , 0ull );
3669
3681
return kvm_debugfs_open (inode , file , vm_stat_get_per_vm ,
3670
- NULL , "%llu\n" );
3682
+ vm_stat_clear_per_vm , "%llu\n" );
3671
3683
}
3672
3684
3673
3685
static const struct file_operations vm_stat_get_per_vm_fops = {
@@ -3693,11 +3705,26 @@ static int vcpu_stat_get_per_vm(void *data, u64 *val)
3693
3705
return 0 ;
3694
3706
}
3695
3707
3708
+ static int vcpu_stat_clear_per_vm (void * data , u64 val )
3709
+ {
3710
+ int i ;
3711
+ struct kvm_stat_data * stat_data = (struct kvm_stat_data * )data ;
3712
+ struct kvm_vcpu * vcpu ;
3713
+
3714
+ if (val )
3715
+ return - EINVAL ;
3716
+
3717
+ kvm_for_each_vcpu (i , vcpu , stat_data -> kvm )
3718
+ * (u64 * )((void * )vcpu + stat_data -> offset ) = 0 ;
3719
+
3720
+ return 0 ;
3721
+ }
3722
+
3696
3723
static int vcpu_stat_get_per_vm_open (struct inode * inode , struct file * file )
3697
3724
{
3698
3725
__simple_attr_check_format ("%llu\n" , 0ull );
3699
3726
return kvm_debugfs_open (inode , file , vcpu_stat_get_per_vm ,
3700
- NULL , "%llu\n" );
3727
+ vcpu_stat_clear_per_vm , "%llu\n" );
3701
3728
}
3702
3729
3703
3730
static const struct file_operations vcpu_stat_get_per_vm_fops = {
@@ -3732,7 +3759,26 @@ static int vm_stat_get(void *_offset, u64 *val)
3732
3759
return 0 ;
3733
3760
}
3734
3761
3735
- DEFINE_SIMPLE_ATTRIBUTE (vm_stat_fops , vm_stat_get , NULL , "%llu\n" );
3762
+ static int vm_stat_clear (void * _offset , u64 val )
3763
+ {
3764
+ unsigned offset = (long )_offset ;
3765
+ struct kvm * kvm ;
3766
+ struct kvm_stat_data stat_tmp = {.offset = offset };
3767
+
3768
+ if (val )
3769
+ return - EINVAL ;
3770
+
3771
+ spin_lock (& kvm_lock );
3772
+ list_for_each_entry (kvm , & vm_list , vm_list ) {
3773
+ stat_tmp .kvm = kvm ;
3774
+ vm_stat_clear_per_vm ((void * )& stat_tmp , 0 );
3775
+ }
3776
+ spin_unlock (& kvm_lock );
3777
+
3778
+ return 0 ;
3779
+ }
3780
+
3781
+ DEFINE_SIMPLE_ATTRIBUTE (vm_stat_fops , vm_stat_get , vm_stat_clear , "%llu\n" );
3736
3782
3737
3783
static int vcpu_stat_get (void * _offset , u64 * val )
3738
3784
{
@@ -3752,7 +3798,27 @@ static int vcpu_stat_get(void *_offset, u64 *val)
3752
3798
return 0 ;
3753
3799
}
3754
3800
3755
- DEFINE_SIMPLE_ATTRIBUTE (vcpu_stat_fops , vcpu_stat_get , NULL , "%llu\n" );
3801
+ static int vcpu_stat_clear (void * _offset , u64 val )
3802
+ {
3803
+ unsigned offset = (long )_offset ;
3804
+ struct kvm * kvm ;
3805
+ struct kvm_stat_data stat_tmp = {.offset = offset };
3806
+
3807
+ if (val )
3808
+ return - EINVAL ;
3809
+
3810
+ spin_lock (& kvm_lock );
3811
+ list_for_each_entry (kvm , & vm_list , vm_list ) {
3812
+ stat_tmp .kvm = kvm ;
3813
+ vcpu_stat_clear_per_vm ((void * )& stat_tmp , 0 );
3814
+ }
3815
+ spin_unlock (& kvm_lock );
3816
+
3817
+ return 0 ;
3818
+ }
3819
+
3820
+ DEFINE_SIMPLE_ATTRIBUTE (vcpu_stat_fops , vcpu_stat_get , vcpu_stat_clear ,
3821
+ "%llu\n" );
3756
3822
3757
3823
static const struct file_operations * stat_fops [] = {
3758
3824
[KVM_STAT_VCPU ] = & vcpu_stat_fops ,
@@ -3770,7 +3836,7 @@ static int kvm_init_debug(void)
3770
3836
3771
3837
kvm_debugfs_num_entries = 0 ;
3772
3838
for (p = debugfs_entries ; p -> name ; ++ p , kvm_debugfs_num_entries ++ ) {
3773
- if (!debugfs_create_file (p -> name , 0444 , kvm_debugfs_dir ,
3839
+ if (!debugfs_create_file (p -> name , 0644 , kvm_debugfs_dir ,
3774
3840
(void * )(long )p -> offset ,
3775
3841
stat_fops [p -> kind ]))
3776
3842
goto out_dir ;
0 commit comments