x86/vmx: Replace __vmread() with vmread()
PATCH v4 3/3 x86/vmx: Replace __vmread() with vmread()
From: Denis Mukhin <[email protected]>
Use vmread() instead of __vmread() as per suggestion in [1] everywhere in the VT-x code.
Remove __vmread() and update ECLAIR configuration.
[1] https://lore.kernel.org/xen-devel/[email protected]/
--- docs/misra/function-macro-properties.json | 9 - xen/arch/x86/cpu/vpmu_intel.c | 3 +- xen/arch/x86/hvm/vmx/intr.c | 26 +-- xen/arch/x86/hvm/vmx/realmode.c | 2 +- xen/arch/x86/hvm/vmx/vmcs.c | 11 +- xen/arch/x86/hvm/vmx/vmx.c | 208 ++++++++++------------ xen/arch/x86/hvm/vmx/vvmx.c | 43 ++--- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 5 - 8 files changed, 122 insertions(+), 185 deletions(-)
docs/misra/function-macro-properties.json +0 -9
@@ -152,15 +152,6 @@ "taken": "" } }, - { - "type": "function", - "value": "^__vmread.*$", - "properties":{ - "pointee_write": "2=always", - "pointee_read": "2=never", - "taken": "" - } - }, { "type": "function", "value": "^hvm_pci_decode_addr.*$",
xen/arch/x86/cpu/vpmu_intel.c +1 -2
@@ -796,8 +796,7 @@ static int cf_check core2_vpmu_do_interrupt(void)else {/* No PMC overflow but perhaps a Trace Message interrupt. */ -__vmread (GUEST_IA32_DEBUGCTL , &msr_content); -if ( !(msr_content &IA32_DEBUGCTLMSR_TR ) ) +if ( !(vmread (GUEST_IA32_DEBUGCTL ) &IA32_DEBUGCTLMSR_TR ) )return 0 ; }
xen/arch/x86/hvm/vmx/intr.c +7 -19
@@ -63,9 +63,8 @@ static void vmx_enable_intr_window(struct vcpu *v, struct hvm_intack intack)if (unlikely (tb_init_done) ) { -unsigned long intr; +unsigned long intr =vmread (VM_ENTRY_INTR_INFO ); -__vmread (VM_ENTRY_INTR_INFO , &intr);TRACE (TRC_HVM_INTR_WINDOW , intack.vector, intack.source, (intr &INTR_INFO_VALID_MASK ) ? intr &0xff :-1 ); }
@@ -81,9 +80,8 @@ static void vmx_enable_intr_window(struct vcpu *v, struct hvm_intack intack)* we may immediately vmexit and hance make no progress! * (see SDM 3B 21.3, "Other Causes of VM Exits"). */ -unsigned long intr_shadow; +unsigned long intr_shadow =vmread (GUEST_INTERRUPTIBILITY_INFO ); -__vmread (GUEST_INTERRUPTIBILITY_INFO , &intr_shadow);if ( intr_shadow &VMX_INTR_SHADOW_STI ) {/* Having both STI-blocking and MOV-SS-blocking fails vmentry. */
@@ -144,14 +142,8 @@ enum hvm_intblk cf_check nvmx_intr_blocked(struct vcpu *v)if ( nvcpu->nv_vmexit_pending || nvcpu->nv_vmswitch_in_progress ) r = hvm_intblk_rflags_ie; -else - { -unsigned long intr_info; - -__vmread (VM_ENTRY_INTR_INFO , &intr_info); -if ( intr_info &INTR_INFO_VALID_MASK ) - r = hvm_intblk_rflags_ie; - } +else if (vmread (VM_ENTRY_INTR_INFO ) &INTR_INFO_VALID_MASK ) + r = hvm_intblk_rflags_ie; }else if ( nvcpu->nv_vmentry_pending ) r = hvm_intblk_rflags_ie;
@@ -253,8 +245,6 @@ void asmlinkage vmx_intr_assist(void) pt_vector =pt_update_irq (v); do { - unsigned long intr_info; - intack = hvm_vcpu_has_pending_irq(v); if ( likely(intack.source == hvm_intsrc_none) ) goto out;
@@ -275,8 +265,7 @@ void asmlinkage vmx_intr_assist(void) goto out; } -__vmread (VM_ENTRY_INTR_INFO , &intr_info); -if ( intr_info &INTR_INFO_VALID_MASK ) +if (vmread (VM_ENTRY_INTR_INFO ) &INTR_INFO_VALID_MASK ) { if ( (intack.source == hvm_intsrc_pic) || (intack.source == hvm_intsrc_nmi) ||
@@ -299,8 +288,7 @@ void asmlinkage vmx_intr_assist(void) }else { -__vmread (VM_ENTRY_INTR_INFO , &intr_info); -if ( intr_info &INTR_INFO_VALID_MASK ) +if (vmread (VM_ENTRY_INTR_INFO ) &INTR_INFO_VALID_MASK ) {vmx_enable_intr_window (v, intack); goto out;
@@ -377,7 +365,7 @@ void asmlinkage vmx_intr_assist(void) }/* we need update the RVI field */ -__vmread (GUEST_INTR_STATUS , &status); + status =vmread (GUEST_INTR_STATUS ); status &= ~VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK ; status |=VMX_GUEST_INTR_STATUS_SUBFIELD_BITMASK & intack.vector;
xen/arch/x86/hvm/vmx/realmode.c +1 -1
@@ -159,7 +159,7 @@ void vmx_realmode(struct cpu_user_regs *regs)unsigned int emulations =0 ;/* Get-and-clear VM_ENTRY_INTR_INFO. */ -__vmread (VM_ENTRY_INTR_INFO , &intr_info); + intr_info =vmread (VM_ENTRY_INTR_INFO );if ( intr_info &INTR_INFO_VALID_MASK )__vmwrite (VM_ENTRY_INTR_INFO ,0 );
xen/arch/x86/hvm/vmx/vmcs.c +4 -7
@@ -1031,7 +1031,7 @@ u64 virtual_vmcs_vmread(const struct vcpu *v, u32 vmcs_encoding)u64 res;virtual_vmcs_enter (v); -__vmread (vmcs_encoding, &res); + res =vmread (vmcs_encoding);virtual_vmcs_exit (v);return res;
@@ -1691,7 +1691,7 @@ void vmx_vcpu_flush_pml_buffer(struct vcpu *v)vmx_vmcs_enter (v); -__vmread (GUEST_PML_INDEX , &pml_idx); + pml_idx =vmread (GUEST_PML_INDEX );/* Do nothing if PML buffer is empty. */ if ( pml_idx == (NR_PML_ENTRIES -1 ) )
@@ -1874,9 +1874,8 @@ void vmx_destroy_vmcs(struct vcpu *v)void vmx_vmentry_failure (void ) {struct vcpu *curr = current; -unsigned long error; +unsigned long error =vmread (VM_INSTRUCTION_ERROR ); -__vmread (VM_INSTRUCTION_ERROR , &error);gprintk (XENLOG_ERR ,"VM%s error: %#lx\n" , curr->arch.hvm.vmx.launched ?"RESUME" :"LAUNCH" , error);
@@ -1905,7 +1904,6 @@ void cf_check vmx_do_resume(void) {struct vcpu *v = current;bool debug_state; -unsigned long host_cr4;if ( v->arch.hvm.vmx.active_cpu ==smp_processor_id () )vmx_vmcs_reload (v);
@@ -1957,8 +1955,7 @@ void cf_check vmx_do_resume(void)hvm_do_resume (v);/* Sync host CR4 in case its value has changed. */ -__vmread (HOST_CR4 , &host_cr4); -if ( host_cr4 !=read_cr4 () ) +if (vmread (HOST_CR4 ) !=read_cr4 () )__vmwrite (HOST_CR4 ,read_cr4 ());reset_stack_and_jump (vmx_asm_do_vmentry);
xen/arch/x86/hvm/vmx/vmx.c +90 -118
590 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vvmx.c +19 -24
169 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -5
@@ -336,11 +336,6 @@ static always_inline unsigned long vmread(unsigned long field)return value; } -static always_inline void __vmread(unsigned long field, unsigned long *value) -{ - *value =vmread (field); -} - static always_inline void __vmwrite(unsigned long field, unsigned long value) { asm goto ( "vmwrite %[value], %[field]\n\t"
Signature · 1 line
2.34.1
xen/arch/x86/hvm/vmx/vmcs.c void cf_check vmx_do_resume(void) · line 1958
Quoted 7 lines · On 26.04.2025 09:28, [email protected] wrote:
xen/arch/x86/hvm/vmx/vmcs.c +1
-2@@ -1957,8 +1955,7 @@ void cf_check vmx_do_resume(void)hvm_do_resume (v);/* Sync host CR4 in case its value has changed. */ -__vmread (HOST_CR4 , &host_cr4); -if ( host_cr4 !=read_cr4 () ) +if (vmread (HOST_CR4 ) !=read_cr4 () )
It's unclear to me whether this constitutes a violation of Misra rule 13.2. There are two function calls in this expression. Both funcs are inline, and vmread() is even always_inline, but they're still function calls, which can be carried out in either order. And neither can plausibly be pure, let alone const.
xen/arch/x86/hvm/vmx/vmx.c static void cf_check vmx_get_nonreg_state(struct vcpu *v, · line 1568
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-3@@ -1573,12 +1565,12 @@ static void cf_check vmx_get_nonreg_state(struct vcpu *v, {vmx_vmcs_enter (v); -__vmread (GUEST_ACTIVITY_STATE , &nrs->vmx.activity_state); -__vmread (GUEST_INTERRUPTIBILITY_INFO , &nrs->vmx.interruptibility_info); -__vmread (GUEST_PENDING_DBG_EXCEPTIONS , &nrs->vmx.pending_dbg); + nrs->vmx.activity_state =vmread (GUEST_ACTIVITY_STATE );
This struct field can now also shrink down to unsigned int (or uit32_t if need be). Likely there are others (and maybe also plain variables). Which in turn is an indication that, as was suggested before, this patch wants further splitting up. That'll also help with overall progress, as then what's uncontroversial and not in need of further adjustment can go in right away.
Jan
Quoted 4 lines · Jan Beulich
Quoted 3 lines · On 26.04.2025 09:28, [email protected] wrote:
xen/arch/x86/hvm/vmx/vmcs.c +0
-0@@ -1957,8 +1955,7 @@ void cf_check vmx_do_resume(void)hvm_do_resume (v);
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c void cf_check vmx_do_resume(void) · line 1958
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmcs.c +1
-2/* Sync host CR4 in case its value has changed. */ -__vmread (HOST_CR4 , &host_cr4); -if ( host_cr4 !=read_cr4 () ) +if (vmread (HOST_CR4 ) !=read_cr4 () )It's unclear to me whether this constitutes a violation of Misra rule 13.2. There are two function calls in this expression. Both funcs are inline, and
vmread()is evenalways_inline, but they're still function calls, which can be carried out in either order. And neither can plausibly be pure, let alone const.
Thanks, I will revert that hunk.
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -1573,12 +1565,12 @@ static void cf_check vmx_get_nonreg_state(struct vcpu *v, {vmx_vmcs_enter (v);
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c static void cf_check vmx_get_nonreg_state(struct vcpu *v, · line 1568
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +1
-3-__vmread (GUEST_ACTIVITY_STATE , &nrs->vmx.activity_state); -__vmread (GUEST_INTERRUPTIBILITY_INFO , &nrs->vmx.interruptibility_info); -__vmread (GUEST_PENDING_DBG_EXCEPTIONS , &nrs->vmx.pending_dbg); + nrs->vmx.activity_state =vmread (GUEST_ACTIVITY_STATE );This struct field can now also shrink down to unsigned int (or
uit32_tif need be). Likely there are others (and maybe also plain variables). Which in turn is an indication that, as was suggested before, this patch wants further splitting up. That'll also help with overall progress, as then what's uncontroversial and not in need of further adjustment can go in right away.
I'll will minimize the churn more in next iteration.
Quoted 2 lines
Jan