aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDario Faggioli <dario.faggioli@citrix.com>2013-09-10 19:53:40 +0200
committerIan Campbell <ian.campbell@citrix.com>2013-09-13 13:06:28 +0100
commit0dd5b654107103765994243017a7f0eb15fda341 (patch)
treeaa5f3648656674a0f48b8b6a3663f5799937b588 /tools
parentbd9a0528ebc68ddb723feef6be57f75096d9df52 (diff)
downloadxen-0dd5b654107103765994243017a7f0eb15fda341.tar.gz
xen-0dd5b654107103765994243017a7f0eb15fda341.tar.bz2
xen-0dd5b654107103765994243017a7f0eb15fda341.zip
libxc: introduce xc_domain_get_guest_width()
As a wrapper to XEN_DOMCTL_get_address_size, and use it wherever the call was being issued directly via do_domctl(), saving quite some line of code. Actually, the function returns the guest width in bytes, rather than directly what XEN_DOMCTL_get_address_size provides (which is a number of bits), since that is what it is useful almost everywhere. Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/libxc/xc_core.c20
-rw-r--r--tools/libxc/xc_cpuid_x86.c8
-rw-r--r--tools/libxc/xc_dom_x86.c13
-rw-r--r--tools/libxc/xc_domain.c16
-rw-r--r--tools/libxc/xc_offline_page.c9
-rw-r--r--tools/libxc/xc_pagetab.c8
-rw-r--r--tools/libxc/xc_resume.c21
-rw-r--r--tools/libxc/xenctrl.h13
-rw-r--r--tools/libxc/xg_save_restore.h9
-rw-r--r--tools/xentrace/xenctx.c9
10 files changed, 48 insertions, 78 deletions
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c
index 4207eed6dc..4bc1abb441 100644
--- a/tools/libxc/xc_core.c
+++ b/tools/libxc/xc_core.c
@@ -417,24 +417,6 @@ elfnote_dump_format_version(xc_interface *xch,
return dump_rtn(xch, args, (char*)&format_version, sizeof(format_version));
}
-static int
-get_guest_width(xc_interface *xch,
- uint32_t domid,
- unsigned int *guest_width)
-{
- DECLARE_DOMCTL;
-
- memset(&domctl, 0, sizeof(domctl));
- domctl.domain = domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
-
- if ( do_domctl(xch, &domctl) != 0 )
- return 1;
-
- *guest_width = domctl.u.address_size.size / 8;
- return 0;
-}
-
int
xc_domain_dumpcore_via_callback(xc_interface *xch,
uint32_t domid,
@@ -478,7 +460,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch,
struct xc_core_section_headers *sheaders = NULL;
Elf64_Shdr *shdr;
- if ( get_guest_width(xch, domid, &dinfo->guest_width) != 0 )
+ if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) != 0 )
{
PERROR("Could not get address size for domain");
return sts;
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index fa47787d3e..bbbf9b80eb 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -436,17 +436,15 @@ static void xc_cpuid_pv_policy(
const unsigned int *input, unsigned int *regs)
{
DECLARE_DOMCTL;
+ unsigned int guest_width;
int guest_64bit, xen_64bit = hypervisor_is_64bit(xch);
char brand[13];
uint64_t xfeature_mask;
xc_cpuid_brand_get(brand);
- memset(&domctl, 0, sizeof(domctl));
- domctl.domain = domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
- do_domctl(xch, &domctl);
- guest_64bit = (domctl.u.address_size.size == 64);
+ xc_domain_get_guest_width(xch, domid, &guest_width);
+ guest_64bit = (guest_width == 8);
/* Detecting Xen's atitude towards XSAVE */
memset(&domctl, 0, sizeof(domctl));
diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index 41f59d3dd1..7cc2ff2411 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -54,24 +54,17 @@ const char *xc_domain_get_native_protocol(xc_interface *xch,
int ret;
uint32_t guest_width;
const char *protocol;
- DECLARE_DOMCTL;
- memset(&domctl, 0, sizeof(domctl));
- domctl.domain = domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
-
- ret = do_domctl(xch, &domctl);
+ ret = xc_domain_get_guest_width(xch, domid, &guest_width);
if ( ret )
return NULL;
- guest_width = domctl.u.address_size.size;
-
switch (guest_width) {
- case 32: /* 32 bit guest */
+ case 4: /* 32 bit guest */
protocol = XEN_IO_PROTO_ABI_X86_32;
break;
- case 64: /* 64 bit guest */
+ case 8: /* 64 bit guest */
protocol = XEN_IO_PROTO_ABI_X86_64;
break;
default:
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 3257e2af94..c0ce079e3d 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -270,6 +270,22 @@ out:
return ret;
}
+int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid,
+ unsigned int *guest_width)
+{
+ DECLARE_DOMCTL;
+
+ memset(&domctl, 0, sizeof(domctl));
+ domctl.domain = domid;
+ domctl.cmd = XEN_DOMCTL_get_address_size;
+
+ if ( do_domctl(xch, &domctl) != 0 )
+ return 1;
+
+ /* We want the result in bytes */
+ *guest_width = domctl.u.address_size.size / 8;
+ return 0;
+}
int xc_domain_getinfo(xc_interface *xch,
uint32_t first_domid,
diff --git a/tools/libxc/xc_offline_page.c b/tools/libxc/xc_offline_page.c
index 36b981285c..1f6dbc6d5e 100644
--- a/tools/libxc/xc_offline_page.c
+++ b/tools/libxc/xc_offline_page.c
@@ -193,21 +193,14 @@ static int get_pt_level(xc_interface *xch, uint32_t domid,
unsigned int *pt_level,
unsigned int *gwidth)
{
- DECLARE_DOMCTL;
xen_capabilities_info_t xen_caps = "";
if (xc_version(xch, XENVER_capabilities, &xen_caps) != 0)
return -1;
- memset(&domctl, 0, sizeof(domctl));
- domctl.domain = domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
-
- if ( do_domctl(xch, &domctl) != 0 )
+ if (xc_domain_get_guest_width(xch, domid, gwidth) != 0)
return -1;
- *gwidth = domctl.u.address_size.size / 8;
-
if (strstr(xen_caps, "xen-3.0-x86_64"))
/* Depends on whether it's a compat 32-on-64 guest */
*pt_level = ( (*gwidth == 8) ? 4 : 3 );
diff --git a/tools/libxc/xc_pagetab.c b/tools/libxc/xc_pagetab.c
index 27c4e9fcbc..8525967527 100644
--- a/tools/libxc/xc_pagetab.c
+++ b/tools/libxc/xc_pagetab.c
@@ -51,15 +51,13 @@ unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom,
pt_levels = (ctx.msr_efer&EFER_LMA) ? 4 : (ctx.cr4&CR4_PAE) ? 3 : 2;
paddr = ctx.cr3 & ((pt_levels == 3) ? ~0x1full : ~0xfffull);
} else {
- DECLARE_DOMCTL;
+ unsigned int gwidth;
vcpu_guest_context_any_t ctx;
if (xc_vcpu_getcontext(xch, dom, vcpu, &ctx) != 0)
return 0;
- domctl.domain = dom;
- domctl.cmd = XEN_DOMCTL_get_address_size;
- if ( do_domctl(xch, &domctl) != 0 )
+ if (xc_domain_get_guest_width(xch, dom, &gwidth) != 0)
return 0;
- if (domctl.u.address_size.size == 64) {
+ if (gwidth == 8) {
pt_levels = 4;
paddr = (uint64_t)xen_cr3_to_pfn_x86_64(ctx.x64.ctrlreg[3])
<< PAGE_SHIFT;
diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c
index 1c43ec612d..cb6165049f 100644
--- a/tools/libxc/xc_resume.c
+++ b/tools/libxc/xc_resume.c
@@ -24,19 +24,6 @@
#include <xen/foreign/x86_64.h>
#include <xen/hvm/params.h>
-static int pv_guest_width(xc_interface *xch, uint32_t domid)
-{
- DECLARE_DOMCTL;
- domctl.domain = domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
- if ( xc_domctl(xch, &domctl) != 0 )
- {
- PERROR("Could not get guest address size");
- return -1;
- }
- return domctl.u.address_size.size / 8;
-}
-
static int modify_returncode(xc_interface *xch, uint32_t domid)
{
vcpu_guest_context_any_t ctxt;
@@ -71,8 +58,7 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
else
{
/* Probe PV guest address width. */
- dinfo->guest_width = pv_guest_width(xch, domid);
- if ( dinfo->guest_width < 0 )
+ if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) )
return -1;
}
@@ -120,7 +106,8 @@ static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)
xc_dominfo_t info;
int i, rc = -1;
#if defined(__i386__) || defined(__x86_64__)
- struct domain_info_context _dinfo = { .p2m_size = 0 };
+ struct domain_info_context _dinfo = { .guest_width = 0,
+ .p2m_size = 0 };
struct domain_info_context *dinfo = &_dinfo;
unsigned long mfn;
vcpu_guest_context_any_t ctxt;
@@ -147,7 +134,7 @@ static int xc_domain_resume_any(xc_interface *xch, uint32_t domid)
return rc;
}
- dinfo->guest_width = pv_guest_width(xch, domid);
+ xc_domain_get_guest_width(xch, domid, &dinfo->guest_width);
if ( dinfo->guest_width != sizeof(long) )
{
ERROR("Cannot resume uncooperative cross-address-size guests");
diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h
index f2cebafc9d..58d51f353a 100644
--- a/tools/libxc/xenctrl.h
+++ b/tools/libxc/xenctrl.h
@@ -560,6 +560,19 @@ int xc_vcpu_getaffinity(xc_interface *xch,
int vcpu,
xc_cpumap_t cpumap);
+
+/**
+ * This function will return the guest_width (in bytes) for the
+ * specified domain.
+ *
+ * @param xch a handle to an open hypervisor interface.
+ * @param domid the domain id one wants the address size width of.
+ * @param addr_size the address size.
+ */
+int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid,
+ unsigned int *guest_width);
+
+
/**
* This function will return information about one or more domains. It is
* designed to iterate over the list of domains. If a single domain is
diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
index 651200339b..f859621f62 100644
--- a/tools/libxc/xg_save_restore.h
+++ b/tools/libxc/xg_save_restore.h
@@ -301,7 +301,6 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
{
xen_capabilities_info_t xen_caps = "";
xen_platform_parameters_t xen_params;
- DECLARE_DOMCTL;
if (xc_version(xch, XENVER_platform_parameters, &xen_params) != 0)
return 0;
@@ -313,15 +312,9 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
*hvirt_start = xen_params.virt_start;
- memset(&domctl, 0, sizeof(domctl));
- domctl.domain = dom;
- domctl.cmd = XEN_DOMCTL_get_address_size;
-
- if ( do_domctl(xch, &domctl) != 0 )
+ if ( xc_domain_get_guest_width(xch, dom, guest_width) != 0)
return 0;
- *guest_width = domctl.u.address_size.size / 8;
-
/* 64-bit tools will see the 64-bit hvirt_start, but 32-bit guests
* will be using the compat one. */
if ( *guest_width < sizeof (unsigned long) )
diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c
index 060e480005..1214185bd8 100644
--- a/tools/xentrace/xenctx.c
+++ b/tools/xentrace/xenctx.c
@@ -771,12 +771,9 @@ static void dump_ctx(int vcpu)
}
ctxt_word_size = (strstr(xen_caps, "xen-3.0-x86_64")) ? 8 : 4;
} else {
- struct xen_domctl domctl;
- memset(&domctl, 0, sizeof domctl);
- domctl.domain = xenctx.domid;
- domctl.cmd = XEN_DOMCTL_get_address_size;
- if (xc_domctl(xenctx.xc_handle, &domctl) == 0)
- ctxt_word_size = guest_word_size = domctl.u.address_size.size / 8;
+ unsigned int gw;
+ if ( !xc_domain_get_guest_width(xenctx.xc_handle, xenctx.domid, &gw) )
+ ctxt_word_size = guest_word_size = gw;
}
}
#endif