Skip to contentSkip to conversation

KVM: reintroduce hc_gpa

RFC In review Sasha Levin 3 participants 18 messages Jun 6, 2012 – Jun 29, 2012

Subsystems (5)
x86 KVM Staging KVM x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

RFC 1/10 KVM: reintroduce hc_gpa

While PV MMU is dead and gone, we'll still want to pass gpa from guest to host, and to do that properly we'll need to revive hc_gpa which died during the great PV MMU massacre of 3.2.

---
 arch/x86/kvm/x86.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +9 -0
index 185a2b8..675dfb8 100644
@@ -4993,6 +4993,15 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
+static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
+				unsigned long a1)
+{
+	if (is_long_mode(vcpu))
+		return a0;
+	else
+		return a0 | ((gpa_t)a1 << 32);
+}
+
 int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 {
 	unsigned long nr, a0, a1, a2, a3, ret;
Signature · 1 line
1.7.8.6
#1 lore raw

RFC 2/10 KVM: wire up the TMEM HC

Wire up a new HC for TMEM, not doing much at the moment besides not doing anything.

---
 arch/x86/kvm/x86.c       |   10 ++++++++++
 include/linux/kvm_para.h |    1 +
 2 files changed, 11 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +10 -0
index 675dfb8..4c5b6ab 100644
@@ -4993,6 +4993,13 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
+static int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
+{
+	*ret = -ENOTSUPP;
+
+	return 0;
+}
+
 static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
 				unsigned long a1)
 {
@@ -5035,6 +5042,9 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 	case KVM_HC_VAPIC_POLL_IRQ:
 		ret = 0;
 		break;
+	case KVM_HC_TMEM:
+		r = kvm_pv_tmem_op(vcpu, hc_gpa(vcpu, a0, a1), &ret);
+		break;
 	default:
 		ret = -KVM_ENOSYS;
 		break;
include/linux/kvm_para.h +1 -0
index ff476dd..78b27bf 100644
@@ -19,6 +19,7 @@
 #define KVM_HC_MMU_OP			2
 #define KVM_HC_FEATURES			3
 #define KVM_HC_PPC_MAP_MAGIC_PAGE	4
+#define KVM_HC_TMEM			5
 
 /*
  * hypercalls use architecture specific
Signature · 1 line
1.7.8.6
#2 lore raw

RFC 3/10 zcache: export zcache interface

In reply to Sasha Levin

This patch exports the zcache interface to be used from the outside world.

---
 drivers/staging/zcache/zcache-main.c |   13 +++++++------
 drivers/staging/zcache/zcache.h      |   17 +++++++++++++++++
 2 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 drivers/staging/zcache/zcache.h
drivers/staging/zcache/zcache-main.c +7 -6
index 784c796..a196aff 100644
@@ -32,6 +32,7 @@
 #include <linux/crypto.h>
 #include <linux/string.h>
 #include "tmem.h"
+#include "zcache.h"
 
 #include "../zsmalloc/zsmalloc.h"
 
@@ -1563,7 +1564,7 @@ static struct shrinker zcache_shrinker = {
  * zcache shims between cleancache/frontswap ops and tmem
  */
 
-static int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
+int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
 				uint32_t index, struct page *page)
 {
 	struct tmem_pool *pool;
@@ -1596,7 +1597,7 @@ out:
 	return ret;
 }
 
-static int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
+int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
 				uint32_t index, struct page *page)
 {
 	struct tmem_pool *pool;
@@ -1616,7 +1617,7 @@ static int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
 	return ret;
 }
 
