xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 3/5] x86/hvm: Improve memory_op hypercall dispatching
Date: Mon, 13 Feb 2017 13:03:46 +0000	[thread overview]
Message-ID: <1486991028-31097-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1486991028-31097-1-git-send-email-andrew.cooper3@citrix.com>

hvm_memory_op() and hvm_memory_op_compat32() are almost identical, but there
is no need to have two functions instantiated at the end of different function
pointers.

Combine the two into single hvm_memory_op() which dispatches to
{do,compat}_memory_op() based on the hcall_64bit setting.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
 xen/arch/x86/hvm/hypercall.c | 68 +++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 39 deletions(-)

diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index 11bd16d..0f3df4e 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -23,6 +23,29 @@
 
 #include <asm/hvm/support.h>
 
+static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
+{
+    struct vcpu *curr = current;
+    long rc;
+
+    switch ( cmd & MEMOP_CMD_MASK )
+    {
+    case XENMEM_machine_memory_map:
+    case XENMEM_machphys_mapping:
+        return -ENOSYS;
+    }
+
+    if ( curr->arch.hvm_vcpu.hcall_64bit )
+        rc = do_memory_op(cmd, arg);
+    else
+        rc = compat_memory_op(cmd, arg);
+
+    if ( (cmd & MEMOP_CMD_MASK) == XENMEM_decrease_reservation )
+        curr->domain->arch.hvm_domain.qemu_mapcache_invalidate = true;
+
+    return rc;
+}
+
 static int grant_table_op_is_allowed(unsigned int cmd)
 {
     switch (cmd) {
@@ -49,23 +72,6 @@ static long hvm_grant_table_op(
     return do_grant_table_op(cmd, uop, count);
 }
 
-static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
-{
-    long rc;
-
-    switch ( cmd & MEMOP_CMD_MASK )
-    {
-    case XENMEM_machine_memory_map:
-    case XENMEM_machphys_mapping:
-        return -ENOSYS;
-    case XENMEM_decrease_reservation:
-        rc = do_memory_op(cmd, arg);
-        current->domain->arch.hvm_domain.qemu_mapcache_invalidate = 1;
-        return rc;
-    }
-    return do_memory_op(cmd, arg);
-}
-
 static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     switch ( cmd )
@@ -92,23 +98,6 @@ static long hvm_grant_table_op_compat32(unsigned int cmd,
     return compat_grant_table_op(cmd, uop, count);
 }
 
-static long hvm_memory_op_compat32(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
-{
-    int rc;
-
-    switch ( cmd & MEMOP_CMD_MASK )
-    {
-    case XENMEM_machine_memory_map:
-    case XENMEM_machphys_mapping:
-        return -ENOSYS;
-    case XENMEM_decrease_reservation:
-        rc = compat_memory_op(cmd, arg);
-        current->domain->arch.hvm_domain.qemu_mapcache_invalidate = 1;
-        return rc;
-    }
-    return compat_memory_op(cmd, arg);
-}
-
 static long hvm_physdev_op_compat32(
     int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
@@ -131,12 +120,14 @@ static long hvm_physdev_op_compat32(
     [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                (hypercall_fn_t *) do_ ## x }
 
+#define HVM_CALL(x)                                          \
+    [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) hvm_ ## x, \
+                               (hypercall_fn_t *) hvm_ ## x }
+
 #define COMPAT_CALL(x)                                       \
     [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                (hypercall_fn_t *) compat_ ## x }
 
-#define do_memory_op          hvm_memory_op
-#define compat_memory_op      hvm_memory_op_compat32
 #define do_physdev_op         hvm_physdev_op
 #define compat_physdev_op     hvm_physdev_op_compat32
 #define do_grant_table_op     hvm_grant_table_op
@@ -144,7 +135,7 @@ static long hvm_physdev_op_compat32(
 #define do_arch_1             paging_domctl_continuation
 
 static const hypercall_table_t hvm_hypercall_table[] = {
-    COMPAT_CALL(memory_op),
+    HVM_CALL(memory_op),
     COMPAT_CALL(grant_table_op),
     COMPAT_CALL(vcpu_op),
     COMPAT_CALL(physdev_op),
@@ -167,8 +158,6 @@ static const hypercall_table_t hvm_hypercall_table[] = {
     HYPERCALL(arch_1)
 };
 
-#undef do_memory_op
-#undef compat_memory_op
 #undef do_physdev_op
 #undef compat_physdev_op
 #undef do_grant_table_op
@@ -176,6 +165,7 @@ static const hypercall_table_t hvm_hypercall_table[] = {
 #undef do_arch_1
 
 #undef HYPERCALL
+#undef HVM_CALL
 #undef COMPAT_CALL
 
 bool hvm_hypercall(struct cpu_user_regs *regs)
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-02-13 13:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 13:03 [PATCH 0/5] Improvements to HVM Hypercall dispatching Andrew Cooper
2017-02-13 13:03 ` [PATCH 1/5] x86/hvm: Rework HVM_HCALL_invalidate handling Andrew Cooper
2017-02-13 15:12   ` Boris Ostrovsky
2017-02-13 16:49   ` Jan Beulich
2017-02-13 17:01     ` Andrew Cooper
2017-02-13 17:23       ` Jan Beulich
2017-02-14  3:10   ` Tian, Kevin
2017-02-13 13:03 ` [PATCH 2/5] x86/hvm: Split the hypercall dispatching infrastructure out of hvm.c Andrew Cooper
2017-02-14 10:33   ` Jan Beulich
2017-02-14 10:33     ` Andrew Cooper
2017-02-14 10:41       ` Jan Beulich
2017-02-13 13:03 ` Andrew Cooper [this message]
2017-02-14 10:35   ` [PATCH 3/5] x86/hvm: Improve memory_op hypercall dispatching Jan Beulich
2017-02-13 13:03 ` [PATCH 4/5] x86/hvm: Improve grant_table_op " Andrew Cooper
2017-02-14 10:37   ` Jan Beulich
2017-02-13 13:03 ` [PATCH 5/5] x86/hvm: Improve physdev_op " Andrew Cooper
2017-02-14 10:38   ` Jan Beulich
2017-02-13 15:20 ` [PATCH 0/5] Improvements to HVM Hypercall dispatching Wei Liu

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=1486991028-31097-4-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).