Improvements to struct semgent_register
v2 cover Improvements to struct semgent_register
No functional change, but the source code is less verbose.
Andrew Cooper (3):
x86/svm: Drop svm_segment_register_t
x86/hvm: Rearange check_segment() to use a switch statement x86/emul: Drop segment_attributes_t
tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 10 +- tools/tests/x86_emulator/test_x86_emulator.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hvm/domain.c | 80 +++++++----- xen/arch/x86/hvm/emulate.c | 20 +-- xen/arch/x86/hvm/hvm.c | 154 ++++++++++++------------ xen/arch/x86/hvm/svm/svm.c | 10 +- xen/arch/x86/hvm/svm/svmdebug.c | 6 +- xen/arch/x86/hvm/svm/vmcb.c | 32 +++-- xen/arch/x86/hvm/vmx/realmode.c | 10 +- xen/arch/x86/hvm/vmx/vmx.c | 41 +++---- xen/arch/x86/mm/shadow/common.c | 6 +- xen/arch/x86/pv/emul-priv-op.c | 40 +++--- xen/arch/x86/vm_event.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 55 +++++---- xen/arch/x86/x86_emulate/x86_emulate.h | 37 +++--- xen/include/asm-x86/hvm/svm/vmcb.h | 37 +++--- 17 files changed, 279 insertions(+), 265 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 1/3 x86/svm: Drop svm_segment_register_t
Most SVM code already uses struct segment_register. Drop the typedef and adjust the definitions in struct vmcb_struct, and svm_dump_sel(). Introduce some build-time assertions that struct segment_register from the common emulation code is usable in struct vmcb_struct.
While making these adjustments, fix some comments to not mix decimal and hexidecimal offsets, and drop all trailing whitespace in vmcb.h
No functional change.
---
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
v2:
* Extend the build assertions.
--- xen/arch/x86/hvm/svm/svmdebug.c | 2 +- xen/arch/x86/hvm/svm/vmcb.c | 16 ++++++++++++++++ xen/include/asm-x86/hvm/svm/vmcb.h | 37 +++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 21 deletions(-)
xen/arch/x86/hvm/svm/svmdebug.c +1 -1
@@ -21,7 +21,7 @@#include <asm/msr-index.h> #include <asm/hvm/svm/svmdebug.h> -static void svm_dump_sel (const char *name,const svm_segment_register_t *s) +static void svm_dump_sel (const char *name,const struct segment_register *s) {printk ("%s: %04x %04x %08x %016" PRIx64"\n" , name, s->sel, s->attr.bytes, s->limit, s->base);
xen/arch/x86/hvm/svm/vmcb.c +16 -0
@@ -310,6 +310,22 @@ void __init setup_vmcb_dump(void)register_keyhandler ('v' , vmcb_dump,"dump AMD-V VMCBs" ,1 ); } +static void __init __maybe_unused build_assertions (void ) +{ +struct segment_register sreg; + +/* Check struct segment_register against the VMCB segment layout. */ +BUILD_BUG_ON (sizeof (sreg) !=16 ); +BUILD_BUG_ON (sizeof (sreg.sel) !=2 ); +BUILD_BUG_ON (sizeof (sreg.attr) !=2 ); +BUILD_BUG_ON (sizeof (sreg.limit) !=4 ); +BUILD_BUG_ON (sizeof (sreg.base) !=8 ); +BUILD_BUG_ON (offsetof(struct segment_register , sel) !=0 ); +BUILD_BUG_ON (offsetof(struct segment_register , attr) !=2 ); +BUILD_BUG_ON (offsetof(struct segment_register , limit) !=4 ); +BUILD_BUG_ON (offsetof(struct segment_register , base) !=8 ); +} +/* * Local variables: * mode: C
xen/include/asm-x86/hvm/svm/vmcb.h +17 -20
@@ -31,7 +31,7 @@ enum GenericIntercept1bitsGENERAL1_INTERCEPT_SMI =1 <<2 ,GENERAL1_INTERCEPT_INIT =1 <<3 ,GENERAL1_INTERCEPT_VINTR =1 <<4 , -GENERAL1_INTERCEPT_CR0_SEL_WRITE =1 <<5 , +GENERAL1_INTERCEPT_CR0_SEL_WRITE =1 <<5 ,GENERAL1_INTERCEPT_IDTR_READ =1 <<6 ,GENERAL1_INTERCEPT_GDTR_READ =1 <<7 , GENERAL1_INTERCEPT_LDTR_READ = 1 << 8,
@@ -304,13 +304,10 @@ enum VMEXIT_EXITCODEVMEXIT_INVALID =-1 }; -/* Definition of segment state is borrowed by the generic HVM code. */ -typedef struct segment_register svm_segment_register_t ; - typedef union { u64 bytes; - struct + struct { u64 vector: 8; u64 type: 3;
@@ -324,7 +321,7 @@ typedef union typedef union { u64 bytes; - struct + struct { u64 tpr: 8; u64 irq: 1;
@@ -342,7 +339,7 @@ typedef union typedef union { u64 bytes; - struct + struct { u64 type: 1; u64 rsv0: 1;
@@ -438,23 +435,23 @@ struct vmcb_struct {u8 guest_ins[15 ];/* offset 0xD1 */ u64 res10a[100 ];/* offset 0xE0 pad to save area */ -svm_segment_register_t es;/* offset 1024 - cleanbit 8 */ -svm_segment_register_t cs;/* cleanbit 8 */ -svm_segment_register_t ss;/* cleanbit 8 */ -svm_segment_register_t ds;/* cleanbit 8 */ -svm_segment_register_t fs; -svm_segment_register_t gs; -svm_segment_register_t gdtr;/* cleanbit 7 */ -svm_segment_register_t ldtr; -svm_segment_register_t idtr;/* cleanbit 7 */ -svm_segment_register_t tr; +struct segment_register es;/* offset 0x400 - cleanbit 8 */ +struct segment_register cs;/* cleanbit 8 */ +struct segment_register ss;/* cleanbit 8 */ +struct segment_register ds;/* cleanbit 8 */ +struct segment_register fs; +struct segment_register gs; +struct segment_register gdtr;/* cleanbit 7 */ +struct segment_register ldtr; +struct segment_register idtr;/* cleanbit 7 */ +struct segment_register tr;u64 res10[5 ];u8 res11[3 ];u8 _cpl;/* cleanbit 8 */ u32 res12; -u64 _efer;/* offset 1024 + 0xD0 - cleanbit 5 */ +u64 _efer;/* offset 0x400 + 0xD0 - cleanbit 5 */ u64 res13[14 ]; -u64 _cr4;/* offset 1024 + 0x148 - cleanbit 5 */ +u64 _cr4;/* offset 0x400 + 0x148 - cleanbit 5 */ u64 _cr3;/* cleanbit 5 */ u64 _cr0;/* cleanbit 5 */ u64 _dr7;/* cleanbit 6 */
@@ -508,7 +505,7 @@ struct arch_svm_struct {uint64_t guest_sysenter_cs;uint64_t guest_sysenter_esp;uint64_t guest_sysenter_eip; - +/* AMD lightweight profiling MSR */ uint64_t guest_lwp_cfg;/* guest version */ uint64_t cpu_lwp_cfg;/* CPU version */
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 1/3] x86/svm: Drop svm_segment_register_t
Quoted 5 lines · Andrew Cooper
Most SVM code already uses struct
segment_register. Drop the typedef and adjust the definitions in structvmcb_struct, andsvm_dump_sel(). Introduce some build-time assertions that structsegment_registerfrom the common emulation code is usable in structvmcb_struct.
Quoted 8 lines
While making these adjustments, fix some comments to not mix decimal and hexidecimal offsets, and drop all trailing whitespace in
vmcb.hNo functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>---
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 2/3 x86/hvm: Rearange check_segment() to use a switch statement
In reply to Andrew CooperThis simplifies the logic by separating the x86_segment check from the type check. No functional change.
--- xen/arch/x86/hvm/domain.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/domain.c +29 -14
@@ -70,23 +70,38 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg)return -EINVAL ; } -if ( seg == x86_seg_cs && !(reg->attr.fields.type &0x8 ) ) +switch ( seg ) { -gprintk (XENLOG_ERR ,"Non-code segment provided for CS\n" ); -return -EINVAL ; - } +case x86_seg_cs: +if ( !(reg->attr.fields.type &0x8 ) ) + { +gprintk (XENLOG_ERR ,"Non-code segment provided for CS\n" ); +return -EINVAL ; + } +break ; -if ( seg == x86_seg_ss && - ((reg->attr.fields.type &0x8 ) || !(reg->attr.fields.type &0x2 )) ) - { -gprintk (XENLOG_ERR ,"Non-writeable segment provided for SS\n" ); -return -EINVAL ; - } +case x86_seg_ss: +if ( (reg->attr.fields.type &0x8 ) || !(reg->attr.fields.type &0x2 ) ) + { +gprintk (XENLOG_ERR ,"Non-writeable segment provided for SS\n" ); +return -EINVAL ; + } +break ; -if ( reg->attr.fields.s && seg != x86_seg_ss && seg != x86_seg_cs && - (reg->attr.fields.type &0x8 ) && !(reg->attr.fields.type &0x2 ) ) - { -gprintk (XENLOG_ERR ,"Non-readable segment provided for DS or ES\n" ); +case x86_seg_ds: +case x86_seg_es: +if ( (reg->attr.fields.type &0x8 ) && !(reg->attr.fields.type &0x2 ) ) + { +gprintk (XENLOG_ERR ,"Non-readable segment provided for DS or ES\n" ); +return -EINVAL ; + } +break ; + +case x86_seg_tr: +break ; + +default : +ASSERT_UNREACHABLE ();return -EINVAL ; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 3/3 x86/emul: Drop segment_attributes_t
In reply to Andrew CooperThe amount of namespace resolution is unnecessarily large, as all code deals in terms of struct segment_register. This removes the attr.fields part of all references, and alters attr.bytes to just attr.
Three areas of code using initialisers for segment_register are tweaked to compile with older versions of GCC. arch_set_info_hvm_guest() has its SEG() macros altered to use plain comma-based initialisation, while {rm,vm86}_{cs,ds}_attr are simplified to plain numbers which matches their description in the manuals.
No functional change. (For some reason, the old {rm,vm86}_{cs,ds}_attr causes GCC to create variable in .rodata, whereas the new code uses immediate operands. As a result, vmx_{get,set}_segment_register() are slightly shorter.)
--- tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 10 +- tools/tests/x86_emulator/test_x86_emulator.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hvm/domain.c | 43 ++++--- xen/arch/x86/hvm/emulate.c | 20 +-- xen/arch/x86/hvm/hvm.c | 154 ++++++++++++------------ xen/arch/x86/hvm/svm/svm.c | 10 +- xen/arch/x86/hvm/svm/svmdebug.c | 4 +- xen/arch/x86/hvm/svm/vmcb.c | 16 +-- xen/arch/x86/hvm/vmx/realmode.c | 10 +- xen/arch/x86/hvm/vmx/vmx.c | 41 +++---- xen/arch/x86/mm/shadow/common.c | 6 +- xen/arch/x86/pv/emul-priv-op.c | 40 +++--- xen/arch/x86/vm_event.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 55 +++++---- xen/arch/x86/x86_emulate/x86_emulate.h | 37 +++--- 16 files changed, 219 insertions(+), 233 deletions(-)
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +5 -5
@@ -583,7 +583,7 @@ static bool in_longmode(struct x86_emulate_ctxt *ctxt)const struct fuzz_state *s = ctxt->data;const struct fuzz_corpus *c = s->corpus; -return long_mode_active (ctxt) && c->segments[x86_seg_cs].attr.fields.l; +return long_mode_active (ctxt) && c->segments[x86_seg_cs].l; }static void set_sizes (struct x86_emulate_ctxt *ctxt)
@@ -597,8 +597,8 @@ static void set_sizes(struct x86_emulate_ctxt *ctxt) ctxt->addr_size = ctxt->sp_size =64 ; else { - ctxt->addr_size = c->segments[x86_seg_cs].attr.fields.db ?32 :16 ; - ctxt->sp_size = c->segments[x86_seg_ss].attr.fields.db ?32 :16 ; + ctxt->addr_size = c->segments[x86_seg_cs].db ?32 :16 ; + ctxt->sp_size = c->segments[x86_seg_ss].db ?32 :16 ; } }
@@ -741,8 +741,8 @@ static void sanitize_input(struct x86_emulate_ctxt *ctxt)/* EFLAGS.VM implies 16-bit mode */ if ( regs->rflags &X86_EFLAGS_VM ) { - c->segments[x86_seg_cs].attr.fields.db =0 ; - c->segments[x86_seg_ss].attr.fields.db =0 ; + c->segments[x86_seg_cs].db =0 ; + c->segments[x86_seg_ss].db =0 ; } }
tools/tests/x86_emulator/test_x86_emulator.c +1 -1
@@ -264,7 +264,7 @@ static int read_segment(if ( !is_x86_user_segment (seg) )return X86EMUL_UNHANDLEABLE ;memset (reg,0 ,sizeof (*reg)); - reg->attr.fields.p =1 ; + reg->p =1 ;return X86EMUL_OKAY ; }
xen/arch/x86/cpu/vpmu.c +1 -1
@@ -304,7 +304,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs) r->cs = seg.sel;hvm_get_segment_register (sampled, x86_seg_ss, &seg); r->ss = seg.sel; - r->cpl = seg.attr.fields.dpl; + r->cpl = seg.dpl;if ( !(sampled->arch.hvm_vcpu.guest_cr[0 ] &X86_CR0_PE ) ) *flags |=PMU_SAMPLE_REAL ; }
xen/arch/x86/hvm/domain.c +21 -22
131 lines not on this page · raw message
xen/arch/x86/hvm/emulate.c +10 -10
@@ -873,7 +873,7 @@ static int __hvmemul_read(if (is_x86_system_segment (seg) ) pfec |= PFEC_implicit; -else if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +else if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_virtual_to_linear(
@@ -995,7 +995,7 @@ static int hvmemul_write(if (is_x86_system_segment (seg) ) pfec |= PFEC_implicit; -else if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +else if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_virtual_to_linear(
@@ -1172,7 +1172,7 @@ static int hvmemul_rep_ins(if ( rc !=X86EMUL_OKAY )return rc; -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(
@@ -1241,7 +1241,7 @@ static int hvmemul_rep_outs(if ( rc !=X86EMUL_OKAY )return rc; -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(
@@ -1288,7 +1288,7 @@ static int hvmemul_rep_movs(if ( rc !=X86EMUL_OKAY )return rc; -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; if ( vio->mmio_access.read_access &&
@@ -1446,7 +1446,7 @@ static int hvmemul_rep_stos( {uint32_t pfec = PFEC_page_present | PFEC_write_access; -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(addr, &gpa, bytes_per_rep, reps, pfec,
@@ -2144,17 +2144,17 @@ void hvm_emulate_init_per_insn( hvmemul_ctxt->ctxt.lma =hvm_long_mode_active (curr);if ( hvmemul_ctxt->ctxt.lma && - hvmemul_ctxt->seg_reg[x86_seg_cs].attr.fields.l ) + hvmemul_ctxt->seg_reg[x86_seg_cs].l ) hvmemul_ctxt->ctxt.addr_size = hvmemul_ctxt->ctxt.sp_size =64 ;else { hvmemul_ctxt->ctxt.addr_size = - hvmemul_ctxt->seg_reg[x86_seg_cs].attr.fields.db ?32 :16 ; + hvmemul_ctxt->seg_reg[x86_seg_cs].db ?32 :16 ; hvmemul_ctxt->ctxt.sp_size = - hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.db ?32 :16 ; + hvmemul_ctxt->seg_reg[x86_seg_ss].db ?32 :16 ; } -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].dpl ==3 ) pfec |= PFEC_user_mode; hvmemul_ctxt->insn_buf_eip = hvmemul_ctxt->ctxt.regs->rip;
xen/arch/x86/hvm/hvm.c +77 -77
446 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +5 -5
@@ -526,9 +526,9 @@ static int svm_guest_x86_mode(struct vcpu *v)return 0 ;if (unlikely (guest_cpu_user_regs ()->eflags &X86_EFLAGS_VM ) )return 1 ; -if (hvm_long_mode_active (v) &&likely (vmcb->cs.attr.fields.l) ) +if (hvm_long_mode_active (v) &&likely (vmcb->cs.l) )return 8 ; -return (likely (vmcb->cs.attr.fields.db) ?4 :2 ); +return likely (vmcb->cs.db) ?4 :2 ; }void svm_update_guest_cr (struct vcpu *v,unsigned int cr)
@@ -653,7 +653,7 @@ static void svm_get_segment_register(struct vcpu *v, enum x86_segment seg,break ;case x86_seg_ss: *reg = vmcb->ss; - reg->attr.fields.dpl =vmcb_get_cpl (vmcb); + reg->dpl =vmcb_get_cpl (vmcb);break ;case x86_seg_tr:svm_sync_vmcb (v);
@@ -726,7 +726,7 @@ static void svm_set_segment_register(struct vcpu *v, enum x86_segment seg,break ;case x86_seg_ss: vmcb->ss = *reg; -vmcb_set_cpl (vmcb, reg->attr.fields.dpl); +vmcb_set_cpl (vmcb, reg->dpl);break ;case x86_seg_tr: vmcb->tr = *reg;
@@ -1442,7 +1442,7 @@ static void svm_inject_event(const struct x86_event *event)* If injecting an event outside of 64bit mode, zero the upper bits of the * %eip and nextrip after the adjustments above. */ -if ( !((vmcb_get_efer (vmcb) &EFER_LMA ) && vmcb->cs.attr.fields.l) ) +if ( !((vmcb_get_efer (vmcb) &EFER_LMA ) && vmcb->cs.l) ) { regs->rip = regs->eip; vmcb->nextrip = (uint32_t )vmcb->nextrip;
xen/arch/x86/hvm/svm/svmdebug.c +2 -2
@@ -24,7 +24,7 @@static void svm_dump_sel (const char *name,const struct segment_register *s) {printk ("%s: %04x %04x %08x %016" PRIx64"\n" , - name, s->sel, s->attr.bytes, s->limit, s->base); + name, s->sel, s->attr, s->limit, s->base); }void svm_vmcb_dump (const char *from,const struct vmcb_struct *vmcb)
@@ -147,7 +147,7 @@ bool svm_vmcb_isvalid(const char *from, const struct vmcb_struct *vmcb, }if ( (efer &EFER_LME ) && (cr0 &X86_CR0_PG ) && (cr4 &X86_CR4_PAE ) && - vmcb->cs.attr.fields.l && vmcb->cs.attr.fields.db ) + vmcb->cs.l && vmcb->cs.db )PRINTF ("EFER_LME, CR0.PG, CR4.PAE, CS.L and CS.D are all non-zero\n" );if ( !(vmcb_get_general2_intercepts (vmcb) &GENERAL2_INTERCEPT_VMRUN ) )
xen/arch/x86/hvm/svm/vmcb.c +8 -8
@@ -158,12 +158,12 @@ static int construct_vmcb(struct vcpu *v) vmcb->gs.base =0 ;/* Guest segment AR bytes. */ - vmcb->es.attr.bytes =0xc93 ;/* read/write, accessed */ - vmcb->ss.attr.bytes =0xc93 ; - vmcb->ds.attr.bytes =0xc93 ; - vmcb->fs.attr.bytes =0xc93 ; - vmcb->gs.attr.bytes =0xc93 ; - vmcb->cs.attr.bytes =0xc9b ;/* exec/read, accessed */ + vmcb->es.attr =0xc93 ;/* read/write, accessed */ + vmcb->ss.attr =0xc93 ; + vmcb->ds.attr =0xc93 ; + vmcb->fs.attr =0xc93 ; + vmcb->gs.attr =0xc93 ; + vmcb->cs.attr =0xc9b ;/* exec/read, accessed */ /* Guest IDT. */ vmcb->idtr.base =0 ;
@@ -177,10 +177,10 @@ static int construct_vmcb(struct vcpu *v) vmcb->ldtr.sel =0 ; vmcb->ldtr.base =0 ; vmcb->ldtr.limit =0 ; - vmcb->ldtr.attr.bytes =0 ; + vmcb->ldtr.attr =0 ;/* Guest TSS. */ - vmcb->tr.attr.bytes =0x08b ;/* 32-bit TSS (busy) */ + vmcb->tr.attr =0x08b ;/* 32-bit TSS (busy) */ vmcb->tr.base =0 ; vmcb->tr.limit =0xff ;
xen/arch/x86/hvm/vmx/realmode.c +5 -5
@@ -70,7 +70,7 @@ static void realmode_deliver_exception( frame[2 ] = regs->flags & ~X86_EFLAGS_RF ;/* We can't test hvmemul_ctxt->ctxt.sp_size: it may not be initialised. */ -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.db ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].db ) pstk = regs->esp -=6 ;else pstk = regs->sp -=6 ;
@@ -207,13 +207,13 @@ void vmx_realmode(struct cpu_user_regs *regs)* DS, ES, FS and GS the most uninvasive trick is to set DPL == RPL. */ sreg =hvmemul_get_seg_reg (x86_seg_ds, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_es, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_fs, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_gs, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->dpl = sreg->sel &3 ; hvmemul_ctxt.seg_reg_dirty |= (1ul << x86_seg_ds) | (1ul << x86_seg_es) | (1ul << x86_seg_fs) | (1ul << x86_seg_gs);
xen/arch/x86/hvm/vmx/vmx.c +18 -23
71 lines not on this page · raw message
xen/arch/x86/mm/shadow/common.c +3 -3
@@ -332,13 +332,13 @@ const struct x86_emulate_ops *shadow_init_emulation( creg =hvm_get_seg_reg (x86_seg_cs, sh_ctxt);/* Work out the emulation mode. */ -if ( sh_ctxt->ctxt.lma && creg->attr.fields.l ) +if ( sh_ctxt->ctxt.lma && creg->l ) sh_ctxt->ctxt.addr_size = sh_ctxt->ctxt.sp_size =64 ;else { sreg =hvm_get_seg_reg (x86_seg_ss, sh_ctxt); - sh_ctxt->ctxt.addr_size = creg->attr.fields.db ?32 :16 ; - sh_ctxt->ctxt.sp_size = sreg->attr.fields.db ?32 :16 ; + sh_ctxt->ctxt.addr_size = creg->db ?32 :16 ; + sh_ctxt->ctxt.sp_size = sreg->db ?32 :16 ; }/* Attempt to prefetch whole instruction. */
xen/arch/x86/pv/emul-priv-op.c +20 -20
@@ -479,7 +479,7 @@ static int priv_op_read_segment(enum x86_segment seg,return X86EMUL_UNHANDLEABLE ; reg->limit = limit; - reg->attr.bytes = ar >>8 ; + reg->attr = ar >>8 ; }else {
@@ -500,19 +500,19 @@ static int priv_op_read_segment(enum x86_segment seg, reg->limit = ~0U ; - reg->attr.bytes =0 ; - reg->attr.fields.type = _SEGMENT_WR >>8 ; + reg->attr =0 ; + reg->type = _SEGMENT_WR >>8 ;if ( seg == x86_seg_cs ) { - reg->attr.fields.type |= _SEGMENT_CODE >>8 ; - reg->attr.fields.l =1 ; + reg->type |= _SEGMENT_CODE >>8 ; + reg->l =1 ; }else - reg->attr.fields.db =1 ; - reg->attr.fields.s =1 ; - reg->attr.fields.dpl =3 ; - reg->attr.fields.p =1 ; - reg->attr.fields.g =1 ; + reg->db =1 ; + reg->s =1 ; + reg->dpl =3 ; + reg->p =1 ; + reg->g =1 ; }/*
@@ -521,9 +521,9 @@ static int priv_op_read_segment(enum x86_segment seg,*/ if ( (seg == x86_seg_ss || (seg == x86_seg_cs && - !(reg->attr.fields.type & (_SEGMENT_EC >>8 )))) && + !(reg->type & (_SEGMENT_EC >>8 )))) &&guest_kernel_mode (current, ctxt->regs) ) - reg->attr.fields.dpl =0 ; + reg->dpl =0 ;return X86EMUL_OKAY ; }
@@ -578,11 +578,11 @@ static int priv_op_rep_ins(uint16_t port,if ( rc !=X86EMUL_OKAY )return rc; -if ( !sreg.attr.fields.p ) +if ( !sreg.p )return X86EMUL_UNHANDLEABLE ; -if ( !sreg.attr.fields.s || - (sreg.attr.fields.type & (_SEGMENT_CODE >>8 )) || - !(sreg.attr.fields.type & (_SEGMENT_WR >>8 )) ) +if ( !sreg.s || + (sreg.type & (_SEGMENT_CODE >>8 )) || + !(sreg.type & (_SEGMENT_WR >>8 )) ) {x86_emul_hw_exception (TRAP_gp_fault,0 , ctxt);return X86EMUL_EXCEPTION ;
@@ -643,11 +643,11 @@ static int priv_op_rep_outs(enum x86_segment seg, unsigned long offset,if ( rc !=X86EMUL_OKAY )return rc; -if ( !sreg.attr.fields.p ) +if ( !sreg.p )return X86EMUL_UNHANDLEABLE ; -if ( !sreg.attr.fields.s || - ((sreg.attr.fields.type & (_SEGMENT_CODE >>8 )) && - !(sreg.attr.fields.type & (_SEGMENT_WR >>8 ))) ) +if ( !sreg.s || + ((sreg.type & (_SEGMENT_CODE >>8 )) && + !(sreg.type & (_SEGMENT_WR >>8 ))) ) { x86_emul_hw_exception(seg != x86_seg_ss ? TRAP_gp_fault : TRAP_stack_error,
xen/arch/x86/vm_event.c +1 -1
@@ -176,7 +176,7 @@ void vm_event_fill_regs(vm_event_request_t *req) req->data.regs.x86.gs_base = seg.base;hvm_get_segment_register (curr, x86_seg_cs, &seg); - req->data.regs.x86.cs_arbytes = seg.attr.bytes; + req->data.regs.x86.cs_arbytes = seg.attr; }void vm_event_emulate_check (struct vcpu *v,vm_event_response_t *rsp)
xen/arch/x86/x86_emulate/x86_emulate.c +27 -28
152 lines not on this page · raw message
xen/arch/x86/x86_emulate/x86_emulate.h +15 -22
@@ -83,33 +83,26 @@ struct x86_event {unsigned long cr2;/* Only for TRAP_page_fault h/w exception */ }; -/* -* Attribute for segment selector. This is a copy of bit 40:47 & 52:55 of the -* segment descriptor. It happens to match the format of an AMD SVM VMCB. -*/ -typedef union segment_attributes { -uint16_t bytes; -struct - { -uint16_t type:4 ;/* 0; Bit 40-43 */ -uint16_t s:1 ;/* 4; Bit 44 */ -uint16_t dpl:2 ;/* 5; Bit 45-46 */ -uint16_t p:1 ;/* 7; Bit 47 */ -uint16_t avl:1 ;/* 8; Bit 52 */ -uint16_t l:1 ;/* 9; Bit 53 */ -uint16_t db:1 ;/* 10; Bit 54 */ -uint16_t g:1 ;/* 11; Bit 55 */ -uint16_t pad:4 ; - } fields; -}segment_attributes_t ; -/* * Full state of a segment register (visible and hidden portions). -* Again, this happens to match the format of an AMD SVM VMCB. +* Chosen to match the format of an AMD SVM VMCB. */ struct segment_register {uint16_t sel; -segment_attributes_t attr; +union { +uint16_t attr; +struct { +uint16_t type:4 ; +uint16_t s:1 ; +uint16_t dpl:2 ; +uint16_t p:1 ; +uint16_t avl:1 ; +uint16_t l:1 ; +uint16_t db:1 ; +uint16_t g:1 ; +uint16_t pad:4 ; + }; + };uint32_t limit;uint64_t base; };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel