public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Oliver Upton <oupton@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, maz@kernel.org,
	kvmarm@vger.kernel.org
Subject: Re: [PATCH 4/5] KVM: Actually create debugfs in kvm_create_vm()
Date: Mon, 16 May 2022 22:19:28 +0000	[thread overview]
Message-ID: <YoLN8M9I0bAnO3Nu@google.com> (raw)
In-Reply-To: <20220415201542.1496582-5-oupton@google.com>

On Fri, Apr 15, 2022, Oliver Upton wrote:
> @@ -1049,7 +1050,7 @@ int __weak kvm_arch_create_vm_debugfs(struct kvm *kvm)
>  	return 0;
>  }
>  
> -static struct kvm *kvm_create_vm(unsigned long type)
> +static struct kvm *kvm_create_vm(unsigned long type, int fd)

I don't love passing in @fd, because actually doing anything but printing the
@fd in a string is doomed to fail.

Rather than pass the raw fd, what about passing in just its name?

---
 virt/kvm/kvm_main.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d94c1d9ecaa9..ac76fc7f2e4d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -964,7 +964,7 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
 	}
 }

-static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
+static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname)
 {
 	static DEFINE_MUTEX(kvm_debugfs_lock);
 	struct dentry *dent;
@@ -987,7 +987,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, int fd)
 	if (!debugfs_initialized())
 		return 0;

-	snprintf(dir_name, sizeof(dir_name), "%d-%d", task_pid_nr(current), fd);
+	snprintf(dir_name, sizeof(dir_name), "%d-%s", task_pid_nr(current), fdname);
 	mutex_lock(&kvm_debugfs_lock);
 	dent = debugfs_lookup(dir_name, kvm_debugfs_dir);
 	if (dent) {
@@ -1076,7 +1076,7 @@ int __weak kvm_arch_create_vm_debugfs(struct kvm *kvm)
 	return 0;
 }

-static struct kvm *kvm_create_vm(unsigned long type, int fd)
+static struct kvm *kvm_create_vm(unsigned long type, const char * fdname)
 {
 	struct kvm *kvm = kvm_arch_alloc_vm();
 	struct kvm_memslots *slots;
@@ -1174,7 +1174,7 @@ static struct kvm *kvm_create_vm(unsigned long type, int fd)
 		goto out_err_mmu_notifier;
 	}

-	r = kvm_create_vm_debugfs(kvm, fd);
+	r = kvm_create_vm_debugfs(kvm, fdname);
 	if (r)
 		goto out_err;

@@ -4781,6 +4781,7 @@ EXPORT_SYMBOL_GPL(file_is_kvm);

 static int kvm_dev_ioctl_create_vm(unsigned long type)
 {
+	char fdname[ITOA_MAX_LEN + 1];
 	int r, fd;
 	struct kvm *kvm;
 	struct file *file;
@@ -4789,7 +4790,9 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
 	if (fd < 0)
 		return fd;

-	kvm = kvm_create_vm(type, fd);
+	snprintf(fdname, sizeof(fdname), "%d", fd);
+
+	kvm = kvm_create_vm(type, fdname);
 	if (IS_ERR(kvm)) {
 		r = PTR_ERR(kvm);
 		goto put_fd;

base-commit: 3d7c3ff77a78f103c2cf1104157a4132f56fd6d1
--


  reply	other threads:[~2022-05-16 22:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 20:15 [PATCH 0/5] KVM: Clean up debugfs+stats init/destroy Oliver Upton
2022-04-15 20:15 ` [PATCH 1/5] KVM: Shove vm stats_id init into kvm_create_vm_debugfs() Oliver Upton
2022-05-16 20:58   ` Sean Christopherson
2022-04-15 20:15 ` [PATCH 2/5] KVM: Shove vcpu stats_id init into kvm_vcpu_create_debugfs() Oliver Upton
2022-05-16 21:01   ` Sean Christopherson
2022-05-16 22:26     ` Oliver Upton
2022-04-15 20:15 ` [PATCH 3/5] KVM: Get an fd before creating the VM Oliver Upton
2022-04-15 20:15 ` [PATCH 4/5] KVM: Actually create debugfs in kvm_create_vm() Oliver Upton
2022-05-16 22:19   ` Sean Christopherson [this message]
2022-05-16 23:55     ` Oliver Upton
2022-04-15 20:15 ` [PATCH 5/5] KVM: Hoist debugfs_dentry init to kvm_create_vm_debugfs() (again) Oliver Upton
2022-04-15 20:19 ` [PATCH 0/5] KVM: Clean up debugfs+stats init/destroy Oliver Upton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YoLN8M9I0bAnO3Nu@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox