Skip to contentSkip to conversation

KVM:define vcpu_get_pid_fops with DEFINE_DEBUGFS_ATTRIBUTE

PATCH In review [email protected] 2 participants 2 messages Aug 15, 2022 – Sep 8, 2022 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM:define vcpu_get_pid_fops with DEFINE_DEBUGFS_ATTRIBUTE

From: ye xingchen <[email protected]>

From the coccinelle check:
./virt/kvm/kvm_main.c line 3847
WARNING vcpu_get_pid_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 515dfe9d3bcf..a0817179f8e4 100644
@@ -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)
 {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 17 lines · On Mon, Aug 15, 2022, [email protected] wrote:

From: ye xingchen <[email protected]>

From the coccinelle check:
./virt/kvm/kvm_main.c line 3847
WARNING vcpu_get_pid_fops should be defined with DEFINE_DEBUGFS_ATTRIBUTE

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +0 -0
index 515dfe9d3bcf..a0817179f8e4 100644

virt/kvm/kvm_main.c static int vcpu_get_pid(void *data, u64 *val) · line 3847

Quoted 5 lines
virt/kvm/kvm_main.c +1 -1
@@ -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");

Based on the comments in scripts/coccinelle/api/debugfs/debugfs_simple_attr.cocci, it seems that using DEFINE_DEBUGFS_ATTRIBUTE is only beneficial if the file is created with debugfs_create_file_unsafe(). IIUC, using DEFINE_DEBUGFS_ATTRIBUTE without switching to debugfs_create_file_unsafe() will actually _add_ overhead.

	//# Rationale: DEFINE_SIMPLE_ATTRIBUTE + debugfs_create_file()
	//# imposes some significant overhead as compared to
	//# DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe().

Using DEFINE_DEBUGFS_ATTRIBUTE also effectively drops ->llseek() support. I assume that's not a problem? But someone that knows how this is actually used should chime in.