Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2564749lkm; Mon, 20 Sep 2021 18:50:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7RjHZXzukENCMjZK+Y6WP4S7k8CuGDNLXpteFxmDpCvtAnfxlucEibAWsC/e/OC5x1+W/ X-Received: by 2002:a02:6d4e:: with SMTP id e14mr12999542jaf.144.1632188913918; Mon, 20 Sep 2021 18:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188913; cv=none; d=google.com; s=arc-20160816; b=dZK656y5Gs7Yflh+WDeA9lxz42Ml9IT4kEk+nys31LrLQ+ZeLDu6i2ndYn+bcDX21d eCbn0XDMX9HzqYEpnoH+wyM0d+vdbphglk0hN7ZxSa5KDOkzGdhdUttErH2ml62+timR ww7p/i9iK+waYNHEJ/FVqNn9eaLlf9p25R2cFv5BWdCaU6R+TT4/CK03MauPIeXCyLBk v3VumlbEhBfimvLph660DjDcP+VxiypnXv9302GvBLugiHID3FgWtm43ntY6Og9zixsr x3OzH39MGbhvkEZ9pEBnkn2rEpUKj0ieIcNp587LFrk4knR881OEHAqKHr9eL6wOkdGu 0TTg== 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=idfmnDjaLDvW2WYeGprq+oU7YNCLlBqccnXzAMiv1mQ=; b=S/DtjOdnCwacpab/0sxbNGFkw7gLomLcXI2pYP3DsIuCe+Jnb3BPEy5fQhSjLGkNH6 baJsVgNh4YlC1U/HjgpgGqWZf8aT4jarS5DfQrP/8lVg38lGSd9+IGBwb2pDhccDLlPV CqYKTi5mKzSHm+aPAWAuWXtgvgaQhV0o5ngDBYnoAV1Tqz1Ov9esh/Rexu2cwzQIVq5I rqq6ZMRF9iTerV8w6AhImOGa1dV8A9OGE+sIw8DWnhE27lDWW4+ce/A28FmVPxnkhZ/5 GN1PEKA8eObsqKI8jstIa8d6TYhIyh/Dgm+BIx1KO0wV/PaE/E6FHzPAAoJRAunZ3nn+ PsbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zpHtX9/7"; 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 n6si9828219jac.111.2021.09.20.18.48.22; Mon, 20 Sep 2021 18:48:33 -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="zpHtX9/7"; 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 S1353071AbhITRnm (ORCPT + 99 others); Mon, 20 Sep 2021 13:43:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:48038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348552AbhITRlO (ORCPT ); Mon, 20 Sep 2021 13:41:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C32D61205; Mon, 20 Sep 2021 17:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157700; bh=pR6ydHKps1CHHFsfAgt4lhr4lBJk6of7DJKdWDaIesw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zpHtX9/7cZyw1x+QLZhKJC7Ig82AAA9UEnu11nHWo58WkhvT4PmjETdy2rThp9iiy wU34W3cODvIqOfa38+Ad6FBfqjw6PiuxibVfxCcVFjzU+6hc7JcOgYZk0b/qOVvosK InlXh7e/07ItzCCOB35OzcamO+Rju/6px1rGVjwY= 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.19 112/293] KVM: x86: Update vCPUs hv_clock before back to guest when tsc_offset is adjusted Date: Mon, 20 Sep 2021 18:41:14 +0200 Message-Id: <20210920163937.092002857@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 @@ -2511,6 +2511,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; }