All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	kvm <kvm@vger.kernel.org>, Wanpeng Li <wanpeng.li@hotmail.com>,
	Yunhong Jiang <yunhong.jiang@gmail.com>
Subject: Re: [PATCH] KVM: vmx: fix underflow in TSC deadline calculation
Date: Tue, 28 Jun 2016 16:46:29 +0800	[thread overview]
Message-ID: <CANRm+Cwk-vPJWWM-_PuifpVoCt28g-8ix5xF59gf_+a20w5K-Q@mail.gmail.com> (raw)
In-Reply-To: <87394b34-800a-d981-48b8-c6f02e39caed@redhat.com>

2016-06-28 16:43 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
>
>
> On 28/06/2016 08:15, Wanpeng Li wrote:
>> 2016-06-27 21:11 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
>>> If the TSC deadline timer is programmed really close to the deadline or
>>> even in the past, the computation in vmx_set_hv_timer can underflow and
>>> cause delta_tsc to be set to a huge value.  This generally results
>>> in vmx_set_hv_timer returning -ERANGE, but we can fix it by limiting
>>> delta_tsc to be positive or zero.
>>>
>>> Reported-by: Wanpeng Li <wanpeng.li@hotmail.com>
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>> ---
>>>  arch/x86/kvm/vmx.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>>> index c1d655c10fd2..85e2f0a882ca 100644
>>> --- a/arch/x86/kvm/vmx.c
>>> +++ b/arch/x86/kvm/vmx.c
>>> @@ -10829,9 +10829,9 @@ static inline int u64_shl_div_u64(u64 a, unsigned int shift,
>>>  static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc)
>>>  {
>>>         struct vcpu_vmx *vmx = to_vmx(vcpu);
>>> -       u64 tscl = rdtsc(), delta_tsc;
>>> -
>>> -       delta_tsc = guest_deadline_tsc - kvm_read_l1_tsc(vcpu, tscl);
>>> +       u64 tscl = rdtsc();
>>> +       u64 guest_tscl = kvm_read_l1_tsc(vcpu, tscl);
>>> +       u64 delta_tsc = max(guest_deadline_tsc, guest_tscl) - guest_tscl;
>>>
>>>         /* Convert to host delta tsc if tsc scaling is enabled */
>>>         if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio &&
>>
>> This patch still can't fix the bug after my testing. I have a patch on
>> hand and will send out soon.
>
> Nice!  Do you think we need both patches?

Yeah, we can keep them separately. :)

Regards,
Wanpeng Li

  reply	other threads:[~2016-06-28  8:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 13:11 [PATCH] KVM: vmx: fix underflow in TSC deadline calculation Paolo Bonzini
2016-06-28  6:15 ` Wanpeng Li
2016-06-28  8:43   ` Paolo Bonzini
2016-06-28  8:46     ` Wanpeng Li [this message]
2016-06-28  6:54 Wanpeng Li
2016-06-28 17:45 ` yunhong jiang
2016-06-28 17:56   ` Paolo Bonzini
2016-06-28 18:34     ` yunhong jiang
2016-06-28 20:07       ` Paolo Bonzini
2016-06-28 22:55         ` Wanpeng Li
2016-06-29  0:39           ` Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANRm+Cwk-vPJWWM-_PuifpVoCt28g-8ix5xF59gf_+a20w5K-Q@mail.gmail.com \
    --to=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wanpeng.li@hotmail.com \
    --cc=yunhong.jiang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.