From nobody Tue Aug 25 02:51:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=infradead.org ARC-Seal: i=1; a=rsa-sha256; t=1783113849; cv=none; d=zohomail.com; s=zohoarc; b=iB+6t8cgPXrt2/ctHsMWKxJxx+dkvkFOK2k0i5/Xu2pOvB+uerchBoPz1Z+JizSFl2+Q48RPph5KjNFWKYnt4N1GUhq2y1oW2+UpCVKYajycDwa16JqVuHe6RCgyDUiDlsTM7CQnLaXoIJ3SqxUSAu83hFdX0DfRrJ//2mfWV+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783113849; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=v5twNDtsGAUIy7fgp54AfjET8D0248IAEiPECDLBGtY=; b=DoPL2KJs7Rdd5jHLb4YtfeZ5MQV0tstqgivZf6dPRITb02pK46ylF5WYJyRNlEMl+zoGNgn5lXFEJtlXuC55wD0czI0uSDBtdc7t/M5E/GeSC2/BR3aW/y3B0jh1jY9wD1nFyNGLiMUI9loOVYsIHR6IwoX3pnB4MI/ziSffLO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1783113849863631.8812525679514; Fri, 3 Jul 2026 14:24:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1353896.1609659 (Exim 4.92) (envelope-from ) id 1wflMY-0007At-4J; Fri, 03 Jul 2026 21:23:54 +0000 Received: by outflank-mailman (output) from mailman id 1353896.1609659; Fri, 03 Jul 2026 21:23:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflMX-00079A-Ue; Fri, 03 Jul 2026 21:23:53 +0000 Received: by outflank-mailman (input) for mailman id 1353896; Fri, 03 Jul 2026 21:23:52 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wflMW-0006v5-KE for xen-devel@lists.xenproject.org; Fri, 03 Jul 2026 21:23:52 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wflMW-000kw0-1F; Fri, 03 Jul 2026 23:23:52 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a482832-2eae-0a2a0a5409dd-0a2a450b92fe-38 for ; Fri, 03 Jul 2026 23:23:52 +0200 Received: from [90.155.92.199] (helo=desiato.infradead.org) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a482867-ac48-0a2a450b0019-5a9b5cc7a076-3 for ; Fri, 03 Jul 2026 23:23:51 +0200 Received: from [2001:8b0:10b:1::425] (helo=i7.infradead.org) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKc-000000059Ny-3C3B; Fri, 03 Jul 2026 21:23:38 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.99.2 #2 (Red Hat Linux)) id 1wflKW-00000001ROH-0fUc; Fri, 03 Jul 2026 22:21:48 +0100 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=desiato.20200630 header.d=infradead.org header.i="@infradead.org" header.h="Sender:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description; bh=v5twNDtsGAUIy7fgp54AfjET8D0248IAEiPECDLBGtY=; b=D3raY3MtOWfOex9Yyi+xdwR0oR uH968+lTAMciyl5YT2WpYYHWkV4kZsN8/ZHM2GRGrwrBj9ui5GYmD9fG5F2abnWtV4WzOKBvaPhA2 Q0QkFD8RDTCmadp3BR9IBi8DDKktdVZV77/JpgdmtpX0sSXUozU4PcguLEOrURgnnk/FD1DDwvg11 GhxzUTCQtWepYdtdsACcCD7qQa4cSuaOUyBMo3ystxYHRyA1I0arDUTqQRtVZrp2cyUSbbXeGS0Ie iCh4Z9aESsuLp+Ly/0B9HNI3BAqiQTUd6lP1/mWLYFZqczT8/eBEz4K0SdSrfmyS9ogn3nh0vMR4J oqQGhlcA==; From: David Woodhouse To: Paolo Bonzini , Jonathan Corbet , Shuah Khan , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vitaly Kuznetsov , Juergen Gross , Boris Ostrovsky , David Woodhouse , Paul Durrant , Jonathan Cameron , Sascha Bischoff , Marc Zyngier , Joey Gouly , Jack Allister , Dongli Zhang , joe.jin@oracle.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-kselftest@vger.kernel.org Subject: [PATCH v6 08/36] KVM: x86: Activate master clock immediately on vCPU creation Date: Fri, 3 Jul 2026 22:17:47 +0100 Message-ID: <20260703212145.343527-9-dwmw2@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260703212145.343527-1-dwmw2@infradead.org> References: <20260703212145.343527-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by desiato.infradead.org. See http://www.infradead.org/rpr.html X-purgate-ID: tlsNG-42698a/1783113832-A7B30220-98314000/0/0 X-purgate-type: clean X-purgate-size: 1254 X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1783113850882158500 Content-Type: text/plain; charset="utf-8" From: David Woodhouse Previously, the master clock was only activated when the first vCPU processed KVM_REQ_MASTERCLOCK_UPDATE during KVM_RUN. This meant that KVM_GET_CLOCK could not return the host_tsc field until after the first KVM_RUN, making it impossible for userspace to follow the documented TSC migration procedure without a dummy vCPU run. Fix this by calling kvm_update_masterclock() directly from kvm_arch_vcpu_postcreate(), after kvm_synchronize_tsc() has already set all_vcpus_matched_freq. This ensures the master clock is active immediately, and KVM_GET_CLOCK returns a valid {host_tsc, realtime} pair as soon as a vCPU exists. Signed-off-by: David Woodhouse --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ff45577ed90c..2039bd8518fb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13110,6 +13110,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) return; vcpu_load(vcpu); kvm_synchronize_tsc(vcpu, NULL); + if (!vcpu->kvm->arch.use_master_clock) + kvm_update_masterclock(vcpu->kvm); vcpu_put(vcpu); =20 /* poll control enabled by default */ --=20 2.54.0