Skip to content

Commit c8e8871

Browse files
babumogerrkrcmar
authored andcommitted
KVM: VMX: Bring the common code to header file
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>
1 parent 18abdc3 commit c8e8871

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

arch/x86/kvm/vmx.c

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,17 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
168168
* Time is measured based on a counter that runs at the same rate as the TSC,
169169
* refer SDM volume 3b section 21.6.13 & 22.1.3.
170170
*/
171-
#define KVM_VMX_DEFAULT_PLE_GAP 128
172-
#define KVM_VMX_DEFAULT_PLE_WINDOW 4096
173-
#define KVM_VMX_DEFAULT_PLE_WINDOW_GROW 2
174-
#define KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK 0
175-
#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX UINT_MAX
176-
177-
static unsigned int ple_gap = KVM_VMX_DEFAULT_PLE_GAP;
178-
module_param(ple_gap, uint, 0444);
171+
static unsigned int ple_gap = KVM_DEFAULT_PLE_GAP;
179172

180173
static unsigned int ple_window = KVM_VMX_DEFAULT_PLE_WINDOW;
181174
module_param(ple_window, uint, 0444);
182175

183176
/* Default doubles per-vcpu window every exit. */
184-
static unsigned int ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW;
177+
static unsigned int ple_window_grow = KVM_DEFAULT_PLE_WINDOW_GROW;
185178
module_param(ple_window_grow, uint, 0444);
186179

187180
/* Default resets per-vcpu window every exit to ple_window. */
188-
static unsigned int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
181+
static unsigned int ple_window_shrink = KVM_DEFAULT_PLE_WINDOW_SHRINK;
189182
module_param(ple_window_shrink, uint, 0444);
190183

191184
/* Default is to compute the maximum so we can never overflow. */
@@ -6982,41 +6975,14 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
69826975
return ret;
69836976
}
69846977

6985-
static unsigned int __grow_ple_window(unsigned int val)
6986-
{
6987-
u64 ret = val;
6988-
6989-
if (ple_window_grow < 1)
6990-
return ple_window;
6991-
6992-
if (ple_window_grow < ple_window)
6993-
ret *= ple_window_grow;
6994-
else
6995-
ret += ple_window_grow;
6996-
6997-
return min(ret, (u64)ple_window_max);
6998-
}
6999-
7000-
static unsigned int __shrink_ple_window(unsigned int val,
7001-
unsigned int modifier, unsigned int minimum)
7002-
{
7003-
if (modifier < 1)
7004-
return ple_window;
7005-
7006-
if (modifier < ple_window)
7007-
val /= modifier;
7008-
else
7009-
val -= modifier;
7010-
7011-
return max(val, minimum);
7012-
}
7013-
70146978
static void grow_ple_window(struct kvm_vcpu *vcpu)
70156979
{
70166980
struct vcpu_vmx *vmx = to_vmx(vcpu);
70176981
int old = vmx->ple_window;
70186982

7019-
vmx->ple_window = __grow_ple_window(old);
6983+
vmx->ple_window = __grow_ple_window(old, ple_window,
6984+
ple_window_grow,
6985+
ple_window_max);
70206986

70216987
if (vmx->ple_window != old)
70226988
vmx->ple_window_dirty = true;
@@ -7029,8 +6995,9 @@ static void shrink_ple_window(struct kvm_vcpu *vcpu)
70296995
struct vcpu_vmx *vmx = to_vmx(vcpu);
70306996
int old = vmx->ple_window;
70316997

7032-
vmx->ple_window = __shrink_ple_window(old,
7033-
ple_window_shrink, ple_window);
6998+
vmx->ple_window = __shrink_ple_window(old, ple_window,
6999+
ple_window_shrink,
7000+
ple_window);
70347001

70357002
if (vmx->ple_window != old)
70367003
vmx->ple_window_dirty = true;

arch/x86/kvm/x86.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
#include <asm/pvclock.h>
77
#include "kvm_cache_regs.h"
88

9+
#define KVM_DEFAULT_PLE_GAP 128
10+
#define KVM_VMX_DEFAULT_PLE_WINDOW 4096
11+
#define KVM_DEFAULT_PLE_WINDOW_GROW 2
12+
#define KVM_DEFAULT_PLE_WINDOW_SHRINK 0
13+
#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX UINT_MAX
14+
15+
static inline unsigned int __grow_ple_window(unsigned int val,
16+
unsigned int base, unsigned int modifier, unsigned int max)
17+
{
18+
u64 ret = val;
19+
20+
if (modifier < 1)
21+
return base;
22+
23+
if (modifier < base)
24+
ret *= modifier;
25+
else
26+
ret += modifier;
27+
28+
return min(ret, (u64)max);
29+
}
30+
31+
static inline unsigned int __shrink_ple_window(unsigned int val,
32+
unsigned int base, unsigned int modifier, unsigned int min)
33+
{
34+
if (modifier < 1)
35+
return base;
36+
37+
if (modifier < base)
38+
val /= modifier;
39+
else
40+
val -= modifier;
41+
42+
return max(val, min);
43+
}
44+
945
#define MSR_IA32_CR_PAT_DEFAULT 0x0007040600070406ULL
1046

1147
static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)