From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 59B714ACCE8 for ; Thu, 6 Aug 2026 23:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059444; cv=none; b=kYBm/+GeZKwZnFDDdRFp3mY8lTSxvNHWwXfpMNXtfQqSS3REa2mZiV7HK1ESgpu50HldKClzCIAXuDnlVW6s+Qk3ToGGGFWztcge+5sxU/03gqpEyjQKafos2Hh9Jlv8uo5wfmYc/7FU8+PuwvIXbjCZO0OZzuq0sT8qQa+FmnM= 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=tV/jonAz; arc=none smtp.client-ip=209.85.215.198 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="tV/jonAz" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-ca7c1e22995so3995579a12.3 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=1786059441; x=1786664241; 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=tV/jonAzD1gvrVOiLa1Z1kILJtb3hVbmkLleBr+MPoZeYYA6GyHhZEiIxNaObrJGEu DYJrl6z6JJNKxkp5/q4OZEmODWsCiknZgzn1kd5VftFf68RWN3c8o2AakTQOhJE8o/mE u8INnngDNFtkdU5w7T9bk8Ibw3yQcrwUFnvxeW/mCm5aTSrW2czaQl1PgPvws4r9kNCv Tw0itHa8O/W4Y4uGX6+4uuau+gSe5KtxRBNJSEYJYgR6A/uXDKTdDxxCmP5ruWz+053A b+KOHcrWmCcfq/La39lSO0KJiO5FLUTwyoC1rwPfwKTJtfahGHsdjcMMVOR3vXkhGEYP Odcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059441; x=1786664241; 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=Q0f6JPB43Fq9cy3HYtF7V9d2of0yWF0TO36/TQOls0FjjJL2Aql/c0zrxh4NKCX5W8 Oxk8zIhaAagBtQRxghUIMqKAuyyqmtIS3qHpIsqwpc9zcfMaM3/ovHT/fnc6LO07MbM3 yCuXBdDd3TRILHYxKivoT1ux3jBofLjilTKq7HijXKE5iyDIAa9hMQ4dqvMiFGO1M1fu CKWOwVPqakEuvbFSs94usoMRiHEjh8LKvEmCoHNLwEOVODzpBeMkPP8vYOSz5d0i97+d UrwzTg8AyD2BfMNxWacy6e7n+HxGMsZWVfmyuq37m32MiBIQ8x+D1NcZD5OSC8esMqmj YZCQ== X-Forwarded-Encrypted: i=1; AHgh+RqfHnQo5h+GBBQIBpj7lXflXNruMQeK7KeVpc7luTmV4WHrgeUpf0JBwTsPyvHWSqKIrN8LvPJI6JnnCPk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9gE38S7M1MjRG4FWWjl0akUCrzfC01ra7dAVT+hd94TPxe+DS Trird3tcp1ewhUc9UvOyHg0RIFHf1XvuGPHJ0jgBbgCjWh+5divEngwh6DnoB3SmoInry2v7NKc WkVLiHw== 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-kernel@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