* [PATCH] KVM: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
@ 2022-11-01 7:25 Bo Liu
2022-11-02 17:48 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Bo Liu @ 2022-11-01 7:25 UTC (permalink / raw)
To: pbonzini; +Cc: kvm, linux-kernel, Bo Liu
Fix the following coccicheck warning:
virt/kvm/kvm_main.c:3847:0-23: WARNING
vcpu_get_pid_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
Signed-off-by: Bo Liu <liubo03@inspur.com>
---
virt/kvm/kvm_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f1df24c2bc84..3f383f27d3d7 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3844,7 +3844,7 @@ static int vcpu_get_pid(void *data, u64 *val)
return 0;
}
-DEFINE_SIMPLE_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
{
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
2022-11-01 7:25 [PATCH] KVM: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE Bo Liu
@ 2022-11-02 17:48 ` Paolo Bonzini
2022-11-02 19:39 ` Sean Christopherson
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2022-11-02 17:48 UTC (permalink / raw)
To: Bo Liu; +Cc: kvm, linux-kernel
On 11/1/22 08:25, Bo Liu wrote:
> Fix the following coccicheck warning:
> virt/kvm/kvm_main.c:3847:0-23: WARNING
> vcpu_get_pid_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
>
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
> virt/kvm/kvm_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index f1df24c2bc84..3f383f27d3d7 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -3844,7 +3844,7 @@ static int vcpu_get_pid(void *data, u64 *val)
> return 0;
> }
>
> -DEFINE_SIMPLE_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
>
> static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
> {
If you really wanted to do this, you would also have to replace
debugfs_create_file with debugfs_create_file_unsafe.
However, this is not a good idea. The rationale in the .cocci file is
that "DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file() imposes some
significant overhead", but this should not really be relevant for a
debugfs file.
Such a patch would only make sense if there was a version of
debugfs_create_file_unsafe() with a less-terrible name (e.g.
debugfs_create_simple_attr?), which could _only_ be used with fops
created by DEFINE_DEBUGFS_ATTRIBUTE. Without such a type-safe trick,
the .cocci file is only adding confusion to perfectly fine code.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
2022-11-02 17:48 ` Paolo Bonzini
@ 2022-11-02 19:39 ` Sean Christopherson
0 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2022-11-02 19:39 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Bo Liu, kvm, linux-kernel
On Wed, Nov 02, 2022, Paolo Bonzini wrote:
> On 11/1/22 08:25, Bo Liu wrote:
> > Fix the following coccicheck warning:
> > virt/kvm/kvm_main.c:3847:0-23: WARNING
> > vcpu_get_pid_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE
> >
> > Signed-off-by: Bo Liu <liubo03@inspur.com>
> > ---
> > virt/kvm/kvm_main.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index f1df24c2bc84..3f383f27d3d7 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -3844,7 +3844,7 @@ static int vcpu_get_pid(void *data, u64 *val)
> > return 0;
> > }
> > -DEFINE_SIMPLE_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
> > +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_get_pid_fops, vcpu_get_pid, NULL, "%llu\n");
> > static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
> > {
>
> If you really wanted to do this, you would also have to replace
> debugfs_create_file with debugfs_create_file_unsafe.
>
> However, this is not a good idea. The rationale in the .cocci file is that
> "DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file() imposes some significant
> overhead", but this should not really be relevant for a debugfs file.
>
> Such a patch would only make sense if there was a version of
> debugfs_create_file_unsafe() with a less-terrible name (e.g.
> debugfs_create_simple_attr?), which could _only_ be used with fops created
> by DEFINE_DEBUGFS_ATTRIBUTE. Without such a type-safe trick, the .cocci
> file is only adding confusion to perfectly fine code.
Heh, some serious deja vu here[1]. This is the second case of identical, flawed
patches being sent in response to misguided coccinelle warnings in a rather short
amount of time, the "return min(r, 0)" horror being the other case[2][3].
The min() thing is supposed to be fixed by commit aeb300c1dbfc ("coccinelle: misc:
minmax: suppress patch generation for err returns"). Is that patch broken, or are
folks just running old scripts?
As for the DEFINE_DEBUGFS_ATTRIBUTE check, can that warning be downgraded (is that
even a thing?) or even deleted? As much as I enjoyed the opportunity to learn more
about debugfs, the unnecessary confusion and wasted time was/is annoying.
[1] https://lore.kernel.org/all/Yxoo1A2fmlAWruyV@google.com
[2] https://lore.kernel.org/all/8881d7b4-0c31-cafd-1158-0d42c1c7f43a@redhat.com
[3] https://lore.kernel.org/all/d8a518c4a4014307b30020b38022d633@AcuMS.aculab.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] KVM: Replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
@ 2021-02-01 8:38 Jiapeng Chong
2021-02-01 9:01 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Jiapeng Chong @ 2021-02-01 8:38 UTC (permalink / raw)
To: pbonzini
Cc: seanjc, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
x86, hpa, kvm, linux-kernel, Jiapeng Chong
Fix the following coccicheck warning:
./arch/x86/kvm/debugfs.c:44:0-23: WARNING: vcpu_tsc_scaling_frac_fops
should be defined with DEFINE_DEBUGFS_ATTRIBUTE.
./arch/x86/kvm/debugfs.c:36:0-23: WARNING: vcpu_tsc_scaling_fops should
be defined with DEFINE_DEBUGFS_ATTRIBUTE.
./arch/x86/kvm/debugfs.c:27:0-23: WARNING: vcpu_tsc_offset_fops should
be defined with DEFINE_DEBUGFS_ATTRIBUTE.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
arch/x86/kvm/debugfs.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index 7e818d6..9c0e29e 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -15,7 +15,7 @@ static int vcpu_get_timer_advance_ns(void *data, u64 *val)
return 0;
}
-DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
static int vcpu_get_tsc_offset(void *data, u64 *val)
{
@@ -24,7 +24,7 @@ static int vcpu_get_tsc_offset(void *data, u64 *val)
return 0;
}
-DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
{
@@ -33,7 +33,7 @@ static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
return 0;
}
-DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
{
@@ -41,7 +41,8 @@ static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
return 0;
}
-DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits,
+ NULL, "%llu\n");
void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
{
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: Replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE
2021-02-01 8:38 [PATCH] KVM: Replace " Jiapeng Chong
@ 2021-02-01 9:01 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2021-02-01 9:01 UTC (permalink / raw)
To: Jiapeng Chong
Cc: seanjc, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
x86, hpa, kvm, linux-kernel
On 01/02/21 09:38, Jiapeng Chong wrote:
> Fix the following coccicheck warning:
>
> ./arch/x86/kvm/debugfs.c:44:0-23: WARNING: vcpu_tsc_scaling_frac_fops
> should be defined with DEFINE_DEBUGFS_ATTRIBUTE.
>
> ./arch/x86/kvm/debugfs.c:36:0-23: WARNING: vcpu_tsc_scaling_fops should
> be defined with DEFINE_DEBUGFS_ATTRIBUTE.
>
> ./arch/x86/kvm/debugfs.c:27:0-23: WARNING: vcpu_tsc_offset_fops should
> be defined with DEFINE_DEBUGFS_ATTRIBUTE.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> arch/x86/kvm/debugfs.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
> index 7e818d6..9c0e29e 100644
> --- a/arch/x86/kvm/debugfs.c
> +++ b/arch/x86/kvm/debugfs.c
> @@ -15,7 +15,7 @@ static int vcpu_get_timer_advance_ns(void *data, u64 *val)
> return 0;
> }
>
> -DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
>
> static int vcpu_get_tsc_offset(void *data, u64 *val)
> {
> @@ -24,7 +24,7 @@ static int vcpu_get_tsc_offset(void *data, u64 *val)
> return 0;
> }
>
> -DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
>
> static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
> {
> @@ -33,7 +33,7 @@ static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
> return 0;
> }
>
> -DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
>
> static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
> {
> @@ -41,7 +41,8 @@ static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
> return 0;
> }
>
> -DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
> +DEFINE_DEBUGFS_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits,
> + NULL, "%llu\n");
>
> void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
> {
>
If you wanted to do this, you would have to use
debugfs_create_file_unsafe() as well.
In practice, nobody does that because it's not a performance-sensitive
path and it's not worth the maintenance cost of using a less safe API.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-02 19:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 7:25 [PATCH] KVM: replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE Bo Liu
2022-11-02 17:48 ` Paolo Bonzini
2022-11-02 19:39 ` Sean Christopherson
-- strict thread matches above, loose matches on Subject: below --
2021-02-01 8:38 [PATCH] KVM: Replace " Jiapeng Chong
2021-02-01 9:01 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).