[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/7] tools/xg: Simplify hypercall stubs



Now there are no pending dependencies on the current form of the hypercall
stubs. Replace them with simpler forms that only take the xc_cpu_policy
object. This way the plumbing logic becomes a lot simpler, allowing the
policy to be extended without touching the plumbing code.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>
---
 tools/libs/guest/xg_cpuid_x86.c | 59 ++++++++++++---------------------
 1 file changed, 22 insertions(+), 37 deletions(-)

diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index e2a2659953..cf07a69764 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -125,16 +125,17 @@ int xc_cpu_policy_get_size(xc_interface *xch, uint32_t 
*nr_leaves,
     return ret;
 }
 
-static int get_system_cpu_policy(xc_interface *xch, uint32_t index,
-                                 uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                                 uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+static int get_system_cpu_policy_serialised(xc_interface *xch, uint32_t index,
+                                            xc_cpu_policy_t *p)
 {
     struct xen_sysctl sysctl = {};
+    xen_cpuid_leaf_t *leaves = p->leaves.buf;
+    xen_msr_entry_t *msrs = p->msrs.buf;
     DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
+                             p->leaves.allocated * sizeof(*leaves),
                              XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
+                             p->msrs.allocated * sizeof(*msrs),
                              XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     int ret;
 
@@ -144,9 +145,9 @@ static int get_system_cpu_policy(xc_interface *xch, 
uint32_t index,
 
     sysctl.cmd = XEN_SYSCTL_get_cpu_policy;
     sysctl.u.cpu_policy.index = index;
-    sysctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    sysctl.u.cpu_policy.nr_leaves = p->leaves.allocated;
     set_xen_guest_handle(sysctl.u.cpu_policy.leaves, leaves);
-    sysctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    sysctl.u.cpu_policy.nr_msrs = p->msrs.allocated;
     set_xen_guest_handle(sysctl.u.cpu_policy.msrs, msrs);
 
     ret = do_sysctl(xch, &sysctl);
@@ -156,23 +157,24 @@ static int get_system_cpu_policy(xc_interface *xch, 
uint32_t index,
 
     if ( !ret )
     {
-        *nr_leaves = sysctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = sysctl.u.cpu_policy.nr_msrs;
+        p->leaves.len = sysctl.u.cpu_policy.nr_leaves;
+        p->msrs.len = sysctl.u.cpu_policy.nr_msrs;
     }
 
     return ret;
 }
 
-static int get_domain_cpu_policy(xc_interface *xch, uint32_t domid,
-                                 uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves,
-                                 uint32_t *nr_msrs, xen_msr_entry_t *msrs)
+static int get_domain_cpu_policy_serialised(xc_interface *xch, uint32_t domid,
+                                            xc_cpu_policy_t *p)
 {
     DECLARE_DOMCTL;
+    xen_cpuid_leaf_t *leaves = p->leaves.buf;
+    xen_msr_entry_t *msrs = p->msrs.buf;
     DECLARE_HYPERCALL_BOUNCE(leaves,
-                             *nr_leaves * sizeof(*leaves),
+                             p->leaves.allocated * sizeof(*leaves),
                              XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     DECLARE_HYPERCALL_BOUNCE(msrs,
-                             *nr_msrs * sizeof(*msrs),
+                             p->msrs.allocated * sizeof(*msrs),
                              XC_HYPERCALL_BUFFER_BOUNCE_OUT);
     int ret;
 
@@ -182,9 +184,9 @@ static int get_domain_cpu_policy(xc_interface *xch, 
uint32_t domid,
 
     domctl.cmd = XEN_DOMCTL_get_cpu_policy;
     domctl.domain = domid;
-    domctl.u.cpu_policy.nr_leaves = *nr_leaves;
+    domctl.u.cpu_policy.nr_leaves = p->leaves.allocated;
     set_xen_guest_handle(domctl.u.cpu_policy.leaves, leaves);
-    domctl.u.cpu_policy.nr_msrs = *nr_msrs;
+    domctl.u.cpu_policy.nr_msrs = p->msrs.allocated;
     set_xen_guest_handle(domctl.u.cpu_policy.msrs, msrs);
 
     ret = do_domctl(xch, &domctl);
@@ -194,8 +196,8 @@ static int get_domain_cpu_policy(xc_interface *xch, 
uint32_t domid,
 
     if ( !ret )
     {
-        *nr_leaves = domctl.u.cpu_policy.nr_leaves;
-        *nr_msrs = domctl.u.cpu_policy.nr_msrs;
+        p->leaves.len = domctl.u.cpu_policy.nr_leaves;
+        p->msrs.len = domctl.u.cpu_policy.nr_msrs;
     }
 
     return ret;
@@ -745,22 +747,14 @@ void xc_cpu_policy_destroy(xc_cpu_policy_t *policy)
 int xc_cpu_policy_get_system(xc_interface *xch, unsigned int policy_idx,
                              xc_cpu_policy_t *policy)
 {
-    unsigned int nr_leaves = policy->leaves.allocated;
-    unsigned int nr_msrs = policy->msrs.allocated;
     int rc;
 
-    rc = get_system_cpu_policy(xch, policy_idx,
-                               &nr_leaves, policy->leaves.buf,
-                               &nr_msrs, policy->msrs.buf);
-    if ( rc )
+    if ( (rc = get_system_cpu_policy_serialised(xch, policy_idx, policy)) )
     {
         PERROR("Failed to obtain %u policy", policy_idx);
         return rc;
     }
 
-    policy->leaves.len = nr_leaves;
-    policy->msrs.len = nr_msrs;
-
     rc = cpu_policy_deserialise_on_self(xch, policy);
     if ( rc )
     {
@@ -774,22 +768,13 @@ int xc_cpu_policy_get_system(xc_interface *xch, unsigned 
int policy_idx,
 int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid,
                              xc_cpu_policy_t *policy)
 {
-    unsigned int nr_leaves = policy->leaves.allocated;
-    unsigned int nr_msrs = policy->msrs.allocated;
-    int rc;
-
-    rc = get_domain_cpu_policy(xch, domid,
-                               &nr_leaves, policy->leaves.buf,
-                               &nr_msrs, policy->msrs.buf);
+    int rc = get_domain_cpu_policy_serialised(xch, domid, policy);
     if ( rc )
     {
         PERROR("Failed to obtain domain %u policy", domid);
         return rc;
     }
 
-    policy->leaves.len = nr_leaves;
-    policy->msrs.len = nr_msrs;
-
     rc = cpu_policy_deserialise_on_self(xch, policy);
     if ( rc )
     {
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.