From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 198CAC3A5A9 for ; Thu, 5 Sep 2019 02:36:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F14802168B for ; Thu, 5 Sep 2019 02:36:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730778AbfIECgo (ORCPT ); Wed, 4 Sep 2019 22:36:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33210 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730776AbfIECgo (ORCPT ); Wed, 4 Sep 2019 22:36:44 -0400 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD2687F769 for ; Thu, 5 Sep 2019 02:36:43 +0000 (UTC) Received: by mail-pf1-f199.google.com with SMTP id w16so701298pfj.9 for ; Wed, 04 Sep 2019 19:36:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HxjOgu8AuJ4sFURxg4u+BP/uqk7UsSBU+RsKI6Kus/8=; b=ntjKcR443uxxn0MfH/YtverIn7quPdsfvGF6lHnjgnIYY023aZReWOqpTRl5QO9DwZ 8jHz01QuVozR2UFW6W3tL9LFFIg4NoN2v685J2lNSR8+GiwPAJxZBvssHSk4YOhClAON Rl5KeIvyijcOEYXi+Kq3D9hFfcMU6rWANuz9wrEptsXJQPtEUh8IKzxOXqPwTIFbbsc7 YrSeaijSyqulU0SygaYVsArZiTz3A2fbFU4N59oEUbTGE4bnwcYxo5e8/SuOAwoqq/Cf 0FBqQPL92SssiICf8Z7jTj2aObr/UXiuvZHfYpk5uqnAovXJPeqtX8wi8KwXkTu/xwUQ ciiw== X-Gm-Message-State: APjAAAX+NJlz4BROnnF/4CxfoyYHeeZ51HbpuXPEBsOEt/Wrcma8iHua OieImzCJcigfGIJna/JKKalz/l5oqOotvqwbeosO+cZLhCKnO/HOEGxsazaM6Gs8WUcZ0Xd1nDM EvGWF51vDkCuc X-Received: by 2002:a17:90a:b393:: with SMTP id e19mr1397015pjr.118.1567651002913; Wed, 04 Sep 2019 19:36:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ0TFaCjzAlYeNNt4S7xfs89HxwHt1HZNbm3+6W2xlASC3ZtcGi1Xf0DuojA+RX/RV0YQECQ== X-Received: by 2002:a17:90a:b393:: with SMTP id e19mr1396996pjr.118.1567651002693; Wed, 04 Sep 2019 19:36:42 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id v10sm326504pjk.23.2019.09.04.19.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 19:36:41 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Wanpeng Li , Krish Sadhukhan , peterx@redhat.com Subject: [PATCH v3 4/4] KVM: VMX: Change ple_window type to unsigned int Date: Thu, 5 Sep 2019 10:36:16 +0800 Message-Id: <20190905023616.29082-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905023616.29082-1-peterx@redhat.com> References: <20190905023616.29082-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The VMX ple_window is 32 bits wide, so logically it can overflow with an int. The module parameter is declared as unsigned int which is good, however the dynamic variable is not. Switching all the ple_window references to use unsigned int. The tracepoint changes will also affect SVM, but SVM is using an even smaller width (16 bits) so it's always fine. Suggested-by: Sean Christopherson Signed-off-by: Peter Xu --- arch/x86/kvm/trace.h | 8 ++++---- arch/x86/kvm/vmx/vmx.c | 4 ++-- arch/x86/kvm/vmx/vmx.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index f1177e03768f..ae924566c401 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -891,13 +891,13 @@ TRACE_EVENT(kvm_pml_full, ); TRACE_EVENT(kvm_ple_window_update, - TP_PROTO(unsigned int vcpu_id, int new, int old), + TP_PROTO(unsigned int vcpu_id, unsigned int new, unsigned int old), TP_ARGS(vcpu_id, new, old), TP_STRUCT__entry( __field( unsigned int, vcpu_id ) - __field( int, new ) - __field( int, old ) + __field( unsigned int, new ) + __field( unsigned int, old ) ), TP_fast_assign( @@ -906,7 +906,7 @@ TRACE_EVENT(kvm_ple_window_update, __entry->old = old; ), - TP_printk("vcpu %u old %d new %d (%s)", + TP_printk("vcpu %u old %u new %u (%s)", __entry->vcpu_id, __entry->old, __entry->new, __entry->old < __entry->new ? "growed" : "shrinked") ); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 469c4134a4a7..1dbb63ffdd6d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5227,7 +5227,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) static void grow_ple_window(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); - int old = vmx->ple_window; + unsigned int old = vmx->ple_window; vmx->ple_window = __grow_ple_window(old, ple_window, ple_window_grow, @@ -5243,7 +5243,7 @@ static void grow_ple_window(struct kvm_vcpu *vcpu) static void shrink_ple_window(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); - int old = vmx->ple_window; + unsigned int old = vmx->ple_window; vmx->ple_window = __shrink_ple_window(old, ple_window, ple_window_shrink, diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 82d0bc3a4d52..64d5a4890aa9 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -253,7 +253,7 @@ struct vcpu_vmx { struct nested_vmx nested; /* Dynamic PLE window. */ - int ple_window; + unsigned int ple_window; bool ple_window_dirty; bool req_immediate_exit; -- 2.21.0