RFC x86/emul: Drop segment_attributes_t
PATCH 1/1 RFC x86/emul: Drop segment_attributes_t
The amount of namespace resolution is unnecessrily large, as all code deals in terms of struct segment_register. This removes the .fields part of all references, and alters .bytes for .raw.
No functional change. For some reason I can't identify, the changes to {rm,vm86}_{cs,ds}_attr causes GCC to encode the values as immedate operands rather than variables in .rodata. As a result, vmx_{get,set}_segment_register() are shorter.
---
CC: Jan Beulich <[email protected]>
RFC, because I'd also like to float the idea of making this adjustment as well:
xen/arch/x86/x86_emulate/x86_emulate.h +2 -2
@@ -90,7 +90,7 @@ struct x86_event { struct segment_register { uint16_t sel; union { - uint16_t raw; + uint16_t attr; struct { uint16_t type:4; /* 0; Bit 40-43 */ uint16_t s: 1; /* 4; Bit 44 */
@@ -102,7 +102,7 @@ struct segment_register { uint16_t g: 1; /* 11; Bit 55 */ uint16_t pad: 4; }; - } attr; + };uint32_t limit;uint64_t base; };
which would turn .attr.raw into just .attr, and remove .attr for accesses into the bitfield.
Furthermore, in a following patch, I intend to make a similar adjustment as
http://xenbits.xen.org/gitweb/?p=xtf.git;a=commitdiff;h=f099211f2ebdadf61ae6416559220d69b788cd2b
to expose the internal code/data field names. This will simplify a lot of code which currently uses opencoded numbers against the type field.
Thoughts?
--- 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 | 42 +++---- 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 | 16 +-- xen/arch/x86/hvm/vmx/realmode.c | 10 +- xen/arch/x86/hvm/vmx/vmx.c | 32 ++--- xen/arch/x86/mm/shadow/common.c | 6 +- xen/arch/x86/traps.c | 40 +++--- xen/arch/x86/vm_event.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 54 ++++----- xen/arch/x86/x86_emulate/x86_emulate.h | 35 +++--- 16 files changed, 217 insertions(+), 224 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].attr.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].attr.db ?32 :16 ; + ctxt->sp_size = c->segments[x86_seg_ss].attr.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].attr.db =0 ; + c->segments[x86_seg_ss].attr.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->attr.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.attr.dpl;if ( !(sampled->arch.hvm_vcpu.guest_cr[0 ] &X86_CR0_PE ) ) *flags |=PMU_SAMPLE_REAL ; }
xen/arch/x86/hvm/domain.c +21 -21
128 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].attr.dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_virtual_to_linear(
@@ -984,7 +984,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].attr.dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_virtual_to_linear(
@@ -1161,7 +1161,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].attr.dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(
@@ -1230,7 +1230,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].attr.dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(
@@ -1277,7 +1277,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].attr.dpl ==3 ) pfec |= PFEC_user_mode; if ( vio->mmio_access.read_access &&
@@ -1435,7 +1435,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].attr.dpl ==3 ) pfec |= PFEC_user_mode; rc = hvmemul_linear_to_phys(addr, &gpa, bytes_per_rep, reps, pfec,
@@ -2133,17 +2133,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].attr.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].attr.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].attr.db ?32 :16 ; } -if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl ==3 ) +if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.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.attr.l) )return 8 ; -return (likely (vmcb->cs.attr.fields.db) ?4 :2 ); +return likely (vmcb->cs.attr.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->_cpl; + reg->attr.dpl = vmcb->_cpl;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->_cpl = vmcb->ss.attr.fields.dpl; + vmcb->_cpl = vmcb->ss.attr.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->_efer &EFER_LMA ) && vmcb->cs.attr.fields.l) ) +if ( !((vmcb->_efer &EFER_LMA ) && vmcb->cs.attr.l) ) { regs->rip = regs->eip; vmcb->nextrip = (uint32_t )vmcb->nextrip;
xen/arch/x86/hvm/svm/svmdebug.c +3 -3
@@ -23,7 +23,7 @@static void svm_dump_sel (const char *name,const svm_segment_register_t *s) {printk ("%s: %04x %04x %08x %016" PRIx64"\n" , - name, s->sel, s->attr.bytes, s->limit, s->base); + name, s->sel, s->attr.raw, s->limit, s->base); }/* This function can directly access fields which are covered by clean bits. */
@@ -163,8 +163,8 @@ svm_vmcb_isvalid(const char *from, struct vmcb_struct *vmcb,if ((vmcb->_efer &EFER_LME ) !=0 && (vmcb->_cr0 &X86_CR0_PG ) !=0 && (vmcb->_cr4 &X86_CR4_PAE ) !=0 - && (vmcb->cs.attr.fields.l !=0 ) - && (vmcb->cs.attr.fields.db !=0 )) + && (vmcb->cs.attr.l !=0 ) + && (vmcb->cs.attr.db !=0 )) {PRINTF ("EFER_LME, CR0.PG, CR4.PAE, CS.L and CS.D are all non-zero.\n" ); }
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.raw =0xc93 ;/* read/write, accessed */ + vmcb->ss.attr.raw =0xc93 ; + vmcb->ds.attr.raw =0xc93 ; + vmcb->fs.attr.raw =0xc93 ; + vmcb->gs.attr.raw =0xc93 ; + vmcb->cs.attr.raw =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.raw =0 ;/* Guest TSS. */ - vmcb->tr.attr.bytes =0x08b ;/* 32-bit TSS (busy) */ + vmcb->tr.attr.raw =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].attr.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->attr.dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_es, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->attr.dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_fs, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->attr.dpl = sreg->sel &3 ; sreg =hvmemul_get_seg_reg (x86_seg_gs, &hvmemul_ctxt); - sreg->attr.fields.dpl = sreg->sel &3 ; + sreg->attr.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 +16 -16
@@ -1074,18 +1074,18 @@ static unsigned int _vmx_get_cpl(struct vcpu *v)* things. We store the ring-3 version in the VMCS to avoid lots of * shuffling on vmenter and vmexit, and translate in these accessors. */ -#define rm_cs_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define rm_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_tr_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) +#define rm_cs_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define rm_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_tr_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw)static void vmx_get_segment_register (struct vcpu *v,enum x86_segment seg,struct segment_register *reg)
@@ -1156,7 +1156,7 @@ static void vmx_get_segment_register(struct vcpu *v, enum x86_segment seg,* Fold VT-x representation into Xen's representation. The Present bit is * unconditionally set to the inverse of unusable. */ - reg->attr.bytes = + reg->attr.raw = (!(attr & (1u <<16 )) <<7 ) | (attr &0x7f ) | ((attr >>4 ) &0xf00 );/* Adjust for virtual 8086 mode */
@@ -1175,7 +1175,7 @@ static void vmx_get_segment_register(struct vcpu *v, enum x86_segment seg,* but for SS we assume it has: the Ubuntu graphical bootloader * does this and gets badly confused if we leave the old SS in * place. */ - reg->attr.bytes = (seg == x86_seg_cs ? rm_cs_attr : rm_ds_attr); + reg->attr.raw = (seg == x86_seg_cs ? rm_cs_attr : rm_ds_attr); *sreg = *reg; }else
@@ -1195,7 +1195,7 @@ static void vmx_set_segment_register(struct vcpu *v, enum x86_segment seg,uint64_t base; sel = reg->sel; - attr = reg->attr.bytes; + attr = reg->attr.raw; limit = reg->limit; base = reg->base;
@@ -1234,7 +1234,7 @@ static void vmx_set_segment_register(struct vcpu *v, enum x86_segment seg,* but otherwise we have to emulate if *any* segment hasn't * been reloaded. */ if ( base <0x100000 && !(base &0xf ) && limit >=0xffff - && reg->attr.fields.p ) + && reg->attr.p ) { sel = base >>4 ; attr = vm86_ds_attr;
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->attr.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->attr.db ?32 :16 ; + sh_ctxt->ctxt.sp_size = sreg->attr.db ?32 :16 ; }/* Attempt to prefetch whole instruction. */
xen/arch/x86/traps.c +20 -20
@@ -1845,7 +1845,7 @@ static int priv_op_read_segment(enum x86_segment seg,return X86EMUL_UNHANDLEABLE ; reg->limit = limit; - reg->attr.bytes = ar >>8 ; + reg->attr.raw = ar >>8 ; }else {
@@ -1866,19 +1866,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.raw =0 ; + reg->attr.type = _SEGMENT_WR >>8 ;if ( seg == x86_seg_cs ) { - reg->attr.fields.type |= _SEGMENT_CODE >>8 ; - reg->attr.fields.l =1 ; + reg->attr.type |= _SEGMENT_CODE >>8 ; + reg->attr.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->attr.db =1 ; + reg->attr.s =1 ; + reg->attr.dpl =3 ; + reg->attr.p =1 ; + reg->attr.g =1 ; }/*
@@ -1887,9 +1887,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->attr.type & (_SEGMENT_EC >>8 )))) &&guest_kernel_mode (current, ctxt->regs) ) - reg->attr.fields.dpl =0 ; + reg->attr.dpl =0 ;return X86EMUL_OKAY ; }
@@ -2260,11 +2260,11 @@ static int priv_op_rep_ins(uint16_t port,if ( rc !=X86EMUL_OKAY )return rc; -if ( !sreg.attr.fields.p ) +if ( !sreg.attr.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.attr.s || + (sreg.attr.type & (_SEGMENT_CODE >>8 )) || + !(sreg.attr.type & (_SEGMENT_WR >>8 )) ) {x86_emul_hw_exception (TRAP_gp_fault,0 , ctxt);return X86EMUL_EXCEPTION ;
@@ -2325,11 +2325,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.attr.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.attr.s || + ((sreg.attr.type & (_SEGMENT_CODE >>8 )) && + !(sreg.attr.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.raw; }void vm_event_emulate_check (struct vcpu *v,vm_event_response_t *rsp)
xen/arch/x86/x86_emulate/x86_emulate.c +27 -27
152 lines not on this page · raw message
xen/arch/x86/x86_emulate/x86_emulate.h +14 -21
@@ -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. */ struct segment_register {uint16_t sel; -segment_attributes_t attr; +union { +uint16_t raw; +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 ; + }; + } attr;uint32_t limit;uint64_t base; };
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 07.06.17 at 15:04, <[email protected]> wrote:
RFC, because I'd also like to float the idea of making this adjustment as well:
xen/arch/x86/x86_emulate/x86_emulate.h +2
-2@@ -90,7 +90,7 @@ struct x86_event { struct segment_register { uint16_t sel; union { - uint16_t raw; + uint16_t attr; struct { uint16_t type:4; /* 0; Bit 40-43 */ uint16_t s: 1; /* 4; Bit 44 */@@ -102,7 +102,7 @@ struct segment_register { uint16_t g: 1; /* 11; Bit 55 */ uint16_t pad: 4; }; - } attr; + };uint32_t limit;uint64_t base; };
Quoted 2 lines
which would turn .attr.raw into just .attr, and remove .attr for accesses into the bitfield.
I'd certainly like this, provided this works with all compiler versions we support (see also below).
Quoted 5 lines
Furthermore, in a following patch, I intend to make a similar adjustment as
http://xenbits.xen.org/gitweb/?p=xtf.git;a=commitdiff;h=f099211f2ebdadf61ae6416559220d69b788cd2b
to expose the internal code/data field names. This will simplify a lot of code which currently uses opencoded numbers against the type field.
This is nice too, with two caveats: The "a" bit is not code segment specific (but placed so) and the "x" bit is an invention of yours afaict, which I'd prefer to be e.g. "code".
xen/arch/x86/x86_emulate/x86_emulate.h int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx) · line 248
Quoted 6 lines
xen/arch/x86/x86_emulate/x86_emulate.h +1
-1@@ -245,7 +245,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx) v->arch.hvm_vcpu.guest_cr[4 ] = regs->cr4; v->arch.hvm_vcpu.guest_efer = regs->efer; -#define SEG (l, a) (struct segment_register){ .limit = (l), .attr.bytes = (a) } +#define SEG (l, a) (struct segment_register){ .limit = (l), .attr.raw = (a) }
Does this and ...
Quoted 20 lines
xen/arch/x86/hvm/vmx/vmx.c +2
-12@@ -1074,18 +1074,18 @@ static unsigned int _vmx_get_cpl(struct vcpu *v)* things. We store the ring-3 version in the VMCS to avoid lots of * shuffling on vmenter and vmexit, and translate in these accessors. */ -#define rm_cs_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define rm_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_tr_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) +#define rm_cs_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \
xen/arch/x86/hvm/vmx/vmx.c static unsigned int _vmx_get_cpl(struct vcpu *v) · line 1088
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +10
-0+ .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define rm_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_tr_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw)
... all of this work with gcc around the 4.3 era?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 33 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 07.06.17 at 15:04, <[email protected]> wrote:
RFC, because I'd also like to float the idea of making this adjustment as well:
xen/arch/x86/x86_emulate/x86_emulate.h +2
-2@@ -90,7 +90,7 @@ struct x86_event { struct segment_register { uint16_t sel; union { - uint16_t raw; + uint16_t attr; struct { uint16_t type:4; /* 0; Bit 40-43 */ uint16_t s: 1; /* 4; Bit 44 */@@ -102,7 +102,7 @@ struct segment_register { uint16_t g: 1; /* 11; Bit 55 */ uint16_t pad: 4; }; - } attr; + };uint32_t limit;uint64_t base; };Quoted 2 lines
which would turn .attr.raw into just .attr, and remove .attr for accesses into the bitfield.
I'd certainly like this, provided this works with all compiler versions we support (see also below).
Quoted 7 lines
Quoted 5 lines
Furthermore, in a following patch, I intend to make a similar adjustment as
http://xenbits.xen.org/gitweb/?p=xtf.git;a=commitdiff;h=f099211f2ebdadf61ae6416559220d69b788cd2b
to expose the internal code/data field names. This will simplify a lot of code which currently uses opencoded numbers against the type field.This is nice too, with two caveats: The "a" bit is not code segment specific (but placed so)
Least bad option I'm afraid. It can't live in the common struct because it is part of the type nibble, and it can't live in both the code and data anonymous unions because it has the same name.
Quoted 2 lines
and the "x" bit is an invention
of yours afaict, which I'd prefer to be e.g. "code".
It is the eXecutable bit. I got the terminology from one of the two manuals, but don't recall exactly where.
Quoted 32 lines
xen/arch/x86/x86_emulate/x86_emulate.h int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx) · line 248
Quoted 7 lines
xen/arch/x86/x86_emulate/x86_emulate.h +1
-1@@ -245,7 +245,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const vcpu_hvm_context_t *ctx) v->arch.hvm_vcpu.guest_cr[4 ] = regs->cr4; v->arch.hvm_vcpu.guest_efer = regs->efer; -#define SEG (l, a) (struct segment_register){ .limit = (l), .attr.bytes = (a) } +#define SEG (l, a) (struct segment_register){ .limit = (l), .attr.raw = (a) }Does this and ...
Quoted 23 lines
xen/arch/x86/hvm/vmx/vmx.c +5
-12@@ -1074,18 +1074,18 @@ static unsigned int _vmx_get_cpl(struct vcpu *v)* things. We store the ring-3 version in the VMCS to avoid lots of * shuffling on vmenter and vmexit, and translate in these accessors. */ -#define rm_cs_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define rm_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_ds_attr (((union segment_attributes) { \ - .fields = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) -#define vm86_tr_attr (((union segment_attributes) { \ - .fields = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ - .l = 0, .db = 0, .g = 0, .pad = 0 } }).bytes) +#define rm_cs_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 1, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define rm_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 0, .p = 1, .avl = 0, \
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c static unsigned int _vmx_get_cpl(struct vcpu *v) · line 1088
Quoted 7 lines
xen/arch/x86/hvm/vmx/vmx.c +7
-0+ .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_ds_attr (((struct segment_register) { \ + .attr = { .type = 0x3, .s = 1, .dpl = 3, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw) +#define vm86_tr_attr (((struct segment_register) { \ + .attr = { .type = 0xb, .s = 0, .dpl = 0, .p = 1, .avl = 0, \ + .l = 0, .db = 0, .g = 0, .pad = 0 } }).attr.raw)... all of this work with gcc around the 4.3 era?
Not sure. I will try.
I had actually wondered why we weren't using plain numbers for these. If this doesn't work for GCC 4.3 and older, I probably will swap these to being raw numbers, rather than lose the other benefits.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 07.06.17 at 17:44, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.06.17 at 15:04, <[email protected]> wrote:
Furthermore, in a following patch, I intend to make a similar adjustment as
http://xenbits.xen.org/gitweb/?p=xtf.git;a=commitdiff;h=f099211f2ebdadf61ae6416559220d69b788cd2b
to expose the internal code/data field names. This will simplify a lot of code which currently uses opencoded numbers against the type field.
Quoted 6 lines
Quoted 2 lines
This is nice too, with two caveats: The "a" bit is not code segment specific (but placed so)
Least bad option I'm afraid. It can't live in the common struct because it is part of the type nibble, and it can't live in both the code and data anonymous unions because it has the same name.
It could be put in a 3rd struct, but I guess that's more extra overhead than actual gain.
Quoted 5 lines
Quoted 2 lines
and the "x" bit is an invention
of yours afaict, which I'd prefer to be e.g. "code".It is the eXecutable bit. I got the terminology from one of the two manuals, but don't recall exactly where.
Oh, okay. I don't recall running across this.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel