From: Nikita Kalyazin <kalyazin@amazon.com>
To: <pbonzini@redhat.com>, <corbet@lwn.net>, <kvm@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jthoughton@google.com>, <brijesh.singh@amd.com>,
<michael.roth@amd.com>, <graf@amazon.de>, <jgowans@amazon.com>,
<roypat@amazon.co.uk>, <derekmn@amazon.com>, <nsaenz@amazon.es>,
<xmarcalx@amazon.com>, <kalyazin@amazon.com>
Subject: [PATCH 2/4] KVM: add KVM_GUEST_MEMFD_POPULATE ioctl for guest_memfd
Date: Thu, 24 Oct 2024 09:54:27 +0000 [thread overview]
Message-ID: <20241024095429.54052-3-kalyazin@amazon.com> (raw)
In-Reply-To: <20241024095429.54052-1-kalyazin@amazon.com>
The ioctl populates guest_memfd with userspace-provided data.
Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
---
include/linux/kvm_host.h | 3 +++
include/uapi/linux/kvm.h | 9 +++++++++
virt/kvm/guest_memfd.c | 7 +++++++
virt/kvm/kvm_main.c | 10 ++++++++++
4 files changed, 29 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index db567d26f7b9..5b0347783598 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2505,6 +2505,9 @@ typedef int (*kvm_gmem_populate_cb)(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
long kvm_gmem_populate(struct kvm *kvm, gfn_t gfn, void __user *src, long npages,
kvm_gmem_populate_cb post_populate, void *opaque);
+
+int kvm_gmem_guest_memfd_populate(struct kvm *kvm,
+ struct kvm_guest_memfd_populate *populate);
#endif
#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 637efc055145..5d8073de0d96 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -1573,4 +1573,13 @@ struct kvm_pre_fault_memory {
__u64 padding[5];
};
+struct kvm_guest_memfd_populate {
+ __u64 gpa;
+ __u64 size;
+ void __user *from;
+ __u64 flags;
+};
+
+#define KVM_GUEST_MEMFD_POPULATE _IOW(KVMIO, 0xd6, struct kvm_guest_memfd_populate)
+
#endif /* __LINUX_KVM_H */
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 954312fac462..08630b87f0e3 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -720,4 +720,11 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
return ret && !i ? ret : i;
}
EXPORT_SYMBOL_GPL(kvm_gmem_populate);
+
+int kvm_gmem_guest_memfd_populate(struct kvm *kvm,
+ struct kvm_guest_memfd_populate *populate)
+{
+ return kvm_gmem_populate(kvm, populate->gpa >> PAGE_SHIFT, populate->from,
+ populate->size >> PAGE_SHIFT, kvm_gmem_post_populate_generic, NULL);
+}
#endif
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 05cbb2548d99..e5bd2c0031bf 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5383,6 +5383,16 @@ static long kvm_vm_ioctl(struct file *filp,
r = kvm_gmem_create(kvm, &guest_memfd);
break;
}
+ case KVM_GUEST_MEMFD_POPULATE: {
+ struct kvm_guest_memfd_populate populate;
+
+ r = -EFAULT;
+ if (copy_from_user(&populate, argp, sizeof(populate)))
+ goto out;
+
+ r = kvm_gmem_guest_memfd_populate(kvm, &populate);
+ break;
+ }
#endif
default:
r = kvm_arch_vm_ioctl(filp, ioctl, arg);
--
2.40.1
next prev parent reply other threads:[~2024-10-24 9:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 9:54 [RFC PATCH 0/4] KVM: ioctl for populating guest_memfd Nikita Kalyazin
2024-10-24 9:54 ` [PATCH 1/4] KVM: guest_memfd: add generic post_populate callback Nikita Kalyazin
2024-11-22 18:40 ` Mike Day
2024-11-25 11:46 ` Nikita Kalyazin
2024-10-24 9:54 ` Nikita Kalyazin [this message]
2024-10-24 9:54 ` [PATCH 3/4] KVM: allow KVM_GUEST_MEMFD_POPULATE in another mm Nikita Kalyazin
2024-10-24 9:54 ` [PATCH 4/4] KVM: document KVM_GUEST_MEMFD_POPULATE ioctl Nikita Kalyazin
2024-11-20 12:09 ` [RFC PATCH 0/4] KVM: ioctl for populating guest_memfd Nikita Kalyazin
2024-11-20 13:46 ` David Hildenbrand
2024-11-20 15:13 ` David Hildenbrand
2024-11-20 15:58 ` Nikita Kalyazin
2024-11-20 16:20 ` David Hildenbrand
2024-11-20 16:44 ` David Hildenbrand
2024-11-20 17:21 ` Nikita Kalyazin
2024-11-20 18:29 ` David Hildenbrand
2024-11-21 16:46 ` Nikita Kalyazin
2024-11-26 16:04 ` Nikita Kalyazin
2024-11-28 12:11 ` David Hildenbrand
2024-11-20 13:55 ` Paolo Bonzini
2024-11-20 17:41 ` Nikita Kalyazin
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=20241024095429.54052-3-kalyazin@amazon.com \
--to=kalyazin@amazon.com \
--cc=brijesh.singh@amd.com \
--cc=corbet@lwn.net \
--cc=derekmn@amazon.com \
--cc=graf@amazon.de \
--cc=jgowans@amazon.com \
--cc=jthoughton@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=nsaenz@amazon.es \
--cc=pbonzini@redhat.com \
--cc=roypat@amazon.co.uk \
--cc=xmarcalx@amazon.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