[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] x86/vmx: Introduce vmread()



commit 881e5993dff7d8f372efeed7e5a9f255207805ed
Author:     Denis Mukhin <dmukhin@xxxxxxxx>
AuthorDate: Sat Apr 26 07:27:29 2025 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Mon Apr 28 21:01:20 2025 +0100

    x86/vmx: Introduce vmread()
    
    The current implementation of __vmread() is void and returns the result via
    pointer argument which leads to excess code in some places.
    
    Introduce a new vmread() function, and implement __vmread() in terms of it.
    
    Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/include/asm/hvm/vmx/vmx.h | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h 
b/xen/arch/x86/include/asm/hvm/vmx/vmx.h
index 33d3d43a38..cc8c53fab1 100644
--- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h
+++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h
@@ -320,16 +320,25 @@ static always_inline void __vmpclear(u64 addr)
     BUG();
 }
 
-static always_inline void __vmread(unsigned long field, unsigned long *value)
+static always_inline unsigned long vmread(unsigned long field)
 {
-    asm volatile ( "vmread %1, %0\n\t"
+    unsigned long value;
+
+    asm volatile ( "vmread %[field], %[value]\n\t"
                    /* CF==1 or ZF==1 --> BUG() */
                    UNLIKELY_START(be, vmread)
                    _ASM_BUGFRAME_TEXT(0)
                    UNLIKELY_END_SECTION
-                   : "=rm" (*value)
-                   : "r" (field),
+                   : [value] "=rm" (value)
+                   : [field] "r" (field),
                      _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) );
+
+    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)
@@ -363,7 +372,7 @@ static inline enum vmx_insn_errno vmread_safe(unsigned long 
field,
     if ( unlikely(fail_invalid) )
         ret = VMX_INSN_FAIL_INVALID;
     else if ( unlikely(fail_valid) )
-        __vmread(VM_INSTRUCTION_ERROR, &ret);
+        ret = vmread(VM_INSTRUCTION_ERROR);
 
     return ret;
 }
@@ -371,8 +380,6 @@ static inline enum vmx_insn_errno vmread_safe(unsigned long 
field,
 static inline enum vmx_insn_errno vmwrite_safe(unsigned long field,
                                                unsigned long value)
 {
-    unsigned long ret;
-
     asm goto ( "vmwrite %[value], %[field]\n\t"
                "jc %l[vmfail_invalid]\n\t"
                "jz %l[vmfail_error]"
@@ -386,8 +393,7 @@ static inline enum vmx_insn_errno vmwrite_safe(unsigned 
long field,
     return VMX_INSN_FAIL_INVALID;
 
  vmfail_error:
-    __vmread(VM_INSTRUCTION_ERROR, &ret);
-    return ret;
+    return vmread(VM_INSTRUCTION_ERROR);
 }
 
 static always_inline void __invept(unsigned long type, uint64_t eptp)
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.