x86/svm: Cleanup vintr_t type
PATCH v2 1/1 x86/svm: Cleanup vintr_t type
From: Ross Lagerwall <[email protected]>
Rearrange the union to drop the .fields infix, rename bytes to the more common raw, adjust types where appropriate, and simplify some names. Adjust the users accordingly.
No functional change intended.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Jason Andryuk <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Denis Mukhin <[email protected]>
v2:
* Further adjustments to names, swap to true/false for bools.
--- xen/arch/x86/hvm/svm/intr.c | 19 +++++++-------- xen/arch/x86/hvm/svm/nestedsvm.c | 33 +++++++++++++------------ xen/arch/x86/hvm/svm/svm.c | 18 +++++++------- xen/arch/x86/hvm/svm/vmcb.c | 6 ++--- xen/arch/x86/hvm/svm/vmcb.h | 41 +++++++++++++++----------------- 5 files changed, 55 insertions(+), 62 deletions(-)
xen/arch/x86/hvm/svm/intr.c +9 -10
@@ -34,9 +34,9 @@ static void svm_inject_nmi(struct vcpu *v)uint32_t general1_intercepts;intinfo_t event; -if ( vintr.fields.vnmi_enable ) +if ( vintr.vnmi_en ) { - vintr.fields.vnmi_pending = true; + vintr.nmi_pending = true;vmcb_set_vintr (vmcb, vintr);return ; }
@@ -93,7 +93,7 @@ static void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack)*/ ASSERT (gvmcb !=NULL ); intr =vmcb_get_vintr (gvmcb); -if ( intr.fields.irq ) +if ( intr.intr_pending )return ; } }
@@ -122,10 +122,10 @@ static void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack)return ; intr =vmcb_get_vintr (vmcb); - intr.fields.irq =1 ; - intr.fields.vector =0 ; - intr.fields.prio = intack.vector >>4 ; - intr.fields.ign_tpr = (intack.source != hvm_intsrc_lapic); + intr.intr_pending = true; + intr.intr_prio = intack.vector >>4 ; + intr.ign_tpr = (intack.source != hvm_intsrc_lapic); + intr.vector =0 ;vmcb_set_vintr (vmcb, intr);vmcb_set_general1_intercepts ( vmcb, general1_intercepts |GENERAL1_INTERCEPT_VINTR );
@@ -153,15 +153,14 @@ void asmlinkage svm_intr_assist(void) intblk =hvm_interrupt_blocked (v, intack);/* -* When vNMI is active, NMIs can be injected by setting vnmi_pending +* When vNMI is active, NMIs can be injected by setting nmi_pending * and hardware will deliver them at the next appropriate opportunity. * Consider them not blocked, to avoid trying to open an NMI Window. * * Correctness here relies on the fact that all vNMI capable hardware * has vGIF, and vGIF is always activated when appropriate. */ -if ( intblk == hvm_intblk_nmi_iret && - vmcb->_vintr.fields.vnmi_enable ) +if ( intblk == hvm_intblk_nmi_iret && vmcb->_vintr.vnmi_en ) intblk = hvm_intblk_none;if ( intblk == hvm_intblk_svm_gif )
xen/arch/x86/hvm/svm/nestedsvm.c +16 -17
@@ -427,7 +427,7 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct cpu_user_regs *regs)if ( !clean.tpr ) { n2vmcb->_vintr = ns_vmcb->_vintr; - n2vmcb->_vintr.fields.intr_masking =1 ; + n2vmcb->_vintr.vintr_masking = true; }/* Interrupt state */
@@ -637,7 +637,7 @@ nsvm_vcpu_vmentry(struct vcpu *v, struct cpu_user_regs *regs, svm->ns_hap_enabled =vmcb_get_np (ns_vmcb);/* Remember the V_INTR_MASK in hostflags */ - svm->ns_hostflags.vintrmask = ns_vmcb->_vintr.fields.intr_masking; + svm->ns_hostflags.vintrmask = ns_vmcb->_vintr.vintr_masking;/* Save l1 guest state (= host state) */ ret =nsvm_vcpu_hostsave (v, inst_len);
@@ -723,8 +723,8 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs,struct vmcb_struct *ns_vmcb;struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb; -if ( vmcb->_vintr.fields.vgif_enable ) - vmcb->_vintr.fields.vgif =0 ; +if ( vmcb->_vintr.vgif_en ) + vmcb->_vintr.gif = false;else svm->ns_gif =0 ;
@@ -979,7 +979,7 @@ nsvm_vmcb_prepare4vmexit(struct vcpu *v, struct cpu_user_regs *regs)/* Virtual Interrupts */ ns_vmcb->_vintr = n2vmcb->_vintr;if ( !svm->ns_hostflags.vintrmask ) - ns_vmcb->_vintr.fields.intr_masking =0 ; + ns_vmcb->_vintr.vintr_masking = false;/* Interrupt state */ ns_vmcb->int_stat = n2vmcb->int_stat;
@@ -1198,8 +1198,8 @@ nestedsvm_vmexit_defer(struct vcpu *v,struct nestedsvm *svm = &vcpu_nestedsvm (v);struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb; -if ( vmcb->_vintr.fields.vgif_enable ) - vmcb->_vintr.fields.vgif =0 ; +if ( vmcb->_vintr.vgif_en ) + vmcb->_vintr.gif = false;else svm->ns_gif =0 ;
@@ -1461,8 +1461,8 @@ nestedsvm_gif_isset(struct vcpu *v)struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;/* get the vmcb gif value if using vgif */ -if ( vmcb->_vintr.fields.vgif_enable ) -return vmcb->_vintr.fields.vgif; +if ( vmcb->_vintr.vgif_en ) +return vmcb->_vintr.gif;else return svm->ns_gif; }
@@ -1509,7 +1509,7 @@ void svm_vmexit_do_clgi(struct cpu_user_regs *regs, struct vcpu *v)/* After a CLGI no interrupts should come */ intr =vmcb_get_vintr (vmcb); - intr.fields.irq =0 ; + intr.intr_pending = false; general1_intercepts &= ~GENERAL1_INTERCEPT_VINTR ;vmcb_set_vintr (vmcb, intr);vmcb_set_general1_intercepts (vmcb, general1_intercepts);
@@ -1543,12 +1543,11 @@ void svm_nested_features_on_efer_update(struct vcpu *v)vmcb_set_general2_intercepts (vmcb, general2_intercepts); } -if ( !vmcb->_vintr.fields.vgif_enable && - cpu_has_svm_vgif ) +if ( !vmcb->_vintr.vgif_en && cpu_has_svm_vgif ) { vintr =vmcb_get_vintr (vmcb); - vintr.fields.vgif = svm->ns_gif; - vintr.fields.vgif_enable =1 ; + vintr.gif = svm->ns_gif; + vintr.vgif_en = true;vmcb_set_vintr (vmcb, vintr); general2_intercepts =vmcb_get_general2_intercepts (vmcb); general2_intercepts &= ~(GENERAL2_INTERCEPT_STGI |
@@ -1567,11 +1566,11 @@ void svm_nested_features_on_efer_update(struct vcpu *v)vmcb_set_general2_intercepts (vmcb, general2_intercepts); } -if ( vmcb->_vintr.fields.vgif_enable ) +if ( vmcb->_vintr.vgif_en ) { vintr =vmcb_get_vintr (vmcb); - svm->ns_gif = vintr.fields.vgif; - vintr.fields.vgif_enable =0 ; + svm->ns_gif = vintr.gif; + vintr.vgif_en = false;vmcb_set_vintr (vmcb, vintr); general2_intercepts =vmcb_get_general2_intercepts (vmcb); general2_intercepts |= (GENERAL2_INTERCEPT_STGI |
xen/arch/x86/hvm/svm/svm.c +8 -10
@@ -498,8 +498,8 @@ static unsigned cf_check int svm_get_interrupt_shadow(struct vcpu *v)if ( vmcb->int_stat.intr_shadow ) intr_shadow |=HVM_INTR_SHADOW_MOV_SS |HVM_INTR_SHADOW_STI ; -if ( vmcb->_vintr.fields.vnmi_enable - ? vmcb->_vintr.fields.vnmi_blocking +if ( vmcb->_vintr.vnmi_en + ? vmcb->_vintr.nmi_blocked : (vmcb_get_general1_intercepts (vmcb) &GENERAL1_INTERCEPT_IRET ) ) intr_shadow |=HVM_INTR_SHADOW_NMI ;
@@ -516,9 +516,9 @@ static void cf_check svm_set_interrupt_shadow( vmcb->int_stat.intr_shadow = !!(intr_shadow & (HVM_INTR_SHADOW_MOV_SS |HVM_INTR_SHADOW_STI )); -if ( vintr.fields.vnmi_enable ) +if ( vintr.vnmi_en ) { - vintr.fields.vnmi_blocking = block_nmi; + vintr.nmi_blocked = block_nmi;vmcb_set_vintr (vmcb, vintr); }else
@@ -964,8 +964,7 @@ static void noreturn cf_check svm_do_resume(void)/* Reflect the vlapic's TPR in the hardware vtpr */ intr =vmcb_get_vintr (vmcb); - intr.fields.tpr = - (vlapic_get_reg (vlapic,APIC_TASKPRI ) &0xFF ) >>4 ; + intr.tpr = (vlapic_get_reg (vlapic,APIC_TASKPRI ) &0xFF ) >>4 ;vmcb_set_vintr (vmcb, intr); }
@@ -2542,7 +2541,7 @@ void asmlinkage svm_vmexit_handler(void) { intr =vmcb_get_vintr (vmcb);vlapic_set_reg (vlapic,APIC_TASKPRI , - ((intr.fields.tpr &0x0F ) <<4 ) | + ((intr.tpr &0x0F ) <<4 ) | (vlapic_get_reg (vlapic,APIC_TASKPRI ) &0x0F )); }
@@ -2776,7 +2775,7 @@ void asmlinkage svm_vmexit_handler(void)u32 general1_intercepts =vmcb_get_general1_intercepts (vmcb); intr =vmcb_get_vintr (vmcb); - intr.fields.irq =0 ; + intr.intr_pending = false; general1_intercepts &= ~GENERAL1_INTERCEPT_VINTR ;vmcb_set_vintr (vmcb, intr);
@@ -3067,8 +3066,7 @@ void asmlinkage svm_vmexit_handler(void)/* The exit may have updated the TPR: reflect this in the hardware vtpr */ intr =vmcb_get_vintr (vmcb); - intr.fields.tpr = - (vlapic_get_reg (vlapic,APIC_TASKPRI ) &0xFF ) >>4 ; + intr.tpr = (vlapic_get_reg (vlapic,APIC_TASKPRI ) &0xFF ) >>4 ;vmcb_set_vintr (vmcb, intr); }
xen/arch/x86/hvm/svm/vmcb.c +3 -3
@@ -105,7 +105,7 @@ static int construct_vmcb(struct vcpu *v) vmcb->_iopm_base_pa =__pa (v->domain->arch.hvm.io_bitmap);/* Virtualise EFLAGS.IF and LAPIC TPR (CR8). */ - vmcb->_vintr.fields.intr_masking =1 ; + vmcb->_vintr.vintr_masking = true;/* Don't need to intercept RDTSC if CPU supports TSC rate scaling */ if ( v->domain->arch.vtsc && !cpu_has_tsc_ratio )
@@ -192,7 +192,7 @@ static int construct_vmcb(struct vcpu *v)if ( default_xen_spec_ctrl ==SPEC_CTRL_STIBP ) v->arch.msrs->spec_ctrl.raw =SPEC_CTRL_STIBP ; - vmcb->_vintr.fields.vnmi_enable = cpu_has_svm_vnmi; + vmcb->_vintr.vnmi_en = cpu_has_svm_vnmi;return 0 ; }
@@ -275,7 +275,7 @@ void svm_vmcb_dump(const char *from, const struct vmcb_struct *vmcb)vmcb_get_iopm_base_pa (vmcb),vmcb_get_msrpm_base_pa (vmcb), vmcb_get_tsc_offset(vmcb));printk ("tlb_control = %#x vintr = %#" PRIx64" int_stat = %#" PRIx64"\n" , - vmcb->tlb_control,vmcb_get_vintr (vmcb).bytes, + vmcb->tlb_control,vmcb_get_vintr (vmcb).raw, vmcb->int_stat.raw); printk("event_inj %016"PRIx64", valid? %d, ec? %d, type %u, vector %#x\n", vmcb->event_inj.raw, vmcb->event_inj.v,
xen/arch/x86/hvm/svm/vmcb.h +19 -22
47 lines not on this page · raw message
Signature · 1 line
2.39.5
Quoted 11 lines · Andrew Cooper
From: Ross Lagerwall <[email protected]>
Rearrange the union to drop the .fields infix, rename bytes to the more common raw, adjust types where appropriate, and simplify some names. Adjust the users accordingly.
No functional change intended.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Ross Lagerwall <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
with a suggestion (below). Also - doesn't this now need your S-o-b as well?
Quoted 6 lines
xen/arch/x86/hvm/svm/intr.c +1
-1@@ -153,15 +153,14 @@ void asmlinkage svm_intr_assist(void) intblk =hvm_interrupt_blocked (v, intack);/* -* When vNMI is active, NMIs can be injected by setting vnmi_pending +* When vNMI is active, NMIs can be injected by setting nmi_pending
xen/arch/x86/hvm/svm/intr.c void asmlinkage svm_intr_assist(void) · line 164
Quoted 10 lines
xen/arch/x86/hvm/svm/intr.c +1
-2* and hardware will deliver them at the next appropriate opportunity. * Consider them not blocked, to avoid trying to open an NMI Window. * * Correctness here relies on the fact that all vNMI capable hardware * has vGIF, and vGIF is always activated when appropriate. */ -if ( intblk == hvm_intblk_nmi_iret && - vmcb->_vintr.fields.vnmi_enable ) +if ( intblk == hvm_intblk_nmi_iret && vmcb->_vintr.vnmi_en ) intblk = hvm_intblk_none;
In the comment, may I suggest to prefix nmi_pending with a dot, to clarify that a struct/union field is meant?
Quoted 38 lines
xen/arch/x86/hvm/svm/vmcb.h +10
-22@@ -328,28 +328,25 @@ typedef union {uint64_t raw; } intstat_t; -typedef union -{ - u64 bytes; - struct - { - u64 tpr: 8; - u64 irq: 1; - u64 vgif: 1; - u64 : 1; - u64 vnmi_pending: 1; - u64 vnmi_blocking:1; - u64 : 3; - u64 prio: 4; - u64 ign_tpr: 1; - u64 rsvd1: 3; - u64 intr_masking: 1; - u64 vgif_enable: 1; - u64 vnmi_enable: 1; - u64 : 5; - u64 vector: 8; - u64 rsvd3: 24; - } fields; +typedef union { + struct { /* Cleanbit 3 (TPR), APM Name */ + uint8_t tpr; /* c V_TPR */ + bool intr_pending:1; /* c V_IRQ */ + bool gif:1; /* VGIF */ + bool :1; + bool nmi_pending:1; /* c V_NMI */ + bool nmi_blocked:1; /* c V_NMI_MASK */ + uint8_t :3; + uint8_t intr_prio:4; /* c V_INTR_PRIO */
xen/arch/x86/hvm/svm/vmcb.h typedef union { · line 350
Quoted 10 lines
xen/arch/x86/hvm/svm/vmcb.h +9
-0+ bool ign_tpr:1; /* c V_IGN_TPR */ + uint8_t :3; + bool vintr_masking:1; /* c V_INTR_MASKING */ + bool vgif_en:1; /* VGIF_EN */ + bool vnmi_en:1; /* V_NMI_ENABLE */ + uint8_t :5; +uint8_t vector;/* c V_INTR_VECTOR */ + }; +uint64_t raw; } vintr_t;
As said in reply to Ross'es v1 - imo uint8_t bitfields would better be avoided; afaict there's no issue with using unsigned int there. (While I'd like us to avoid such unnecessary uses of compiler extensions, I'm also not going to insist here, as we have too many other instances of this same pattern.)
Jan