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 7C5CB420E69 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=RZlIfFkkpKyaZUKlDI2CJqMH+hpkQQVxjfyH7qLa7pndU0sNOVp3FZOnPsiasq6DNVcjL+rKC8g45F4Xcu4weXJ3FM0gtzuHVn2hDBAGh/ybr722Utwhaok242+fm6awxtxYNfju9//UBSi5xI8MWauFjjjj0JVbz56m5ADi5HM= 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=dHd7XyVK; 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="dHd7XyVK" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ca5d2474c7so22057865ad.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=1782934385; x=1783539185; 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=dHd7XyVKyAT2i3sC8SnIqYcGONJqAL9xOm6b312tYFr1pEuX8Pec8xT/FBI/7b+LvQ 7WXHf2QeoSp+gypLlErAUT9/IyNI3d61CEme6kMal20UWYDb+DBb0+fCB67pCnPqTNQG Ck+tp1c2/9DnJWvLMi9l8GaAO0dMOLtLZhmq2wgCpunrK+xc0gN95qALFGXyTki6ppV9 g7sqle2XGJM7uw31WZYcOnAROqnlJI10oLpN/XDrwKPJ1GOSJvW0wrhrQwlfdoMomeK6 HBruIkAwnwJQSxsa4rCdHlJLGwrCG12BONyQXBwNYdkWUDwnPW8en1t70OzBalgTC3Wo FIow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782934385; x=1783539185; 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=R8mn3RdXqP2/PxbV4qfrT0ObGIpRXXOM+wzybm1oIY4aRPhJu9swxLM21h/fp8r1vQ ascWNTlwVnwpdT00lbty7aC5mallAJ1a+0ND8Fl3q7oUDvZsk1W7m/m1Zy6bjt2TinKe G56heZUSlvMIMTfzW5/pEploIZN4AMYZo8otxiW54lOba3Zy1HKsZT5tUQb+4YqGqyCX RcjXIC1daBSHTYog7PoKKHD8dwcXVk2AWNB24IEXR2rWeOvuZ8il+N7c8CswcqxCL8PT iyIkfjEy0jSAfRwWXpMAtS4f4v1puPKrgE4wFWSTE+saIaeWmt2qfi8sgKdz9N1eVAqR isLg== X-Forwarded-Encrypted: i=1; AHgh+RqRXSmUIp/gqlx8fEY4qKwQAaot+yz1Ngpq3eMIxw6kyTFWQ1RjEs74M9VMNssd0992tpZXGcdYJwIXQ4k=@vger.kernel.org X-Gm-Message-State: AOJu0YzknW4i+/XFbY0QIZmLxdSIwYHBhvsAhzemrX4bpW+MFkdE83qt tHF0kR3cGYxz9PVyw0Ae9S3OoFUhNe30vVC0Cp08rL9RMeT3JDzFcbDRCOtkgW+kmzVVXf9FZby qVWSxJQ== 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-hyperv@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