From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 7CC26420E6A for ; Wed, 1 Jul 2026 19:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934388; cv=none; b=ByfxXoxZpUTleurRmxVmjSOdbOVaj/hisAMn5VHTyhzyIIm/8Z1AcIdV8ykjHdIwOzCyvQALB4ENGa+BxKuHva5TKsQ5oluKcFf7DDPXZj9nGN7th2/m4wTjApWBQsAxfQjFWXnnjgYBqUWCaL4q4kMmoztSDYpfI0dnlA98CYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934388; c=relaxed/simple; bh=7YsySPptQ6kA1DOmr538pF/lRTH1eLru41S1skeiyMY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NaqTZydsPuNRdQc24KMwq8tAjzqPU6WCbtPFPxkIH8oREpCnhCUi2gxhz8IW1lRz1+6a0y02GmGAVFjPtVqdps4QttBWggQKCZfi2h+dLA+CFhFWxZMuKr/0i0fYbe1ODt5HnQsgwoUE8Vuj00hknNXTlQYWQR6bW5J9BXiD5Ks= 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=qDYcWEjy; arc=none smtp.client-ip=209.85.214.201 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="qDYcWEjy" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ca5d2474c7so22057885ad.2 for ; Wed, 01 Jul 2026 12:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782934386; x=1783539186; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=E6ig/L0f6Bi8iYQ5fSK4jpuHUho56x4PQqpcZJJeUg4=; b=qDYcWEjyVnmrepn6lNJO4QZtDLwOJGC/htoLPYECtvhT5KfGhsUrbW+oJnQKrpz/R9 vEP3qFzleLZEflaqCVW9SMEefdv/2eHC/jVhjHmwDjVjzdpCZ2CS6KNYQ419RRmpWsxF JD8b19wmpnn8jFtwdB/ScqPRbBI0PYyTtTd/qlkNLfC0vXUAiU65oTLpYC/NqH23L+fw 6DS+evXVS1Zo0aF6Te84cRB6TZBCvfYPiNxeS1H6MUYgDEEgymMfFV1tnXM+4O+rDWnr IuF4cz8zVyhbzrNcs6VdLYjlKe1kd/RxvopEzU1aAx4Cwqx4AhkP2GD30e1FX1A8U63J LosQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782934386; x=1783539186; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E6ig/L0f6Bi8iYQ5fSK4jpuHUho56x4PQqpcZJJeUg4=; b=KuyCe23YffzClzDXE3je1GnKye6pyz40kChCfEfMNCRJymbwNXNMrRCS6KeRJk821S ut9IHYOUcsu6YVwAQ4EiB8u7wLuBB+etRA4TDoEtytcBnsGE0CmTmPyEr2RlFd7MVoCd iCX+9VF85rsxhtEMsQJm/nJQLD6s/E/aQH9qV8iHjM8Tqo2V1nLgJYt0Xa+8fKSo5w2G xhJCd3HrECX8B6NEQMIXPnM2u7P87lXJKLhNzzX65BE9UKjKpLNGdNXdJ+c2a9MM28nv 0Owht51u4aPW+lpa4AoFfmp+l6Yfnk2CEWQ35A0iGnR/F85gKJ2WMHbpwrEtCiPHqdHR PPQQ== X-Forwarded-Encrypted: i=1; AHgh+RqgasieyDLV2JGIUQuvz+W/GovMkaL4N3cJ9Ac/GFXv27C3Fq+jUg78oSMODMtWl6Ws3jW0phtIQQI=@vger.kernel.org X-Gm-Message-State: AOJu0YyYmg/iOdsqwXO1Lv3GTsllZPzyDf5zbemcSCpdszro0ExiV+ZT AbtZ3N0SzK1oc944j9KSDOR71SwYLrPp8Wf45iWKOAMiAQM7FUDHO2fcl7B3EFs650liDHmQNmD swHuA1A== X-Received: from plbmt13.prod.google.com ([2002:a17:903:b0d:b0:2c6:b7bd:4804]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1acb:b0:2c9:c54a:7915 with SMTP id d9443c01a7336-2ca91140306mr23508775ad.14.1782934385462; Wed, 01 Jul 2026 12:33:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 1 Jul 2026 12:31:52 -0700 In-Reply-To: <20260701193212.749551-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260701193212.749551-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260701193212.749551-32-seanjc@google.com> Subject: [PATCH v5 31/51] x86/paravirt: Move handling of unstable PV clocks into paravirt_set_sched_clock() From: Sean Christopherson To: Jonathan Corbet , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , John Stultz Cc: Shuah Khan , "H. Peter Anvin" , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Michael Kelley , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Move the handling of unstable PV clocks, of which kvmclock is the only example, into paravirt_set_sched_clock(). This will allow modifying paravirt_set_sched_clock() to keep using the TSC for sched_clock in certain scenarios without unintentionally marking the TSC-based clock as unstable. No functional change intended. Reviewed-by: David Woodhouse Signed-off-by: Sean Christopherson --- arch/x86/include/asm/timer.h | 7 ++++++- arch/x86/kernel/kvmclock.c | 5 +---- arch/x86/kernel/tsc.c | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h index c71b466d6ace..fe41d40a9ae6 100644 --- a/arch/x86/include/asm/timer.h +++ b/arch/x86/include/asm/timer.h @@ -14,7 +14,12 @@ extern int no_timer_check; extern bool using_native_sched_clock(void); #ifdef CONFIG_PARAVIRT -void paravirt_set_sched_clock(u64 (*func)(void)); +void __paravirt_set_sched_clock(u64 (*func)(void), bool stable); + +static inline void paravirt_set_sched_clock(u64 (*func)(void)) +{ + __paravirt_set_sched_clock(func, true); +} #endif /* diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index a3ec298d56d7..4bc0495f1f9e 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -115,10 +114,8 @@ static noinstr u64 kvm_sched_clock_read(void) static inline void kvm_sched_clock_init(bool stable) { - if (!stable) - clear_sched_clock_stable(); kvm_sched_clock_offset = kvm_clock_read(); - paravirt_set_sched_clock(kvm_sched_clock_read); + __paravirt_set_sched_clock(kvm_sched_clock_read, stable); pr_info("kvm-clock: using sched offset of %llu cycles", kvm_sched_clock_offset); diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 375b0279df66..a762cb5cec0f 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -280,8 +280,11 @@ bool using_native_sched_clock(void) return static_call_query(pv_sched_clock) == native_sched_clock; } -void paravirt_set_sched_clock(u64 (*func)(void)) +void __paravirt_set_sched_clock(u64 (*func)(void), bool stable) { + if (!stable) + clear_sched_clock_stable(); + static_call_update(pv_sched_clock, func); } #else -- 2.55.0.rc0.799.gd6f94ed593-goog