Rewrite this function such as it doesn't rely on goto, also change the
type of "type" to match the __invvpid function call.
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
---
 xen/arch/x86/include/asm/hvm/vmx/vmx.h | 29 +++++++++-----------------
 1 file changed, 10 insertions(+), 19 deletions(-)
diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h
index 56bea252cc..8559343857 100644
--- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h
+++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h
@@ -287,10 +287,10 @@ extern uint8_t posted_intr_vector;
 #define cpu_has_vmx_vpid_invvpid_single_context_retaining_global    \
     (vmx_caps.vpid & VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL)
 
-#define INVVPID_INDIVIDUAL_ADDR                 0
-#define INVVPID_SINGLE_CONTEXT                  1
-#define INVVPID_ALL_CONTEXT                     2
-#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3
+#define INVVPID_INDIVIDUAL_ADDR                 0UL
+#define INVVPID_SINGLE_CONTEXT                  1UL
+#define INVVPID_ALL_CONTEXT                     2UL
+#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3UL
 
 static always_inline void __vmptrld(u64 addr)
 {
@@ -454,25 +454,16 @@ void ept_sync_domain(struct p2m_domain *p2m);
 
 static inline void vpid_sync_vcpu_gva(struct vcpu *v, unsigned long gva)
 {
-    int type = INVVPID_INDIVIDUAL_ADDR;
+    unsigned long type;
 
-    /*
-     * If individual address invalidation is not supported, we escalate to
-     * use single context invalidation.
-     */
+    /* Use the most precise invalidation type available. */
     if ( likely(cpu_has_vmx_vpid_invvpid_individual_addr) )
-        goto execute_invvpid;
-
-    type = INVVPID_SINGLE_CONTEXT;
-
-    /*
-     * If single context invalidation is not supported, we escalate to
-     * use all context invalidation.
-     */
-    if ( !cpu_has_vmx_vpid_invvpid_single_context )
+        type = INVVPID_INDIVIDUAL_ADDR;
+    else if ( likely(cpu_has_vmx_vpid_invvpid_single_context) )
+        type = INVVPID_SINGLE_CONTEXT;
+    else
         type = INVVPID_ALL_CONTEXT;
 
-execute_invvpid:
     __invvpid(type, v->arch.hvm.n1asid.asid, (u64)gva);
 }
 
-- 
2.50.0
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.techOn 26.06.2025 16:01, Teddy Astie wrote: > Rewrite this function such as it doesn't rely on goto, also change the > type of "type" to match the __invvpid function call. While this type change is probably okay (and benign to code generation), ... > --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h > +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h > @@ -287,10 +287,10 @@ extern uint8_t posted_intr_vector; > #define cpu_has_vmx_vpid_invvpid_single_context_retaining_global \ > (vmx_caps.vpid & VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL) > > -#define INVVPID_INDIVIDUAL_ADDR 0 > -#define INVVPID_SINGLE_CONTEXT 1 > -#define INVVPID_ALL_CONTEXT 2 > -#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3 > +#define INVVPID_INDIVIDUAL_ADDR 0UL > +#define INVVPID_SINGLE_CONTEXT 1UL > +#define INVVPID_ALL_CONTEXT 2UL > +#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3UL ... I don't follow the need for these extra adjustments. Preferably with them dropped Reviewed-by: Jan Beulich <jbeulich@suse.com> Jan
Le 31/07/2025 à 17:54, Jan Beulich a écrit : > On 26.06.2025 16:01, Teddy Astie wrote: >> Rewrite this function such as it doesn't rely on goto, also change the >> type of "type" to match the __invvpid function call. > > While this type change is probably okay (and benign to code generation), ... > >> --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h >> +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h >> @@ -287,10 +287,10 @@ extern uint8_t posted_intr_vector; >> #define cpu_has_vmx_vpid_invvpid_single_context_retaining_global \ >> (vmx_caps.vpid & VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL) >> >> -#define INVVPID_INDIVIDUAL_ADDR 0 >> -#define INVVPID_SINGLE_CONTEXT 1 >> -#define INVVPID_ALL_CONTEXT 2 >> -#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3 >> +#define INVVPID_INDIVIDUAL_ADDR 0UL >> +#define INVVPID_SINGLE_CONTEXT 1UL >> +#define INVVPID_ALL_CONTEXT 2UL >> +#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3UL > > ... I don't follow the need for these extra adjustments. Preferably with > them dropped With the type change from int to unsigned long to match __invvpid() parameter, IIUC MISRA rule 7.2 requires that integer literals that are used for unsigned must have the proper suffix. > Reviewed-by: Jan Beulich <jbeulich@suse.com> > > Jan > Teddy Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
On 31.07.2025 18:18, Teddy Astie wrote: > Le 31/07/2025 à 17:54, Jan Beulich a écrit : >> On 26.06.2025 16:01, Teddy Astie wrote: >>> Rewrite this function such as it doesn't rely on goto, also change the >>> type of "type" to match the __invvpid function call. >> >> While this type change is probably okay (and benign to code generation), ... >> >>> --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h >>> +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h >>> @@ -287,10 +287,10 @@ extern uint8_t posted_intr_vector; >>> #define cpu_has_vmx_vpid_invvpid_single_context_retaining_global \ >>> (vmx_caps.vpid & VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL) >>> >>> -#define INVVPID_INDIVIDUAL_ADDR 0 >>> -#define INVVPID_SINGLE_CONTEXT 1 >>> -#define INVVPID_ALL_CONTEXT 2 >>> -#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3 >>> +#define INVVPID_INDIVIDUAL_ADDR 0UL >>> +#define INVVPID_SINGLE_CONTEXT 1UL >>> +#define INVVPID_ALL_CONTEXT 2UL >>> +#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3UL >> >> ... I don't follow the need for these extra adjustments. Preferably with >> them dropped > > With the type change from int to unsigned long to match __invvpid() > parameter, IIUC MISRA rule 7.2 requires that integer literals that are > used for unsigned must have the proper suffix. No, it doesn't. Please re-read carefully what docs/misra/rules.rst says in this regard. Jan
© 2016 - 2025 Red Hat, Inc.