Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319024pxb; Mon, 20 Sep 2021 18:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybUFbBg49xE4fxx5FW9SELpfxmIeF+YQxIwhvA7pETywUQrqkQBzWPTxRwLoRM+ZVbQ5eU X-Received: by 2002:a05:6e02:1a4d:: with SMTP id u13mr5724598ilv.4.1632188505831; Mon, 20 Sep 2021 18:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188505; cv=none; d=google.com; s=arc-20160816; b=W4OuzL5kD4M4lLB+wnCBQa4PLa2gdX3BaKE6hi93FeLLsRjpjPxmQJEA4GEP/wiRDy CzrZplY138C7ErHIQMltU3/5LNOcR8gwbDa2EuQ/C9kVbLP+x0nq1kTthKsghU4wPRoM nOLwi+t88uhPURfrDvNlpGH3zJ75pHbGodY8IsdR1/jvZTwYMcn9UbYHi1XnIC6F56kT +nSZoiO5gFceGo0C5g8v8sZN5VWUMSafjRMHuxSpOJ+6A2zZcVtT+YrYw1Hgb4hIsi/C QyNDQa4tWcYAaOKsZYVorJhaFkxesaGqgU4VfFBTyDf4lfr83FSG0nXZrn+X9ZGgxGJK pIdA== 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=/X1tZ+RckztOJVgYHynD8RGnFlAKYxb+w4jVIBFa15A=; b=MzCkLxDx0FmOCrD7vHW5FNTyl8uRFsFJHqaHf0lOCAtQgaHOKvS84mK9TfqpKSCznQ L4w+9UYZrzl+zR6A9c/foWD1nQSzGNLu9YOiYzMqniOKYiuQi+3bwvzJiN6ge8smQrEX lDwPdXFU01K4wCwXUyx42rAYxUGE34aM2TsON0Yii+uR9lNb2vW4o+NJsW9yMTZngxgr Tg5U5HXDgf0gwFw6y51s/OgGrVvePt3+qO5A++IAM0s8Rhpic3Wqx9jRtB5e9rCziRE0 +yhnIBOnWzaqYgq5wV7jk7w2qLKNgW6ivHY0wXFChtTmGc7O2xo1p29UkO+/aNAS+VW/ YBnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OWNJwyyR; 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 n9si17264901ilk.2.2021.09.20.18.41.34; Mon, 20 Sep 2021 18:41:45 -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=OWNJwyyR; 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 S230012AbhITQuk (ORCPT + 99 others); Mon, 20 Sep 2021 12:50:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:35806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242396AbhITQtK (ORCPT ); Mon, 20 Sep 2021 12:49:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5219E61222; Mon, 20 Sep 2021 16:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156458; bh=dEv5uWSnTsZuRdQzUV80WWkPD19ZrAlZ393d2hK5Kis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWNJwyyRj3etI+EP/rircdAcTj02ZD4KgzejO2n8qrbKCKiWjfoePV/WlB1ntOpmL fmrq0moI/wr2L/OBbVG3f1ytFCr9FVp8FRG/6Yg1bnBNMRAt74Skax//hAvXrurQRm vH4AGTfQIDT6xDU9KPtNuS3YRNiztyP3esDClcGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zelin Deng , Paolo Bonzini Subject: [PATCH 4.4 069/133] KVM: x86: Update vCPUs hv_clock before back to guest when tsc_offset is adjusted Date: Mon, 20 Sep 2021 18:42:27 +0200 Message-Id: <20210920163914.908269791@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 @@ -2172,6 +2172,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; }