From: Jean Guyader <jean.guyader@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: Re: [PATCH] libxc: use vcpu_guest_context_either_t instead of vcpu_guest_context_t
Date: Thu, 19 Jun 2008 15:58:12 +0100 [thread overview]
Message-ID: <485A7404.8030702@eu.citrix.com> (raw)
In-Reply-To: <485A6742.6040806@eu.citrix.com>
[-- Attachment #1: Type: text/plain, Size: 81 bytes --]
This is a new version without falling back for the domctl.
--
Jean Guyader
[-- Attachment #2: vcpu_guest_context_either_t_2.patch --]
[-- Type: text/plain, Size: 17367 bytes --]
diff -r 3da148fb7d9b tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_core.c Thu Jun 19 15:51:59 2008 +0100
@@ -407,7 +407,7 @@ xc_domain_dumpcore_via_callback(int xc_h
int nr_vcpus = 0;
char *dump_mem, *dump_mem_start = NULL;
- vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
+ vcpu_guest_context_either_t ctxt[MAX_VIRT_CPUS];
struct xc_core_arch_context arch_ctxt;
char dummy[PAGE_SIZE];
int dummy_len;
@@ -581,10 +581,10 @@ xc_domain_dumpcore_via_callback(int xc_h
PERROR("Could not get section header for .xen_prstatus");
goto out;
}
- filesz = sizeof(ctxt[0]) * nr_vcpus;
+ filesz = sizeof(ctxt[0].c) * nr_vcpus;
sts = xc_core_shdr_set(shdr, strtab, XEN_DUMPCORE_SEC_PRSTATUS,
SHT_PROGBITS, offset, filesz,
- __alignof__(ctxt[0]), sizeof(ctxt[0]));
+ __alignof__(ctxt[0].c), sizeof(ctxt[0].c));
if ( sts != 0 )
goto out;
offset += filesz;
@@ -707,7 +707,7 @@ xc_domain_dumpcore_via_callback(int xc_h
goto out;
/* prstatus: .xen_prstatus */
- sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
+ sts = dump_rtn(args, (char *)&ctxt[0].c, sizeof(ctxt[0].c) * nr_vcpus);
if ( sts != 0 )
goto out;
diff -r 3da148fb7d9b tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_domain.c Thu Jun 19 15:51:59 2008 +0100
@@ -298,7 +298,7 @@ int xc_vcpu_getcontext(int xc_handle,
int xc_vcpu_getcontext(int xc_handle,
uint32_t domid,
uint32_t vcpu,
- vcpu_guest_context_t *ctxt)
+ vcpu_guest_context_either_t *ctxt)
{
int rc;
DECLARE_DOMCTL;
@@ -307,21 +307,12 @@ int xc_vcpu_getcontext(int xc_handle,
domctl.cmd = XEN_DOMCTL_getvcpucontext;
domctl.domain = (domid_t)domid;
domctl.u.vcpucontext.vcpu = (uint16_t)vcpu;
- set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
+ set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
- /*
- * We may be asked to lock either a 32-bit or a 64-bit context. Lock the
- * larger of the two if possible, otherwise fall back to native size.
- */
+
if ( (rc = lock_pages(ctxt, sz)) != 0 )
- {
- sz = sizeof(*ctxt);
- if ( (rc = lock_pages(ctxt, sz)) != 0 )
- return rc;
- }
-
+ return rc;
rc = do_domctl(xc_handle, &domctl);
-
unlock_pages(ctxt, sz);
return rc;
@@ -626,32 +617,28 @@ int xc_vcpu_setcontext(int xc_handle,
int xc_vcpu_setcontext(int xc_handle,
uint32_t domid,
uint32_t vcpu,
- vcpu_guest_context_t *ctxt)
+ vcpu_guest_context_either_t *ctxt)
{
DECLARE_DOMCTL;
int rc;
size_t sz = sizeof(vcpu_guest_context_either_t);
+ if (ctxt == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
domctl.cmd = XEN_DOMCTL_setvcpucontext;
domctl.domain = domid;
domctl.u.vcpucontext.vcpu = vcpu;
- set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
+ set_xen_guest_handle(domctl.u.vcpucontext.ctxt, &ctxt->c);
- /*
- * We may be asked to lock either a 32-bit or a 64-bit context. Lock the
- * larger of the two if possible, otherwise fall back to native size.
- */
- if ( (ctxt != NULL) && (rc = lock_pages(ctxt, sz)) != 0 )
- {
- sz = sizeof(*ctxt);
- if ( (rc = lock_pages(ctxt, sz)) != 0 )
- return rc;
- }
-
+ if ( (rc = lock_pages(ctxt, sz)) != 0 )
+ return rc;
rc = do_domctl(xc_handle, &domctl);
-
- if ( ctxt != NULL )
- unlock_pages(ctxt, sz);
+
+ unlock_pages(ctxt, sz);
return rc;
}
diff -r 3da148fb7d9b tools/libxc/xc_domain_save.c
--- a/tools/libxc/xc_domain_save.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_domain_save.c Thu Jun 19 15:51:59 2008 +0100
@@ -735,7 +735,7 @@ static xen_pfn_t *map_and_save_p2m_table
p2m_frame_list[i/FPP] = mfn_to_pfn(p2m_frame_list[i/FPP]);
}
- if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt.c) )
+ if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt) )
{
ERROR("Could not get vcpu context");
goto out;
@@ -1536,7 +1536,7 @@ int xc_domain_save(int xc_handle, int io
}
}
- if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt.c) )
+ if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt) )
{
ERROR("Could not get vcpu context");
goto out;
@@ -1556,7 +1556,7 @@ int xc_domain_save(int xc_handle, int io
if ( !(vcpumap & (1ULL << i)) )
continue;
- if ( (i != 0) && xc_vcpu_getcontext(xc_handle, dom, i, &ctxt.c) )
+ if ( (i != 0) && xc_vcpu_getcontext(xc_handle, dom, i, &ctxt) )
{
ERROR("No context for VCPU%d", i);
goto out;
diff -r 3da148fb7d9b tools/libxc/xc_pagetab.c
--- a/tools/libxc/xc_pagetab.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_pagetab.c Thu Jun 19 15:51:59 2008 +0100
@@ -48,7 +48,7 @@ unsigned long xc_translate_foreign_addre
unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
int vcpu, unsigned long long virt )
{
- vcpu_guest_context_t ctx;
+ vcpu_guest_context_either_t ctx;
unsigned long long cr3;
void *pd, *pt, *pdppage = NULL, *pdp, *pml = NULL;
unsigned long long pde, pte, pdpe, pmle;
@@ -78,7 +78,7 @@ unsigned long xc_translate_foreign_addre
DPRINTF("failed to retreive vcpu context\n");
goto out;
}
- cr3 = ((unsigned long long)xen_cr3_to_pfn(ctx.ctrlreg[3])) << PAGE_SHIFT;
+ cr3 = ((unsigned long long)xen_cr3_to_pfn(ctx.c.ctrlreg[3])) << PAGE_SHIFT;
/* Page Map Level 4 */
diff -r 3da148fb7d9b tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_private.h Thu Jun 19 15:51:59 2008 +0100
@@ -188,9 +188,9 @@ int xc_map_foreign_ranges(int xc_handle,
privcmd_mmap_entry_t *entries, int nr);
void *map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
- vcpu_guest_context_t *ctxt);
+ vcpu_guest_context_either_t *ctxt);
int xc_waitdomain_core(int xc_handle, int domain, int *status,
- int options, vcpu_guest_context_t *ctxt);
+ int options, vcpu_guest_context_either_t *ctxt);
void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);
diff -r 3da148fb7d9b tools/libxc/xc_ptrace.c
--- a/tools/libxc/xc_ptrace.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_ptrace.c Thu Jun 19 15:51:59 2008 +0100
@@ -40,9 +40,9 @@ static int current_isfile;
static int current_isfile;
static int current_is_hvm;
-static uint64_t online_cpumap;
-static uint64_t regs_valid;
-static vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
+static uint64_t online_cpumap;
+static uint64_t regs_valid;
+static vcpu_guest_context_either_t ctxt[MAX_VIRT_CPUS];
extern int ffsll(long long int);
#define FOREACH_CPU(cpumap, i) for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) )
@@ -96,9 +96,9 @@ xc_register_event_handler(thr_ev_handler
}
static inline int
-paging_enabled(vcpu_guest_context_t *v)
+paging_enabled(vcpu_guest_context_either_t *v)
{
- unsigned long cr0 = v->ctrlreg[0];
+ unsigned long cr0 = v->c.ctrlreg[0];
return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG);
}
@@ -174,7 +174,7 @@ map_domain_va_32(
l2 = xc_map_foreign_range(
xc_handle, current_domid, PAGE_SIZE, PROT_READ,
- xen_cr3_to_pfn(ctxt[cpu].ctrlreg[3]));
+ xen_cr3_to_pfn(ctxt[cpu].c.ctrlreg[3]));
if ( l2 == NULL )
return NULL;
@@ -216,7 +216,7 @@ map_domain_va_pae(
l3 = xc_map_foreign_range(
xc_handle, current_domid, PAGE_SIZE, PROT_READ,
- xen_cr3_to_pfn(ctxt[cpu].ctrlreg[3]));
+ xen_cr3_to_pfn(ctxt[cpu].c.ctrlreg[3]));
if ( l3 == NULL )
return NULL;
@@ -494,26 +494,26 @@ xc_ptrace(
case PTRACE_GETREGS:
if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
goto out_error;
- SET_PT_REGS(pt, ctxt[cpu].user_regs);
+ SET_PT_REGS(pt, ctxt[cpu].c.user_regs);
memcpy(data, &pt, sizeof(struct gdb_regs));
break;
case PTRACE_GETFPREGS:
if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
goto out_error;
- memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof (elf_fpregset_t));
+ memcpy(data, &ctxt[cpu].c.fpu_ctxt, sizeof (elf_fpregset_t));
break;
case PTRACE_GETFPXREGS:
if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
goto out_error;
- memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
+ memcpy(data, &ctxt[cpu].c.fpu_ctxt, sizeof(ctxt[cpu].c.fpu_ctxt));
break;
case PTRACE_SETREGS:
if (current_isfile)
goto out_unsupported; /* XXX not yet supported */
- SET_XC_REGS(((struct gdb_regs *)data), ctxt[cpu].user_regs);
+ SET_XC_REGS(((struct gdb_regs *)data), ctxt[cpu].c.user_regs);
if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu,
&ctxt[cpu])))
goto out_error_domctl;
@@ -525,7 +525,7 @@ xc_ptrace(
/* XXX we can still have problems if the user switches threads
* during single-stepping - but that just seems retarded
*/
- ctxt[cpu].user_regs.eflags |= PSL_T;
+ ctxt[cpu].c.user_regs.eflags |= PSL_T;
if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu,
&ctxt[cpu])))
goto out_error_domctl;
@@ -542,9 +542,9 @@ xc_ptrace(
if (fetch_regs(xc_handle, cpu, NULL))
goto out_error;
/* Clear trace flag */
- if ( ctxt[cpu].user_regs.eflags & PSL_T )
+ if ( ctxt[cpu].c.user_regs.eflags & PSL_T )
{
- ctxt[cpu].user_regs.eflags &= ~PSL_T;
+ ctxt[cpu].c.user_regs.eflags &= ~PSL_T;
if ((retval = xc_vcpu_setcontext(xc_handle, current_domid,
cpu, &ctxt[cpu])))
goto out_error_domctl;
diff -r 3da148fb7d9b tools/libxc/xc_ptrace_core.c
--- a/tools/libxc/xc_ptrace_core.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_ptrace_core.c Thu Jun 19 15:51:59 2008 +0100
@@ -641,24 +641,24 @@ static const struct xc_core_format_type*
void *
map_domain_va_core(unsigned long domfd, int cpu, void *guest_va,
- vcpu_guest_context_t *ctxt)
+ vcpu_guest_context_either_t *ctxt)
{
if (current_format_type == NULL)
return NULL;
return (current_format_type->map_domain_va_core)(domfd, cpu, guest_va,
- ctxt);
+ &ctxt->c);
}
int
xc_waitdomain_core(int xc_handle, int domfd, int *status, int options,
- vcpu_guest_context_t *ctxt)
+ vcpu_guest_context_either_t *ctxt)
{
int ret;
int i;
for (i = 0; i < NR_FORMAT_TYPE; i++) {
ret = (format_type[i].waitdomain_core)(xc_handle, domfd, status,
- options, ctxt);
+ options, &ctxt->c);
if (ret == 0) {
current_format_type = &format_type[i];
break;
diff -r 3da148fb7d9b tools/libxc/xc_resume.c
--- a/tools/libxc/xc_resume.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xc_resume.c Thu Jun 19 15:51:59 2008 +0100
@@ -39,7 +39,7 @@ static int modify_returncode(int xc_hand
return -1;
}
- if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt.c)) != 0 )
+ if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt)) != 0 )
return rc;
if ( !info.hvm )
@@ -49,7 +49,7 @@ static int modify_returncode(int xc_hand
else
ctxt.x32.user_regs.eax = 1;
- if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt.c)) != 0 )
+ if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt)) != 0 )
return rc;
return 0;
@@ -89,7 +89,7 @@ static int xc_domain_resume_any(int xc_h
int i, rc = -1;
#if defined(__i386__) || defined(__x86_64__)
unsigned long mfn, p2m_size = 0;
- vcpu_guest_context_t ctxt;
+ vcpu_guest_context_either_t ctxt;
start_info_t *start_info;
shared_info_t *shinfo = NULL;
xen_pfn_t *p2m_frame_list_list = NULL;
@@ -167,7 +167,7 @@ static int xc_domain_resume_any(int xc_h
goto out;
}
- mfn = ctxt.user_regs.edx;
+ mfn = ctxt.c.user_regs.edx;
start_info = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
PROT_READ | PROT_WRITE, mfn);
diff -r 3da148fb7d9b tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xenctrl.h Thu Jun 19 15:51:59 2008 +0100
@@ -30,6 +30,11 @@
#include <xen/xsm/acm.h>
#include <xen/xsm/acm_ops.h>
#include <xen/xsm/flask_op.h>
+
+#if defined(__i386__) || defined(__x86_64__)
+#include <xen/foreign/x86_32.h>
+#include <xen/foreign/x86_64.h>
+#endif
#ifdef __ia64__
#define XC_PAGE_SHIFT 14
@@ -162,6 +167,35 @@ typedef struct xc_dominfo {
} xc_dominfo_t;
typedef xen_domctl_getdomaininfo_t xc_domaininfo_t;
+
+typedef union
+{
+#if defined(__i386__) || defined(__x86_64__)
+ vcpu_guest_context_x86_64_t x64;
+ vcpu_guest_context_x86_32_t x32;
+#endif
+ vcpu_guest_context_t c;
+} vcpu_guest_context_either_t;
+
+typedef union
+{
+#if defined(__i386__) || defined(__x86_64__)
+ shared_info_x86_64_t x64;
+ shared_info_x86_32_t x32;
+#endif
+ shared_info_t s;
+} shared_info_either_t;
+
+typedef union
+{
+#if defined(__i386__) || defined(__x86_64__)
+ start_info_x86_64_t x64;
+ start_info_x86_32_t x32;
+#endif
+ start_info_t s;
+} start_info_either_t;
+
+
int xc_domain_create(int xc_handle,
uint32_t ssidref,
xen_domain_handle_t handle,
@@ -307,7 +341,7 @@ int xc_vcpu_setcontext(int xc_handle,
int xc_vcpu_setcontext(int xc_handle,
uint32_t domid,
uint32_t vcpu,
- vcpu_guest_context_t *ctxt);
+ vcpu_guest_context_either_t *ctxt);
/**
* This function will return information about one or more domains, using a
* single hypercall. The domain information will be stored into the supplied
@@ -368,7 +402,7 @@ int xc_vcpu_getcontext(int xc_handle,
int xc_vcpu_getcontext(int xc_handle,
uint32_t domid,
uint32_t vcpu,
- vcpu_guest_context_t *ctxt);
+ vcpu_guest_context_either_t *ctxt);
typedef xen_domctl_getvcpuinfo_t xc_vcpuinfo_t;
int xc_vcpu_getinfo(int xc_handle,
diff -r 3da148fb7d9b tools/libxc/xg_save_restore.h
--- a/tools/libxc/xg_save_restore.h Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/libxc/xg_save_restore.h Thu Jun 19 15:51:59 2008 +0100
@@ -112,28 +112,6 @@ static inline int get_platform_info(int
#define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
-/* 32-on-64 support: saving 32bit guests from 64bit tools and vice versa */
-typedef union
-{
- vcpu_guest_context_x86_64_t x64;
- vcpu_guest_context_x86_32_t x32;
- vcpu_guest_context_t c;
-} vcpu_guest_context_either_t;
-
-typedef union
-{
- shared_info_x86_64_t x64;
- shared_info_x86_32_t x32;
- shared_info_t s;
-} shared_info_either_t;
-
-typedef union
-{
- start_info_x86_64_t x64;
- start_info_x86_32_t x32;
- start_info_t s;
-} start_info_either_t;
-
#define GET_FIELD(_p, _f) ((guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f))
#define SET_FIELD(_p, _f, _v) do { \
diff -r 3da148fb7d9b tools/xentrace/xenctx.c
--- a/tools/xentrace/xenctx.c Thu Jun 19 11:09:10 2008 +0100
+++ b/tools/xentrace/xenctx.c Thu Jun 19 15:51:59 2008 +0100
@@ -22,6 +22,8 @@
#include <string.h>
#include <inttypes.h>
#include <getopt.h>
+#include <xen/foreign/x86_64.h>
+#include <xen/foreign/x86_32.h>
#include "xenctrl.h"
@@ -702,7 +704,7 @@ void dump_ctx(int vcpu)
void dump_ctx(int vcpu)
{
int ret;
- vcpu_guest_context_t ctx;
+ vcpu_guest_context_either_t ctx;
xc_dominfo_t dominfo;
xc_handle = xc_interface_open(); /* for accessing control interface */
@@ -727,10 +729,10 @@ void dump_ctx(int vcpu)
exit(-1);
}
- print_ctx(&ctx);
+ print_ctx(&ctx.c);
#ifndef NO_TRANSLATION
- if (is_kernel_text(INSTR_POINTER((&ctx.user_regs))))
- print_stack(&ctx, vcpu);
+ if (is_kernel_text(INSTR_POINTER((&ctx.c.user_regs))))
+ print_stack(&ctx.c, vcpu);
#endif
if (!dominfo.paused) {
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2008-06-19 14:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-19 14:03 [PATCH] libxc: use vcpu_guest_context_either_t instead of vcpu_guest_context_t Jean Guyader
2008-06-19 14:58 ` Jean Guyader [this message]
2008-06-20 3:25 ` [PATCH] compilation fix caused by 17880:d3a87899985d (was Re: [PATCH] libxc: use vcpu_guest_context_either_t instead of vcpu_guest_context_t) Isaku Yamahata
2008-06-20 10:01 ` [PATCH] compilation fix for x86_64 caused by 17880:d3a87899985d Jean Guyader
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=485A7404.8030702@eu.citrix.com \
--to=jean.guyader@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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.