Skip to content

Commit

Permalink
KVM: VMX: Remove ple_window_actual_max
Browse files Browse the repository at this point in the history
Get rid of ple_window_actual_max, because its benefits are really
minuscule and the logic is complicated.

The overflows(and underflow) are controlled in __ple_window_grow
and _ple_window_shrink respectively.

Suggested-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
[Fixed potential wraparound and change the max to UINT_MAX. - Radim]
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
  • Loading branch information
Babu Moger authored and Radim Krčmář committed Mar 28, 2018
1 parent 7fbc85a commit 18abdc3
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions arch/x86/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
#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 \
INT_MAX / KVM_VMX_DEFAULT_PLE_WINDOW_GROW
#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);
Expand All @@ -190,7 +189,6 @@ static unsigned int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK;
module_param(ple_window_shrink, uint, 0444);

/* Default is to compute the maximum so we can never overflow. */
static unsigned int ple_window_actual_max = KVM_VMX_DEFAULT_PLE_WINDOW_MAX;
static unsigned int ple_window_max = KVM_VMX_DEFAULT_PLE_WINDOW_MAX;
module_param(ple_window_max, uint, 0444);

Expand Down Expand Up @@ -6986,17 +6984,17 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)

static unsigned int __grow_ple_window(unsigned int val)
{
u64 ret = val;

if (ple_window_grow < 1)
return ple_window;

val = min(val, ple_window_actual_max);

if (ple_window_grow < ple_window)
val *= ple_window_grow;
ret *= ple_window_grow;
else
val += ple_window_grow;
ret += ple_window_grow;

return val;
return min(ret, (u64)ple_window_max);
}

static unsigned int __shrink_ple_window(unsigned int val,
Expand Down Expand Up @@ -7040,21 +7038,6 @@ static void shrink_ple_window(struct kvm_vcpu *vcpu)
trace_kvm_ple_window_shrink(vcpu->vcpu_id, vmx->ple_window, old);
}

/*
* ple_window_actual_max is computed to be one grow_ple_window() below
* ple_window_max. (See __grow_ple_window for the reason.)
* This prevents overflows, because ple_window_max is int.
* ple_window_max effectively rounded down to a multiple of ple_window_grow in
* this process.
* ple_window_max is also prevented from setting vmx->ple_window < ple_window.
*/
static void update_ple_window_actual_max(void)
{
ple_window_actual_max =
__shrink_ple_window(max(ple_window_max, ple_window),
ple_window_grow, INT_MIN);
}

/*
* Handler for POSTED_INTERRUPT_WAKEUP_VECTOR.
*/
Expand Down Expand Up @@ -7175,8 +7158,6 @@ static __init int hardware_setup(void)
else
kvm_disable_tdp();

update_ple_window_actual_max();

/*
* Only enable PML when hardware supports PML feature, and both EPT
* and EPT A/D bit features are enabled -- PML depends on them to work.
Expand Down

0 comments on commit 18abdc3

Please sign in to comment.