Skip to contentSkip to conversation

: PVH xen: supporting changes.

RFC PATCH In review Mukesh Rathor 3 participants 8 messages Jan 12, 2013 – Jan 25, 2013

lore
Share & tools
lore
#0 lore raw

RFC PATCH 5/16 : PVH xen: supporting changes.

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

xen/arch/x86/hvm/vmx/vmcs.c +0 -8
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/hvm/vmx/vmcs.c
@@ -1170,14 +1170,6 @@ void vmx_do_resume(struct vcpu *v)
     reset_stack_and_jump(vmx_asm_do_vmentry);
 }
 
-static unsigned long vmr(unsigned long field)
-{
-    int rc;
-    unsigned long val;
-    val = __vmread_safe(field, &rc);
-    return rc ? 0 : val;
-}
-
 static void vmx_dump_sel(char *name, uint32_t selector)
 {
     uint32_t sel, attr, limit;
xen/arch/x86/hvm/vmx/vmx.c +5 -17
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/hvm/vmx/vmx.c
@@ -593,7 +593,7 @@ static int vmx_load_vmcs_ctxt(struct vcp
     return 0;
 }
 
-static void vmx_fpu_enter(struct vcpu *v)
+void vmx_fpu_enter(struct vcpu *v)
 {
     vcpu_restore_fpu_lazy(v);
     v->arch.hvm_vmx.exception_bitmap &= ~(1u << TRAP_no_device);
@@ -1543,19 +1543,7 @@ struct hvm_function_table * __init start
     return &vmx_function_table;
 }
 
-/*
- * Not all cases receive valid value in the VM-exit instruction length field.
- * Callers must know what they're doing!
- */
-static int get_instruction_length(void)
-{
-    int len;
-    len = __vmread(VM_EXIT_INSTRUCTION_LEN); /* Safe: callers audited */
-    BUG_ON((len < 1) || (len > 15));
-    return len;
-}
-
-static void update_guest_eip(void)
+void update_guest_eip(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     unsigned long x;
@@ -1633,8 +1621,8 @@ static void vmx_do_cpuid(struct cpu_user
     regs->edx = edx;
 }
 
-static void vmx_dr_access(unsigned long exit_qualification,
-                          struct cpu_user_regs *regs)
+void vmx_dr_access(unsigned long exit_qualification,
+                   struct cpu_user_regs *regs)
 {
     struct vcpu *v = current;
 
@@ -2009,7 +1997,7 @@ gp_fault:
     return X86EMUL_EXCEPTION;
 }
 
-static void vmx_do_extint(struct cpu_user_regs *regs)
+void vmx_do_extint(struct cpu_user_regs *regs)
 {
     unsigned int vector;
 
xen/arch/x86/traps.c +2 -2
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/traps.c
@@ -723,7 +723,7 @@ int cpuid_hypervisor_leaves( uint32_t id
     return 1;
 }
 
-static void pv_cpuid(struct cpu_user_regs *regs)
+void pv_cpuid(struct cpu_user_regs *regs)
 {
     uint32_t a, b, c, d;
 
@@ -900,7 +900,7 @@ static int emulate_invalid_rdtscp(struct
     return EXCRET_fault_fixed;
 }
 
-static int emulate_forced_invalid_op(struct cpu_user_regs *regs)
+int emulate_forced_invalid_op(struct cpu_user_regs *regs)
 {
     char sig[5], instr[2];
     unsigned long eip, rc;
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -0
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -415,6 +415,7 @@ int vmx_add_host_load_msr(u32 msr);
 void vmx_vmcs_switch(struct vmcs_struct *from, struct vmcs_struct *to);
 void vmx_set_eoi_exit_bitmap(struct vcpu *v, u8 vector);
 void vmx_clear_eoi_exit_bitmap(struct vcpu *v, u8 vector);
+void vmx_fpu_enter(struct vcpu *v);
 
 #endif /* ASM_X86_HVM_VMX_VMCS_H__ */
 
xen/include/asm-x86/hvm/vmx/vmx.h +23 -0
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/hvm/vmx/vmx.h
@@ -389,6 +389,26 @@ static inline int __vmxon(u64 addr)
     return rc;
 }
 
+static inline unsigned long vmr(unsigned long field)
+{
+    int rc;
+    unsigned long val;
+    val = __vmread_safe(field, &rc);
+    return rc ? 0 : val;
+}
+
+/*
+ * Not all cases receive valid value in the VM-exit instruction length field.
+ * Callers must know what they're doing!
+ */
+static inline int get_instruction_length(void)
+{
+    int len;
+    len = __vmread(VM_EXIT_INSTRUCTION_LEN); /* Safe: callers audited */
+    BUG_ON((len < 1) || (len > 15));
+    return len;
+}
+
 void vmx_get_segment_register(struct vcpu *, enum x86_segment,
                               struct segment_register *);
 void vmx_inject_extint(int trap);
@@ -397,6 +417,9 @@ void vmx_inject_nmi(void);
 void ept_p2m_init(struct p2m_domain *p2m);
 void ept_walk_table(struct domain *d, unsigned long gfn);
 void setup_ept_dump(void);
+void update_guest_eip(void);
+void vmx_dr_access(unsigned long exit_qualification,struct cpu_user_regs *regs);
+void vmx_do_extint(struct cpu_user_regs *regs);
 
 /* EPT violation qualifications definitions */
 #define _EPT_READ_VIOLATION         0
xen/include/asm-x86/processor.h +2 -0
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/processor.h
@@ -551,6 +551,8 @@ int wrmsr_hypervisor_regs(uint32_t idx, 
 void microcode_set_module(unsigned int);
 int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long len);
 int microcode_resume_cpu(int cpu);
+void pv_cpuid(struct cpu_user_regs *regs);
+int emulate_forced_invalid_op(struct cpu_user_regs *regs);
 
 #endif /* !__ASSEMBLY__ */
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

As these functions are VMX-specific, I think they ought to get renamed to express that. However, the mere fact that you intend to use VMX functions outside of VMX code looks wrong.

Jan

Quoted 166 lines

diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/hvm/vmx/vmcs.c

xen/arch/x86/hvm/vmx/vmcs.c +0 -8
@@ -1170,14 +1170,6 @@ void vmx_do_resume(struct vcpu *v)
     reset_stack_and_jump(vmx_asm_do_vmentry);
 }
 
-static unsigned long vmr(unsigned long field)
-{
-    int rc;
-    unsigned long val;
-    val = __vmread_safe(field, &rc);
-    return rc ? 0 : val;
-}
-
 static void vmx_dump_sel(char *name, uint32_t selector)
 {
     uint32_t sel, attr, limit;

diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/hvm/vmx/vmx.c

xen/arch/x86/hvm/vmx/vmx.c +5 -17
@@ -593,7 +593,7 @@ static int vmx_load_vmcs_ctxt(struct vcp
     return 0;
 }
 
-static void vmx_fpu_enter(struct vcpu *v)
+void vmx_fpu_enter(struct vcpu *v)
 {
     vcpu_restore_fpu_lazy(v);
     v->arch.hvm_vmx.exception_bitmap &= ~(1u << TRAP_no_device);
@@ -1543,19 +1543,7 @@ struct hvm_function_table * __init start
     return &vmx_function_table;
 }
 
-/*
- * Not all cases receive valid value in the VM-exit instruction length field.
- * Callers must know what they're doing!
- */
-static int get_instruction_length(void)
-{
-    int len;
-    len = __vmread(VM_EXIT_INSTRUCTION_LEN); /* Safe: callers audited */
-    BUG_ON((len < 1) || (len > 15));
-    return len;
-}
-
-static void update_guest_eip(void)
+void update_guest_eip(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
     unsigned long x;
@@ -1633,8 +1621,8 @@ static void vmx_do_cpuid(struct cpu_user
     regs->edx = edx;
 }
 
-static void vmx_dr_access(unsigned long exit_qualification,
-                          struct cpu_user_regs *regs)
+void vmx_dr_access(unsigned long exit_qualification,
+                   struct cpu_user_regs *regs)
 {
     struct vcpu *v = current;
 
@@ -2009,7 +1997,7 @@ gp_fault:
     return X86EMUL_EXCEPTION;
 }
 
-static void vmx_do_extint(struct cpu_user_regs *regs)
+void vmx_do_extint(struct cpu_user_regs *regs)
 {
     unsigned int vector;
 

diff -r 0339f85f6068 -r fadb3f2f5d97 xen/arch/x86/traps.c

xen/arch/x86/traps.c +2 -2
@@ -723,7 +723,7 @@ int cpuid_hypervisor_leaves( uint32_t id
     return 1;
 }
 
-static void pv_cpuid(struct cpu_user_regs *regs)
+void pv_cpuid(struct cpu_user_regs *regs)
 {
     uint32_t a, b, c, d;
 
@@ -900,7 +900,7 @@ static int emulate_invalid_rdtscp(struct
     return EXCRET_fault_fixed;
 }
 
-static int emulate_forced_invalid_op(struct cpu_user_regs *regs)
+int emulate_forced_invalid_op(struct cpu_user_regs *regs)
 {
     char sig[5], instr[2];
     unsigned long eip, rc;

diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/hvm/vmx/vmcs.h

xen/include/asm-x86/hvm/vmx/vmcs.h +1 -0
@@ -415,6 +415,7 @@ int vmx_add_host_load_msr(u32 msr);
 void vmx_vmcs_switch(struct vmcs_struct *from, struct vmcs_struct *to);
 void vmx_set_eoi_exit_bitmap(struct vcpu *v, u8 vector);
 void vmx_clear_eoi_exit_bitmap(struct vcpu *v, u8 vector);
+void vmx_fpu_enter(struct vcpu *v);
 
 #endif /* ASM_X86_HVM_VMX_VMCS_H__ */
 

diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/hvm/vmx/vmx.h

xen/include/asm-x86/hvm/vmx/vmx.h +10 -0
@@ -389,6 +389,26 @@ static inline int __vmxon(u64 addr)
     return rc;
 }
 
+static inline unsigned long vmr(unsigned long field)
+{
+    int rc;
+    unsigned long val;
+    val = __vmread_safe(field, &rc);
+    return rc ? 0 : val;
+}
+
+/*
+ * Not all cases receive valid value in the VM-exit instruction length 

field.
+ * Callers must know what they're doing!
+ */

xen/include/asm-x86/hvm/vmx/vmx.h +11 -0
+static inline int get_instruction_length(void)
+{
+    int len;
+    len = __vmread(VM_EXIT_INSTRUCTION_LEN); /* Safe: callers audited */
+    BUG_ON((len < 1) || (len > 15));
+    return len;
+}
+
 void vmx_get_segment_register(struct vcpu *, enum x86_segment,
                               struct segment_register *);
 void vmx_inject_extint(int trap);
@@ -397,6 +417,9 @@ void vmx_inject_nmi(void);
 void ept_p2m_init(struct p2m_domain *p2m);
 void ept_walk_table(struct domain *d, unsigned long gfn);
 void setup_ept_dump(void);
+void update_guest_eip(void);
+void vmx_dr_access(unsigned long exit_qualification,struct cpu_user_regs 
 *regs);
+void vmx_do_extint(struct cpu_user_regs *regs);
 
 /* EPT violation qualifications definitions */

#define _EPT_READ_VIOLATION 0
diff -r 0339f85f6068 -r fadb3f2f5d97 xen/include/asm-x86/processor.h

xen/include/asm-x86/processor.h +2 -0
@@ -551,6 +551,8 @@ int wrmsr_hypervisor_regs(uint32_t idx, 
 void microcode_set_module(unsigned int);
 int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long 
 len);
 int microcode_resume_cpu(int cpu);
+void pv_cpuid(struct cpu_user_regs *regs);
+int emulate_forced_invalid_op(struct cpu_user_regs *regs);
 
 #endif /* !__ASSEMBLY__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 10 lines · On Mon, 14 Jan 2013 11:27:15 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

On 12.01.13 at 02:48, Mukesh Rathor <[email protected]> wrote:

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

As these functions are VMX-specific, I think they ought to get renamed to express that. However, the mere fact that you intend to use VMX functions outside of VMX code looks wrong.

Not sure what you are referring to. The functions vmr, get_instruction_length(), etc.. are called from VMX code, ie, vmx_pvh.c. I'll rename them with vmx_ prefix.

The two functions, pv_cpuid and emulate_forced_invalid_op are not vmx specific, they are called from non vmx code, ie, PV also. So renaming them doesn't make sense IMO. Recall, PVH is a PV guest.

thanks,
Mukesh

#3 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
Quoted 6 lines · On Mon, 14 Jan 2013 11:27:15 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

Quoted 7 lines
Quoted 3 lines

As these functions are VMX-specific, I think they ought to get renamed to express that. However, the mere fact that you intend to use VMX functions outside of VMX code looks wrong.

Not sure what you are referring to. The functions vmr, get_instruction_length(), etc.. are called from VMX code, ie, vmx_pvh.c. I'll rename them with vmx_ prefix.

That's fine then (perhaps even without the rename if the declarations sit in a header _only_ included by VMX code).

Quoted 3 lines

The two functions, pv_cpuid and emulate_forced_invalid_op are not vmx specific, they are called from non vmx code, ie, PV also. So renaming them doesn't make sense IMO. Recall, PVH is a PV guest.

Sure - these ones I didn't have in mind.

Jan

#4 lore raw
In reply to Mukesh Rathor
Quoted 4 lines · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

Please don't export vmr(). It silently suppresses errors, which is OK for its current use (as a helper function in the state dump) but not for actual guest state manipulations.

Tim.

#5 lore raw
Quoted 9 lines · On Thu, 24 Jan 2013 15:22:21 +0000 Tim Deegan <[email protected]> wrote:
Quoted 4 lines · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

Please don't export vmr(). It silently suppresses errors, which is OK for its current use (as a helper function in the state dump) but not for actual guest state manipulations.

Ok, done. I'll assueme it's ok to export get_instruction_length().

#6 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
Quoted 6 lines · On Thu, 24 Jan 2013 15:22:21 +0000 Tim Deegan <[email protected]> wrote:
Quoted 4 lines · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

Quoted 5 lines
Quoted 3 lines

Please don't export vmr(). It silently suppresses errors, which is OK for its current use (as a helper function in the state dump) but not for actual guest state manipulations.

Ok, done. I'll assueme it's ok to export get_instruction_length().

With a properly qualified name that's fine I think.

Jan

#7 lore raw
In reply to Mukesh Rathor
Quoted 9 lines · Mukesh Rathor
Quoted 6 lines · On Thu, 24 Jan 2013 15:22:21 +0000 Tim Deegan <[email protected]> wrote:
Quoted 4 lines · Mukesh Rathor

In this patch, we make pv_cpuid() and emulate_forced_invalid_op() public to be used by PVH. Also put vmx functions like vmr(), get_instruction_length(), inlined in header file to be used by PVH. No real code change.

Quoted 5 lines
Quoted 3 lines

Please don't export vmr(). It silently suppresses errors, which is OK for its current use (as a helper function in the state dump) but not for actual guest state manipulations.

Ok, done.

Thanks.

Quoted 1 line

I'll assueme it's ok to export get_instruction_length().

Yes, that's fine as long as the warnings about when it's safe to use are preserved! And, as Jan suggested, it should be renamed to vmx_get_instruction_length().

Cheers,

Tim.