-static int zcache_flush_page(int cli_id, int pool_id,
+int zcache_flush_page(int cli_id, int pool_id,
 				struct tmem_oid *oidp, uint32_t index)
 {
 	struct tmem_pool *pool;
@@ -1637,7 +1638,7 @@ static int zcache_flush_page(int cli_id, int pool_id,
 	return ret;
 }
 
-static int zcache_flush_object(int cli_id, int pool_id,
+int zcache_flush_object(int cli_id, int pool_id,
 				struct tmem_oid *oidp)
 {
 	struct tmem_pool *pool;
@@ -1658,7 +1659,7 @@ static int zcache_flush_object(int cli_id, int pool_id,
 	return ret;
 }
 
-static int zcache_destroy_pool(int cli_id, int pool_id)
+int zcache_destroy_pool(int cli_id, int pool_id)
 {
 	struct tmem_pool *pool = NULL;
 	struct zcache_client *cli = NULL;
@@ -1941,7 +1942,7 @@ struct frontswap_ops zcache_frontswap_register_ops(void)
  * NOTHING HAPPENS!
  */
 
-static int zcache_enabled;
+int zcache_enabled;
 
 static int __init enable_zcache(char *s)
 {
drivers/staging/zcache/zcache.h new file +17 -0
new file mode 100644
index 0000000..ec06ea2
@@ -0,0 +1,17 @@
+#ifndef _ZCACHE_H_
+#define _ZCACHE_H_
+
+extern int zcache_enabled;
+
+extern int zcache_new_pool(uint16_t cli_id, uint32_t flags);
+extern int zcache_destroy_pool(int cli_id, int pool_id);
+extern int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
+			uint32_t index, struct page *page);
+extern int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
+			uint32_t index, struct page *page);
+extern int zcache_flush_page(int cli_id, int pool_id,
+			struct tmem_oid *oidp, uint32_t index);
+extern int zcache_flush_object(int cli_id, int pool_id,
+			struct tmem_oid *oidp);
+
+#endif
Signature · 1 line
1.7.8.6
#3 lore raw

RFC 4/10 KVM: add KVM TMEM entries in the appropriate config menu entry

In reply to Sasha Levin

Provide the ability to enable/disable any (future) KVM TMEM code.

---
 arch/x86/kvm/Kconfig       |    1 +
 arch/x86/kvm/Makefile      |    2 ++
 arch/x86/kvm/tmem/Kconfig  |   16 ++++++++++++++++
 arch/x86/kvm/tmem/Makefile |    1 +
 4 files changed, 20 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/Kconfig
 create mode 100644 arch/x86/kvm/tmem/Makefile
arch/x86/kvm/Kconfig +1 -0
index 1a7fe86..08d2249 100644
@@ -81,6 +81,7 @@ config KVM_MMU_AUDIT
 
 # OK, it's a little counter-intuitive to do this, but it puts it neatly under
 # the virtualization menu.
+source arch/x86/kvm/tmem/Kconfig
 source drivers/vhost/Kconfig
 source drivers/lguest/Kconfig
 
arch/x86/kvm/Makefile +2 -0
index 4f579e8..0df19bc 100644
@@ -19,3 +19,5 @@ kvm-amd-y		+= svm.o
 obj-$(CONFIG_KVM)	+= kvm.o
 obj-$(CONFIG_KVM_INTEL)	+= kvm-intel.o
 obj-$(CONFIG_KVM_AMD)	+= kvm-amd.o
+
+obj-$(CONFIG_KVM_TMEM)	+= tmem/
arch/x86/kvm/tmem/Kconfig new file +16 -0
new file mode 100644
index 0000000..15d8301
@@ -0,0 +1,16 @@
+#
+# KVM TMEM configuration
+#
+
+menuconfig KVM_TMEM
+	bool "TMEM support"
+	depends on KVM && ZCACHE
+	default n
+	---help---
+	This option provides the ability to use TMEM along with KVM, which provides
+	TMEM capabilities across multiple guests and (possible hosts).
+
+
+if KVM_TMEM
+
+endif # KVM_TMEM
arch/x86/kvm/tmem/Makefile new file +1 -0
new file mode 100644
index 0000000..6812d46
@@ -0,0 +1 @@
+ccflags-y += -Idrivers/staging/zcache/
Signature · 1 line
1.7.8.6
#4 lore raw

RFC 5/10 KVM: bring in general tmem definitions

In reply to Sasha Levin

Define basic structures to be used by both host side and guest side.

---
 arch/x86/kvm/tmem/tmem.h |   62 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/tmem.h
arch/x86/kvm/tmem/tmem.h new file +62 -0
new file mode 100644
index 0000000..a6f0032
@@ -0,0 +1,62 @@
+#ifndef _KVM_TMEM_H_
+#define _KVM_TMEM_H_
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/kvm_types.h>
+
+#define TMEM_CONTROL			0
+#define TMEM_NEW_POOL			1
+#define TMEM_DESTROY_POOL		2
+#define TMEM_NEW_PAGE			3
+#define TMEM_PUT_PAGE			4
+#define TMEM_GET_PAGE			5
+#define TMEM_FLUSH_PAGE			6
+#define TMEM_FLUSH_OBJECT		7
+#define TMEM_READ			8
+#define TMEM_WRITE			9
+#define TMEM_XCHG			10
+
+#define TMEM_POOL_PERSIST		1
+#define TMEM_POOL_SHARED		2
+#define TMEM_POOL_PAGESIZE_SHIFT	4
+#define TMEM_VERSION_SHIFT		24
+
+#define TMEM_SPEC_VERSION		1
+
+struct tmem_pool_uuid {
+	__u64 uuid_lo;
+	__u64 uuid_hi;
+};
+
+struct tmem_oid {
+	__u64 oid[3];
+};
+
+struct tmem_kvm_op {
+	__u32 cmd;
+	__s32 pool_id;
+	__u16 cli_id;
+	union {
+		struct {  /* for cmd == TMEM_NEW_POOL */
+			__u64 uuid[2];
+			__u32 flags;
+		} new;
+		struct {
+			struct tmem_oid oid;
+			__u32 index;
+			__u32 tmem_offset;
+			__u32 pfn_offset;
+			__u32 len;
+			gfn_t gfn; /* guest machine page frame */
+		} gen;
+	} u;
+};
+
+#define TMEM_POOL_PRIVATE_UUID  { 0, 0 }
+
+/* flags for tmem_ops.new_pool */
+#define TMEM_POOL_PERSIST          1
+#define TMEM_POOL_SHARED           2
+
+#endif /* _KVM_TMEM_H_ */
Signature · 1 line
1.7.8.6
#5 lore raw

RFC 6/10 zcache: move out client declaration and add a KVM client

In reply to Sasha Levin

Move out client declarations to be visible in the header, and introduce a new KVM client.

---
 drivers/staging/zcache/zcache.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/staging/zcache/zcache.h +3 -0
index ec06ea2..4693fd6 100644
@@ -1,6 +1,9 @@
 #ifndef _ZCACHE_H_
 #define _ZCACHE_H_
 
+#define LOCAL_CLIENT ((uint16_t)-1)
+#define KVM_CLIENT 1
+
 extern int zcache_enabled;
 
 extern int zcache_new_pool(uint16_t cli_id, uint32_t flags);
Signature · 1 line
1.7.8.6
#6 lore raw

RFC 7/10 KVM: add KVM TMEM host side interface

In reply to Sasha Levin

This is the host side interface that the guests which support KVM TMEM talk to.

---
 arch/x86/kvm/tmem/Kconfig            |    6 +++
 arch/x86/kvm/tmem/Makefile           |    2 +
 arch/x86/kvm/tmem/host.c             |   78 ++++++++++++++++++++++++++++++++++
 arch/x86/kvm/tmem/host.h             |   20 +++++++++
 arch/x86/kvm/x86.c                   |    8 +---
 drivers/staging/zcache/zcache-main.c |   35 +++++++++++++++-
 6 files changed, 141 insertions(+), 8 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/host.c
 create mode 100644 arch/x86/kvm/tmem/host.h
arch/x86/kvm/tmem/Kconfig +6 -0
index 15d8301..1a59e4f 100644
@@ -13,4 +13,10 @@ menuconfig KVM_TMEM
 
 if KVM_TMEM
 
+config KVM_TMEM_HOST
+	bool "Host-side KVM TMEM"
+	---help---
+	With this option on, the KVM host will be able to process KVM TMEM requests
+	coming from guests.
+
 endif # KVM_TMEM
arch/x86/kvm/tmem/Makefile +2 -0
index 6812d46..706cd36 100644
@@ -1 +1,3 @@
 ccflags-y += -Idrivers/staging/zcache/
+
+obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
arch/x86/kvm/tmem/host.c new file +78 -0

78 lines not on this page · raw message

arch/x86/kvm/tmem/host.h new file +20 -0
new file mode 100644
index 0000000..17ba0c4
@@ -0,0 +1,20 @@
+#ifndef _KVM_TMEM_HOST_H_
+#define _KVM_TMEM_HOST_H_
+
+#ifdef CONFIG_KVM_TMEM_HOST
+
+extern int use_kvm_tmem_host;
+
+extern int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret);
+
+#else
+
+static inline int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
+{
+	*ret = -ENOSUPP;
+	return 0;
+}
+
+#endif
+
+#endif
arch/x86/kvm/x86.c +1 -7
index 4c5b6ab..c92d4c8 100644
@@ -27,6 +27,7 @@
 #include "kvm_cache_regs.h"
 #include "x86.h"
 #include "cpuid.h"
+#include "tmem/host.h"
 
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -4993,13 +4994,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
-static int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
-{
-	*ret = -ENOTSUPP;
-
-	return 0;
-}
-
 static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
 				unsigned long a1)
 {
drivers/staging/zcache/zcache-main.c +34 -1
index a196aff..65c0ab0 100644
@@ -1692,7 +1692,7 @@ out:
 	return ret;
 }
 
-static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
+int zcache_new_pool(uint16_t cli_id, uint32_t flags)
 {
 	int poolid = -1;
 	struct tmem_pool *pool;
@@ -2011,6 +2011,37 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_KVM_TMEM_HOST
+extern int use_kvm_tmem_host;
+
+static int __zcache_init_kvm(void)
+{
+	int ret = 0;
+
+	if (use_kvm_tmem_host) {
+		ret = zcache_new_client(KVM_CLIENT);
+		if (ret) {
+			pr_err("zcache: can't create client\n");
+			return -1;
+		} else {
+			pr_info("zcache: enabled support for KVM TMEM\n");
+		}
+	}
+	zbud_init();
+	register_shrinker(&zcache_shrinker);
+
+	return 0;
+}
+
+#else
+
+static inline int static int __zcache_init_kvm(void)
+{
+	return 0;
+}
+
+#endif
+
 static int __init zcache_init(void)
 {
 	int ret = 0;
@@ -2053,6 +2084,8 @@ static int __init zcache_init(void)
 		pr_err("zcache: can't create client\n");
 		goto out;
 	}
+	if (__zcache_init_kvm())
+		goto out;
 #endif
 #ifdef CONFIG_CLEANCACHE
 	if (zcache_enabled && use_cleancache) {
Signature · 1 line
1.7.8.6
#7 lore raw

Re: [RFC 07/10] KVM: add KVM TMEM host side interface

Quoted 48 lines · Sasha Levin

This is the host side interface that the guests which support KVM TMEM talk to.

---
 arch/x86/kvm/tmem/Kconfig            |    6 +++
 arch/x86/kvm/tmem/Makefile           |    2 +
 arch/x86/kvm/tmem/host.c             |   78 ++++++++++++++++++++++++++++++++++
 arch/x86/kvm/tmem/host.h             |   20 +++++++++
 arch/x86/kvm/x86.c                   |    8 +---
 drivers/staging/zcache/zcache-main.c |   35 +++++++++++++++-
 6 files changed, 141 insertions(+), 8 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/host.c
 create mode 100644 arch/x86/kvm/tmem/host.h
arch/x86/kvm/tmem/Kconfig +6 -0
index 15d8301..1a59e4f 100644
@@ -13,4 +13,10 @@ menuconfig KVM_TMEM
 
 if KVM_TMEM
 
+config KVM_TMEM_HOST
+	bool "Host-side KVM TMEM"
+	---help---
+	With this option on, the KVM host will be able to process KVM TMEM requests
+	coming from guests.
+
 endif # KVM_TMEM
arch/x86/kvm/tmem/Makefile +2 -0
index 6812d46..706cd36 100644
@@ -1 +1,3 @@
 ccflags-y += -Idrivers/staging/zcache/
+
+obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
arch/x86/kvm/tmem/host.c new file +4 -0
new file mode 100644
index 0000000..9e73395
@@ -0,0 +1,78 @@
+/*
+ * KVM TMEM host side interface
+ *
+ * Copyright (c) 2012 Sasha Levin

arch/x86/kvm/tmem/host.c line 14

Quoted 10 lines
arch/x86/kvm/tmem/host.c new file +10 -0
+ *
+ */
+
+#include <linux/kvm_types.h>
+#include <linux/kvm_host.h>
+
+#include "tmem.h"
+#include <zcache.h>
+
+int use_kvm_tmem_host = 1;

__mostly_read and bool

Quoted 15 lines
arch/x86/kvm/tmem/host.c new file +15 -0
+
+static int no_kvmtmemhost(char *s)
+{
+	use_kvm_tmem_host = 0;
+	return 1;
+}
+
+__setup("nokvmtmemhost", no_kvmtmemhost);
+
+int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
+{
+	struct tmem_kvm_op op;
+	struct page *page;
+	int r;
+	unsigned long flags;

arch/x86/kvm/tmem/host.c line 39

Quoted 10 lines
arch/x86/kvm/tmem/host.c new file +10 -0
+
+	if (!use_kvm_tmem_host || !zcache_enabled) {
+		*ret = -ENXIO;
+		return 0;
+	}
+
+	r = kvm_read_guest(vcpu->kvm, addr, &op, sizeof(op));
+	if (r < 0) {
+		*ret = r;
+		return 0;

Shouldn't this return r?

Quoted 153 lines
arch/x86/kvm/tmem/host.c new file +39 -0
+	}
+
+	switch (op.cmd) {
+	case TMEM_NEW_POOL:
+		*ret = zcache_new_pool(op.cli_id, op.u.new.flags);
+		break;
+	case TMEM_DESTROY_POOL:
+		*ret = zcache_destroy_pool(op.cli_id, op.pool_id);
+		break;
+	case TMEM_NEW_PAGE:
+		break;
+	case TMEM_PUT_PAGE:
+		page = gfn_to_page(vcpu->kvm, op.u.gen.gfn);
+		local_irq_save(flags);
+		*ret = zcache_put_page(op.cli_id, op.pool_id,
+				&op.u.gen.oid, op.u.gen.index, page);
+		local_irq_restore(flags);
+		break;
+	case TMEM_GET_PAGE:
+		page = gfn_to_page(vcpu->kvm, op.u.gen.gfn);
+		local_irq_save(flags);
+		*ret = zcache_get_page(op.cli_id, op.pool_id,
+			&op.u.gen.oid, op.u.gen.index, page);
+		local_irq_restore(flags);
+		break;
+	case TMEM_FLUSH_PAGE:
+		local_irq_save(flags);
+		*ret = zcache_flush_page(op.cli_id, op.pool_id,
+				&op.u.gen.oid, op.u.gen.index);
+		local_irq_restore(flags);
+		break;
+	case TMEM_FLUSH_OBJECT:
+		local_irq_save(flags);
+		*ret = zcache_flush_object(op.cli_id, op.pool_id, &op.u.gen.oid);
+		local_irq_restore(flags);
+		break;
+	}
+	return 0;
+}
arch/x86/kvm/tmem/host.h new file +20 -0
new file mode 100644
index 0000000..17ba0c4
@@ -0,0 +1,20 @@
+#ifndef _KVM_TMEM_HOST_H_
+#define _KVM_TMEM_HOST_H_
+
+#ifdef CONFIG_KVM_TMEM_HOST
+
+extern int use_kvm_tmem_host;
+
+extern int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret);
+
+#else
+
+static inline int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
+{
+	*ret = -ENOSUPP;
+	return 0;
+}
+
+#endif
+
+#endif
arch/x86/kvm/x86.c +1 -7
index 4c5b6ab..c92d4c8 100644
@@ -27,6 +27,7 @@
 #include "kvm_cache_regs.h"
 #include "x86.h"
 #include "cpuid.h"
+#include "tmem/host.h"
 
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -4993,13 +4994,6 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 	return 1;
 }
 
-static int kvm_pv_tmem_op(struct kvm_vcpu *vcpu, gpa_t addr, unsigned long *ret)
-{
-	*ret = -ENOTSUPP;
-
-	return 0;
-}
-
 static inline gpa_t hc_gpa(struct kvm_vcpu *vcpu, unsigned long a0,
 				unsigned long a1)
 {
drivers/staging/zcache/zcache-main.c +34 -1
index a196aff..65c0ab0 100644
@@ -1692,7 +1692,7 @@ out:
 	return ret;
 }
 
-static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
+int zcache_new_pool(uint16_t cli_id, uint32_t flags)
 {
 	int poolid = -1;
 	struct tmem_pool *pool;
@@ -2011,6 +2011,37 @@ out:
 	return ret;
 }
 
+#ifdef CONFIG_KVM_TMEM_HOST
+extern int use_kvm_tmem_host;
+
+static int __zcache_init_kvm(void)
+{
+	int ret = 0;
+
+	if (use_kvm_tmem_host) {
+		ret = zcache_new_client(KVM_CLIENT);
+		if (ret) {
+			pr_err("zcache: can't create client\n");
+			return -1;
+		} else {
+			pr_info("zcache: enabled support for KVM TMEM\n");
+		}
+	}
+	zbud_init();
+	register_shrinker(&zcache_shrinker);
+
+	return 0;
+}
+
+#else
+
+static inline int static int __zcache_init_kvm(void)
+{
+	return 0;
+}
+
+#endif
+
 static int __init zcache_init(void)
 {
 	int ret = 0;
@@ -2053,6 +2084,8 @@ static int __init zcache_init(void)
 		pr_err("zcache: can't create client\n");
 		goto out;
 	}
+	if (__zcache_init_kvm())
+		goto out;
 #endif
 #ifdef CONFIG_CLEANCACHE
 	if (zcache_enabled && use_cleancache) {
Signature · 1 line
1.7.8.6
#8 lore raw

RFC 8/10 KVM: add KVM TMEM guest support

In reply to Sasha Levin

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

---
 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
arch/x86/kvm/tmem/Kconfig +3 -0
index 1a59e4f..85ec25b 100644
@@ -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
arch/x86/kvm/tmem/Makefile +1 -0
index 706cd36..1b15e20 100644
@@ -1,3 +1,4 @@
 ccflags-y += -Idrivers/staging/zcache/
 
 obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
+obj-$(CONFIG_KVM_TMEM_GUEST)			+= guest.o
arch/x86/kvm/tmem/guest.c new file +95 -0

95 lines not on this page · raw message

arch/x86/kvm/tmem/guest.h new file +11 -0
new file mode 100644
index 0000000..9225451
@@ -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
Signature · 1 line
1.7.8.6
#9 lore raw

RFC 9/10 KVM: support guest side cleancache

In reply to Sasha Levin

This patch adds support for guest-side cleancache. This is the part which communicates with the host regarding cleancache TMEM actions.

---
 arch/x86/kvm/tmem/Kconfig      |    9 +++
 arch/x86/kvm/tmem/Makefile     |    1 +
 arch/x86/kvm/tmem/cleancache.c |  120 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/cleancache.c
arch/x86/kvm/tmem/Kconfig +9 -0
index 85ec25b..4734db2 100644
@@ -22,4 +22,13 @@ config KVM_TMEM_HOST
 config KVM_TMEM_GUEST
 	bool
 
+config KVM_TMEM_GUEST_CLEANCACHE
+	bool "Guest-side cleancache support"
+	depends on CLEANCACHE
+	select KVM_TMEM_GUEST
+	---help---
+	This options enables guest to use cleanswap with the KVM host acting
+	as the TMEM target, which means that cleanswap may be used across
+	VMs (and even hosts).
+
 endif # KVM_TMEM
arch/x86/kvm/tmem/Makefile +1 -0
index 1b15e20..b972c2b 100644
@@ -2,3 +2,4 @@ ccflags-y += -Idrivers/staging/zcache/
 
 obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
 obj-$(CONFIG_KVM_TMEM_GUEST)			+= guest.o
+obj-$(CONFIG_KVM_TMEM_GUEST_CLEANCACHE)		+= cleancache.o
arch/x86/kvm/tmem/cleancache.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#10 lore raw

RFC 10/10 KVM: support guest side frontswap

In reply to Sasha Levin

This patch adds support for guest-side frontswap. This is the part which communicates with the host regarding frontswap TMEM actions.

---
 arch/x86/kvm/tmem/Kconfig     |    9 +++
 arch/x86/kvm/tmem/Makefile    |    1 +
 arch/x86/kvm/tmem/frontswap.c |  139 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kvm/tmem/frontswap.c
arch/x86/kvm/tmem/Kconfig +9 -0
index 4734db2..ae46299 100644
@@ -31,4 +31,13 @@ config KVM_TMEM_GUEST_CLEANCACHE
 	as the TMEM target, which means that cleanswap may be used across
 	VMs (and even hosts).
 
+config KVM_TMEM_GUEST_FRONTSWAP
+	bool "Guest-side frontswap support
+	depends on FRONTSWAP
+	select KVM_TMEM_GUEST
+	---help---
+	This option enables guest to use frontswap with the KVM host acting
+	as the TMEM target, which means that frontswap may be used across
+	VMs (and even hosts).
+
 endif # KVM_TMEM
arch/x86/kvm/tmem/Makefile +1 -0
index b972c2b..40c0561 100644
@@ -3,3 +3,4 @@ ccflags-y += -Idrivers/staging/zcache/
 obj-$(CONFIG_KVM_TMEM_HOST)			+= host.o
 obj-$(CONFIG_KVM_TMEM_GUEST)			+= guest.o
 obj-$(CONFIG_KVM_TMEM_GUEST_CLEANCACHE)		+= cleancache.o
+obj-$(CONFIG_KVM_TMEM_GUEST_FRONTSWAP)		+= frontswap.o
arch/x86/kvm/tmem/frontswap.c new file +139 -0

139 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#11 lore raw
In reply to Sasha Levin
Quoted 3 lines · Sasha Levin

While PV MMU is dead and gone, we'll still want to pass gpa from guest to host, and to do that properly we'll need to revive hc_gpa which died during the great PV MMU massacre of 3.2.

Missing 00/10 with a general explanation and benchmark results.

Signature · 1 line
error compiling committee.c: too many arguments to function
#12 lore raw
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Sasha Levin

While PV MMU is dead and gone, we'll still want to pass gpa from guest to host, and to do that properly we'll need to revive hc_gpa which died during the great PV MMU massacre of 3.2.

Missing 00/10 with a general explanation

Coming right up.

Quoted 1 line

and benchmark results.

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

#13 lore raw
Quoted 6 lines · Sasha Levin
Quoted 2 lines

and benchmark results.

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

Those are fine, thanks.

btw, IIUC, a guest can have two tmem providers: the hypervisor and zcache. How does it choose?

Signature · 1 line
error compiling committee.c: too many arguments to function
#14 lore raw
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Sasha Levin
Quoted 2 lines

and benchmark results.

Quoted 8 lines
Quoted 3 lines

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

Those are fine, thanks.

btw, IIUC, a guest can have two tmem providers: the hypervisor and zcache. How does it choose?

The guest will try to use the hypervisor, unless:

- 'nokvmcleancache' is passed as param - in that case cleancache will
use the local zcache provider.

- 'nokvmfrontswap' is passed as param - in that case frontswap will use
the local zcache provider.

#15 lore raw
Quoted 14 lines · Sasha Levin
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Sasha Levin
Quoted 2 lines

and benchmark results.

Quoted 8 lines
Quoted 3 lines

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

Those are fine, thanks.

btw, IIUC, a guest can have two tmem providers: the hypervisor and zcache. How does it choose?

Quoted 7 lines

The guest will try to use the hypervisor, unless:

- 'nokvmcleancache' is passed as param - in that case cleancache will
use the local zcache provider.

- 'nokvmfrontswap' is passed as param - in that case frontswap will use
the local zcache provider.

The guest may have more memory than free host memory, and its memory is certainly faster; but I'm not sure how to integrate this better.

Signature · 1 line
error compiling committee.c: too many arguments to function
#16 lore raw
Quoted 17 lines · Avi Kivity
Quoted 16 lines · Sasha Levin
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Sasha Levin
Quoted 2 lines

and benchmark results.

Quoted 8 lines
Quoted 3 lines

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

Those are fine, thanks.

btw, IIUC, a guest can have two tmem providers: the hypervisor and zcache. How does it choose?

The guest will try to use the hypervisor, unless:

Quoted 8 lines
Quoted 5 lines

- 'nokvmcleancache' is passed as param - in that case cleancache will
use the local zcache provider.

- 'nokvmfrontswap' is passed as param - in that case frontswap will use
the local zcache provider.

The guest may have more memory than free host memory, and its memory is certainly faster; but I'm not sure how to integrate this better.

Won't the free guest memory be exhausted first by regular local caching before cleancache springs into action?

#17 lore raw
Quoted 21 lines · Sasha Levin
Quoted 20 lines · Avi Kivity
Quoted 19 lines · Sasha Levin
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Sasha Levin
Quoted 2 lines

and benchmark results.

Quoted 8 lines
Quoted 3 lines

Is there a specific test you'd like to see? My tests were based around the "streaming test" you proposed last time this discussion came up, and runs of 'fio' in guests.

Those are fine, thanks.

btw, IIUC, a guest can have two tmem providers: the hypervisor and zcache. How does it choose?

The guest will try to use the hypervisor, unless:

- 'nokvmcleancache' is passed as param - in that case cleancache will
use the local zcache provider.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

- 'nokvmfrontswap' is passed as param - in that case frontswap will use
the local zcache provider.

The guest may have more memory than free host memory, and its memory is certainly faster; but I'm not sure how to integrate this better.

Won't the free guest memory be exhausted first by regular local caching before cleancache springs into action?

It would. But we don't know whether it would be better to compress and store on the guest (if we have 2:1 compression ratio, we need to process two pages to free one) or compress and store on the host (where the backing store is more or less free, but may be smaller, and is more expensive to access).

Signature · 1 line
error compiling committee.c: too many arguments to function