]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
KVM: VMX: Bring the common code to header file
authorBabu Moger <babu.moger@amd.com>
Fri, 16 Mar 2018 20:37:24 +0000 (16:37 -0400)
committerRadim Krčmář <rkrcmar@redhat.com>
Wed, 28 Mar 2018 20:47:06 +0000 (22:47 +0200)
This patch brings some of the code from vmx to x86.h header file. Now, we
can share this code between vmx and svm. Modified couple functions to make
it common.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.h

index 7a92e2e1ea2efb0832657132ce14dc9c89a64b76..48d93d8cb8839fb2c3d0cae3412d4826acb473a2 100644 (file)
@@ -168,24 +168,17 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
  * Time is measured based on a counter that runs at the same rate as the TSC,
  * refer SDM volume 3b section 21.6.13 & 22.1.3.
  */
-#define KVM_VMX_DEFAULT_PLE_GAP           128
-#define KVM_VMX_DEFAULT_PLE_WINDOW        4096
-#define KVM_VMX_DEFAULT_PLE_WINDOW_GROW   2
-#define KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK 0
-#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX    UINT_MAX
-
-static unsigned int ple_gap = KVM_VMX_DEFAULT_PLE_GAP;
-module_param(ple_gap, uint, 0444);
+static unsigned int ple_gap = KVM_DEFAULT_PLE_GAP;
 
 static unsigned int ple_window = KVM_VMX_DEFAULT_PLE_WINDOW;
 module_param(ple_window, uint, 0444);
 
 /* Default doubles per-vcpu window every exit. */
-static unsigned int ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW;
+static unsigned int ple_window_grow = KVM_DEFAULT_PLE_WINDOW_GROW;
 module_param(ple_window_grow, uint, 0444);
 
 /* Default resets per-vcpu window every exit to ple_window. */
-static unsigned int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
+static unsigned int ple_window_shrink = KVM_DEFAULT_PLE_WINDOW_SHRINK;
 module_param(ple_window_shrink, uint, 0444);
 
 /* Default is to compute the maximum so we can never overflow. */
@@ -6982,41 +6975,14 @@ out:
        return ret;
 }
 
-static unsigned int __grow_ple_window(unsigned int val)
-{
-       u64 ret = val;
-
-       if (ple_window_grow < 1)
-               return ple_window;
-
-       if (ple_window_grow < ple_window)
-               ret *= ple_window_grow;
-       else
-               ret += ple_window_grow;
-
-       return min(ret, (u64)ple_window_max);
-}
-
-static unsigned int __shrink_ple_window(unsigned int val,
-               unsigned int modifier, unsigned int minimum)
-{
-       if (modifier < 1)
-               return ple_window;
-
-       if (modifier < ple_window)
-               val /= modifier;
-       else
-               val -= modifier;
-
-       return max(val, minimum);
-}
-
 static void grow_ple_window(struct kvm_vcpu *vcpu)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
        int old = vmx->ple_window;
 
-       vmx->ple_window = __grow_ple_window(old);
+       vmx->ple_window = __grow_ple_window(old, ple_window,
+                                           ple_window_grow,
+                                           ple_window_max);
 
        if (vmx->ple_window != old)
                vmx->ple_window_dirty = true;
@@ -7029,8 +6995,9 @@ static void shrink_ple_window(struct kvm_vcpu *vcpu)
        struct vcpu_vmx *vmx = to_vmx(vcpu);
        int old = vmx->ple_window;
 
-       vmx->ple_window = __shrink_ple_window(old,
-                                             ple_window_shrink, ple_window);
+       vmx->ple_window = __shrink_ple_window(old, ple_window,
+                                             ple_window_shrink,
+                                             ple_window);
 
        if (vmx->ple_window != old)
                vmx->ple_window_dirty = true;
index 35efd567a6765f6079ee06f9f9083460381a5b01..0804722b809ef75891ee3434f1b495083436c885 100644 (file)
@@ -6,6 +6,42 @@
 #include <asm/pvclock.h>
 #include "kvm_cache_regs.h"
 
+#define KVM_DEFAULT_PLE_GAP            128
+#define KVM_VMX_DEFAULT_PLE_WINDOW     4096
+#define KVM_DEFAULT_PLE_WINDOW_GROW    2
+#define KVM_DEFAULT_PLE_WINDOW_SHRINK  0
+#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX UINT_MAX
+
+static inline unsigned int __grow_ple_window(unsigned int val,
+               unsigned int base, unsigned int modifier, unsigned int max)
+{
+       u64 ret = val;
+
+       if (modifier < 1)
+               return base;
+
+       if (modifier < base)
+               ret *= modifier;
+       else
+               ret += modifier;
+
+       return min(ret, (u64)max);
+}
+
+static inline unsigned int __shrink_ple_window(unsigned int val,
+               unsigned int base, unsigned int modifier, unsigned int min)
+{
+       if (modifier < 1)
+               return base;
+
+       if (modifier < base)
+               val /= modifier;
+       else
+               val -= modifier;
+
+       return max(val, min);
+}
+
 #define MSR_IA32_CR_PAT_DEFAULT  0x0007040600070406ULL
 
 static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)