From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xen.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Keir Fraser <keir@xen.org>, Tim Deegan <tim@xen.org>,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH RFC v13 12/20] pvh: read_descriptor for PVH guests.
Date: Mon, 23 Sep 2013 17:49:52 +0100 [thread overview]
Message-ID: <1379955000-11050-13-git-send-email-george.dunlap@eu.citrix.com> (raw)
In-Reply-To: <1379955000-11050-1-git-send-email-george.dunlap@eu.citrix.com>
This is in preparation for enabling emulated privops for PVH guests.
This one unfortunately has a bit more of an impedance mismatch:
* For PV, the selector is hard-coded in by passing #name in the
#define. For PVH, we have to do a switch statement.
* For PV, given the desrciptor, it can read the resulting base, limit,
&c directly; for PVH, we have to read the values currently loaded in the vmcs.
This leads to a rather awkward construct where we *both* read the
descriptor, *and* specify a selector, and introduce an intermediate function,
read_descriptor_sel.
Unfortunately, without introducing a rather pointless switch()
statement to the PV path similar to the one in the PVH path, there's
no way to make this less awkward.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Signed-off-by: Mukesh Rathor <mukesh.rathor@oracle.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
v13: Removed stray space
CC: Jan Beulich <jbeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Keir Fraser <keir@xen.org>
---
xen/arch/x86/traps.c | 73 ++++++++++++++++++++++++++++++++++++++------
xen/include/asm-x86/desc.h | 4 ++-
2 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 1eac9ff..0463697 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -1518,6 +1518,49 @@ static int read_descriptor(unsigned int sel,
return 1;
}
+static int read_descriptor_sel(unsigned int sel,
+ enum x86_segment which_sel,
+ struct vcpu *v,
+ const struct cpu_user_regs *regs,
+ unsigned long *base,
+ unsigned long *limit,
+ unsigned int *ar,
+ unsigned int vm86attr)
+{
+ struct segment_register seg;
+ bool_t long_mode;
+
+ if ( !is_pvh_vcpu(v) )
+ return read_descriptor(sel, v, regs, base, limit, ar, vm86attr);
+
+ hvm_get_segment_register(v, x86_seg_cs, &seg);
+ long_mode = seg.attr.fields.l;
+
+ if ( which_sel != x86_seg_cs )
+ hvm_get_segment_register(v, which_sel, &seg);
+
+ /* "ar" is returned packed as in segment_attributes_t. Fix it up. */
+ *ar = seg.attr.bytes;
+ *ar = (*ar & 0xff) | ((*ar & 0xf00) << 4);
+ *ar <<= 8;
+
+ if ( long_mode )
+ {
+ *limit = ~0UL;
+
+ if ( which_sel < x86_seg_fs )
+ {
+ *base = 0UL;
+ return 1;
+ }
+ }
+ else
+ *limit = seg.limit;
+
+ *base = seg.base;
+ return 1;
+}
+
static int read_gate_descriptor(unsigned int gate_sel,
const struct vcpu *v,
unsigned int *sel,
@@ -1845,6 +1888,7 @@ static int is_cpufreq_controller(struct domain *d)
static int emulate_privileged_op(struct cpu_user_regs *regs)
{
+ enum x86_segment which_sel;
struct vcpu *v = current;
unsigned long *reg, eip = regs->eip;
u8 opcode, modrm_reg = 0, modrm_rm = 0, rep_prefix = 0, lock = 0, rex = 0;
@@ -1867,9 +1911,10 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
void (*io_emul)(struct cpu_user_regs *) __attribute__((__regparm__(1)));
uint64_t val, msr_content;
- if ( !read_descriptor(regs->cs, v, regs,
- &code_base, &code_limit, &ar,
- _SEGMENT_CODE|_SEGMENT_S|_SEGMENT_DPL|_SEGMENT_P) )
+ if ( !read_descriptor_sel(regs->cs, x86_seg_cs, v, regs,
+ &code_base, &code_limit, &ar,
+ _SEGMENT_CODE|_SEGMENT_S|
+ _SEGMENT_DPL|_SEGMENT_P) )
goto fail;
op_default = op_bytes = (ar & (_SEGMENT_L|_SEGMENT_DB)) ? 4 : 2;
ad_default = ad_bytes = (ar & _SEGMENT_L) ? 8 : op_default;
@@ -1880,6 +1925,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
/* emulating only opcodes not allowing SS to be default */
data_sel = read_segment_register(v, regs, ds);
+ which_sel = x86_seg_ds;
/* Legacy prefixes. */
for ( i = 0; i < 8; i++, rex == opcode || (rex = 0) )
@@ -1895,23 +1941,29 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
continue;
case 0x2e: /* CS override */
data_sel = regs->cs;
+ which_sel = x86_seg_cs;
continue;
case 0x3e: /* DS override */
data_sel = read_segment_register(v, regs, ds);
+ which_sel = x86_seg_ds;
continue;
case 0x26: /* ES override */
data_sel = read_segment_register(v, regs, es);
+ which_sel = x86_seg_es;
continue;
case 0x64: /* FS override */
data_sel = read_segment_register(v, regs, fs);
+ which_sel = x86_seg_fs;
lm_ovr = lm_seg_fs;
continue;
case 0x65: /* GS override */
data_sel = read_segment_register(v, regs, gs);
+ which_sel = x86_seg_gs;
lm_ovr = lm_seg_gs;
continue;
case 0x36: /* SS override */
data_sel = regs->ss;
+ which_sel = x86_seg_ss;
continue;
case 0xf0: /* LOCK */
lock = 1;
@@ -1955,15 +2007,16 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
if ( !(opcode & 2) )
{
data_sel = read_segment_register(v, regs, es);
+ which_sel = x86_seg_es;
lm_ovr = lm_seg_none;
}
if ( !(ar & _SEGMENT_L) )
{
- if ( !read_descriptor(data_sel, v, regs,
- &data_base, &data_limit, &ar,
- _SEGMENT_WR|_SEGMENT_S|_SEGMENT_DPL|
- _SEGMENT_P) )
+ if ( !read_descriptor_sel(data_sel, which_sel, v, regs,
+ &data_base, &data_limit, &ar,
+ _SEGMENT_WR|_SEGMENT_S|_SEGMENT_DPL|
+ _SEGMENT_P) )
goto fail;
if ( !(ar & _SEGMENT_S) ||
!(ar & _SEGMENT_P) ||
@@ -1993,9 +2046,9 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
}
}
else
- read_descriptor(data_sel, v, regs,
- &data_base, &data_limit, &ar,
- 0);
+ read_descriptor_sel(data_sel, which_sel, v, regs,
+ &data_base, &data_limit, &ar,
+ 0);
data_limit = ~0UL;
ar = _SEGMENT_WR|_SEGMENT_S|_SEGMENT_DPL|_SEGMENT_P;
}
diff --git a/xen/include/asm-x86/desc.h b/xen/include/asm-x86/desc.h
index 354b889..041e9d3 100644
--- a/xen/include/asm-x86/desc.h
+++ b/xen/include/asm-x86/desc.h
@@ -38,7 +38,9 @@
#ifndef __ASSEMBLY__
-#define GUEST_KERNEL_RPL(d) (is_pv_32bit_domain(d) ? 1 : 3)
+/* PVH 32bitfixme : see emulate_gate_op call from do_general_protection */
+#define GUEST_KERNEL_RPL(d) ({ ASSERT(is_pv_domain(d)); \
+ is_pv_32bit_domain(d) ? 1 : 3; })
/* Fix up the RPL of a guest segment selector. */
#define __fixup_guest_selector(d, sel) \
--
1.7.9.5
next prev parent reply other threads:[~2013-09-23 16:49 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-23 16:49 [PATCH RFC v13 00/20] Introduce PVH domU support George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 01/20] Allow vmx_update_debug_state to be called when v!=current George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 02/20] pvh prep: code motion George Dunlap
2013-09-26 9:20 ` Tim Deegan
2013-10-04 15:29 ` Roger Pau Monné
2013-09-23 16:49 ` [PATCH RFC v13 03/20] Introduce pv guest type and has_hvm_container macros George Dunlap
2013-09-26 11:53 ` Tim Deegan
2013-09-26 12:54 ` Ian Campbell
2013-09-26 13:46 ` George Dunlap
2013-09-26 15:31 ` Konrad Rzeszutek Wilk
2013-09-26 16:24 ` Tim Deegan
2013-09-23 16:49 ` [PATCH RFC v13 04/20] pvh: Introduce PVH guest type George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 05/20] pvh: Disable unneeded features of HVM containers George Dunlap
2013-09-26 15:22 ` Jan Beulich
2013-11-04 12:31 ` George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 06/20] pvh: vmx-specific changes George Dunlap
2013-09-26 15:29 ` Jan Beulich
2013-11-07 14:14 ` George Dunlap
2013-11-07 14:29 ` Jan Beulich
2013-10-07 15:55 ` Roger Pau Monné
2013-10-07 16:06 ` George Dunlap
2013-10-07 16:12 ` Tim Deegan
2013-10-07 16:20 ` George Dunlap
2013-10-07 17:08 ` Tim Deegan
2013-10-08 8:45 ` Jan Beulich
2013-11-07 12:02 ` George Dunlap
2013-11-07 13:12 ` Jan Beulich
2013-09-23 16:49 ` [PATCH RFC v13 07/20] pvh: Do not allow PVH guests to change paging modes George Dunlap
2013-09-26 15:30 ` Jan Beulich
2013-09-23 16:49 ` [PATCH RFC v13 08/20] pvh: PVH access to hypercalls George Dunlap
2013-09-26 15:33 ` Jan Beulich
2013-09-27 21:15 ` Mukesh Rathor
2013-09-30 6:38 ` Jan Beulich
2013-09-23 16:49 ` [PATCH RFC v13 09/20] pvh: Use PV e820 George Dunlap
2013-09-27 17:57 ` Konrad Rzeszutek Wilk
2013-09-23 16:49 ` [PATCH RFC v13 10/20] pvh: Support guest_kernel_mode for PVH George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 11/20] pvh: Support read_segment_register " George Dunlap
2013-09-26 15:36 ` Jan Beulich
2013-09-23 16:49 ` George Dunlap [this message]
2013-09-27 18:34 ` [PATCH RFC v13 12/20] pvh: read_descriptor for PVH guests Konrad Rzeszutek Wilk
2013-09-23 16:49 ` [PATCH RFC v13 13/20] pvh: Set up more PV stuff in set_info_guest George Dunlap
2013-09-26 15:43 ` Jan Beulich
2013-11-07 15:57 ` George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 14/20] pvh: Use PV handlers for emulated forced invalid ops, cpuid, and IO George Dunlap
2013-09-26 15:52 ` Jan Beulich
2013-09-23 16:49 ` [PATCH RFC v13 15/20] pvh: Disable 32-bit guest support for now George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 16/20] pvh: Restrict tsc_mode to NEVER_EMULATE " George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 17/20] pvh: Disable debug traps when doing pv emulation for PVH domains George Dunlap
2013-09-26 15:55 ` Jan Beulich
2013-09-23 16:49 ` [PATCH RFC v13 18/20] pvh: Documentation George Dunlap
2013-09-23 16:49 ` [PATCH RFC v13 19/20] PVH xen tools: libxc changes to build a PVH guest George Dunlap
2013-09-27 18:37 ` Konrad Rzeszutek Wilk
2013-10-18 16:45 ` Roger Pau Monné
2013-11-04 11:56 ` George Dunlap
2013-11-04 13:18 ` Roger Pau Monné
2013-09-23 16:50 ` [PATCH RFC v13 20/20] PVH xen tools: libxl changes to create " George Dunlap
2013-09-27 18:38 ` Konrad Rzeszutek Wilk
2013-09-27 13:08 ` [PATCH RFC v13 00/20] Introduce PVH domU support Konrad Rzeszutek Wilk
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=1379955000-11050-13-git-send-email-george.dunlap@eu.citrix.com \
--to=george.dunlap@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@xen.org \
--cc=tim@xen.org \
--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).