x86/emul: Cleanup
cover x86/emul: Cleanup
Cleanup from recent observations.
From a future backporting perspective, now is about the least bad time to take patchs 2 and 3, at the point we're doing all the other structural rearrangements.
Andrew Cooper (3):
x86/emul: Adjust comments in x86-types.h
x86/emul: Drop trailing r from x86_seg_[lgi]dt names x86/emul: Drop the union in x86_event had have a single data field
.../fuzz/x86_instruction_emulator/fuzz-emul.c | 2 +- tools/tests/x86_emulator/test_x86_emulator.c | 4 +- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/hvm.c | 46 +++++++++---------- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 30 ++++++------ xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 24 +++++----- xen/arch/x86/include/asm/domain.h | 6 +-- xen/arch/x86/include/asm/hvm/hvm.h | 3 +- xen/arch/x86/include/asm/x86-event.h | 14 ++++-- xen/arch/x86/include/asm/x86-types.h | 15 +++--- xen/arch/x86/pv/traps.c | 10 ++-- xen/arch/x86/vm_event.c | 4 +- xen/arch/x86/x86_emulate/0f01.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 6 +-- xen/arch/x86/x86_emulate/x86_emulate.h | 2 +- 17 files changed, 89 insertions(+), 85 deletions(-)
base-commit: 0a249bcb0279a99b7ddad683fcc84a5e256c13f1
Signature · 1 line
2.39.5
PATCH 1/3 x86/emul: Adjust comments in x86-types.h
x86_segment enumerates segments, not segment registers. Adjust the comment to make this clearer.
Fix a stray tab with the closing #endif.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
--- xen/arch/x86/include/asm/x86-types.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/x86-types.h +5 -4
@@ -16,9 +16,10 @@#endif /* -* Comprehensive enumeration of x86 segment registers. Various bits of code -* rely on this order (general purpose before system, tr at the beginning of -* system). +* x86 Segments. +* +* Various areas of code rely on this order (general purpose before system, tr +* at the beginning of system). */ enum x86_segment {/* General purpose. Matches the SReg3 encoding in opcode/ModRM bytes. */
@@ -73,4 +74,4 @@ struct segment_register { uint64_t base; }; -#endif /* X86_X86_TYPES_H */ +#endif /* X86_X86_TYPES_H */
Signature · 1 line
2.39.5
Re: [PATCH 1/3] x86/emul: Adjust comments in x86-types.h
Quoted 8 lines · Andrew Cooper
x86_segmentenumerates segments, not segment registers. Adjust the comment to make this clearer.Fix a stray tab with the closing #endif.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
I wonder though if we wouldn't better ...
xen/arch/x86/include/asm/x86-types.h line 19
Quoted 10 lines
xen/arch/x86/include/asm/x86-types.h +1
-3@@ -16,9 +16,10 @@#endif /* -* Comprehensive enumeration of x86 segment registers. Various bits of code -* rely on this order (general purpose before system, tr at the beginning of -* system). +* x86 Segments.
... insert "(kind of)" here: "sys" and "none" aren't really "segments", and iirc we said we may need to gain one more such pseudo-segment here to deal with WR{,U}SS.
Jan
Re: [PATCH 1/3] x86/emul: Adjust comments in x86-types.h
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
x86_segmentenumerates segments, not segment registers. Adjust the comment to make this clearer.Fix a stray tab with the closing #endif.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks.
Quoted 8 lines
I wonder though if we wouldn't better ...
Quoted 5 lines
xen/arch/x86/include/asm/x86-types.h +0
-0@@ -16,9 +16,10 @@#endif
Quoted 6 lines
xen/arch/x86/include/asm/x86-types.h line 19
Quoted 5 lines
xen/arch/x86/include/asm/x86-types.h +1
-3/* -* Comprehensive enumeration of x86 segment registers. Various bits of code -* rely on this order (general purpose before system, tr at the beginning of -* system). +* x86 Segments. ... insert "(kind of)" here: "sys" and "none" aren't really "segments",
System segments absolutely are segments. The VMCB/VMCS layouts hint at it, and various bits of microcode reverse engineering show explicitly that they're considered segments (or at least, address spaces) at the microarchitecture level.
"none" is fine without further explanation. "linear" is the weird one but there's a comment explaining it.
Quoted 2 lines
and iirc we said we may need to gain one more such pseudo-segment here to deal with WR{,U}SS.
Most likely yes, but again that's going to come with a comment.
We're probably going to need a phys segment at some point too, depending on how exactly we want to fit VMLOAD/VMSAVE into the emulator. This too is a segment as far as microcode is concerned.
I don't think qualifying "(kind of)" is an improvement here.
~Andrew
PATCH 2/3 x86/emul: Drop trailing r from x86_seg_[lgi]dt names
In reply to Andrew CooperThese refer to the segment, not to the segment registers. TR is the odd-one-out having "register" in it's name.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
--- .../fuzz/x86_instruction_emulator/fuzz-emul.c | 2 +- tools/tests/x86_emulator/test_x86_emulator.c | 4 +- xen/arch/x86/hvm/hvm.c | 42 +++++++++---------- xen/arch/x86/hvm/svm/svm.c | 22 +++++----- xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 22 +++++----- xen/arch/x86/include/asm/x86-types.h | 6 +-- xen/arch/x86/vm_event.c | 4 +- xen/arch/x86/x86_emulate/0f01.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 6 +-- 10 files changed, 56 insertions(+), 56 deletions(-)
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +1 -1
@@ -362,7 +362,7 @@ static int fuzz_cmpxchg(if (is_x86_user_segment (seg) )assert (ctxt->addr_size ==64 || !(offset >>32 ));else -assert ((seg == x86_seg_gdtr || seg == x86_seg_ldtr) && !(offset >>16 )); +assert ((seg == x86_seg_gdt || seg == x86_seg_ldt) && !(offset >>16 ));return maybe_fail (ctxt,"cmpxchg" , true); }
tools/tests/x86_emulator/test_x86_emulator.c +2 -2
@@ -559,7 +559,7 @@ static int read( {uint64_t value; -case x86_seg_gdtr: +case x86_seg_gdt:/* Fake system segment type matching table index. */ if ( (offset &7 ) || (bytes >8 ) )return X86EMUL_UNHANDLEABLE ;
@@ -579,7 +579,7 @@ static int read(memcpy (p_data, &value, bytes);return X86EMUL_OKAY ; -case x86_seg_ldtr: +case x86_seg_ldt:/* Fake user segment type matching table index. */ if ( (offset &7 ) || (bytes >8 ) )return X86EMUL_UNHANDLEABLE ;
xen/arch/x86/hvm/hvm.c +21 -21
140 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +11 -11
@@ -627,15 +627,15 @@ static void cf_check svm_get_segment_register( *reg = vmcb->tr;break ; -case x86_seg_gdtr: +case x86_seg_gdt: *reg = vmcb->gdtr;break ; -case x86_seg_idtr: +case x86_seg_idt: *reg = vmcb->idtr;break ; -case x86_seg_ldtr: +case x86_seg_ldt:svm_sync_vmcb (v, vmcb_in_sync); *reg = vmcb->ldtr;break ;
@@ -664,15 +664,15 @@ static void cf_check svm_set_segment_register( vmcb->cleanbits.seg = false;break ; -case x86_seg_gdtr: -case x86_seg_idtr: +case x86_seg_gdt: +case x86_seg_idt: vmcb->cleanbits.dt = false;break ;case x86_seg_fs:case x86_seg_gs:case x86_seg_tr: -case x86_seg_ldtr: +case x86_seg_ldt:if ( v == current )svm_sync_vmcb (v, vmcb_needs_vmload);break ;
@@ -698,17 +698,17 @@ static void cf_check svm_set_segment_register( vmcb->tr = *reg;break ; -case x86_seg_gdtr: +case x86_seg_gdt: vmcb->gdtr.base = reg->base; vmcb->gdtr.limit = reg->limit;break ; -case x86_seg_idtr: +case x86_seg_idt: vmcb->idtr.base = reg->base; vmcb->idtr.limit = reg->limit;break ; -case x86_seg_ldtr: +case x86_seg_ldt: vmcb->ldtr = *reg;break ;
@@ -1163,8 +1163,8 @@ static void svm_emul_swint_injection(struct x86_event *event)* this entry, even though we don't look at all the words read. */ hvm_get_segment_register (curr, x86_seg_cs, &cs); -hvm_get_segment_register (curr, x86_seg_idtr, &idtr); -if ( !hvm_virtual_to_linear_addr (x86_seg_idtr, &idtr, idte_offset, +hvm_get_segment_register (curr, x86_seg_idt, &idtr); +if ( !hvm_virtual_to_linear_addr (x86_seg_idt, &idtr, idte_offset, idte_size, hvm_access_read, &cs, &idte_linear_addr) ) goto raise_exception;
xen/arch/x86/hvm/vmx/realmode.c +1 -1
@@ -34,7 +34,7 @@ static void realmode_deliver_exception(uint16_t frame[3 ];unsigned int last_byte; - idtr =hvmemul_get_seg_reg (x86_seg_idtr, hvmemul_ctxt); + idtr =hvmemul_get_seg_reg (x86_seg_idt, hvmemul_ctxt); csr =hvmemul_get_seg_reg (x86_seg_cs, hvmemul_ctxt);__set_bit (x86_seg_cs, &hvmemul_ctxt->seg_reg_dirty);
xen/arch/x86/hvm/vmx/vmx.c +11 -11
@@ -1227,19 +1227,19 @@ static void cf_check vmx_get_segment_register( }/* -* Xen's x86_seg_* enumeration *almost* matches the VMCS encoding order. +* Xen's x86_segment encoding *almost* matches the VMCS encoding order. * -* tr and ldtr are reversed, and other areas of code rely on this, so we +* tr and ldt are reversed, and other areas of code rely on this, so we * can't just re-enumerate. */ BUILD_BUG_ON (x86_seg_tr !=6 ); -BUILD_BUG_ON (x86_seg_ldtr !=7 ); -BUILD_BUG_ON (x86_seg_gdtr !=8 ); -BUILD_BUG_ON (x86_seg_idtr !=9 ); +BUILD_BUG_ON (x86_seg_ldt !=7 ); +BUILD_BUG_ON (x86_seg_gdt !=8 ); +BUILD_BUG_ON (x86_seg_idt !=9 );switch ( tmp_seg = seg ) {case x86_seg_tr: -case x86_seg_ldtr: +case x86_seg_ldt: tmp_seg ^=1 ;/* Flip tr and ldtr so GUEST_SEG_*() works. */ fallthrough;
@@ -1248,8 +1248,8 @@ static void cf_check vmx_get_segment_register(__vmread (GUEST_SEG_AR_BYTES (tmp_seg), &attr); fallthrough; -case x86_seg_gdtr: -case x86_seg_idtr: +case x86_seg_gdt: +case x86_seg_idt:__vmread (GUEST_SEG_LIMIT (tmp_seg), &limit);__vmread (GUEST_SEG_BASE (tmp_seg), ®->base);break ;
@@ -1368,7 +1368,7 @@ static void cf_check vmx_set_segment_register(switch ( seg ) {case x86_seg_tr: -case x86_seg_ldtr: +case x86_seg_ldt: seg ^=1 ;/* Flip tr and ldtr so GUEST_SEG_*() works. */ fallthrough;
@@ -1377,8 +1377,8 @@ static void cf_check vmx_set_segment_register(__vmwrite (GUEST_SEG_AR_BYTES (seg), attr); fallthrough; -case x86_seg_gdtr: -case x86_seg_idtr: +case x86_seg_gdt: +case x86_seg_idt:__vmwrite (GUEST_SEG_LIMIT (seg), limit);__vmwrite (GUEST_SEG_BASE (seg), base);break ;
xen/arch/x86/include/asm/x86-types.h +3 -3
@@ -31,9 +31,9 @@ enum x86_segment { x86_seg_gs,/* System: Valid to use for implicit table references. */ x86_seg_tr, - x86_seg_ldtr, - x86_seg_gdtr, - x86_seg_idtr, + x86_seg_ldt, + x86_seg_gdt, + x86_seg_idt,/* No Segment: For (system/normal) accesses which are already linear. */ x86_seg_sys, x86_seg_none
xen/arch/x86/vm_event.c +2 -2
@@ -183,7 +183,7 @@ static void vm_event_pack_segment_register(enum x86_segment segment, reg->es_sel = seg.sel;break ; -case x86_seg_gdtr: +case x86_seg_gdt: reg->gdtr_base = seg.base; reg->gdtr_limit = seg.limit;break ;
@@ -248,7 +248,7 @@ void vm_event_fill_regs(vm_event_request_t *req)vm_event_pack_segment_register (x86_seg_ss, &req->data.regs.x86);vm_event_pack_segment_register (x86_seg_ds, &req->data.regs.x86);vm_event_pack_segment_register (x86_seg_es, &req->data.regs.x86); -vm_event_pack_segment_register (x86_seg_gdtr, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_gdt, &req->data.regs.x86); req->data.regs.x86.shadow_gs = ctxt.shadow_gs; req->data.regs.x86.dr6 = ctxt.dr6;
xen/arch/x86/x86_emulate/0f01.c +1 -1
@@ -22,7 +22,7 @@ int x86emul_0f01(struct x86_emulate_state *s,struct x86_emulate_ctxt *ctxt, const struct x86_emulate_ops *ops) { - enum x86_segment seg = (s->modrm_reg & 1) ? x86_seg_idtr : x86_seg_gdtr; + enum x86_segment seg = (s->modrm_reg & 1) ? x86_seg_idt : x86_seg_gdt;int rc; switch ( s->modrm )
xen/arch/x86/x86_emulate/x86_emulate.c +3 -3
@@ -891,7 +891,7 @@ protmode_load_seg( const struct x86_emulate_ops *ops) {const struct cpu_policy *cp = ctxt->cpu_policy; -enum x86_segment sel_seg = (sel &4 ) ? x86_seg_ldtr : x86_seg_gdtr; +enum x86_segment sel_seg = (sel &4 ) ? x86_seg_ldt : x86_seg_gdt;struct {uint32_t a, b; } desc, desc_hi = {};uint8_t dpl, rpl;int cpl =x86emul_get_cpl (ctxt, ops);
@@ -992,7 +992,7 @@ protmode_load_seg(if ( (dpl != cpl) || (dpl != rpl) ) goto raise_exn;break ; -case x86_seg_ldtr: +case x86_seg_ldt:/* LDT system segment? */ if ( (desc.b & (15u <<8 )) != (2u <<8 ) ) goto raise_exn;
@@ -2914,7 +2914,7 @@ x86_emulate(break ;case X86EMUL_OPC (0x0f ,0x00 ):/* Grp6 */ - seg = (modrm_reg &1 ) ? x86_seg_tr : x86_seg_ldtr; + seg = (modrm_reg &1 ) ? x86_seg_tr : x86_seg_ldt;generate_exception_if (!in_protmode (ctxt, ops),X86_EXC_UD );switch ( modrm_reg &6 ) {
Signature · 1 line
2.39.5
Re: [PATCH 2/3] x86/emul: Drop trailing r from x86_seg_[lgi]dt names
Quoted 2 lines · Andrew Cooper
These refer to the segment, not to the segment registers. TR is the odd-one-out having "register" in it's name.
The more consistent naming would then appear to be x86_seg_tss?
Jan
Re: [PATCH 2/3] x86/emul: Drop trailing r from x86_seg_[lgi]dt names
Quoted 4 lines · Jan Beulich
Quoted 2 lines · Andrew Cooper
These refer to the segment, not to the segment registers. TR is the odd-one-out having "register" in it's name.
The more consistent naming would then appear to be
x86_seg_tss?
I was debating doing this, and you're now the second person to suggest it.
~Andrew
PATCH v2 2/3 x86/emul: Rename the x86_seg_* system segments
In reply to Andrew CooperThese refer to the segments themsevles, not to the registers, even if there is a tight coupling between the two.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
v2:
* Rename x86_seg_tr => x86_seg_tss too.
* Fix up a couple of comments refering to the old names.
--- .../fuzz/x86_instruction_emulator/fuzz-emul.c | 4 +- tools/tests/x86_emulator/test_x86_emulator.c | 4 +- xen/arch/x86/hvm/domain.c | 15 +++-- xen/arch/x86/hvm/hvm.c | 56 +++++++++---------- xen/arch/x86/hvm/svm/svm.c | 28 +++++----- xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 44 +++++++-------- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 2 +- xen/arch/x86/include/asm/x86-types.h | 10 ++-- xen/arch/x86/pv/emul-priv-op.c | 2 +- xen/arch/x86/vm_event.c | 4 +- xen/arch/x86/x86_emulate/0f01.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 16 +++--- xen/arch/x86/x86_emulate/x86_emulate.h | 2 +- 14 files changed, 97 insertions(+), 94 deletions(-)
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +2 -2
@@ -173,7 +173,7 @@ static int fuzz_read(/* Reads expected for all user and system segments. */ if (is_x86_user_segment (seg) )assert (ctxt->addr_size ==64 || !(offset >>32 )); -else if ( seg == x86_seg_tr ) +else if ( seg == x86_seg_tss )/* * The TSS is special in that accesses below the segment base are * possible, as the Interrupt Redirection Bitmap starts 32 bytes
@@ -362,7 +362,7 @@ static int fuzz_cmpxchg(if (is_x86_user_segment (seg) )assert (ctxt->addr_size ==64 || !(offset >>32 ));else -assert ((seg == x86_seg_gdtr || seg == x86_seg_ldtr) && !(offset >>16 )); +assert ((seg == x86_seg_gdt || seg == x86_seg_ldt) && !(offset >>16 ));return maybe_fail (ctxt,"cmpxchg" , true); }
tools/tests/x86_emulator/test_x86_emulator.c +2 -2
@@ -559,7 +559,7 @@ static int read( {uint64_t value; -case x86_seg_gdtr: +case x86_seg_gdt:/* Fake system segment type matching table index. */ if ( (offset &7 ) || (bytes >8 ) )return X86EMUL_UNHANDLEABLE ;
@@ -579,7 +579,7 @@ static int read(memcpy (p_data, &value, bytes);return X86EMUL_OKAY ; -case x86_seg_ldtr: +case x86_seg_ldt:/* Fake user segment type matching table index. */ if ( (offset &7 ) || (bytes >8 ) )return X86EMUL_UNHANDLEABLE ;
xen/arch/x86/hvm/domain.c +9 -6
@@ -34,7 +34,7 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg)return 0 ; } -if ( seg == x86_seg_tr ) +if ( seg == x86_seg_tss ) {if ( reg->s ) {
@@ -88,7 +88,7 @@ static int check_segment(struct segment_register *reg, enum x86_segment seg) }break ; -case x86_seg_tr: +case x86_seg_tss:break ;default :
@@ -131,18 +131,21 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx)#define SEG (s, r) ({ \ s = (struct segment_register) \ { 0, { (r)->s ## _ar }, (r)->s ## _limit, (r)->s ## _base }; \ -/* Set accessed / busy bit for present segments. */ \ +/* Set accessed bit for present segments. */ \if ( (s).p ) \ - (s).type |= (x86_seg_ ## s != x86_seg_tr ? 1 : 2); \ + (s).type |=2 ; \ check_segment(&(s), x86_seg_ ## s); }) rc =SEG (cs, regs); rc |=SEG (ds, regs); rc |=SEG (ss, regs); rc |=SEG (es, regs); - rc |=SEG (tr, regs);#undef SEG + tr = (struct segment_register ){ +0 , { regs->tr_ar |1 /* Busy */ }, regs->tr_limit, regs->tr_base }; + rc |=check_segment (&tr, x86_seg_tss); +if ( rc !=0 )return rc;
@@ -307,7 +310,7 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx)hvm_set_segment_register (v, x86_seg_ds, &ds);hvm_set_segment_register (v, x86_seg_ss, &ss);hvm_set_segment_register (v, x86_seg_es, &es); -hvm_set_segment_register (v, x86_seg_tr, &tr); +hvm_set_segment_register (v, x86_seg_tss, &tr);/* Sync AP's TSC with BSP's. */ v->arch.hvm.cache_tsc_offset =
xen/arch/x86/hvm/hvm.c +28 -28
181 lines not on this page · raw message
xen/arch/x86/hvm/svm/svm.c +14 -14
@@ -622,20 +622,20 @@ static void cf_check svm_get_segment_register( reg->dpl =vmcb_get_cpl (vmcb);break ; -case x86_seg_tr: +case x86_seg_tss:svm_sync_vmcb (v, vmcb_in_sync); *reg = vmcb->tr;break ; -case x86_seg_gdtr: +case x86_seg_gdt: *reg = vmcb->gdtr;break ; -case x86_seg_idtr: +case x86_seg_idt: *reg = vmcb->idtr;break ; -case x86_seg_ldtr: +case x86_seg_ldt:svm_sync_vmcb (v, vmcb_in_sync); *reg = vmcb->ldtr;break ;
@@ -664,15 +664,15 @@ static void cf_check svm_set_segment_register( vmcb->cleanbits.seg = false;break ; -case x86_seg_gdtr: -case x86_seg_idtr: +case x86_seg_gdt: +case x86_seg_idt: vmcb->cleanbits.dt = false;break ;case x86_seg_fs:case x86_seg_gs: -case x86_seg_tr: -case x86_seg_ldtr: +case x86_seg_tss: +case x86_seg_ldt:if ( v == current )svm_sync_vmcb (v, vmcb_needs_vmload);break ;
@@ -694,21 +694,21 @@ static void cf_check svm_set_segment_register( vmcb->sreg[seg] = *reg;break ; -case x86_seg_tr: +case x86_seg_tss: vmcb->tr = *reg;break ; -case x86_seg_gdtr: +case x86_seg_gdt: vmcb->gdtr.base = reg->base; vmcb->gdtr.limit = reg->limit;break ; -case x86_seg_idtr: +case x86_seg_idt: vmcb->idtr.base = reg->base; vmcb->idtr.limit = reg->limit;break ; -case x86_seg_ldtr: +case x86_seg_ldt: vmcb->ldtr = *reg;break ;
@@ -1163,8 +1163,8 @@ static void svm_emul_swint_injection(struct x86_event *event)* this entry, even though we don't look at all the words read. */ hvm_get_segment_register (curr, x86_seg_cs, &cs); -hvm_get_segment_register (curr, x86_seg_idtr, &idtr); -if ( !hvm_virtual_to_linear_addr (x86_seg_idtr, &idtr, idte_offset, +hvm_get_segment_register (curr, x86_seg_idt, &idtr); +if ( !hvm_virtual_to_linear_addr (x86_seg_idt, &idtr, idte_offset, idte_size, hvm_access_read, &cs, &idte_linear_addr) ) goto raise_exception;
xen/arch/x86/hvm/vmx/realmode.c +1 -1
@@ -34,7 +34,7 @@ static void realmode_deliver_exception(uint16_t frame[3 ];unsigned int last_byte; - idtr =hvmemul_get_seg_reg (x86_seg_idtr, hvmemul_ctxt); + idtr =hvmemul_get_seg_reg (x86_seg_idt, hvmemul_ctxt); csr =hvmemul_get_seg_reg (x86_seg_cs, hvmemul_ctxt);__set_bit (x86_seg_cs, &hvmemul_ctxt->seg_reg_dirty);
xen/arch/x86/hvm/vmx/vmx.c +22 -22
99 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +1 -1
@@ -174,7 +174,7 @@ struct vmx_vcpu {/* Bitmask of segments that we can't safely use in virtual 8086 mode */ uint16_t vm86_segment_mask;/* Shadow CS, SS, DS, ES, FS, GS, TR while in virtual 8086 mode */ -struct segment_register vm86_saved_seg[x86_seg_tr +1 ]; +struct segment_register vm86_saved_seg[x86_seg_tss +1 ];/* Remember EFLAGS while in virtual 8086 mode */ uint32_t vm86_saved_eflags;int hostenv_migrated;
xen/arch/x86/include/asm/x86-types.h +5 -5
@@ -30,10 +30,10 @@ enum x86_segment { x86_seg_fs, x86_seg_gs,/* System: Valid to use for implicit table references. */ - x86_seg_tr, - x86_seg_ldtr, - x86_seg_gdtr, - x86_seg_idtr, + x86_seg_tss, + x86_seg_ldt, + x86_seg_gdt, + x86_seg_idt,/* No Segment: For (system/normal) accesses which are already linear. */ x86_seg_sys, x86_seg_none
@@ -47,7 +47,7 @@ static inline bool is_x86_user_segment(enum x86_segment seg) }static inline bool is_x86_system_segment (enum x86_segment seg) { -return seg >= x86_seg_tr && seg < x86_seg_none; +return seg >= x86_seg_tss && seg < x86_seg_none; }/*
xen/arch/x86/pv/emul-priv-op.c +1 -1
@@ -504,7 +504,7 @@ static int cf_check read_segment( struct x86_emulate_ctxt *ctxt) {/* Check if this is an attempt to access the I/O bitmap. */ -if ( seg == x86_seg_tr ) +if ( seg == x86_seg_tss ) {switch ( ctxt->opcode ) {
xen/arch/x86/vm_event.c +2 -2
@@ -183,7 +183,7 @@ static void vm_event_pack_segment_register(enum x86_segment segment, reg->es_sel = seg.sel;break ; -case x86_seg_gdtr: +case x86_seg_gdt: reg->gdtr_base = seg.base; reg->gdtr_limit = seg.limit;break ;
@@ -248,7 +248,7 @@ void vm_event_fill_regs(vm_event_request_t *req)vm_event_pack_segment_register (x86_seg_ss, &req->data.regs.x86);vm_event_pack_segment_register (x86_seg_ds, &req->data.regs.x86);vm_event_pack_segment_register (x86_seg_es, &req->data.regs.x86); -vm_event_pack_segment_register (x86_seg_gdtr, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_gdt, &req->data.regs.x86); req->data.regs.x86.shadow_gs = ctxt.shadow_gs; req->data.regs.x86.dr6 = ctxt.dr6;
xen/arch/x86/x86_emulate/0f01.c +1 -1
@@ -22,7 +22,7 @@ int x86emul_0f01(struct x86_emulate_state *s,struct x86_emulate_ctxt *ctxt, const struct x86_emulate_ops *ops) { - enum x86_segment seg = (s->modrm_reg & 1) ? x86_seg_idtr : x86_seg_gdtr; + enum x86_segment seg = (s->modrm_reg & 1) ? x86_seg_idt : x86_seg_gdt;int rc; switch ( s->modrm )
xen/arch/x86/x86_emulate/x86_emulate.c +8 -8
@@ -814,13 +814,13 @@ static int ioport_access_check(* X86EMUL_DONE coming back here may be used to defer the port * permission check to the respective ioport hook. */ -if ( (rc = ops->read_segment (x86_seg_tr, &tr, ctxt)) !=0 ) +if ( (rc = ops->read_segment (x86_seg_tss, &tr, ctxt)) !=0 )return rc ==X86EMUL_DONE ?X86EMUL_OKAY : rc;/* Ensure the TSS has an io-bitmap-offset field. */ generate_exception_if (tr.type !=0xb ,X86_EXC_GP ,0 ); -switch ( rc =read_ulong (x86_seg_tr,0x66 , &iobmp,2 , ctxt, ops) ) +switch ( rc =read_ulong (x86_seg_tss,0x66 , &iobmp,2 , ctxt, ops) ) {case X86EMUL_OKAY :break ;
@@ -834,7 +834,7 @@ static int ioport_access_check( }/* Read two bytes including byte containing first port. */ -switch ( rc =read_ulong (x86_seg_tr, iobmp + first_port /8 , +switch ( rc =read_ulong (x86_seg_tss, iobmp + first_port /8 , &iobmp,2 , ctxt, ops) ) {case X86EMUL_OKAY :
@@ -891,7 +891,7 @@ protmode_load_seg( const struct x86_emulate_ops *ops) {const struct cpu_policy *cp = ctxt->cpu_policy; -enum x86_segment sel_seg = (sel &4 ) ? x86_seg_ldtr : x86_seg_gdtr; +enum x86_segment sel_seg = (sel &4 ) ? x86_seg_ldt : x86_seg_gdt;struct {uint32_t a, b; } desc, desc_hi = {};uint8_t dpl, rpl;int cpl =x86emul_get_cpl (ctxt, ops);
@@ -912,7 +912,7 @@ protmode_load_seg(break ;/* fall through */ case x86_seg_cs: -case x86_seg_tr: +case x86_seg_tss: goto raise_exn; } if ( seg == x86_seg_none || !_amd_like(cp) || vcpu_has_nscb() ||
@@ -992,13 +992,13 @@ protmode_load_seg(if ( (dpl != cpl) || (dpl != rpl) ) goto raise_exn;break ; -case x86_seg_ldtr: +case x86_seg_ldt:/* LDT system segment? */ if ( (desc.b & (15u <<8 )) != (2u <<8 ) ) goto raise_exn; a_flag =0 ;break ; -case x86_seg_tr: +case x86_seg_tss:/* Available TSS system segment? */ if ( (desc.b & (15u <<8 )) != (9u <<8 ) ) goto raise_exn;
@@ -2914,7 +2914,7 @@ x86_emulate(break ;case X86EMUL_OPC (0x0f ,0x00 ):/* Grp6 */ - seg = (modrm_reg &1 ) ? x86_seg_tr : x86_seg_ldtr; + seg = (modrm_reg &1 ) ? x86_seg_tss : x86_seg_ldt;generate_exception_if (!in_protmode (ctxt, ops),X86_EXC_UD );switch ( modrm_reg &6 ) {
xen/arch/x86/x86_emulate/x86_emulate.h +1 -1
@@ -51,7 +51,7 @@ struct x86_emul_fpu_aux {/* * Operation fully done by one of the hooks: * - validate(): operation completed (except common insn retire logic) -* - read_segment(x86_seg_tr, ...): bypass I/O bitmap access +* - read_segment(x86_seg_tss, ...): bypass I/O bitmap access * - read_io() / write_io(): bypass GPR update (non-string insns only) * Undefined behavior when used anywhere else. */
Signature · 1 line
2.39.5
Re: [PATCH v2 2/3] x86/emul: Rename the x86_seg_* system segments
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 136
Quoted 8 lines · Andrew Cooper
xen/arch/x86/hvm/domain.c +1
-2@@ -131,18 +131,21 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx)#define SEG (s, r) ({ \ s = (struct segment_register) \ { 0, { (r)->s ## _ar }, (r)->s ## _limit, (r)->s ## _base }; \ -/* Set accessed / busy bit for present segments. */ \ +/* Set accessed bit for present segments. */ \if ( (s).p ) \ - (s).type |= (x86_seg_ ## s != x86_seg_tr ? 1 : 2); \
From this, ...
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 136
Quoted 1 line
xen/arch/x86/hvm/domain.c +1
-0+ (s).type |=2 ; \
... this wants to be 1, while ...
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 146
Quoted 11 lines
xen/arch/x86/hvm/domain.c +2
-1check_segment(&(s), x86_seg_ ## s); }) rc =SEG (cs, regs); rc |=SEG (ds, regs); rc |=SEG (ss, regs); rc |=SEG (es, regs); - rc |=SEG (tr, regs);#undef SEG + tr = (struct segment_register ){ +0 , { regs->tr_ar |1 /* Busy */ }, regs->tr_limit, regs->tr_base };
... this wants to be 2. Then:
Jan
Re: [PATCH v2 2/3] x86/emul: Rename the x86_seg_* system segments
Quoted 23 lines · Jan Beulich
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 136
Quoted 8 lines · Andrew Cooper
xen/arch/x86/hvm/domain.c +1
-2@@ -131,18 +131,21 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx)#define SEG (s, r) ({ \ s = (struct segment_register) \ { 0, { (r)->s ## _ar }, (r)->s ## _limit, (r)->s ## _base }; \ -/* Set accessed / busy bit for present segments. */ \ +/* Set accessed bit for present segments. */ \if ( (s).p ) \ - (s).type |= (x86_seg_ ## s != x86_seg_tr ? 1 : 2); \From this, ...
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 136
Quoted 1 line
xen/arch/x86/hvm/domain.c +1
-0+ (s).type |=2 ; \... this wants to be 1, while ...
Quoted 9 lines
xen/arch/x86/hvm/domain.c +0
-1check_segment(&(s), x86_seg_ ## s); }) rc =SEG (cs, regs); rc |=SEG (ds, regs); rc |=SEG (ss, regs); rc |=SEG (es, regs); - rc |=SEG (tr, regs);#undef SEG
Quoted 3 lines
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 146
Quoted 2 lines
xen/arch/x86/hvm/domain.c +2
-0+ tr = (struct segment_register ){ +0 , { regs->tr_ar |1 /* Busy */ }, regs->tr_limit, regs->tr_base };... this wants to be 2.
Yes, I did spot that just after sending. I thought I emailed out, but clearly didn't.
Quoted 2 lines
Then:
Reviewed-by Jan Beulich <[email protected]>
Thanks.
~Andrew
PATCH 3/3 x86/emul: Drop the union in x86_event had have a single data field
In reply to Andrew CooperFRED has formalised the event_data field. It already has more uses than given (e.g. the NMI Source Bitmap), and further uses are expected in the future.
Collapse the union into a single field called 'data' as the struct has event in it's name, as well as 'event' being the common name for the variable. Refer to the FRED spec rather than keeping an out-of-date list of uses.
Adjust all users of the old names.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
--- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 8 ++++---- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/include/asm/domain.h | 6 ++---- xen/arch/x86/include/asm/hvm/hvm.h | 3 +-- xen/arch/x86/include/asm/x86-event.h | 14 ++++++++++---- xen/arch/x86/pv/traps.c | 10 +++++----- xen/arch/x86/x86_emulate/x86_emulate.h | 2 +- 10 files changed, 28 insertions(+), 25 deletions(-)
xen/arch/x86/hvm/dm.c +1 -1
@@ -315,7 +315,7 @@ static int inject_event(struct domain *d, v->arch.hvm.inject_event.type = data->type; v->arch.hvm.inject_event.insn_len = data->insn_len; v->arch.hvm.inject_event.error_code = data->error_code; - v->arch.hvm.inject_event.cr2 = data->cr2; + v->arch.hvm.inject_event.data = data->cr2;smp_wmb (); v->arch.hvm.inject_event.vector = data->vector;
xen/arch/x86/hvm/hvm.c +2 -2
@@ -513,7 +513,7 @@ void hvm_migrate_pirqs(struct vcpu *v)static bool hvm_get_pending_event (struct vcpu *v,struct x86_event *info) { - info->cr2 = v->arch.hvm.guest_cr[2 ]; + info->data = v->arch.hvm.guest_cr[2 ];return alternative_call (hvm_funcs.get_pending_event, v, info); }
@@ -555,7 +555,7 @@ void hvm_do_resume(struct vcpu *v)if (hvm_get_pending_event (v, &info) ) {hvm_monitor_interrupt (info.vector, info.type, info.error_code, - info.cr2); + info.data); v->arch.monitor.next_interrupt_enabled = false; } }
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
@@ -775,7 +775,7 @@ int cf_check nsvm_vcpu_vmexit_event(ASSERT (vcpu_nestedhvm (v).nv_vvmcx !=NULL );nestedsvm_vmexit_defer (v,VMEXIT_EXCEPTION_DE + event->vector, - event->error_code, event->cr2); + event->error_code, event->data);return NESTEDHVM_VMEXIT_DONE ; }
xen/arch/x86/hvm/svm/svm.c +4 -4
@@ -1177,7 +1177,7 @@ static void svm_emul_swint_injection(struct x86_event *event) { fault =X86_EXC_PF ; ec = pfinfo.ec; - event->cr2 = pfinfo.linear; + event->data = pfinfo.linear; } goto raise_exception;
@@ -1270,8 +1270,8 @@ static void cf_check svm_inject_event(const struct x86_event *event)case X86_EXC_PF :ASSERT (_event.type ==X86_ET_HW_EXC ); - curr->arch.hvm.guest_cr[2 ] = _event.cr2; -vmcb_set_cr2 (vmcb, _event.cr2); + curr->arch.hvm.guest_cr[2 ] = _event.data; +vmcb_set_cr2 (vmcb, _event.data);break ; }
@@ -1354,7 +1354,7 @@ static void cf_check svm_inject_event(const struct x86_event *event)if ( _event.vector ==X86_EXC_PF && _event.type ==X86_ET_HW_EXC )TRACE (TRC_HVM_PF_INJECT64 , _event.error_code, - _event.cr2, _event.cr2 >>32 ); + _event.data, _event.data >>32 );else TRACE (TRC_HVM_INJ_EXC , _event.vector, _event.error_code); }
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -2106,7 +2106,7 @@ static void cf_check vmx_inject_event(const struct x86_event *event)case X86_EXC_PF :ASSERT (_event.type ==X86_ET_HW_EXC ); - curr->arch.hvm.guest_cr[2 ] = _event.cr2; + curr->arch.hvm.guest_cr[2 ] = _event.data;break ; }
xen/arch/x86/include/asm/domain.h +2 -4
@@ -747,10 +747,9 @@ static inline void pv_inject_DB(unsigned long pending_dbg) .vector = X86_EXC_DB, .type = X86_ET_HW_EXC, .error_code = X86_EVENT_NO_EC, + .data = pending_dbg, }; - event.pending_dbg = pending_dbg; -pv_inject_event (&event); }
@@ -760,10 +759,9 @@ static inline void pv_inject_page_fault(int errcode, unsigned long cr2) .vector = X86_EXC_PF, .type = X86_ET_HW_EXC, .error_code = errcode, + .data = cr2, }; - event.cr2 = cr2; -pv_inject_event (&event); }
xen/arch/x86/include/asm/hvm/hvm.h +1 -2
@@ -569,10 +569,9 @@ static inline void hvm_inject_page_fault(int errcode, unsigned long cr2) .vector = X86_EXC_PF, .type = X86_ET_HW_EXC, .error_code = errcode, + .data = cr2, }; - event.cr2 = cr2; -hvm_inject_event (&event); }
xen/arch/x86/include/asm/x86-event.h +10 -4
@@ -22,10 +22,16 @@ struct x86_event {uint8_t type;/* X86_ET_* */ uint8_t insn_len;/* Instruction length */ int32_t error_code;/* X86_EVENT_NO_EC if n/a */ -union { -unsigned long cr2;/* #PF */ -unsigned long pending_dbg;/* #DB (new DR6 bits, positive polarity) */ - }; + +/* +* As per the FRED spec. +* +* A subset of uses occur in IDT mode as well: +* - #PF: CR2 +* - #DB: PENDING_DBG (DR6 with positive polarity) +* - #NM: XFD_ERR (AMX) +*/ + unsigned long data; };#endif /* X86_X86_EVENT_H */
xen/arch/x86/pv/traps.c +5 -5
@@ -58,20 +58,20 @@ void pv_inject_event(const struct x86_event *event)switch ( vector | -(event->type ==X86_ET_SW_INT ) ) {case X86_EXC_PF : - curr->arch.pv.ctrlreg[2 ] = event->cr2; -arch_set_cr2 (curr, event->cr2); + curr->arch.pv.ctrlreg[2 ] = event->data; +arch_set_cr2 (curr, event->data);/* Re-set error_code.user flag appropriately for the guest. */ error_code &= ~PFEC_user_mode;if ( !guest_kernel_mode (curr, regs) ) error_code |= PFEC_user_mode; -trace_pv_page_fault (event->cr2, error_code); +trace_pv_page_fault (event->data, error_code);break ;case X86_EXC_DB : curr->arch.dr6 =x86_merge_dr6 (curr->domain->arch.cpu_policy, - curr->arch.dr6, event->pending_dbg); + curr->arch.dr6, event->data); fallthrough;default :trace_pv_trap (vector, regs->rip, use_error_code, error_code);
@@ -94,7 +94,7 @@ void pv_inject_event(const struct x86_event *event) vector, vector_name(vector), error_code);if ( vector ==X86_EXC_PF ) -show_page_walk (event->cr2); +show_page_walk (event->data); } }
xen/arch/x86/x86_emulate/x86_emulate.h +1 -1
@@ -758,7 +758,7 @@ static inline void x86_emul_pagefault( ctxt->event.vector =X86_EXC_PF ; ctxt->event.type =X86_ET_HW_EXC ; ctxt->event.error_code = error_code; - ctxt->event.cr2 = cr2; + ctxt->event.data = cr2; ctxt->event_pending = true; }
Signature · 1 line
2.39.5
Re: [PATCH 3/3] x86/emul: Drop the union in x86_event had have a single data field
Quoted 8 lines · Andrew Cooper
FRED has formalised the
event_datafield. It already has more uses than given (e.g. the NMI Source Bitmap), and further uses are expected in the future.Collapse the union into a single field called 'data' as the struct has event in it's name, as well as 'event' being the common name for the variable. Refer to the FRED spec rather than keeping an out-of-date list of uses.
Quoted 5 lines
Adjust all users of the old names.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>