lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230629164838.66847-1-likexu@tencent.com>
Date:   Fri, 30 Jun 2023 00:48:38 +0800
From:   Like Xu <like.xu.linux@...il.com>
To:     Sean Christopherson <seanjc@...gle.com>,
        Paolo Bonzini <pbonzini@...hat.com>
Cc:     kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] KVM: x86/tsc: Update guest tsc_offset again before vcpu first runs

From: Like Xu <likexu@...cent.com>

When a new vcpu is created and subsequently restored by vcpu snapshot,
apply kvm_vcpu_write_tsc_offset() before vcpu runs for the first time.

Before a vcpu runs for the first time, the user space (VMM) sets the guest
tsc as it wants, which may triggers the time synchronization mechanism with
other vcpus (if any). In a scenario where a vcpu snapshot is used to
restore, like the bugzilla report [*], the newly target guest tsc (e.g.
at the time of vcpu restoration) is synchronized with its the most
primitive guest timestamp initialized at the time of vcpu creation.

Furthermore, the VMM can actually update the target guest tsc multiple
times before the vcpu actually gets running, which requires the tsc_offset
to be updated every time it is set. In this scenario, it can be considered
as unstable tsc (even this vcpu has not yet even started ticking to follow
the intended logic of KVM timer emulation).

It is only necessary to delay this step until kvm_arch_vcpu_load() to
catch up with guest expectation with the help of kvm_vcpu_has_run(),
and the change is expected to not break any of the cumbersome existing
virt timer features.

Reported-by: Yong He <alexyonghe@...cent.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217423 [*] 
Tested-by: Jinrong Liang <cloudliang@...cent.com>
Signed-off-by: Like Xu <likexu@...cent.com>
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 439312e04384..616940fc3791 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4818,7 +4818,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 		if (tsc_delta < 0)
 			mark_tsc_unstable("KVM discovered backwards TSC");
 
-		if (kvm_check_tsc_unstable()) {
+		if (kvm_check_tsc_unstable() || !kvm_vcpu_has_run(vcpu)) {
 			u64 offset = kvm_compute_l1_tsc_offset(vcpu,
 						vcpu->arch.last_guest_tsc);
 			kvm_vcpu_write_tsc_offset(vcpu, offset);

base-commit: 88bb466c9dec4f70d682cf38c685324e7b1b3d60
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