* [PATCH/RFC] Per-architecture hypercall definitions
@ 2007-10-11 12:06 Christian Borntraeger
[not found] ` <200710111406.09439.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Christian Borntraeger @ 2007-10-11 12:06 UTC (permalink / raw)
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Currently kvm provides hypercalls only for x86* architectures. To
provide hypercall infrastructure for other kvm architectures I split
kvm_para.h into a generic header file and architecture specific
definitions.
Currently there are definitions for s390 (experimental, ABI not final,
and I still have to find out how to get an assigned diagnose number)
and x86. I already made the split using the common x86 architecture
folder that will hit 2.6.24-rc soon.
One point for discussion:
i386 only supports up to 4 parameters. On s390 I coded definitions for
up to 6 parameters. Are we going to limit kvm to 4 parameters?
Besides the experimental state of the s390 ABI, the patch should be
mergable as soon as the x86 merge is finished.
Feedback is welcome.
Christian
---
include/asm-s390/kvm_para.h | 128 ++++++++++++++++++++++++++++++++++++++++++++
include/asm-x86/kvm_para.h | 110 +++++++++++++++++++++++++++++++++++++
include/linux/kvm_para.h | 112 ++++----------------------------------
3 files changed, 251 insertions(+), 99 deletions(-)
Index: kvm/include/asm-x86/kvm_para.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ kvm/include/asm-x86/kvm_para.h 2007-10-11 14:05:25.000000000 +0200
@@ -0,0 +1,108 @@
+#ifndef __X86_KVM_PARA_H
+#define __X86_KVM_PARA_H
+
+/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
+ * should be used to determine that a VM is running under KVM.
+ */
+#define KVM_CPUID_SIGNATURE 0x40000000
+
+/* This CPUID returns a feature bitmap in eax. Before enabling a particular
+ * paravirtualization, the appropriate feature bit should be checked.
+ */
+#define KVM_CPUID_FEATURES 0x40000001
+
+/* Return values for hypercalls */
+#define KVM_ENOSYS 1000
+
+#ifdef __KERNEL__
+#include <asm/processor.h>
+
+/* This instruction is vmcall. On non-VT architectures, it will generate a
+ * trap that we will then rewrite to the appropriate instruction.
+ */
+#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
+
+/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
+ * instruction. The hypervisor may replace it with something else but only the
+ * instructions are guaranteed to be supported.
+ *
+ * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
+ * The hypercall number should be placed in rax and the return value will be
+ * placed in rax. No other registers will be clobbered unless explicited
+ * noted by the particular hypercall.
+ */
+
+static inline long kvm_hypercall0(unsigned int nr)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr));
+ return ret;
+}
+
+static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1));
+ return ret;
+}
+
+static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
+ unsigned long p2)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2));
+ return ret;
+}
+
+static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
+ return ret;
+}
+
+static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
+ return ret;
+}
+
+static inline int kvm_para_available(void)
+{
+ unsigned int eax, ebx, ecx, edx;
+ char signature[13];
+
+ cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
+ memcpy(signature + 0, &ebx, 4);
+ memcpy(signature + 4, &ecx, 4);
+ memcpy(signature + 8, &edx, 4);
+ signature[12] = 0;
+
+ if (strcmp(signature, "KVMKVMKVM") == 0)
+ return 1;
+
+ return 0;
+}
+
+static inline unsigned int kvm_arch_para_features(void)
+{
+ return cpuid_eax(KVM_CPUID_FEATURES);
+}
+
+#endif
+
+#endif
Index: kvm/include/linux/kvm_para.h
===================================================================
--- kvm.orig/include/linux/kvm_para.h 2007-10-11 13:28:46.000000000 +0200
+++ kvm/include/linux/kvm_para.h 2007-10-11 14:06:47.000000000 +0200
@@ -1,110 +1,36 @@
#ifndef __LINUX_KVM_PARA_H
#define __LINUX_KVM_PARA_H
-/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
- * should be used to determine that a VM is running under KVM.
+/*
+ * This header file provides a method for making a hypercall to the host
+ * Architectures should define:
+ * - kvm_hypercall0, kvm_hypercall1...
+ * - kvm_arch_para_features
+ * - kvm_para_available
*/
-#define KVM_CPUID_SIGNATURE 0x40000000
-
-/* This CPUID returns a feature bitmap in eax. Before enabling a particular
- * paravirtualization, the appropriate feature bit should be checked.
- */
-#define KVM_CPUID_FEATURES 0x40000001
-
-/* Return values for hypercalls */
-#define KVM_ENOSYS 1000
#ifdef __KERNEL__
-#include <asm/processor.h>
-
-/* This instruction is vmcall. On non-VT architectures, it will generate a
- * trap that we will then rewrite to the appropriate instruction.
+/*
+ * hypercalls use architecture specific
*/
-#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
-
-/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
- * instruction. The hypervisor may replace it with something else but only the
- * instructions are guaranteed to be supported.
- *
- * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
- * The hypercall number should be placed in rax and the return value will be
- * placed in rax. No other registers will be clobbered unless explicited
- * noted by the particular hypercall.
- */
-
-static inline long kvm_hypercall0(unsigned int nr)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr));
- return ret;
-}
-
-static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1));
- return ret;
-}
-
-static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
- unsigned long p2)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2));
- return ret;
-}
-
-static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
- unsigned long p2, unsigned long p3)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
- return ret;
-}
-
-static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
- unsigned long p2, unsigned long p3,
- unsigned long p4)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
- return ret;
-}
-
-static inline int kvm_para_available(void)
-{
- unsigned int eax, ebx, ecx, edx;
- char signature[13];
-
- cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
- memcpy(signature + 0, &ebx, 4);
- memcpy(signature + 4, &ecx, 4);
- memcpy(signature + 8, &edx, 4);
- signature[12] = 0;
-
- if (strcmp(signature, "KVMKVMKVM") == 0)
- return 1;
-
- return 0;
-}
+#include <asm/kvm_para.h>
static inline int kvm_para_has_feature(unsigned int feature)
{
- if (cpuid_eax(KVM_CPUID_FEATURES) & (1UL << feature))
+ if (kvm_arch_para_features() & (1UL << feature))
return 1;
return 0;
}
-#endif
+#define kvm_hypercall(nr_params, args...) \
+({ \
+ long __ret; \
+ \
+ __ret = kvm_hypercall##nr_params(args); \
+ \
+ __ret; \
+})
+
+#endif
#endif
Index: kvm/include/asm-s390/kvm_para.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ kvm/include/asm-s390/kvm_para.h 2007-10-11 14:09:12.000000000 +0200
@@ -0,0 +1,146 @@
+#ifndef __S390_KVM_PARA_H
+#define __S390_KVM_PARA_H
+
+/*
+ * This is subject to change:
+ *
+ * Hypercalls for KVM on s390. The calling convention is similar to the
+ * s390 ABI, so we use R2-R6 for parameters 1-5. In addition we use R1
+ * as hypercall number and R7 as parameter 6. The return value is
+ * written to R2. We use the diagnose instruction as hypercall. To avoid
+ * conflicts with existing diagnoses for LPAR and z/VM, we do not use
+ * the instruction encoded number, but specify the number in R1 and
+ * use 0xBB as KVM diagnose number.
+ *
+ * Copyright 2007, IBM Corp.
+ * Author(s) Christian Borntraeger <borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.
+ */
+
+static inline long kvm_hypercall0(unsigned long nr)
+{
+ register unsigned long __nr asm("1") = nr;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr): "memory", "cc");
+ return __rc;
+}
+
+static inline long kvm_hypercall1(unsigned long nr, unsigned long p1)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1) : "memory", "cc");
+ return __rc;
+}
+
+static inline long kvm_hypercall2(unsigned long nr, unsigned long p1,
+ unsigned long p2)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register unsigned long __p2 asm("3") = p2;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2)
+ : "memory", "cc");
+ return __rc;
+}
+
+static inline long kvm_hypercall3(unsigned long nr, unsigned long p1,
+ unsigned long p2, unsigned long p3)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register unsigned long __p2 asm("3") = p2;
+ register unsigned long __p3 asm("4") = p3;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
+ "d" (__p3) : "memory", "cc");
+ return __rc;
+}
+
+
+static inline long kvm_hypercall4(unsigned long nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register unsigned long __p2 asm("3") = p2;
+ register unsigned long __p3 asm("4") = p3;
+ register unsigned long __p4 asm("5") = p4;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
+ "d" (__p3), "d" (__p4) : "memory", "cc");
+ return __rc;
+}
+
+static inline long kvm_hypercall5(unsigned long nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4, unsigned long p5)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register unsigned long __p2 asm("3") = p2;
+ register unsigned long __p3 asm("4") = p3;
+ register unsigned long __p4 asm("5") = p4;
+ register unsigned long __p5 asm("6") = p5;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
+ "d" (__p3), "d" (__p4), "d" (__p5) : "memory", "cc");
+ return __rc;
+}
+
+static inline long kvm_hypercall6(unsigned long nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4, unsigned long p5,
+ unsigned long p6)
+{
+ register unsigned long __nr asm("1") = nr;
+ register unsigned long __p1 asm("2") = p1;
+ register unsigned long __p2 asm("3") = p2;
+ register unsigned long __p3 asm("4") = p3;
+ register unsigned long __p4 asm("5") = p4;
+ register unsigned long __p5 asm("6") = p5;
+ register unsigned long __p6 asm("7") = p6;
+ register long __rc asm("2");
+
+ asm volatile ("diag 2,4,0xBB\n"
+ : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
+ "d" (__p3), "d" (__p4), "d" (__p5), "d" (__p6)
+ : "memory", "cc");
+ return __rc;
+}
+
+/*
+ * FIXME: make a real check as soon as we define how to check
+ */
+static inline int kvm_para_available(void)
+{
+ return 1;
+}
+
+/*
+ * FIXME: return available features
+ */
+static inline unsigned int kvm_arch_para_features(void)
+{
+ return 0;
+}
+
+
+
+#endif /* __S390_KVM_PARA_H */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC] Per-architecture hypercall definitions
[not found] ` <200710111406.09439.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
@ 2007-10-11 12:18 ` Avi Kivity
2007-10-11 13:14 ` Anthony Liguori
1 sibling, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2007-10-11 12:18 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Christian Borntraeger wrote:
> Currently kvm provides hypercalls only for x86* architectures. To
> provide hypercall infrastructure for other kvm architectures I split
> kvm_para.h into a generic header file and architecture specific
> definitions.
> Currently there are definitions for s390 (experimental, ABI not final,
> and I still have to find out how to get an assigned diagnose number)
> and x86. I already made the split using the common x86 architecture
> folder that will hit 2.6.24-rc soon.
>
>
Looks good. I'll commit (minus the s390 part) once the x86 merge is
behind us.
> One point for discussion:
>
> i386 only supports up to 4 parameters. On s390 I coded definitions for
> up to 6 parameters. Are we going to limit kvm to 4 parameters?
>
I guess we can add more parameters if the need arises. We don't clobber
registers so there's no issue with that.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC] Per-architecture hypercall definitions
[not found] ` <200710111406.09439.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-10-11 12:18 ` Avi Kivity
@ 2007-10-11 13:14 ` Anthony Liguori
[not found] ` <470E21A3.50909-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
1 sibling, 1 reply; 6+ messages in thread
From: Anthony Liguori @ 2007-10-11 13:14 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Christian Borntraeger wrote:
> ---
> include/asm-s390/kvm_para.h | 128 ++++++++++++++++++++++++++++++++++++++++++++
> include/asm-x86/kvm_para.h | 110 +++++++++++++++++++++++++++++++++++++
> include/linux/kvm_para.h | 112 ++++----------------------------------
> 3 files changed, 251 insertions(+), 99 deletions(-)
>
> Index: kvm/include/asm-x86/kvm_para.h
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ kvm/include/asm-x86/kvm_para.h 2007-10-11 14:05:25.000000000 +0200
> @@ -0,0 +1,108 @@
> +#ifndef __X86_KVM_PARA_H
> +#define __X86_KVM_PARA_H
> +
> +/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
> + * should be used to determine that a VM is running under KVM.
> + */
> +#define KVM_CPUID_SIGNATURE 0x40000000
> +
> +/* This CPUID returns a feature bitmap in eax. Before enabling a particular
> + * paravirtualization, the appropriate feature bit should be checked.
> + */
> +#define KVM_CPUID_FEATURES 0x40000001
> +
> +/* Return values for hypercalls */
> +#define KVM_ENOSYS 1000
>
errno's can probably be in common code, right?
>
> +#define kvm_hypercall(nr_params, args...) \
> +({ \
> + long __ret; \
> + \
> + __ret = kvm_hypercall##nr_params(args); \
> + \
> + __ret; \
> +})
>
Why store results to a variable? It would also probably be better to
use the C99 variadic macro format which would be:
#define kvm_hypercall(nr_params, ...) kvm_hypercall##nr_params(__VA_ARGS__)
I originally had one of these in my paravirt_ops implementation but
quickly found that the code it produced was pretty ugly. I think:
kvm_hypercall0(KVM_HYPERCALL_FOO);
Is a lot more understandable than:
kvm_hypercall(0, KVM_HYPERCALL_FOO);
It's much harder to guess with the later what the significance of the
first parameter is.
Regards,
Anthony Liguori
> +#endif
> #endif
> Index: kvm/include/asm-s390/kvm_para.h
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ kvm/include/asm-s390/kvm_para.h 2007-10-11 14:09:12.000000000 +0200
> @@ -0,0 +1,146 @@
> +#ifndef __S390_KVM_PARA_H
> +#define __S390_KVM_PARA_H
> +
> +/*
> + * This is subject to change:
> + *
> + * Hypercalls for KVM on s390. The calling convention is similar to the
> + * s390 ABI, so we use R2-R6 for parameters 1-5. In addition we use R1
> + * as hypercall number and R7 as parameter 6. The return value is
> + * written to R2. We use the diagnose instruction as hypercall. To avoid
> + * conflicts with existing diagnoses for LPAR and z/VM, we do not use
> + * the instruction encoded number, but specify the number in R1 and
> + * use 0xBB as KVM diagnose number.
> + *
> + * Copyright 2007, IBM Corp.
> + * Author(s) Christian Borntraeger <borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.
> + */
> +
> +static inline long kvm_hypercall0(unsigned long nr)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr): "memory", "cc");
> + return __rc;
> +}
> +
> +static inline long kvm_hypercall1(unsigned long nr, unsigned long p1)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1) : "memory", "cc");
> + return __rc;
> +}
> +
> +static inline long kvm_hypercall2(unsigned long nr, unsigned long p1,
> + unsigned long p2)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register unsigned long __p2 asm("3") = p2;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2)
> + : "memory", "cc");
> + return __rc;
> +}
> +
> +static inline long kvm_hypercall3(unsigned long nr, unsigned long p1,
> + unsigned long p2, unsigned long p3)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register unsigned long __p2 asm("3") = p2;
> + register unsigned long __p3 asm("4") = p3;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
> + "d" (__p3) : "memory", "cc");
> + return __rc;
> +}
> +
> +
> +static inline long kvm_hypercall4(unsigned long nr, unsigned long p1,
> + unsigned long p2, unsigned long p3,
> + unsigned long p4)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register unsigned long __p2 asm("3") = p2;
> + register unsigned long __p3 asm("4") = p3;
> + register unsigned long __p4 asm("5") = p4;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
> + "d" (__p3), "d" (__p4) : "memory", "cc");
> + return __rc;
> +}
> +
> +static inline long kvm_hypercall5(unsigned long nr, unsigned long p1,
> + unsigned long p2, unsigned long p3,
> + unsigned long p4, unsigned long p5)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register unsigned long __p2 asm("3") = p2;
> + register unsigned long __p3 asm("4") = p3;
> + register unsigned long __p4 asm("5") = p4;
> + register unsigned long __p5 asm("6") = p5;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
> + "d" (__p3), "d" (__p4), "d" (__p5) : "memory", "cc");
> + return __rc;
> +}
> +
> +static inline long kvm_hypercall6(unsigned long nr, unsigned long p1,
> + unsigned long p2, unsigned long p3,
> + unsigned long p4, unsigned long p5,
> + unsigned long p6)
> +{
> + register unsigned long __nr asm("1") = nr;
> + register unsigned long __p1 asm("2") = p1;
> + register unsigned long __p2 asm("3") = p2;
> + register unsigned long __p3 asm("4") = p3;
> + register unsigned long __p4 asm("5") = p4;
> + register unsigned long __p5 asm("6") = p5;
> + register unsigned long __p6 asm("7") = p6;
> + register long __rc asm("2");
> +
> + asm volatile ("diag 2,4,0xBB\n"
> + : "=d" (__rc) : "d" (__nr), "0" (__p1), "d" (__p2),
> + "d" (__p3), "d" (__p4), "d" (__p5), "d" (__p6)
> + : "memory", "cc");
> + return __rc;
> +}
> +
> +/*
> + * FIXME: make a real check as soon as we define how to check
> + */
> +static inline int kvm_para_available(void)
> +{
> + return 1;
> +}
> +
> +/*
> + * FIXME: return available features
> + */
> +static inline unsigned int kvm_arch_para_features(void)
> +{
> + return 0;
> +}
> +
> +
> +
> +#endif /* __S390_KVM_PARA_H */
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> kvm-devel mailing list
> kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC] Per-architecture hypercall definitions
[not found] ` <470E21A3.50909-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
@ 2007-10-11 13:34 ` Christian Borntraeger
[not found] ` <200710111534.17372.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Christian Borntraeger @ 2007-10-11 13:34 UTC (permalink / raw)
To: Anthony Liguori; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
> > +/* Return values for hypercalls */
> > +#define KVM_ENOSYS 1000
> >
>
> errno's can probably be in common code, right?
Yes, they can. Will move.
> I originally had one of these in my paravirt_ops implementation but
> quickly found that the code it produced was pretty ugly. I think:
>
> kvm_hypercall0(KVM_HYPERCALL_FOO);
>
> Is a lot more understandable than:
>
> kvm_hypercall(0, KVM_HYPERCALL_FOO);
>
> It's much harder to guess with the later what the significance of the
> first parameter is.
I agree. It seems I can simply remove the kvm_hypercall macro.
Here is the updated patch (without the s390 parts. Will send them later
when ready) and the changes mentioned above.
Avi, Anthony, comments?
[PATCH/RFC] Per-architecture hypercall definitions
Currently kvm provides hypercalls only for x86* architectures. To
provide hypercall infrastructure for other kvm architectures I split
kvm_para.h into a generic header file and architecture specific
definitions.
Signed-off-by: Christian Borntraeger <borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
Index: kvm/include/asm-x86/kvm_para.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ kvm/include/asm-x86/kvm_para.h 2007-10-11 15:41:24.000000000 +0200
@@ -0,0 +1,105 @@
+#ifndef __X86_KVM_PARA_H
+#define __X86_KVM_PARA_H
+
+/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
+ * should be used to determine that a VM is running under KVM.
+ */
+#define KVM_CPUID_SIGNATURE 0x40000000
+
+/* This CPUID returns a feature bitmap in eax. Before enabling a particular
+ * paravirtualization, the appropriate feature bit should be checked.
+ */
+#define KVM_CPUID_FEATURES 0x40000001
+
+#ifdef __KERNEL__
+#include <asm/processor.h>
+
+/* This instruction is vmcall. On non-VT architectures, it will generate a
+ * trap that we will then rewrite to the appropriate instruction.
+ */
+#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
+
+/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
+ * instruction. The hypervisor may replace it with something else but only the
+ * instructions are guaranteed to be supported.
+ *
+ * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
+ * The hypercall number should be placed in rax and the return value will be
+ * placed in rax. No other registers will be clobbered unless explicited
+ * noted by the particular hypercall.
+ */
+
+static inline long kvm_hypercall0(unsigned int nr)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr));
+ return ret;
+}
+
+static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1));
+ return ret;
+}
+
+static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
+ unsigned long p2)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2));
+ return ret;
+}
+
+static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
+ return ret;
+}
+
+static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
+ unsigned long p2, unsigned long p3,
+ unsigned long p4)
+{
+ long ret;
+ asm volatile(KVM_HYPERCALL
+ : "=a"(ret)
+ : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
+ return ret;
+}
+
+static inline int kvm_para_available(void)
+{
+ unsigned int eax, ebx, ecx, edx;
+ char signature[13];
+
+ cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
+ memcpy(signature + 0, &ebx, 4);
+ memcpy(signature + 4, &ecx, 4);
+ memcpy(signature + 8, &edx, 4);
+ signature[12] = 0;
+
+ if (strcmp(signature, "KVMKVMKVM") == 0)
+ return 1;
+
+ return 0;
+}
+
+static inline unsigned int kvm_arch_para_features(void)
+{
+ return cpuid_eax(KVM_CPUID_FEATURES);
+}
+
+#endif
+
+#endif
Index: kvm/include/linux/kvm_para.h
===================================================================
--- kvm.orig/include/linux/kvm_para.h 2007-10-11 13:28:46.000000000 +0200
+++ kvm/include/linux/kvm_para.h 2007-10-11 15:41:53.000000000 +0200
@@ -1,110 +1,29 @@
#ifndef __LINUX_KVM_PARA_H
#define __LINUX_KVM_PARA_H
-/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
- * should be used to determine that a VM is running under KVM.
+/*
+ * This header file provides a method for making a hypercall to the host
+ * Architectures should define:
+ * - kvm_hypercall0, kvm_hypercall1...
+ * - kvm_arch_para_features
+ * - kvm_para_available
*/
-#define KVM_CPUID_SIGNATURE 0x40000000
-
-/* This CPUID returns a feature bitmap in eax. Before enabling a particular
- * paravirtualization, the appropriate feature bit should be checked.
- */
-#define KVM_CPUID_FEATURES 0x40000001
/* Return values for hypercalls */
#define KVM_ENOSYS 1000
#ifdef __KERNEL__
-#include <asm/processor.h>
-
-/* This instruction is vmcall. On non-VT architectures, it will generate a
- * trap that we will then rewrite to the appropriate instruction.
- */
-#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
-
-/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
- * instruction. The hypervisor may replace it with something else but only the
- * instructions are guaranteed to be supported.
- *
- * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
- * The hypercall number should be placed in rax and the return value will be
- * placed in rax. No other registers will be clobbered unless explicited
- * noted by the particular hypercall.
+/*
+ * hypercalls use architecture specific
*/
-
-static inline long kvm_hypercall0(unsigned int nr)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr));
- return ret;
-}
-
-static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1));
- return ret;
-}
-
-static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
- unsigned long p2)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2));
- return ret;
-}
-
-static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
- unsigned long p2, unsigned long p3)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
- return ret;
-}
-
-static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
- unsigned long p2, unsigned long p3,
- unsigned long p4)
-{
- long ret;
- asm volatile(KVM_HYPERCALL
- : "=a"(ret)
- : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
- return ret;
-}
-
-static inline int kvm_para_available(void)
-{
- unsigned int eax, ebx, ecx, edx;
- char signature[13];
-
- cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
- memcpy(signature + 0, &ebx, 4);
- memcpy(signature + 4, &ecx, 4);
- memcpy(signature + 8, &edx, 4);
- signature[12] = 0;
-
- if (strcmp(signature, "KVMKVMKVM") == 0)
- return 1;
-
- return 0;
-}
+#include <asm/kvm_para.h>
static inline int kvm_para_has_feature(unsigned int feature)
{
- if (cpuid_eax(KVM_CPUID_FEATURES) & (1UL << feature))
+ if (kvm_arch_para_features() & (1UL << feature))
return 1;
return 0;
}
+#endif /* __KERNEL__ */
+#endif /* __LINUX_KVM_PARA_H */
-#endif
-
-#endif
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC] Per-architecture hypercall definitions
[not found] ` <200710111534.17372.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
@ 2007-10-11 14:11 ` Anthony Liguori
2007-10-22 12:06 ` Avi Kivity
1 sibling, 0 replies; 6+ messages in thread
From: Anthony Liguori @ 2007-10-11 14:11 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Christian Borntraeger wrote:
>
> I agree. It seems I can simply remove the kvm_hypercall macro.
>
> Here is the updated patch (without the s390 parts. Will send them later
> when ready) and the changes mentioned above.
>
> Avi, Anthony, comments?
>
It looks good to me.
Regards,
Anthony Liguori
> [PATCH/RFC] Per-architecture hypercall definitions
>
> Currently kvm provides hypercalls only for x86* architectures. To
> provide hypercall infrastructure for other kvm architectures I split
> kvm_para.h into a generic header file and architecture specific
> definitions.
>
> Signed-off-by: Christian Borntraeger <borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
>
> Index: kvm/include/asm-x86/kvm_para.h
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ kvm/include/asm-x86/kvm_para.h 2007-10-11 15:41:24.000000000 +0200
> @@ -0,0 +1,105 @@
> +#ifndef __X86_KVM_PARA_H
> +#define __X86_KVM_PARA_H
> +
> +/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
> + * should be used to determine that a VM is running under KVM.
> + */
> +#define KVM_CPUID_SIGNATURE 0x40000000
> +
> +/* This CPUID returns a feature bitmap in eax. Before enabling a particular
> + * paravirtualization, the appropriate feature bit should be checked.
> + */
> +#define KVM_CPUID_FEATURES 0x40000001
> +
> +#ifdef __KERNEL__
> +#include <asm/processor.h>
> +
> +/* This instruction is vmcall. On non-VT architectures, it will generate a
> + * trap that we will then rewrite to the appropriate instruction.
> + */
> +#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
> +
> +/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
> + * instruction. The hypervisor may replace it with something else but only the
> + * instructions are guaranteed to be supported.
> + *
> + * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
> + * The hypercall number should be placed in rax and the return value will be
> + * placed in rax. No other registers will be clobbered unless explicited
> + * noted by the particular hypercall.
> + */
> +
> +static inline long kvm_hypercall0(unsigned int nr)
> +{
> + long ret;
> + asm volatile(KVM_HYPERCALL
> + : "=a"(ret)
> + : "a"(nr));
> + return ret;
> +}
> +
> +static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
> +{
> + long ret;
> + asm volatile(KVM_HYPERCALL
> + : "=a"(ret)
> + : "a"(nr), "b"(p1));
> + return ret;
> +}
> +
> +static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
> + unsigned long p2)
> +{
> + long ret;
> + asm volatile(KVM_HYPERCALL
> + : "=a"(ret)
> + : "a"(nr), "b"(p1), "c"(p2));
> + return ret;
> +}
> +
> +static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
> + unsigned long p2, unsigned long p3)
> +{
> + long ret;
> + asm volatile(KVM_HYPERCALL
> + : "=a"(ret)
> + : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
> + return ret;
> +}
> +
> +static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> + unsigned long p2, unsigned long p3,
> + unsigned long p4)
> +{
> + long ret;
> + asm volatile(KVM_HYPERCALL
> + : "=a"(ret)
> + : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
> + return ret;
> +}
> +
> +static inline int kvm_para_available(void)
> +{
> + unsigned int eax, ebx, ecx, edx;
> + char signature[13];
> +
> + cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
> + memcpy(signature + 0, &ebx, 4);
> + memcpy(signature + 4, &ecx, 4);
> + memcpy(signature + 8, &edx, 4);
> + signature[12] = 0;
> +
> + if (strcmp(signature, "KVMKVMKVM") == 0)
> + return 1;
> +
> + return 0;
> +}
> +
> +static inline unsigned int kvm_arch_para_features(void)
> +{
> + return cpuid_eax(KVM_CPUID_FEATURES);
> +}
> +
> +#endif
> +
> +#endif
> Index: kvm/include/linux/kvm_para.h
> ===================================================================
> --- kvm.orig/include/linux/kvm_para.h 2007-10-11 13:28:46.000000000 +0200
> +++ kvm/include/linux/kvm_para.h 2007-10-11 15:41:53.000000000 +0200
> @@ -1,110 +1,29 @@
> #ifndef __LINUX_KVM_PARA_H
> #define __LINUX_KVM_PARA_H
>
> -/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
> - * should be used to determine that a VM is running under KVM.
> +/*
> + * This header file provides a method for making a hypercall to the host
> + * Architectures should define:
> + * - kvm_hypercall0, kvm_hypercall1...
> + * - kvm_arch_para_features
> + * - kvm_para_available
> */
> -#define KVM_CPUID_SIGNATURE 0x40000000
> -
> -/* This CPUID returns a feature bitmap in eax. Before enabling a particular
> - * paravirtualization, the appropriate feature bit should be checked.
> - */
> -#define KVM_CPUID_FEATURES 0x40000001
>
> /* Return values for hypercalls */
> #define KVM_ENOSYS 1000
>
> #ifdef __KERNEL__
> -#include <asm/processor.h>
> -
> -/* This instruction is vmcall. On non-VT architectures, it will generate a
> - * trap that we will then rewrite to the appropriate instruction.
> - */
> -#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
> -
> -/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
> - * instruction. The hypervisor may replace it with something else but only the
> - * instructions are guaranteed to be supported.
> - *
> - * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
> - * The hypercall number should be placed in rax and the return value will be
> - * placed in rax. No other registers will be clobbered unless explicited
> - * noted by the particular hypercall.
> +/*
> + * hypercalls use architecture specific
> */
> -
> -static inline long kvm_hypercall0(unsigned int nr)
> -{
> - long ret;
> - asm volatile(KVM_HYPERCALL
> - : "=a"(ret)
> - : "a"(nr));
> - return ret;
> -}
> -
> -static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
> -{
> - long ret;
> - asm volatile(KVM_HYPERCALL
> - : "=a"(ret)
> - : "a"(nr), "b"(p1));
> - return ret;
> -}
> -
> -static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
> - unsigned long p2)
> -{
> - long ret;
> - asm volatile(KVM_HYPERCALL
> - : "=a"(ret)
> - : "a"(nr), "b"(p1), "c"(p2));
> - return ret;
> -}
> -
> -static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
> - unsigned long p2, unsigned long p3)
> -{
> - long ret;
> - asm volatile(KVM_HYPERCALL
> - : "=a"(ret)
> - : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
> - return ret;
> -}
> -
> -static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> - unsigned long p2, unsigned long p3,
> - unsigned long p4)
> -{
> - long ret;
> - asm volatile(KVM_HYPERCALL
> - : "=a"(ret)
> - : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
> - return ret;
> -}
> -
> -static inline int kvm_para_available(void)
> -{
> - unsigned int eax, ebx, ecx, edx;
> - char signature[13];
> -
> - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
> - memcpy(signature + 0, &ebx, 4);
> - memcpy(signature + 4, &ecx, 4);
> - memcpy(signature + 8, &edx, 4);
> - signature[12] = 0;
> -
> - if (strcmp(signature, "KVMKVMKVM") == 0)
> - return 1;
> -
> - return 0;
> -}
> +#include <asm/kvm_para.h>
>
> static inline int kvm_para_has_feature(unsigned int feature)
> {
> - if (cpuid_eax(KVM_CPUID_FEATURES) & (1UL << feature))
> + if (kvm_arch_para_features() & (1UL << feature))
> return 1;
> return 0;
> }
> +#endif /* __KERNEL__ */
> +#endif /* __LINUX_KVM_PARA_H */
>
> -#endif
> -
> -#endif
>
>
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH/RFC] Per-architecture hypercall definitions
[not found] ` <200710111534.17372.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-10-11 14:11 ` Anthony Liguori
@ 2007-10-22 12:06 ` Avi Kivity
1 sibling, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2007-10-22 12:06 UTC (permalink / raw)
To: Christian Borntraeger; +Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Christian Borntraeger wrote:
> [PATCH/RFC] Per-architecture hypercall definitions
>
> Currently kvm provides hypercalls only for x86* architectures. To
> provide hypercall infrastructure for other kvm architectures I split
> kvm_para.h into a generic header file and architecture specific
> definitions.
>
>
Applied, thanks.
--
error compiling committee.c: too many arguments to function
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-10-22 12:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-11 12:06 [PATCH/RFC] Per-architecture hypercall definitions Christian Borntraeger
[not found] ` <200710111406.09439.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-10-11 12:18 ` Avi Kivity
2007-10-11 13:14 ` Anthony Liguori
[not found] ` <470E21A3.50909-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-10-11 13:34 ` Christian Borntraeger
[not found] ` <200710111534.17372.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-10-11 14:11 ` Anthony Liguori
2007-10-22 12:06 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox