All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gregory Haskins <ghaskins@novell.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, avi@redhat.com
Subject: [RFC PATCH 1/3] add generic hypercall support
Date: Tue, 05 May 2009 09:24:37 -0400	[thread overview]
Message-ID: <20090505132437.19891.42922.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090505132005.19891.78436.stgit@dev.haskins.net>

We add a generic hypercall() mechanism for use by IO code which is
compatible with a variety of hypervisors, but which prefers to use
hypercalls over other types of hypervisor traps for performance and/or
feature reasons.

For instance, consider an emulated PCI device in KVM.  Today we can chose
to do IO over MMIO or PIO infrastructure, but they each have their own
distinct disadvantages:

*) MMIO causes a page-fault, which must be decoded by the hypervisor and is
   therefore fairly expensive.

*) PIO is more direct than MMIO, but it poses other problems such as:
      a) can have a small limited address space (x86 is 2^16)
      b) is a narrow-band interface (one 8, 16, 32, 64 bit word at a time)
      c) not available on all archs (PCI mentions ppc as problematic) and
         is therefore recommended to avoid.

Hypercalls, on the other hand, offer a direct access path like PIOs, yet
do not suffer the same drawbacks such as a limited address space or a
narrow-band interface.  Hypercalls are much more friendly to software
to software interaction since we can pack multiple registers in a way
that is natural and simple for software to utilize.

The problem with hypercalls today is that there is no generic support.
There is various support for hypervisor specific implementations (for
instance, see  kvm_hypercall0() in arch/x86/include/asm/kvm_para.h).  This
makes it difficult to implement a device that is hypervisor agnostic since
it would not only need to know the hypercall ABI, but also which platform
specific function call it should make.

If we can convey a dynamic binding to a specific hypercall vector in a
generic way (out of the scope of this patch series), then an IO driver
could utilize that dynamic binding to communicate without requiring
hypervisor specific knowledge.  Therefore, we implement a system wide
hypercall() interface based on a variable length list of unsigned longs
(representing registers to pack) and expect that various arch/hypervisor
implementations can fill in the details, if supported.  This is expected
to be done as part of the pv_ops infrastructure, which is the natural
hook-point for hypervisor specific code.  Note, however, that the
generic hypercall() interface does not require the implementation to use
pv_ops if so desired.

Example use case:
------------------

Consider a PCI device "X".  It can already advertise MMIO/PIO regions via
its BAR infrastructure.  With this new model it could also advertise a
hypercall vector in its device-specific upper configuration space.  (The
allocation and assignment of this vector on the backend is beyond the scope
of this series).  The guest-side driver for device "X" would sense (via
something like a feature-bit) if the hypercall was available and valid,
read the value with a configuration cycle, and proceed to ignore the BARs
in favor of using the hypercall() interface.

Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---

 include/linux/hypercall.h |   83 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/hypercall.h

