From: Oliver Upton <oliver.upton@linux.dev>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Oliver Upton <oupton@google.com>
Subject: [PATCH v3 3/6] KVM: Get an fd before creating the VM
Date: Wed, 20 Jul 2022 09:22:49 +0000 [thread overview]
Message-ID: <20220720092259.3491733-4-oliver.upton@linux.dev> (raw)
In-Reply-To: <20220720092259.3491733-1-oliver.upton@linux.dev>
From: Oliver Upton <oupton@google.com>
Allocate a VM's fd at the very beginning of kvm_dev_ioctl_create_vm() so
that KVM can use the fd value to generate strigns, e.g. for debugfs,
when creating and initializing the VM.
Signed-off-by: Oliver Upton <oupton@google.com>
---
virt/kvm/kvm_main.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1f78b7ad5430..e270cff3c9f4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4889,25 +4889,27 @@ EXPORT_SYMBOL_GPL(file_is_kvm);
static int kvm_dev_ioctl_create_vm(unsigned long type)
{
- int r;
+ int r, fd;
struct kvm *kvm;
struct file *file;
+ fd = get_unused_fd_flags(O_CLOEXEC);
+ if (fd < 0)
+ return fd;
+
kvm = kvm_create_vm(type);
- if (IS_ERR(kvm))
- return PTR_ERR(kvm);
+ if (IS_ERR(kvm)) {
+ r = PTR_ERR(kvm);
+ goto put_fd;
+ }
+
#ifdef CONFIG_KVM_MMIO
r = kvm_coalesced_mmio_init(kvm);
if (r < 0)
goto put_kvm;
#endif
- r = get_unused_fd_flags(O_CLOEXEC);
- if (r < 0)
- goto put_kvm;
-
file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
if (IS_ERR(file)) {
- put_unused_fd(r);
r = PTR_ERR(file);
goto put_kvm;
}
@@ -4918,18 +4920,20 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
* cases it will be called by the final fput(file) and will take
* care of doing kvm_put_kvm(kvm).
*/
- if (kvm_create_vm_debugfs(kvm, r) < 0) {
- put_unused_fd(r);
+ if (kvm_create_vm_debugfs(kvm, fd) < 0) {
fput(file);
- return -ENOMEM;
+ r = -ENOMEM;
+ goto put_fd;
}
kvm_uevent_notify_change(KVM_EVENT_CREATE_VM, kvm);
- fd_install(r, file);
- return r;
+ fd_install(fd, file);
+ return fd;
put_kvm:
kvm_put_kvm(kvm);
+put_fd:
+ put_unused_fd(fd);
return r;
}
--
2.37.0.170.g444d1eabd0-goog
next prev parent reply other threads:[~2022-07-20 9:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 9:22 [PATCH v3 0/6] KVM: Clean up debugfs init/destroy Oliver Upton
2022-07-20 9:22 ` [PATCH v3 1/6] KVM: Shove vm stats_id init into kvm_create_vm() Oliver Upton
2022-08-05 19:09 ` Sean Christopherson
2022-07-20 9:22 ` [PATCH v3 2/6] KVM: Shove vcpu stats_id init into kvm_vcpu_init() Oliver Upton
2022-08-05 19:06 ` Sean Christopherson
2022-08-09 14:52 ` Paolo Bonzini
2022-07-20 9:22 ` Oliver Upton [this message]
2022-08-05 19:03 ` [PATCH v3 3/6] KVM: Get an fd before creating the VM Sean Christopherson
2022-07-20 9:22 ` [PATCH v3 4/6] KVM: Pass the name of the VM fd to kvm_create_vm_debugfs() Oliver Upton
2022-08-05 19:20 ` Sean Christopherson
2022-07-20 9:22 ` [PATCH v3 5/6] KVM: Actually create debugfs in kvm_create_vm() Oliver Upton
2022-08-05 19:16 ` Sean Christopherson
2022-07-20 9:22 ` [PATCH v3 6/6] KVM: Hoist debugfs_dentry init to kvm_create_vm_debugfs() (again) Oliver Upton
2022-08-05 19:02 ` Sean Christopherson
2022-08-09 14:56 ` Paolo Bonzini
2022-08-09 19:59 ` Oliver Upton
2022-07-20 9:22 ` [PATCH v3 0/6] KVM: Clean up debugfs init/destroy Oliver Upton
2022-07-20 9:22 ` [PATCH v3 1/6] KVM: Shove vm stats_id init into kvm_create_vm() Oliver Upton
2022-07-20 9:22 ` [PATCH v3 2/6] KVM: Shove vcpu stats_id init into kvm_vcpu_init() 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=20220720092259.3491733-4-oliver.upton@linux.dev \
--to=oliver.upton@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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