From patchwork Tue Aug 19 20:35:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 4745881 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DBF70C0338 for ; Tue, 19 Aug 2014 20:39:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1FA62013A for ; Tue, 19 Aug 2014 20:39:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18A382015A for ; Tue, 19 Aug 2014 20:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbaHSUh7 (ORCPT ); Tue, 19 Aug 2014 16:37:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34420 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbaHSUh6 (ORCPT ); Tue, 19 Aug 2014 16:37:58 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7JKbo6t031326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Aug 2014 16:37:51 -0400 Received: from potion (dhcp-1-113.brq.redhat.com [10.34.1.113]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id s7JKbl3j002933; Tue, 19 Aug 2014 16:37:48 -0400 Received: by potion (sSMTP sendmail emulation); Tue, 19 Aug 2014 22:37:46 +0200 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , Gleb Natapov , Raghavendra KT , Vinod Chegu , Hui-Zhi Subject: [PATCH 8/9] KVM: VMX: runtime knobs for dynamic PLE window Date: Tue, 19 Aug 2014 22:35:35 +0200 Message-Id: <1408480536-8240-9-git-send-email-rkrcmar@redhat.com> In-Reply-To: <1408480536-8240-1-git-send-email-rkrcmar@redhat.com> References: <1408480536-8240-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ple_window is updated on every vmentry, so there is no reason to have it read-only anymore. ple_window_* weren't writable to prevent runtime overflow races; they are mitigated by clamping the value of ple_window. Signed-off-by: Radim Kr?má? --- If we decide to ignore insane overflows, last two hunks can be dropped. arch/x86/kvm/vmx.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index c6cfb71..d7f58e8 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -134,19 +134,19 @@ static int ple_gap = KVM_VMX_DEFAULT_PLE_GAP; module_param(ple_gap, int, S_IRUGO); static int ple_window = KVM_VMX_DEFAULT_PLE_WINDOW; -module_param(ple_window, int, S_IRUGO); +module_param(ple_window, int, S_IRUGO | S_IWUSR); /* Default doubles per-vcpu window every exit. */ static int ple_window_grow = KVM_VMX_DEFAULT_PLE_WINDOW_GROW; -module_param(ple_window_grow, int, S_IRUGO); +module_param(ple_window_grow, int, S_IRUGO | S_IWUSR); /* Default resets per-vcpu window every exit to ple_window. */ static int ple_window_shrink = KVM_VMX_DEFAULT_PLE_WINDOW_SHRINK; -module_param(ple_window_shrink, int, S_IRUGO); +module_param(ple_window_shrink, int, S_IRUGO | S_IWUSR); /* Default is to compute the maximum so we can never overflow. */ static int ple_window_max = INT_MAX / KVM_VMX_DEFAULT_PLE_WINDOW_GROW; -module_param(ple_window_max, int, S_IRUGO); +module_param(ple_window_max, int, S_IRUGO | S_IWUSR); extern const ulong vmx_return; @@ -5694,7 +5694,8 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) out: return ret; } -#define make_ple_window_modifier(type, oplt, opge, cmp, bound) \ + +#define make_ple_window_modifier(type, oplt, opge) \ static void type##_ple_window(struct kvm_vcpu *vcpu) \ { \ struct vcpu_vmx *vmx = to_vmx(vcpu); \ @@ -5708,13 +5709,13 @@ static void type##_ple_window(struct kvm_vcpu *vcpu) \ else \ new = old opge ple_window_##type; \ \ - vmx->ple_window = cmp(new, bound); \ + vmx->ple_window = clamp(new, ple_window, ple_window_max); \ \ trace_kvm_ple_window_##type(vcpu->vcpu_id, vmx->ple_window, old); \ } -make_ple_window_modifier(grow, *, +, min, ple_window_max) -make_ple_window_modifier(shrink, /, -, max, ple_window) +make_ple_window_modifier(grow, *, +) /* grow_ple_window */ +make_ple_window_modifier(shrink, /, -) /* shrink_ple_window */ /* * Indicate a busy-waiting vcpu in spinlock. We do not enable the PAUSE