From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DCF13B42CE for ; Mon, 10 Aug 2026 22:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786402506; cv=none; b=uCX9we3J6LDspJHcdt10qZgWWLaY1PUyj5KonaK3PIAFKBEOhhDi+t13UCu0NEPTsIi9wJr/udK7IaZWERu1Al1K0HCbxS2VMrULyuz6LENNenOsbZKLtJ38G4m3sxnkeMYhpdaxONCZ4czeFmNxjcmbRkR8bu8pieApNefLrcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786402506; c=relaxed/simple; bh=UyzjMYugLeXCRTiphTD2D8j6nW8JZFiz/UgO9cW0TeQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=rJoItF9ZBJmfzxJD/zRQXYlny1dGm7XkeVXtSqHLYxxwIjt5V1lmPuzI2a5OqJfSNQjLBZ/dxd75E0POHJIemWdXc3/PD5pg8v2C/g2lhZ+aMGBLP1OB1ytM+95iiFIsPdj7L6UicJSeqvLFAk+6mPUcPI9W6+QMVjm5ebEqicY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vmnAGzzW; arc=none smtp.client-ip=209.85.210.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vmnAGzzW" Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-848662cd2a1so2750319b3a.2 for ; Mon, 10 Aug 2026 15:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786402503; x=1787007303; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:from:to:cc:subject:date:message-id:reply-to:content-type; bh=gtRN2ZX2D3EX3PQYRghtvXXKZWu23JNO6Tdf9z8vOt8=; b=vmnAGzzWwx2eGmS2dTYyo68D0ohitatLv9APJcdxtciBmOfuL54PA8MiXsNqMuyC1g zjiiXstOFT+nRcNn05CAEVg6UlzqbNK+w9HDo1TUw014ftG1qzmiF1MUb42TjGnPB4E+ +gw16JObUKts2LkdyoCzdgamPc/UUgyPCtemqfFePYKTcOpMZ3lvVZcfcOWZv3S9T0Nv /yVwTYnWgIsOF0Xx+HZfOcrUONtaeXedUvpXyOKoVvkiLb7RmEJSRaW0P/Zb5Bulww6E 23v5C8EdxKw8k1XQ6psCqpRZurdRZKo3DbnpCmz4JoNtcnb7fA4y651Z/8CiK/FO2one ZimA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786402503; x=1787007303; h=content-type:cc:to:from:subject:message-id:mime-version:date :reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=gtRN2ZX2D3EX3PQYRghtvXXKZWu23JNO6Tdf9z8vOt8=; b=ZsFkmKK8VquFJ0JXnD0yot6+4gKuHt5XT8evaRRclnWphgoIsLIjh2r/9IX0FT/ivS 3TIs6TeNZAOej9TQwWlnwRVQHwFrCfz+nq5iszKbHnVoHhmFviRaJ7l7byzMLHQ4xocR Hp3AUI21FfHpnPeLNpCVKyxfI0mZjn41oL6GtqLWu8vJmK22OOjh3fpsVy7Owo0TdPkJ jxvkFQvRAsupsMzUAT1VkOkzpHCuTGfmHeIJzGStRfWAaD0QkttT23V1Yelkt+gM8X/b AKDNFeImZDm90U/nwoHhamiOdw6UgMkJQ9qrYrHL9oDpxhbu8INGNPjA+vCer7gV0ajZ 6t1w== X-Forwarded-Encrypted: i=1; AHgh+Rrwrv8cRDYYfg70qDI42wcmejWCPYpzZxjdOdxxTPnebWAu5wazna+pFWpJnnWMWMAZMPY0CoEovZxXMjI=@vger.kernel.org X-Gm-Message-State: AOJu0YwPW2nHOK+tV3lOB+FNqtXqDUAjs3J8yEhU7/+3ivmCwxj0Bg7G EjjZdbalztrbUqt6BCDv/YSLQFhxV8VvM02FXZ465SK9g6w1zQw6YjRIIZ2XRDKLoSpM0N+dpgA XY8Ne/w== X-Received: from pfh25.prod.google.com ([2002:a05:6a00:12d9:b0:845:c4b8:9730]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1c89:b0:845:2ff5:b66d with SMTP id d2e1a72fcca58-84f697338d0mr25674176b3a.35.1786402503184; Mon, 10 Aug 2026 15:55:03 -0700 (PDT) Reply-To: Sean Christopherson Date: Mon, 10 Aug 2026 15:54:38 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260810225500.869288-1-seanjc@google.com> Subject: [PATCH v9 00/21] KVM: x86: Cleaning up the KVM clock mess, part 1 From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Durrant , David Woodhouse , Dongli Zhang Content-Type: text/plain; charset="UTF-8" Part 1 of David's series to clean up the host-side mess of kvmclock. The cut point in this version is still quite arbitrary, but what's left for "part 2" fits nicely into 2-3 buckets: 1: Masterclock overhaul 2. New uAPI and tests As mentioned elsewhere, my plan is to throw this into an unstable topic branch asap so it can be used as a base for part 2, but will target 7.4, not 7.3. I won't publish it to kvm-x86/next until 7.3-rc1, to avoid polluting linux-next, and I'll rebase the whole thing on one of 7.3-rc1, 7.3-rc2, or an updated kvm/next. v9: - Pull in "Compute kvmclock base without pvclock_gtod_data" before "Avoid NTP frequency skew for KVM clock on 32-bit host" to avoid having to provide what is effectively an open-coded version of ktime_mono_to_any() to avoid data races. [Sashiko]. - Pull in use of kernel timekeeping snapshots, split in three patches purely to aid review and bisection. - Check and clear KVM_REQ_MASTERCLOCK_UPDATE in kvm_arch_vcpu_postcreate(). [me, Sashiko] - Add the missing return value in "Move "no master clock" fallback from...". [Sashiko] v8: - Obviously cut partway through the full series. - Update commit references for 633d7652f80f ("KVM: x86/xen: Do not corrupt KVM clock in kvm_xen_shared_info_init()"). - Chunk the "Restructure ..." patches into individual logical changes ("Restructure kvm_guest_time_update() for TSC upscaling" in particular was quite gnarly). - Ensure the TSC+freq pair during guest time updates happens on a single CPU. [Sashiko] - Keep __get_kvmclock() as a masterclock-specific helper to avoid deep indentation and gotos. - Do waaaaay too much spelunking to try piece together the history of some of the many warts. - Ensure preemption is disabled in get_kvmclock() when getting the TSC freq. v7: https://lore.kernel.org/all/20260728144954.355376-1-dwmw2@infradead.org David Woodhouse (14): KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force KVM: x86: Explicitly disable TSC scaling without CONSTANT_TSC KVM: x86: Activate master clock immediately on vCPU creation KVM: x86: Compute kvmclock base without pvclock_gtod_data KVM: x86: Avoid NTP frequency skew for KVM clock on 32-bit host KVM: x86: Wrap all of __get_kvmclock_master_clock() with CONFIG_X86_64=y KVM: x86: Fall back to non-master-clock if clockread fails in get_kvmclock() KVM: x86: Fix KVM clock precision in get_kvmclock() with TSC scaling KVM: x86: Use get_kvmclock() in kvm_get_wall_clock_epoch() KVM: x86: Fix compute_guest_tsc() to handle negative time deltas KVM: x86: Upscale TSC to "now", not master clock when updating PV clocks KVM: x86: Simplify and comment kvm_get_time_scale() KVM: x86: Remove implicit rdtsc() from kvm_compute_l1_tsc_offset() KVM: x86: Use kernel timekeeping snapshots for getting kvmclock time since boot Sean Christopherson (7): KVM: x86: Update "last guest TSC" snapshot prior to enabling IRQs/preemption KVM: x86: Drop unnecessary CPU pinning when computing/getting kvmclock KVM: x86: Move "no master clock" fallback from __get_kvmclock() to get_kvmclock() KVM: x86: Disable preemption, not IRQs, when getting TSC+freq pair KVM: x86: Make master clock logic in guest PV clock updates 64-bit only KVM: x86: Use kernel timekeeping snapshot for monotonic clock KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC arch/x86/include/asm/kvm_host.h | 6 +- arch/x86/kvm/cpuid.c | 1 + arch/x86/kvm/msrs.c | 3 +- arch/x86/kvm/svm/svm.c | 3 +- arch/x86/kvm/vmx/vmx.c | 10 + arch/x86/kvm/x86.c | 491 +++++++++++++++----------------- arch/x86/kvm/x86.h | 3 +- 7 files changed, 245 insertions(+), 272 deletions(-) base-commit: 1b731e5ded480bd1e5546aed35584238661ce72e -- 2.55.0.679.g6767b8d81c-goog