From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 24FF74ACCE1 for ; Thu, 6 Aug 2026 23:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059444; cv=none; b=qZMsEWWU9KWtIvofbU4+vb4lLb880j45Fx4jQIrpjIoewm2swRM0vrQAD4Bk0w1al+2MWrhQWLJeTi4yg/thQw+9zEjz26LKWvsLZVUN7S/w/GYuf/nKxGtUcedg6p+FxBphpHefM5iRj0ztH+q7IV+ITHDNZmfaej2NpWBfAZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059444; c=relaxed/simple; bh=wE5Lnirgd+SKewLj9G18nlZgvflnuTi/pbn67D/XsGQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UP/XbZPlF0quemnkBHShb6Di2s9m8izRUVJCow5p9R9xAd2rhJIkIKGC4BIZCEUjNymuOgn6/C2wrO5B3V3PouRChudUTX4tvASzSw444RRxxg1xV/4uMdJIhz3IT4vcLhOwD4Dfz/4rgONp5HvV6BCV4gRaSFipz8grmKl90/Q= 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=Z0iQpv+0; arc=none smtp.client-ip=209.85.216.71 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="Z0iQpv+0" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38dc085b0a7so4045351a91.2 for ; Thu, 06 Aug 2026 16:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059442; x=1786664242; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=+in/CASVMXdQrSwySi/14FWqsmLN6M2d30MjdmJLYfo=; b=Z0iQpv+0wQ53l7Cu5HnTFGCJRbn2wttLJYthHetQ1KPOeA1AFIbefFqCKwKJZaC0at aTeZCRYsHZnzQq2KrbBZ+ewYD4TwshaTudw6zWeuRMJCh9DkDhbD1GlP6HLq2RYZqIEw cEg/cng97X1PVVn/HgyZ19HYtkIVqC+SQVX0CRKCNnuCIJJqK1JpurpgLq29y8k6PuiF R1D42RIi/Wwf11Ps6RRQ7tO9uZRBIANkQ5LS2GUY1KDxH0Tup85P35+hGwVbiPGknD0T v+vwRzE+EDw9KoSke5IrOJreNLk6KPlD1RdVwHkVBaEwlhqJst7W+BeSTk4c2Sf1xze+ uUVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059442; x=1786664242; h=content-type: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:content-type; bh=+in/CASVMXdQrSwySi/14FWqsmLN6M2d30MjdmJLYfo=; b=WziLY6YVlwJS7ciYRhhhcm0C7mnzeU3HWDM77QjTFVFLyurtUJV6mhB7anpxrPyMLG 950jvt00KjyLN9HyC7t+8U0ZOETYMLVmAeVAVBJg35/COZ/7r1/unlmbseudH9OFI4/i 9sgCe7q0hFCkufRcHq2ccmGXKqkKIItnYrI2N44qAz5cpbAo86KsF++oCTIG4Ml4CE0f iNzxRcVRaz3+hMBlMPywRK7N5pgsNpy0SHU3urab55H6zg0hxWn/JaSRBVnl+AaqAVRD iRp6IqxHCXtdKKxJTdAOlZ5yWz+1eSBmo+691EqO2YGZ+OMymFZ1GBK0tbKdtY7bekEb 6Uug== X-Forwarded-Encrypted: i=1; AHgh+RpFSihEiRNiGRpeKHPNHa/5llxDweXFW+liUC/Iwu5PUm1zhLlWLeBaW92ONtlIDGpBYDRLVs3YLdS0WS4=@vger.kernel.org X-Gm-Message-State: AOJu0YwfsryWKa8T4lKUc11W96OZFsBgjR9rz8LRBIKKnqBIvRDt5fLI ys5jzt7djYpcqQOwCkjmse/dRH7P8SUFa9SLfnseAS69BBU3U0TDe3EPrUOJcWohCbqWCm5ncln IWnn7Lg== X-Received: from pgii4.prod.google.com ([2002:a63:2204:0:b0:c8d:62a8:ee35]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a9c:b0:3bf:983d:e9b4 with SMTP id adf61e73a8af0-3cb8603af0dmr21846910637.33.1786059441366; Thu, 06 Aug 2026 16:37:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:36:03 -0700 In-Reply-To: <20260806233609.212337-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: <20260806233609.212337-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806233609.212337-47-seanjc@google.com> Subject: [PATCH v6 46/51] x86/paravirt: Plumb a return code into __paravirt_set_sched_clock() From: Sean Christopherson To: Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , Thomas Gleixner , John Stultz Cc: Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , Miroslav Lichvar , x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Michael Kelley , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Add a return code to __paravirt_set_sched_clock() so that the kernel can reject attempts to use a PV sched_clock without breaking the caller. E.g. when running as a CoCo VM with a secure TSC, using a PV clock is generally undesirable. Note, kvmclock is the only PV clock that does anything "extra" beyond simply registering itself as sched_clock, i.e. is the only caller that needs to check the new return value. Reviewed-by: David Woodhouse Signed-off-by: Sean Christopherson --- arch/x86/include/asm/timer.h | 6 +++--- arch/x86/kernel/kvmclock.c | 9 ++++++--- arch/x86/kernel/tsc.c | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h index 96ae7feac47c..ca5c95d48c03 100644 --- a/arch/x86/include/asm/timer.h +++ b/arch/x86/include/asm/timer.h @@ -14,14 +14,14 @@ extern int no_timer_check; extern bool using_native_sched_clock(void); #ifdef CONFIG_PARAVIRT -void __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, - void (*save)(void), void (*restore)(void)); +int __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, + void (*save)(void), void (*restore)(void)); static __always_inline void paravirt_set_sched_clock(u64 (*func)(void), void (*save)(void), void (*restore)(void)) { - __paravirt_set_sched_clock(func, true, save, restore); + (void)__paravirt_set_sched_clock(func, true, save, restore); } #endif diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 2cc3dd2ba355..22e8855fcd4d 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -332,10 +332,13 @@ static int kvmclock_setup_percpu(unsigned int cpu) static __init void kvm_sched_clock_init(bool stable) { + /* Ensure the offset is configured before making kvmclock visible! */ kvm_sched_clock_offset = kvm_clock_read(); - __paravirt_set_sched_clock(kvm_sched_clock_read, stable, - kvm_save_sched_clock_state, - kvm_restore_sched_clock_state); + + if (__paravirt_set_sched_clock(kvm_sched_clock_read, stable, + kvm_save_sched_clock_state, + kvm_restore_sched_clock_state)) + return; /* * The BSP's clock is managed via dedicated sched_clock save/restore diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 363145c83919..fcf331ffd874 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -280,8 +280,8 @@ bool using_native_sched_clock(void) return static_call_query(pv_sched_clock) == native_sched_clock; } -void __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, - void (*save)(void), void (*restore)(void)) +int __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, + void (*save)(void), void (*restore)(void)) { if (!stable) clear_sched_clock_stable(); @@ -289,6 +289,7 @@ void __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, static_call_update(pv_sched_clock, func); x86_platform.save_sched_clock_state = save; x86_platform.restore_sched_clock_state = restore; + return 0; } #else u64 sched_clock_noinstr(void) __attribute__((alias("native_sched_clock"))); -- 2.55.0.679.g6767b8d81c-goog