From: Ryan Afranji <afranji@google.com>
To: afranji@google.com, ackerleytng@google.com, pbonzini@redhat.com,
seanjc@google.com, tglx@linutronix.de, x86@kernel.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, tabba@google.com
Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, shuah@kernel.org, andrew.jones@linux.dev,
ricarkol@google.com, chao.p.peng@linux.intel.com,
jarkko@kernel.org, yu.c.zhang@linux.intel.com,
vannapurve@google.com, erdemaktas@google.com,
mail@maciej.szmigiero.name, vbabka@suse.cz, david@redhat.com,
qperret@google.com, michael.roth@amd.com, wei.w.wang@intel.com,
liam.merwick@oracle.com, isaku.yamahata@gmail.com,
kirill.shutemov@linux.intel.com, sagis@google.com,
jthoughton@google.com
Subject: [RFC PATCH v2 03/13] KVM: guest_mem: Refactor out kvm_gmem_alloc_view()
Date: Fri, 16 May 2025 19:19:23 +0000 [thread overview]
Message-ID: <1322a07a0eaad85938446a561d868cfcad7b4ecb.1747368092.git.afranji@google.com> (raw)
In-Reply-To: <cover.1747368092.git.afranji@google.com>
From: Ackerley Tng <ackerleytng@google.com>
kvm_gmem_alloc_view() will allocate and build a file out of an inode.
Will be reused later by kvm_gmem_link()
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
Co-developed-by: Ryan Afranji <afranji@google.com>
Signed-off-by: Ryan Afranji <afranji@google.com>
---
virt/kvm/guest_memfd.c | 61 +++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 34 deletions(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 2ee26695dc31..a3918d1695b9 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -470,49 +470,47 @@ static struct inode *kvm_gmem_inode_make_secure_inode(const char *name,
return inode;
}
-static struct file *kvm_gmem_inode_create_getfile(void *priv, loff_t size,
- u64 flags)
+static struct file *kvm_gmem_alloc_view(struct kvm *kvm, struct inode *inode,
+ const char *name)
{
- static const char *name = "[kvm-gmem]";
- struct inode *inode;
+ struct kvm_gmem *gmem;
struct file *file;
- int err;
- err = -ENOENT;
if (!try_module_get(kvm_gmem_fops.owner))
- goto err;
+ return ERR_PTR(-ENOENT);
- inode = kvm_gmem_inode_make_secure_inode(name, size, flags);
- if (IS_ERR(inode)) {
- err = PTR_ERR(inode);
+ gmem = kzalloc(sizeof(*gmem), GFP_KERNEL);
+ if (!gmem) {
+ file = ERR_PTR(-ENOMEM);
goto err_put_module;
}
file = alloc_file_pseudo(inode, kvm_gmem_mnt, name, O_RDWR,
&kvm_gmem_fops);
- if (IS_ERR(file)) {
- err = PTR_ERR(file);
- goto err_put_inode;
- }
+ if (IS_ERR(file))
+ goto err_gmem;
file->f_flags |= O_LARGEFILE;
- file->private_data = priv;
+ file->private_data = gmem;
+
+ kvm_get_kvm(kvm);
+ gmem->kvm = kvm;
+ xa_init(&gmem->bindings);
+ list_add(&gmem->entry, &file_inode(file)->i_mapping->i_private_list);
-out:
return file;
-err_put_inode:
- iput(inode);
+err_gmem:
+ kfree(gmem);
err_put_module:
module_put(kvm_gmem_fops.owner);
-err:
- file = ERR_PTR(err);
- goto out;
+ return file;
}
static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
{
- struct kvm_gmem *gmem;
+ static const char *name = "[kvm-gmem]";
+ struct inode *inode;
struct file *file;
int fd, err;
@@ -520,28 +518,23 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
if (fd < 0)
return fd;
- gmem = kzalloc(sizeof(*gmem), GFP_KERNEL);
- if (!gmem) {
- err = -ENOMEM;
+ inode = kvm_gmem_inode_make_secure_inode(name, size, flags);
+ if (IS_ERR(inode)) {
+ err = PTR_ERR(inode);
goto err_fd;
}
- file = kvm_gmem_inode_create_getfile(gmem, size, flags);
+ file = kvm_gmem_alloc_view(kvm, inode, name);
if (IS_ERR(file)) {
err = PTR_ERR(file);
- goto err_gmem;
+ goto err_put_inode;
}
- kvm_get_kvm(kvm);
- gmem->kvm = kvm;
- xa_init(&gmem->bindings);
- list_add(&gmem->entry, &file_inode(file)->i_mapping->i_private_list);
-
fd_install(fd, file);
return fd;
-err_gmem:
- kfree(gmem);
+err_put_inode:
+ iput(inode);
err_fd:
put_unused_fd(fd);
return err;
--
2.49.0.1101.gccaa498523-goog
next prev parent reply other threads:[~2025-05-16 19:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 19:19 [RFC PATCH v2 00/13] New KVM ioctl to link a gmem inode to a new gmem file Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 01/13] fs: Refactor to provide function that allocates a secure anonymous inode Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 02/13] KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodes Ryan Afranji
2025-05-16 19:19 ` Ryan Afranji [this message]
2025-05-16 19:19 ` [RFC PATCH v2 04/13] KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFD Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 05/13] KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctl Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 06/13] KVM: selftests: Test transferring private memory to another VM Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 07/13] KVM: x86: Refactor sev's flag migration_in_progress to kvm struct Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 08/13] KVM: x86: Refactor common code out of sev.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 09/13] KVM: x86: Refactor common migration preparation code out of sev_vm_move_enc_context_from Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 10/13] KVM: x86: Let moving encryption context be configurable Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 11/13] KVM: x86: Handle moving of memory context for intra-host migration Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 12/13] KVM: selftests: Generalize migration functions from sev_migrate_tests.c Ryan Afranji
2025-05-16 19:19 ` [RFC PATCH v2 13/13] KVM: selftests: Add tests for migration of private mem Ryan Afranji
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=1322a07a0eaad85938446a561d868cfcad7b4ecb.1747368092.git.afranji@google.com \
--to=afranji@google.com \
--cc=ackerleytng@google.com \
--cc=andrew.jones@linux.dev \
--cc=bp@alien8.de \
--cc=chao.p.peng@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=erdemaktas@google.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@gmail.com \
--cc=jarkko@kernel.org \
--cc=jthoughton@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mail@maciej.szmigiero.name \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qperret@google.com \
--cc=ricarkol@google.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=wei.w.wang@intel.com \
--cc=x86@kernel.org \
--cc=yu.c.zhang@linux.intel.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
all inboxes | Powered by JetHome®