diff --git a/include/linux/hypercall.h b/include/linux/hypercall.h
new file mode 100644
index 0000000..c8a1492
--- /dev/null
+++ b/include/linux/hypercall.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2009 Novell.  All Rights Reserved.
+ *
+ * Author:
+ *      Gregory Haskins <ghaskins@novell.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _LINUX_HYPERCALL_H
+#define _LINUX_HYPERCALL_H
+
+#ifdef CONFIG_HAVE_HYPERCALL
+
+long hypercall(unsigned long nr, unsigned long *args, size_t count);
+
+#else
+
+static inline long
+hypercall(unsigned long nr, unsigned long *args, size_t count)
+{
+	return -EINVAL;
+}
+
+#endif /* CONFIG_HAVE_HYPERCALL */
+
+#define hypercall0(nr) hypercall(nr, NULL, 0)
+#define hypercall1(nr, a1)                                              \
+	({						                \
+		unsigned long __args[] = { a1, };	                \
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+#define hypercall2(nr, a1, a2)						\
+	({						                \
+		unsigned long __args[] = { a1, a2, };	                \
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+#define hypercall3(nr, a1, a2, a3)			       		\
+	({						                \
+		unsigned long __args[] = { a1, a2, a3, };		\
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+#define hypercall4(nr, a1, a2, a3, a4)					\
+	({						                \
+		unsigned long __args[] = { a1, a2, a3, a4, };		\
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+#define hypercall5(nr, a1, a2, a3, a4, a5)				\
+	({						                \
+		unsigned long __args[] = { a1, a2, a3, a4, a5, };	\
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+#define hypercall6(nr, a1, a2, a3, a4, a5, a6)				\
+	({						                \
+		unsigned long __args[] = { a1, a2, a3, a4, a5, a6, };	\
+		long __ret;				                \
+		__ret = hypercall(nr, __args, ARRAY_SIZE(__args));      \
+		__ret;                                                  \
+	})
+
+
+#endif /* _LINUX_HYPERCALL_H */


  reply	other threads:[~2009-05-05 13:25 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-05 13:24 [RFC PATCH 0/3] generic hypercall support Gregory Haskins
2009-05-05 13:24 ` Gregory Haskins [this message]
2009-05-05 17:03   ` [RFC PATCH 1/3] add " Hollis Blanchard
2009-05-06 13:52   ` Anthony Liguori
2009-05-06 15:16     ` Gregory Haskins
2009-05-06 16:52       ` Arnd Bergmann
2009-05-05 13:24 ` [RFC PATCH 2/3] x86: " Gregory Haskins
2009-05-05 13:24 ` [RFC PATCH 3/3] kvm: add pv_cpu_ops.hypercall support to the guest Gregory Haskins
2009-05-05 13:36 ` [RFC PATCH 0/3] generic hypercall support Avi Kivity
2009-05-05 13:40   ` Gregory Haskins
2009-05-05 14:00     ` Avi Kivity
2009-05-05 14:14       ` Gregory Haskins
2009-05-05 14:21         ` Gregory Haskins
2009-05-05 15:02         ` Avi Kivity
2009-05-05 23:17         ` Chris Wright
2009-05-06  3:51           ` Gregory Haskins
2009-05-06  7:22             ` Chris Wright
2009-05-06 13:17               ` Gregory Haskins
2009-05-06 16:07                 ` Chris Wright
2009-05-07 17:03                   ` Gregory Haskins
2009-05-07 18:05                     ` Avi Kivity
2009-05-07 18:08                       ` Gregory Haskins
2009-05-07 18:12                         ` Avi Kivity
2009-05-07 18:16                           ` Gregory Haskins
2009-05-07 18:24                             ` Avi Kivity
2009-05-07 18:37                               ` Gregory Haskins
2009-05-07 19:00                                 ` Avi Kivity
2009-05-07 19:05                                   ` Gregory Haskins
2009-05-07 19:43                                     ` Avi Kivity
2009-05-07 20:07                                       ` Gregory Haskins
2009-05-07 20:15                                         ` Avi Kivity
2009-05-07 20:26                                           ` Gregory Haskins
2009-05-08  8:35                                             ` Avi Kivity
2009-05-08 11:29                                               ` Gregory Haskins
2009-05-07 19:07                                   ` Chris Wright
2009-05-07 19:12                                     ` Gregory Haskins
2009-05-07 19:21                                       ` Chris Wright
2009-05-07 19:26                                         ` Avi Kivity
2009-05-07 19:44                                           ` Avi Kivity
2009-05-07 19:29                                         ` Gregory Haskins
2009-05-07 20:25                                           ` Chris Wright
2009-05-07 20:34                                             ` Gregory Haskins
2009-05-07 20:54                                           ` Arnd Bergmann
2009-05-07 21:13                                             ` Gregory Haskins
2009-05-07 21:57                                               ` Chris Wright
2009-05-07 22:11                                                 ` Arnd Bergmann
2009-05-08 22:33                                                   ` Benjamin Herrenschmidt
2009-05-11 13:01                                                     ` Arnd Bergmann
2009-05-11 13:04                                                       ` Gregory Haskins
2009-05-07 20:00                             ` Arnd Bergmann
2009-05-07 20:31                               ` Gregory Haskins
2009-05-07 20:42                                 ` Arnd Bergmann
2009-05-07 20:47                                   ` Arnd Bergmann
2009-05-07 20:50                                 ` Chris Wright
2009-05-07 23:35                     ` Marcelo Tosatti
2009-05-07 23:43                       ` Marcelo Tosatti
2009-05-08  3:17                         ` Gregory Haskins
2009-05-08  7:55                         ` Avi Kivity
     [not found]                           ` <20090508103253.GC3011@amt.cnet>
2009-05-08 11:37                             ` Avi Kivity
2009-05-08 14:35                           ` Marcelo Tosatti
2009-05-08 14:45                             ` Gregory Haskins
2009-05-08 15:51                               ` Marcelo Tosatti
2009-05-08 19:56                                 ` David S. Ahern
2009-05-08 20:01                                   ` Gregory Haskins
2009-05-08 23:23                                     ` David S. Ahern
2009-05-09  8:45                                       ` Avi Kivity
2009-05-09 11:27                                         ` Gregory Haskins
2009-05-10  4:27                                           ` David S. Ahern
2009-05-10  5:24                                             ` Avi Kivity
2009-05-10  4:24                                         ` David S. Ahern
2009-05-08  3:13                       ` Gregory Haskins
2009-05-08  7:59                       ` Avi Kivity
2009-05-08 11:09                         ` Gregory Haskins
     [not found]                         ` <20090508104228.GD3011@amt.cnet>
2009-05-08 12:43                           ` Gregory Haskins
2009-05-08 15:33                             ` Marcelo Tosatti
2009-05-08 19:02                               ` Avi Kivity
2009-05-08 16:48                             ` Paul E. McKenney
2009-05-08 19:55                               ` Gregory Haskins
2009-05-08 14:15                       ` Gregory Haskins
2009-05-08 14:53                         ` Anthony Liguori
2009-05-08 18:50                           ` Avi Kivity
2009-05-08 19:02                             ` Anthony Liguori
2009-05-08 19:06                               ` Avi Kivity
2009-05-11 16:37                               ` Jeremy Fitzhardinge
2009-05-07 12:29                 ` Avi Kivity
2009-05-08 14:59                   ` Anthony Liguori
2009-05-09 12:01                     ` Gregory Haskins
2009-05-10 18:38                       ` Anthony Liguori
2009-05-11 13:14                         ` Gregory Haskins
2009-05-11 16:35                           ` Hollis Blanchard
2009-05-11 17:06                             ` Avi Kivity
2009-05-11 17:29                               ` Gregory Haskins
2009-05-11 17:53                                 ` Avi Kivity
2009-05-11 17:51                               ` Anthony Liguori
2009-05-11 18:02                                 ` Avi Kivity
2009-05-11 18:18                                   ` Anthony Liguori
2009-05-11 17:31                           ` Anthony Liguori
2009-05-13 10:53                             ` Gregory Haskins
2009-05-13 14:45                             ` Gregory Haskins
2009-05-11 16:44                         ` Hollis Blanchard
2009-05-11 17:54                           ` Anthony Liguori
2009-05-11 19:24                             ` PowerPC page faults Hollis Blanchard
2009-05-11 22:17                               ` Anthony Liguori
2009-05-12  5:46                                 ` Liu Yu-B13201
2009-05-12 14:50                                 ` Hollis Blanchard
2009-05-06 13:56             ` [RFC PATCH 0/3] generic hypercall support Anthony Liguori
2009-05-06 16:03               ` Gregory Haskins
2009-05-08  8:17                 ` Avi Kivity
2009-05-08 15:20                   ` Gregory Haskins
2009-05-08 17:00                     ` Avi Kivity
2009-05-08 18:55                       ` Gregory Haskins
2009-05-08 19:05                         ` Anthony Liguori
2009-05-08 19:12                         ` Avi Kivity
2009-05-08 19:59                           ` Gregory Haskins
2009-05-10  9:59                             ` 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=20090505132437.19891.42922.stgit@dev.haskins.net \
    --to=ghaskins@novell.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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.