All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
To: Christian Borntraeger
	<borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH/RFC] Per-architecture hypercall definitions
Date: Thu, 11 Oct 2007 08:14:11 -0500	[thread overview]
Message-ID: <470E21A3.50909@codemonkey.ws> (raw)
In-Reply-To: <200710111406.09439.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>

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/

  parent reply	other threads:[~2007-10-11 13:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
     [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

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=470E21A3.50909@codemonkey.ws \
    --to=anthony-rdkfgonbjusknkdkm+me6a@public.gmane.org \
    --cc=borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.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.