From nobody Tue Aug 25 10:47:53 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=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1782934414; cv=none; d=zohomail.com; s=zohoarc; b=kpa+S8uiQdRr6/kcgoNet7bbA4cPIDMtkSW77Zl7lvt5OX+eWsNBtd//ADbQj6P6Q9qiFUXNmG276hQPdCE0XiSHaJ+qViR/eCfjnawvEyBWgfGqW31iXMYMOO0sI/33VNVQr64EYVU1Iz+q1QW+Dr8LGZGd+VsldwS7N5H6A0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782934414; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=V+q3+pR5470wsF5QmCXBVWy55xlVZlxhghTF4iDuO4s=; b=Lu9kXAmPFl+4kgAmD6IUc9/4AZ8N9kWbkGczx/EhRGwey+hM9QjoKZT23yLJXVm2lgiPZvFpepKziCGfSro06RS/fNckoarlRLIhXh0K1SzG/gNvat/vXOgyhIIJuYAC1ILiOTCBq8zM10ej8r/APC99DbvmCfdKRb8/IDuwNls= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 178293441428955.15024602819324; Wed, 1 Jul 2026 12:33:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1350471.1607996 (Exim 4.92) (envelope-from ) id 1wf0gN-0007DJ-Hx; Wed, 01 Jul 2026 19:33:15 +0000 Received: by outflank-mailman (output) from mailman id 1350471.1607996; Wed, 01 Jul 2026 19:33:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wf0gN-0007DC-EU; Wed, 01 Jul 2026 19:33:15 +0000 Received: by outflank-mailman (input) for mailman id 1350471; Wed, 01 Jul 2026 19:33:14 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from <3dmtFagYKCbstfbokdhpphmf.dpnyfo-efwfmmjtut.yfoqspkfdu.psh@flex--seanjc.bounces.google.com>) id 1wf0gM-00077Q-5r for xen-devel@lists.xenproject.org; Wed, 01 Jul 2026 19:33:14 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wf0gL-00B3zO-J2 for xen-devel@lists.xenproject.org; Wed, 01 Jul 2026 21:33:13 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from <3dmtFagYKCbstfbokdhpphmf.dpnyfo-efwfmmjtut.yfoqspkfdu.psh@flex--seanjc.bounces.google.com>) id 6a456b79-5cb7-0a2a0a5109dd-0a2a4504c410-0 for ; Wed, 01 Jul 2026 21:33:13 +0200 Received: from [209.85.210.201] (helo=mail-pf1-f201.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from <3dmtFagYKCbstfbokdhpphmf.dpnyfo-efwfmmjtut.yfoqspkfdu.psh@flex--seanjc.bounces.google.com>) id 6a456b77-a01d-0a2a45040019-d155d2c9e504-3 for ; Wed, 01 Jul 2026 21:33:13 +0200 Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8423f1fe39eso1388375b3a.1 for ; Wed, 01 Jul 2026 12:33:12 -0700 (PDT) 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 Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=google.com header.i="@google.com" header.h="Cc:To:From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782934391; x=1783539191; darn=lists.xenproject.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=V+q3+pR5470wsF5QmCXBVWy55xlVZlxhghTF4iDuO4s=; b=k/jTfYAXzhYkYwJe2JoqeSZsue0Bv+f08tun5UaL/5Ytz5h2e0lkBz1mRhR5qWkDjZ qewBBvuv7qCJ5QBWztC+B9uUv1G+defKU3U+99BCzBD5DWcW1/wfh6HedKpK+fJLIoNW vly2dFFRvk3+diZLZi6Goqht29p1tPS666bOMs6uRYFLGGgYMvw8VbR3Trqcpnmo3S/f 0fvoxxKtc1Px5IlCtscD5NkRCSa0Tx1SoypmQVHQNu3V4r9cTqVWaU6uBUenGN2ef2Cw +plK28ccWd1Fw/qdEJzuRaQcvfRgP3RkCCOoRLv4TmZFvCZJ+CcXn5DY6Fni2Ez1Jwvx 0Dwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782934391; x=1783539191; 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=V+q3+pR5470wsF5QmCXBVWy55xlVZlxhghTF4iDuO4s=; b=DhV56l2G4NT6wV7U3bSzKp41bhVvBNAn3Jd1gkMfOtfvPCveWJbRUYnn0YCsV3CyFp HoAXrsYeM8sKSvUq2hUyQe4fq0Tnb23u08jpk7YfJJi2mjlnCTpe//YzB7x9hnDzXk3y eZ67JVtsN6c1Lf6H9pQ4ev+Aa656Uu/39mvGsxPE7etT4C9uFuXTrX/FUk+lQO1TmoU2 w1nFZr6WbyG2jXGxgPBWqPiQvSh+kuMfSvPdyL43u4hbZHXtb2pdy1uArsW8DrIJ5SHr kmlv+6pMqTRaxcFb+m2MQtoFYImUketSTtgw7cDeOHTo4o5eJuEujFRkMJcpMTeHeIIs A6sQ== X-Forwarded-Encrypted: i=1; AFNElJ8gxUfFUT6Z9+J18d0Fgq03EVQ7dd/jta98mspO7G4DZnbZwFsUiA/fksQMr9sWV1OdQCFM7wSIik4=@lists.xenproject.org X-Gm-Message-State: AOJu0YzYkIPehdpksCBvAYJggMRBNgh+asMawGM2UR2ahtZAcCUMhzt3 Tw+ecLsqZOzfjtLkrlP6gLyc0b2pzprZqHe0db0SSZAy8LmEIMF89+kmqkSiGXWTF0UrnE5zNI5 1vj7/Eg== X-Received: from pfblh19.prod.google.com ([2002:a05:6a00:7113:b0:847:926b:dc16]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2d0e:b0:845:d284:9e11 with SMTP id d2e1a72fcca58-847c51d242emr1964528b3a.56.1782934390999; Wed, 01 Jul 2026 12:33:10 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 1 Jul 2026 12:31:57 -0700 In-Reply-To: <20260701193212.749551-1-seanjc@google.com> 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-37-seanjc@google.com> Subject: [PATCH v5 36/51] x86/paravirt: Pass sched_clock save/restore helpers during registration 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 X-purgate-ID: tlsNG-ebf023/1782934393-2E95B1CC-BFF08E8F/0/0 X-purgate-type: clean X-purgate-size: 5719 X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1782934416436158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass in a PV clock's save/restore helpers when configuring sched_clock instead of relying on each PV clock to manually set the save/restore hooks. In addition to bringing sanity to the code, this will allow gracefully "rejecting" a PV sched_clock, e.g. when running as a CoCo guest that has access to a "secure" TSC. No functional change intended. Reviewed-by: David Woodhouse Signed-off-by: Sean Christopherson Reviewed-by: Michael Kelley --- arch/x86/include/asm/timer.h | 9 ++++++--- arch/x86/kernel/cpu/vmware.c | 8 +++----- arch/x86/kernel/kvmclock.c | 6 +++--- arch/x86/kernel/tsc.c | 5 ++++- arch/x86/xen/time.c | 5 ++--- drivers/clocksource/hyperv_timer.c | 6 ++---- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h index fe41d40a9ae6..e97cd1ae03d1 100644 --- a/arch/x86/include/asm/timer.h +++ b/arch/x86/include/asm/timer.h @@ -14,11 +14,14 @@ extern int no_timer_check; extern bool using_native_sched_clock(void); =20 #ifdef CONFIG_PARAVIRT -void __paravirt_set_sched_clock(u64 (*func)(void), bool stable); +void __paravirt_set_sched_clock(u64 (*func)(void), bool stable, + void (*save)(void), void (*restore)(void)); =20 -static inline void paravirt_set_sched_clock(u64 (*func)(void)) +static inline void paravirt_set_sched_clock(u64 (*func)(void), + void (*save)(void), + void (*restore)(void)) { - __paravirt_set_sched_clock(func, true); + __paravirt_set_sched_clock(func, true, save, restore); } #endif =20 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 5c1ccaf4a25e..232255279a6e 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -347,11 +347,9 @@ static void __init vmware_paravirt_ops_setup(void) =20 vmware_cyc2ns_setup(); =20 - if (vmw_sched_clock) { - paravirt_set_sched_clock(vmware_sched_clock); - x86_platform.save_sched_clock_state =3D x86_init_noop; - x86_platform.restore_sched_clock_state =3D x86_init_noop; - } + if (vmw_sched_clock) + paravirt_set_sched_clock(vmware_sched_clock, + x86_init_noop, x86_init_noop); =20 if (vmware_is_stealclock_available()) { has_steal_clock =3D true; diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 07e875738c39..5b9955343199 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -158,7 +158,9 @@ static void kvm_restore_sched_clock_state(void) static inline void kvm_sched_clock_init(bool stable) { kvm_sched_clock_offset =3D kvm_clock_read(); - __paravirt_set_sched_clock(kvm_sched_clock_read, stable); + __paravirt_set_sched_clock(kvm_sched_clock_read, stable, + kvm_save_sched_clock_state, + kvm_restore_sched_clock_state); =20 pr_info("kvm-clock: using sched offset of %llu cycles", kvm_sched_clock_offset); @@ -367,8 +369,6 @@ void __init kvmclock_init(bool prefer_tsc) #ifdef CONFIG_SMP x86_cpuinit.early_percpu_clock_init =3D kvm_setup_secondary_clock; #endif - x86_platform.save_sched_clock_state =3D kvm_save_sched_clock_state; - x86_platform.restore_sched_clock_state =3D kvm_restore_sched_clock_state; kvm_get_preset_lpj(); =20 /* diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7473dcab4775..83353d643150 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -280,12 +280,15 @@ bool using_native_sched_clock(void) return static_call_query(pv_sched_clock) =3D=3D native_sched_clock; } =20 -void __paravirt_set_sched_clock(u64 (*func)(void), bool stable) +void __paravirt_set_sched_clock(u64 (*func)(void), bool stable, + void (*save)(void), void (*restore)(void)) { if (!stable) clear_sched_clock_stable(); =20 static_call_update(pv_sched_clock, func); + x86_platform.save_sched_clock_state =3D save; + x86_platform.restore_sched_clock_state =3D restore; } #else u64 sched_clock_noinstr(void) __attribute__((alias("native_sched_clock"))); diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 477441752f40..8cd8bfaf1320 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -566,13 +566,12 @@ static void __init xen_init_time_common(void) { xen_sched_clock_offset =3D xen_clocksource_read(); static_call_update(pv_steal_clock, xen_steal_clock); - paravirt_set_sched_clock(xen_sched_clock); + /* * Xen has paravirtualized suspend/resume and so doesn't use the common * x86 sched_clock save/restore hooks. */ - x86_platform.save_sched_clock_state =3D x86_init_noop; - x86_platform.restore_sched_clock_state =3D x86_init_noop; + paravirt_set_sched_clock(xen_sched_clock, x86_init_noop, x86_init_noop); =20 x86_init.hyper.get_tsc_khz =3D xen_tsc_khz; x86_platform.get_wallclock =3D xen_get_wallclock; diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyper= v_timer.c index 220668207d19..8ee7a9de0f4f 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -570,10 +570,8 @@ static void hv_restore_sched_clock_state(void) static __always_inline void hv_setup_sched_clock(void *sched_clock) { /* We're on x86/x64 *and* using PV ops */ - paravirt_set_sched_clock(sched_clock); - - x86_platform.save_sched_clock_state =3D hv_save_sched_clock_state; - x86_platform.restore_sched_clock_state =3D hv_restore_sched_clock_state; + paravirt_set_sched_clock(sched_clock, hv_save_sched_clock_state, + hv_restore_sched_clock_state); } #else /* !CONFIG_GENERIC_SCHED_CLOCK && !CONFIG_PARAVIRT */ static __always_inline void hv_setup_sched_clock(void *sched_clock) {} --=20 2.55.0.rc0.799.gd6f94ed593-goog