Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp92274pxb; Mon, 13 Sep 2021 13:51:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMVzi1/MPH1H070yHWxEiqNPXsMAFxwFF8HZuWnApE7vxNgbgJc6R4jarJqV0nLIJd/8ih X-Received: by 2002:a05:6402:1a53:: with SMTP id bf19mr9057374edb.235.1631566319411; Mon, 13 Sep 2021 13:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631566319; cv=none; d=google.com; s=arc-20160816; b=vDLkwYnXZS1ikPU88TZiB6rRXYkoUPIvscf2aLTLiRk1etOKc579Ow0SHwLjjiwMBy a1UgTqsjtPugZGnLuoF60lieYLpPXE5bT/rjDuObHlQOYMzlXIVkVwXT16MuhetIlDUW ULgqdqTCWCRmqu4jUE8ryY6BLf4kxgMGa9p4I/oe7bngpzpo54V07UZTCgMGdFg5tOGo 9MzdoebqsuxgKyYFQVoFKY6uldwwEeM++MjJNJ52TRy6SGynHNWb4su9of511aDyvbhA 7Zz6CPh+rsMBpW07oTx81vbtBFQrJ67kehNyY1RTS2cuYWKFcVHBGNSQpWiYEpnVmttK wQnQ== 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=XHhW+OdH+9JQInMaoKI/sWhBveBOq0Mv/3oIxLGQ6zo=; b=xAf8kokg0+PZ4LUc92gj1XeJ+BneIOMhVFTUQQ5oRxBzmwyv1awn7qdZ37RIclDZAA whREbB4GP6Am4UkENe1H+tUTgaBO+NG4d2cH1zYfLtfGRzAVSMinkEguU+7iMVpVVXhd c/jPMABQ6xgCcMmWwUfikmrS3wm3uRXQ6gE94rRxhVRA5ROCSqiHtGL2JsVQGQIGIxUh y7PhIHVlb/P5J6/5xop1A6qzxhHfFytSV8o1gEcPCrlMUwA+Tg0A33625zJkQwZEtdnP UHC1EyQCJqlxe+2aYlo/o4pKUzC8RB/9nnzg0vnaq71VAajdooayvebjRQEyC35LV1Fr Wx0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pEvUVrXP; 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 p14si8855244eju.82.2021.09.13.13.51.35; Mon, 13 Sep 2021 13:51:59 -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=pEvUVrXP; 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 S242036AbhIMNvr (ORCPT + 99 others); Mon, 13 Sep 2021 09:51:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:50740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243276AbhIMNrd (ORCPT ); Mon, 13 Sep 2021 09:47:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CB53D61211; Mon, 13 Sep 2021 13:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539950; bh=QZzrdQ2cwn4WxiPAJIowrMx9IsdAja4shefopQdmRgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEvUVrXPsrRJ7sBJb0lJAp/cJzL0Dn2ZfgyHSzohCY7NmI4H0ZWOxVCYjy/X9Q/4N D5YcuK6nmlaiXqqT8OQmgxC3gOpXRCZAUFQyXga1zlZtNa8KXLc9xZliWULXLeXBsb rYieixOyJO7pr/7CjoNc1VP5i4tWdBngOPppF9GI= 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.10 226/236] KVM: x86: Update vCPUs hv_clock before back to guest when tsc_offset is adjusted Date: Mon, 13 Sep 2021 15:15:31 +0200 Message-Id: <20210913131108.039455298@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 @@ -3116,6 +3116,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; }