From: ehrhardt@linux.vnet.ibm.com
To: kvm-ppc@vger.kernel.org, embedded-hypervisor@power.org,
linuxppc-dev@ozlabs.org
Cc: hollisb@us.ibm.com
Subject: [PATCH 5/6] kvmppc: magic page paravirtualization - guest part
Date: Wed, 23 Jul 2008 08:36:46 +0000 [thread overview]
Message-ID: <1216802207-32675-6-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1216802207-32675-1-git-send-email-ehrhardt@linux.vnet.ibm.com>
From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
This patch adds the guest handling for the magic page mechanism. A Hypervisor
can modify the device tree passed to the guest. Using that already existing
interface a guest can simply detect available hypervisor features and agree
on the supported ones using hypercalls.
In this example it is checked for the feature switch "feature,pv-magicpage"
in the hypervisor node and additional data which represents the size the
hypervisor requests in "data,pv-magicpage-size".
When the guest read that data and wants to support it the memory is allocated
and passed to the hypervisor using the KVM_HCALL_RESERVE_MAGICPAGE hypercall.
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---
[diffstat]
arch/powerpc/kernel/kvm.c | 48 +++++++++++++++++++++++++++++++++++++++++
include/asm-powerpc/kvm_para.h | 27 ++++++++++++++++++++++-
2 files changed, 74 insertions(+), 1 deletion(-)
[diff]
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -22,9 +22,57 @@
#include <linux/percpu.h>
#include <linux/mm.h>
#include <linux/kvm_para.h>
+#include <linux/bootmem.h>
+
+/*
+ * this is guest memory granted to the hypervisor;
+ * the hypervisor can place data in this area and rewrite
+ * privileged instructions to read from this area without
+ * trapping.
+ * Only the Hypervisor needs to be aware of the structure layout
+ * which makes the guest more felxible - the guest only guarantees
+ * the size which is requested by the hypervisor and read from a
+ * device tree entry.
+ */
+void *kvm_magicpage;
+
+static void __init kvmppc_register_magic_page(void)
+{
+ unsigned long paddr;
+ int size;
+ long err;
+
+ size = kvmppc_pv_read_data(KVM_PVDATA_MAGICPAGE_SIZE);
+ if (size < 0) {
+ printk(KERN_ERR"%s: couldn't read size for kvmppc style "
+ "paravirtualization support (got %d)\n",
+ __func__, size);
+ return;
+ }
+
+ /* FIXME Guest SMP needs that percpu
+ * On SMP we might also need a free implementation */
+ kvm_magicpage = alloc_bootmem(size);
+ if (!kvm_magicpage) {
+ printk(KERN_ERR"%s - failed to allocate %d bytes\n",
+ __func__, size);
+ return;
+ }
+
+ paddr = (unsigned long)__pa(kvm_magicpage);
+ err = kvm_hypercall1(KVM_HCALL_RESERVE_MAGICPAGE, paddr);
+ if (err)
+ printk(KERN_ERR"%s: couldn't register magic page\n", __func__);
+ else
+ printk(KERN_NOTICE"%s: registered %d bytes for "
+ "virtualization support\n", __func__, size);
+}
void __init kvm_guest_init(void)
{
if (!kvm_para_available())
return;
+
+ if (kvm_para_has_feature(KVM_FEATURE_PPCPV_MAGICPAGE))
+ kvmppc_register_magic_page();
}
diff --git a/include/asm-powerpc/kvm_para.h b/include/asm-powerpc/kvm_para.h
--- a/include/asm-powerpc/kvm_para.h
+++ b/include/asm-powerpc/kvm_para.h
@@ -28,10 +28,18 @@
#define KVM_HYPERCALL_BIN 0x03ffffff
+#define KVM_HCALL_RESERVE_MAGICPAGE 0
+
+#define KVM_PVDATA_MAGICPAGE_SIZE "data,pv-magicpage-size"
+
+/* List of PV features supported, returned as a bitfield */
+#define KVM_FEATURE_PPCPV_MAGICPAGE 0
+
static struct kvmppc_para_features {
char *dtcell;
int feature;
} para_features[] = {
+ { "feature,pv-magicpage", KVM_FEATURE_PPCPV_MAGICPAGE }
};
static inline int kvm_para_available(void)
@@ -54,13 +62,30 @@
if (!dn)
return 0;
- for (i = 0; i < ARRAY_SIZE(para_features)-1; i++) {
+ for (i = 0; i < ARRAY_SIZE(para_features); i++) {
dtval = of_get_property(dn, para_features[i].dtcell, NULL);
if (dtval && *dtval = 1)
features |= (1 << para_features[i].feature);
}
return features;
+}
+
+/* reads the specified data field out of the hypervisor node */
+static inline int kvmppc_pv_read_data(char *dtcell)
+{
+ struct device_node *dn;
+ const int *dtval;
+
+ dn = of_find_node_by_path("/hypervisor");
+ if (!dn)
+ return -EINVAL;
+
+ dtval = of_get_property(dn, dtcell, NULL);
+ if (dtval)
+ return *dtval;
+ else
+ return -EINVAL;
}
void kvm_guest_init(void);
WARNING: multiple messages have this Message-ID (diff)
From: ehrhardt@linux.vnet.ibm.com
To: kvm-ppc@vger.kernel.org, embedded-hypervisor@power.org,
linuxppc-dev@ozlabs.org
Cc: hollisb@us.ibm.com
Subject: [PATCH 5/6] kvmppc: magic page paravirtualization - guest part
Date: Wed, 23 Jul 2008 10:36:46 +0200 [thread overview]
Message-ID: <1216802207-32675-6-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1216802207-32675-1-git-send-email-ehrhardt@linux.vnet.ibm.com>
From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
This patch adds the guest handling for the magic page mechanism. A Hypervisor
can modify the device tree passed to the guest. Using that already existing
interface a guest can simply detect available hypervisor features and agree
on the supported ones using hypercalls.
In this example it is checked for the feature switch "feature,pv-magicpage"
in the hypervisor node and additional data which represents the size the
hypervisor requests in "data,pv-magicpage-size".
When the guest read that data and wants to support it the memory is allocated
and passed to the hypervisor using the KVM_HCALL_RESERVE_MAGICPAGE hypercall.
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---
[diffstat]
arch/powerpc/kernel/kvm.c | 48 +++++++++++++++++++++++++++++++++++++++++
include/asm-powerpc/kvm_para.h | 27 ++++++++++++++++++++++-
2 files changed, 74 insertions(+), 1 deletion(-)
[diff]
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -22,9 +22,57 @@
#include <linux/percpu.h>
#include <linux/mm.h>
#include <linux/kvm_para.h>
+#include <linux/bootmem.h>
+
+/*
+ * this is guest memory granted to the hypervisor;
+ * the hypervisor can place data in this area and rewrite
+ * privileged instructions to read from this area without
+ * trapping.
+ * Only the Hypervisor needs to be aware of the structure layout
+ * which makes the guest more felxible - the guest only guarantees
+ * the size which is requested by the hypervisor and read from a
+ * device tree entry.
+ */
+void *kvm_magicpage;
+
+static void __init kvmppc_register_magic_page(void)
+{
+ unsigned long paddr;
+ int size;
+ long err;
+
+ size = kvmppc_pv_read_data(KVM_PVDATA_MAGICPAGE_SIZE);
+ if (size < 0) {
+ printk(KERN_ERR"%s: couldn't read size for kvmppc style "
+ "paravirtualization support (got %d)\n",
+ __func__, size);
+ return;
+ }
+
+ /* FIXME Guest SMP needs that percpu
+ * On SMP we might also need a free implementation */
+ kvm_magicpage = alloc_bootmem(size);
+ if (!kvm_magicpage) {
+ printk(KERN_ERR"%s - failed to allocate %d bytes\n",
+ __func__, size);
+ return;
+ }
+
+ paddr = (unsigned long)__pa(kvm_magicpage);
+ err = kvm_hypercall1(KVM_HCALL_RESERVE_MAGICPAGE, paddr);
+ if (err)
+ printk(KERN_ERR"%s: couldn't register magic page\n", __func__);
+ else
+ printk(KERN_NOTICE"%s: registered %d bytes for "
+ "virtualization support\n", __func__, size);
+}
void __init kvm_guest_init(void)
{
if (!kvm_para_available())
return;
+
+ if (kvm_para_has_feature(KVM_FEATURE_PPCPV_MAGICPAGE))
+ kvmppc_register_magic_page();
}
diff --git a/include/asm-powerpc/kvm_para.h b/include/asm-powerpc/kvm_para.h
--- a/include/asm-powerpc/kvm_para.h
+++ b/include/asm-powerpc/kvm_para.h
@@ -28,10 +28,18 @@
#define KVM_HYPERCALL_BIN 0x03ffffff
+#define KVM_HCALL_RESERVE_MAGICPAGE 0
+
+#define KVM_PVDATA_MAGICPAGE_SIZE "data,pv-magicpage-size"
+
+/* List of PV features supported, returned as a bitfield */
+#define KVM_FEATURE_PPCPV_MAGICPAGE 0
+
static struct kvmppc_para_features {
char *dtcell;
int feature;
} para_features[] = {
+ { "feature,pv-magicpage", KVM_FEATURE_PPCPV_MAGICPAGE }
};
static inline int kvm_para_available(void)
@@ -54,13 +62,30 @@
if (!dn)
return 0;
- for (i = 0; i < ARRAY_SIZE(para_features)-1; i++) {
+ for (i = 0; i < ARRAY_SIZE(para_features); i++) {
dtval = of_get_property(dn, para_features[i].dtcell, NULL);
if (dtval && *dtval == 1)
features |= (1 << para_features[i].feature);
}
return features;
+}
+
+/* reads the specified data field out of the hypervisor node */
+static inline int kvmppc_pv_read_data(char *dtcell)
+{
+ struct device_node *dn;
+ const int *dtval;
+
+ dn = of_find_node_by_path("/hypervisor");
+ if (!dn)
+ return -EINVAL;
+
+ dtval = of_get_property(dn, dtcell, NULL);
+ if (dtval)
+ return *dtval;
+ else
+ return -EINVAL;
}
void kvm_guest_init(void);
next prev parent reply other threads:[~2008-07-23 8:36 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 8:36 [PATCH 0/6][RFC] kvmppc: paravirtualization interface ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-23 8:36 ` [PATCH 1/6] kvmppc: read device tree hypervisor node infrastructure ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-24 1:41 ` Tony Breeds
2008-07-24 1:41 ` Tony Breeds
2008-07-24 7:44 ` Christian Ehrhardt
2008-07-24 7:44 ` Christian Ehrhardt
2008-07-23 8:36 ` [PATCH 2/6] kvmppc: add hypercall infrastructure - host part ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-24 1:43 ` Tony Breeds
2008-07-24 1:43 ` Tony Breeds
2008-07-30 13:41 ` Geert Uytterhoeven
2008-07-30 13:41 ` Geert Uytterhoeven
2008-07-23 8:36 ` [PATCH 3/6] kvmppc: add hypercall infrastructure - guest part ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-24 1:45 ` Tony Breeds
2008-07-24 1:45 ` Tony Breeds
2008-07-24 7:56 ` Christian Ehrhardt
2008-07-24 7:56 ` Christian Ehrhardt
2008-07-23 8:36 ` [PATCH 4/6] kvmppc: magic page hypercall - host part ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-24 1:49 ` Tony Breeds
2008-07-24 1:49 ` Tony Breeds
2008-07-23 8:36 ` ehrhardt [this message]
2008-07-23 8:36 ` [PATCH 5/6] kvmppc: magic page paravirtualization - guest part ehrhardt
2008-07-24 1:59 ` Tony Breeds
2008-07-24 1:59 ` Tony Breeds
2008-07-23 8:36 ` [PATCH 6/6] kvmppc: kvm-userspace: device tree modification for magicpage ehrhardt
2008-07-23 8:36 ` ehrhardt
2008-07-24 2:01 ` [PATCH 0/6][RFC] kvmppc: paravirtualization interface Tony Breeds
2008-07-24 2:01 ` Tony Breeds
2008-07-24 8:17 ` Christian Ehrhardt
2008-07-24 8:17 ` Christian Ehrhardt
2008-07-25 1:08 ` Tony Breeds
2008-07-25 1:08 ` Tony Breeds
2008-08-19 10:36 ` [PATCH 0/6][RFC] kvmppc: paravirtualization interface - host part v2 ehrhardt
2008-09-16 6:27 ` [PATCH 0/6][RFC] kvmppc: paravirtualization interface - host part v3 ehrhardt
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=1216802207-32675-6-git-send-email-ehrhardt@linux.vnet.ibm.com \
--to=ehrhardt@linux.vnet.ibm.com \
--cc=embedded-hypervisor@power.org \
--cc=hollisb@us.ibm.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.