[RFC 08/10] KVM: add KVM TMEM guest support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This part deals with the guest side. This is a common interface
for communicating with the host using the standard TMEM API.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 arch/x86/kvm/tmem/Kconfig  |    3 +
 arch/x86/kvm/tmem/Makefile |    1 +
 arch/x86/kvm/tmem/guest.c  |   95 ++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kvm/tmem/guest.h  |   11 +++++
 4 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/guest.c
 create mode 100644 arch/x86/kvm/tmem/guest.h

diff --git a/arch/x86/kvm/tmem/Kconfig b/arch/x86/kvm/tmem/Kconfig
index 1a59e4f..85ec25b 100644
--- a/arch/x86/kvm/tmem/Kconfig
+++ b/arch/x86/kvm/tmem/Kconfig
@@ -19,4 +19,7 @@ config KVM_TMEM_HOST
 	With this option on, the KVM host will be able to process KVM TMEM requests
 	coming from guests.
 
+config KVM_TMEM_GUEST
+	bool
+
 endif # KVM_TMEM
diff --git a/arch/x86/kvm/tmem/Makefile b/arch/x86/kvm/tmem/Makefile
index 706cd36..1b15e20 100644
--- a/arch/x86/kvm/tmem/Makefile
+++ b/arch/x86/kvm/tmem/Makefile
@@ -1,3 +1,4 @@
 ccflags-y += -Idrivers/staging/zcache/
 
 obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
+obj-$(CONFIG_KVM_TMEM_GUEST)			+= guest.o
diff --git a/arch/x86/kvm/tmem/guest.c b/arch/x86/kvm/tmem/guest.c
new file mode 100644
index 0000000..465cc86
--- /dev/null
+++ b/arch/x86/kvm/tmem/guest.c
@@ -0,0 +1,95 @@
+/*
+ * KVM TMEM guest side interface
+ *
+ * Copyright (c) 2012 Sasha Levin
+ *
+ */
+
+#include <linux/kvm_para.h>
+#include <linux/kvm_types.h>
+#include <asm/io.h>
+
+#include "tmem.h"
+#include "guest.h"
+
+#include <zcache.h>
+
+int kvm_tmem_new_pool(__u16 cli_id, __u32 flags, unsigned long pagesize)
+{
+	struct tmem_kvm_op op = {0};
+
+	flags |= ((ilog2(pagesize) - PAGE_SHIFT) << TMEM_POOL_PAGESIZE_SHIFT) |
+		(TMEM_SPEC_VERSION << TMEM_VERSION_SHIFT);
+
+	op = (struct tmem_kvm_op) {
+		.cmd = TMEM_NEW_POOL,
+		.cli_id = cli_id,
+		.u.new.flags = flags,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
+
+int kvm_tmem_put_page(__u32 pool_id, struct tmem_oid oid, __u32 index, unsigned long gfn)
+{
+	struct tmem_kvm_op op = {
+		.cmd = TMEM_PUT_PAGE,
+		.cli_id = KVM_CLIENT,
+		.pool_id = pool_id,
+		.u.gen.oid = oid,
+		.u.gen.index = index,
+		.u.gen.gfn = gfn,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
+
+int kvm_tmem_get_page(__u32 pool_id, struct tmem_oid oid, __u32 index, unsigned long gfn)
+{
+	struct tmem_kvm_op op = {
+		.cmd = TMEM_GET_PAGE,
+		.cli_id = KVM_CLIENT,
+		.pool_id = pool_id,
+		.u.gen.oid = oid,
+		.u.gen.index = index,
+		.u.gen.gfn = gfn,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
+
+int kvm_tmem_flush_page(__u32 pool_id, struct tmem_oid oid, __u32 index)
+{
+	struct tmem_kvm_op op = {
+		.cmd = TMEM_FLUSH_PAGE,
+		.cli_id = KVM_CLIENT,
+		.pool_id = pool_id,
+		.u.gen.oid = oid,
+		.u.gen.index = index,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
+
+int kvm_tmem_flush_object(__u32 pool_id, struct tmem_oid oid)
+{
+	struct tmem_kvm_op op = {
+		.cmd = TMEM_FLUSH_OBJECT,
+		.cli_id = KVM_CLIENT,
+		.pool_id = pool_id,
+		.u.gen.oid = oid,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
+
+int kvm_tmem_destroy_pool(__u32 pool_id)
+{
+	struct tmem_kvm_op op = {
+		.cmd = TMEM_DESTROY_POOL,
+		.cli_id = KVM_CLIENT,
+		.pool_id = pool_id,
+	};
+
+	return kvm_hypercall2(KVM_HC_TMEM, virt_to_phys(&op), 0);
+}
diff --git a/arch/x86/kvm/tmem/guest.h b/arch/x86/kvm/tmem/guest.h
new file mode 100644
index 0000000..9225451
--- /dev/null
+++ b/arch/x86/kvm/tmem/guest.h
@@ -0,0 +1,11 @@
+#ifndef _KVM_TMEM_GUEST_H
+#define _KVM_TMEM_GUEST_H
+
+extern int kvm_tmem_new_pool(uint16_t cli_id, __u32 flags, unsigned long pagesize);
+extern int kvm_tmem_put_page(__u32 pool_id, struct tmem_oid oid, __u32 index, unsigned long gfn);
+extern int kvm_tmem_get_page(u32 pool_id, struct tmem_oid oid, __u32 index, unsigned long gfn);
+extern int kvm_tmem_flush_page(__u32 pool_id, struct tmem_oid oid, __u32 index);
+extern int kvm_tmem_flush_object(__u32 pool_id, struct tmem_oid oid);
+extern int kvm_tmem_destroy_pool(__u32 pool_id);
+
+#endif
-- 
1.7.8.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux