Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp43351pxb; Mon, 13 Sep 2021 12:26:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIHeYMi1NOMlaG9a3xspTua2hrNISaPCtog/8zyL7OAlxwWaPFuC6hd9NVYxLvbcmRKSf1 X-Received: by 2002:a50:ff0b:: with SMTP id a11mr14701591edu.373.1631561185348; Mon, 13 Sep 2021 12:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631561185; cv=none; d=google.com; s=arc-20160816; b=JERnWxvKoC2KshvOdUZ4nhDTmnw2oApCY4X0iBsItlxznvE5ni5wUErKYflH1pp4uu kk5t/edPR5TCLfohcvvJFel0T+NZmi2qsqbh14kzSLr8aAa42IwKAzxlEmlk6bNe8egy gpzOab673QfdD/6UjItHM8GicauaDUfl3SQyp5asXXq2drJFqQwLMEQ7KWPhDZpqt+D6 LkqEgvm4lJvBi7MppReWAkZp/xyZGFoTJhV6y2nWCcjHLrpkb59SiLE6NfvVNWZOY5KV qjZY0/9ogTmTl2cIkZNNH1V1zUHj3+Ds1Cofg7Up/AzcueAY7YU0lIxoPXFrBmz8BKgk 6FmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W2FFxLURe++cwMsit8UAy6nvygYu0R0RhiBMgyL+R7k=; b=bsDOpzf0qqzj6w+X7kf2JBOxy/fOl9NUJeDFb3a+Q+LNWYwnrn7S/xy+Cfj+4lJJKC BOrmLrl/Lb2FP0/UecDa9tXoeyciRXCYIIlrVJo3eOTO1qMDQis6q4Qy9WWYblgjgNXd ui4qURwfT/2lzqBKnURwx9ukO65Q3LPOPXx9iDAcqiKKO+H/B6U8J36v3n2j0bn53qcU K5W4hmh4tZOhD95ZkK3bAwIWMCULvqMi6NxkJaRkgVLjbEHM8ea7K5UDt05u8Ye/VvLC iffFMGcO/EQ59TLGe2J2X5IwFbaNA3ykiOqNog8TWa+TgEr0yoM1DBH+Uq2ayEkgTS4P CbIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zbSEzsOc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si8200059eds.131.2021.09.13.12.26.01; Mon, 13 Sep 2021 12:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zbSEzsOc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241219AbhIMNaL (ORCPT + 99 others); Mon, 13 Sep 2021 09:30:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241406AbhIMNZx (ORCPT ); Mon, 13 Sep 2021 09:25:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 97B896124F; Mon, 13 Sep 2021 13:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539348; bh=BNUQ91d/Lullesgw99EjLMu/iP6LnWrweewAFbZkZ2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zbSEzsOcU7C/Q0BJN3M/cgIB/37r3+O+B2R6S1RByI5ujUaUVrK8gxgpXt4krerlA mb7cPEQsC6aOqSDPjj5QxF/f307YU8zpaeKXhhyIORX+mwrHQZKZKoqs0Ca4Qt2g7R DkmKEz9awOLJeaLvtT2SoLMPzyJihgQP8SRE80B0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zelin Deng , Paolo Bonzini Subject: [PATCH 5.4 136/144] KVM: x86: Update vCPUs hv_clock before back to guest when tsc_offset is adjusted Date: Mon, 13 Sep 2021 15:15:17 +0200 Message-Id: <20210913131052.484327380@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zelin Deng commit d9130a2dfdd4b21736c91b818f87dbc0ccd1e757 upstream. When MSR_IA32_TSC_ADJUST is written by guest due to TSC ADJUST feature especially there's a big tsc warp (like a new vCPU is hot-added into VM which has been up for a long time), tsc_offset is added by a large value then go back to guest. This causes system time jump as tsc_timestamp is not adjusted in the meantime and pvclock monotonic character. To fix this, just notify kvm to update vCPU's guest time before back to guest. Cc: stable@vger.kernel.org Signed-off-by: Zelin Deng Signed-off-by: Paolo Bonzini Message-Id: <1619576521-81399-2-git-send-email-zelin.deng@linux.alibaba.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2764,6 +2764,10 @@ int kvm_set_msr_common(struct kvm_vcpu * if (!msr_info->host_initiated) { s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr; adjust_tsc_offset_guest(vcpu, adj); + /* Before back to guest, tsc_timestamp must be adjusted + * as well, otherwise guest's percpu pvclock time could jump. + */ + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); } vcpu->arch.ia32_tsc_adjust_msr = data; }