Re: [PATCH RFC 1/1] x86/paravirt: introduce param to disable pv sched_clock

2023-10-19 Thread Sean Christopherson
rg/all/zojf2dmbgw%2fzv...@google.com > > > 2. The sched_clock. > > > > The scheduling is impacted if there is big drift. > > ... > > > Unfortunately, the "no-kvmclock" kernel parameter disables all pv clock > > operations (not only sched_clock

Re: [PATCH RFC 1/1] x86/paravirt: introduce param to disable pv sched_clock

2023-10-19 Thread Sean Christopherson
On Thu, Oct 19, 2023, David Woodhouse wrote: > On Thu, 2023-10-19 at 08:40 -0700, Sean Christopherson wrote: > > > If for some 'historical reasons' we can't revoke features we can always > > > introduce a new PV feature bit saying that TSC is preferred. >

Re: [PATCH] x86/tdx: Enhance code generation for TDCALL and SEAMCALL wrappers

2024-06-04 Thread Sean Christopherson
On Tue, Jun 04, 2024, Kirill A. Shutemov wrote: > On Mon, Jun 03, 2024 at 06:37:45AM -0700, Dave Hansen wrote: > > On 6/2/24 04:54, Kirill A. Shutemov wrote: > > > Sean observed that the compiler is generating inefficient code to clear > > > the tdx_module_args struct for TDCALL and SEAMCALL wrappe

Re: [PATCH] clockevents/drivers/i8253: Do not zero timer counter in shutdown

2024-08-02 Thread Sean Christopherson
On Fri, Aug 02, 2024, David Woodhouse wrote: > On Thu, 2024-08-01 at 20:54 +0200, Thomas Gleixner wrote: > > On Thu, Aug 01 2024 at 16:14, Michael Kelley wrote: > > > I don't have a convenient way to test my sequence on KVM. > > > > But still fails in KVM > > By KVM you mean the in-kernel one tha

Re: [PATCH] clockevents/drivers/i8253: Do not zero timer counter in shutdown

2024-08-12 Thread Sean Christopherson
On Fri, Aug 02, 2024, David Woodhouse wrote: > On Fri, 2024-08-02 at 07:55 -0700, Sean Christopherson wrote: > > On Fri, Aug 02, 2024, David Woodhouse wrote: > > > On Thu, 2024-08-01 at 20:54 +0200, Thomas Gleixner wrote: > > > > On Thu, Aug 01 2024 at 16:14, Mic

Re: [PATCH] x86/tdx: Enhance code generation for TDCALL and SEAMCALL wrappers

2024-09-11 Thread Sean Christopherson
On Wed, Aug 28, 2024, Rick P Edgecombe wrote: > On Tue, 2024-06-04 at 12:34 -0700, Sean Christopherson wrote: > > > > If we're willing to suffer a few gnarly macros, I think we get a > > satisfactory mix of standardized arguments and explicit operands, and > > gene

Re: [PATCH 16/16] x86/kvmclock: Use TSC for sched_clock if it's constant and non-stop

2025-02-07 Thread Sean Christopherson
Dropping a few people/lists whose emails are bouncing. On Fri, Jan 31, 2025, Sean Christopherson wrote: > @@ -369,6 +369,11 @@ void __init kvmclock_init(void) > #ifdef CONFIG_X86_LOCAL_APIC > x86_cpuinit.early_percpu_clock_init = kvm_setup_secondary_clock;

Re: [PATCH 16/16] x86/kvmclock: Use TSC for sched_clock if it's constant and non-stop

2025-02-10 Thread Sean Christopherson
On Sat, Feb 08, 2025, Michael Kelley wrote: > From: Sean Christopherson Sent: Friday, February 7, 2025 > 9:23 AM > > > > Dropping a few people/lists whose emails are bouncing. > > > > On Fri, Jan 31, 2025, Sean Christopherson wrote: > > > @@ -369,6 +3

Re: [PATCH 03/16] x86/tsc: Add helper to register CPU and TSC freq calibration routines

2025-02-11 Thread Sean Christopherson
On Tue, Feb 11, 2025, Borislav Petkov wrote: > On Fri, Jan 31, 2025 at 06:17:05PM -0800, Sean Christopherson wrote: > > > Add a TODO to call out that AMD_MEM_ENCRYPT is a mess and doesn't depend on > > HYPERVISOR_GUEST because it gates both guest and host code. > > W

Re: [PATCH 16/16] x86/kvmclock: Use TSC for sched_clock if it's constant and non-stop

2025-02-12 Thread Sean Christopherson
On Wed, Feb 12, 2025, Michael Kelley wrote: > From: Sean Christopherson Sent: Monday, February 10, 2025 > 8:22 AM > > On Sat, Feb 08, 2025, Michael Kelley wrote: > > > But I would be good with some restructuring so that setting the sched > > > clock > > >

[PATCH v2 00/38] x86: Try to wrangle PV clocks vs. TSC

2025-02-26 Thread Sean Christopherson
warts created by kvmclock. - Fix more bugs in kvmclock's suspend/resume handling. - Try to harden kvmclock against future bugs. v1: https://lore.kernel.org/all/20250201021718.699411-1-sea...@google.com Sean Christopherson (38): x86/tsc: Add a standalone helpers for getting TSC info

[PATCH v2 01/38] x86/tsc: Add a standalone helpers for getting TSC info from CPUID.0x15

2025-02-26 Thread Sean Christopherson
e TSC frequency based on CPUID.0x16 when the core crystal frequency isn't known. Opportunsitically drop native_calibrate_tsc()'s "== 0" and "!= 0" check in favor of the kernel's preferred style. No functional change intended. Signed-off-by: Sean Christophers

[PATCH v2 02/38] x86/tsc: Add standalone helper for getting CPU frequency from CPUID

2025-02-26 Thread Sean Christopherson
functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/tsc.h | 1 + arch/x86/kernel/tsc.c | 37 +++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/t

[PATCH v2 03/38] x86/tsc: Add helper to register CPU and TSC freq calibration routines

2025-02-26 Thread Sean Christopherson
guard against unwanted usage. Add a TODO to call out that AMD_MEM_ENCRYPT is a mess and doesn't depend on HYPERVISOR_GUEST because it gates both guest and host code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/coco/sev/core.c | 4 ++-- arch/x86/i

[PATCH v2 05/38] x86/sev: Move check for SNP Secure TSC support to tsc_early_init()

2025-02-26 Thread Sean Christopherson
dacky Reviewed-by: Nikunj A Dadhania Signed-off-by: Sean Christopherson --- arch/x86/coco/sev/core.c | 3 --- arch/x86/kernel/tsc.c| 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index e6ce4ca72465..dab386f782ce 1

[PATCH v2 06/38] x86/tdx: Override PV calibration routines with CPUID-based calibration

2025-02-26 Thread Sean Christopherson
explaining that CoCo TSC initialization needs to come after hypervisor specific initialization. Cc: Kirill A. Shutemov Signed-off-by: Sean Christopherson --- arch/x86/coco/tdx/tdx.c| 30 +++--- arch/x86/include/asm/tdx.h | 2 ++ arch/x86/kernel/tsc.c | 8

[PATCH v2 07/38] x86/acrn: Mark TSC frequency as known when using ACRN for calibration

2025-02-26 Thread Sean Christopherson
Mark the TSC frequency as known when using ACRN's PV CPUID information. Per commit 81a71f51b89e ("x86/acrn: Set up timekeeping") and common sense, the TSC freq is explicitly provided by the hypervisor. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/acrn.c | 1 + 1

[PATCH v2 08/38] clocksource: hyper-v: Register sched_clock save/restore iff it's necessary

2025-02-26 Thread Sean Christopherson
hich will be reduced in future cleanups) doesn't meaningfully pollute generic code. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/mshyperv.c | 58 -- drivers/clocksource/hyperv_timer.c | 50 ++ 2 files changed, 50 insertions(

[PATCH v2 09/38] clocksource: hyper-v: Drop wrappers to sched_clock save/restore helpers

2025-02-26 Thread Sean Christopherson
Now that all of the Hyper-V timer sched_clock code is located in a single file, drop the superfluous wrappers for the save/restore flows. No functional change intended. Signed-off-by: Sean Christopherson --- drivers/clocksource/hyperv_timer.c | 34 +- include

[PATCH v2 13/38] x86/paravirt: Move handling of unstable PV clocks into paravirt_set_sched_clock()

2025-02-26 Thread Sean Christopherson
functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/paravirt.h | 7 ++- arch/x86/kernel/kvmclock.c | 5 + arch/x86/kernel/paravirt.c | 6 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/paravirt.h b

[PATCH v2 11/38] x86/kvmclock: Setup kvmclock for secondary CPUs iff CONFIG_SMP=y

2025-02-26 Thread Sean Christopherson
PIC got carried forward unnecessarily. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index b898b95a7d50..80d1a06609c8 100644 --- a/arch/x86/kernel/k

[PATCH v2 10/38] clocksource: hyper-v: Don't save/restore TSC offset when using HV sched_clock

2025-02-26 Thread Sean Christopherson
re was, it belongs in common PV code). Signed-off-by: Sean Christopherson --- drivers/clocksource/hyperv_timer.c | 10 -- 1 file changed, 10 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 5a52d0acf31f..4a21874e91b9 100644 ---

[PATCH v2 12/38] x86/kvm: Don't disable kvmclock on BSP in syscore_suspend()

2025-02-26 Thread Sean Christopherson
to kvmclock's suspend/resume logic. Fixes: c02027b5742b ("x86/kvm: Disable kvmclock on all CPUs on shutdown") Cc: sta...@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_para.h | 8 +++- arch/x86/kernel/kvm.c | 15 +++

[PATCH v2 14/38] x86/kvmclock: Move sched_clock save/restore helpers up in kvmclock.c

2025-02-26 Thread Sean Christopherson
Move kvmclock's sched_clock save/restore helper "up" so that they can (eventually) be referenced by kvm_sched_clock_init(). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 108 ++--- 1 f

[PATCH v2 15/38] x86/xen/time: Nullify x86_platform's sched_clock save/restore hooks

2025-02-26 Thread Sean Christopherson
Nullify the x86_platform sched_clock save/restore hooks when setting up Xen's PV clock to make it somewhat obvious the hooks aren't used when running as a Xen guest (Xen uses a paravirtualized suspend/resume flow). Signed-off-by: Sean Christopherson --- arch/x86/xen/time.c | 6

[PATCH v2 16/38] x86/vmware: Nullify save/restore hooks when using VMware's sched_clock

2025-02-26 Thread Sean Christopherson
;s safe/correct for VMware guests to do nothing on suspend/resume, but that's a pre-existing problem. Leave it for a VMware expert to sort out. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/vmware.c | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86

[PATCH v2 17/38] x86/tsc: WARN if TSC sched_clock save/restore used with PV sched_clock

2025-02-26 Thread Sean Christopherson
Now that all PV clocksources override the sched_clock save/restore hooks when overriding sched_clock, WARN if the "default" TSC hooks are invoked when using a PV sched_clock, e.g. to guard against regressions. Signed-off-by: Sean Christopherson --- arch/x86/kernel/tsc.c | 4 ++-- 1 fi

[PATCH v2 18/38] x86/paravirt: Pass sched_clock save/restore helpers during registration

2025-02-26 Thread Sean Christopherson
that has access to a "secure" TSC. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/paravirt.h| 8 +--- arch/x86/kernel/cpu/vmware.c | 7 ++- arch/x86/kernel/kvmclock.c | 5 ++--- arch/x86/kernel/paravirt.c

[PATCH v2 19/38] x86/kvmclock: Move kvm_sched_clock_init() down in kvmclock.c

2025-02-26 Thread Sean Christopherson
int to inline a single-use function, and an extra CALL+RET pair during boot is a complete non-issue. And, if the compiler ignores the hint and does NOT inline the function, the resulting code may not get discarded after boot due lack of an __init annotation. No functional change intended. Signed-off

[PATCH v2 21/38] x86/pvclock: Mark setup helpers and related various as __init/__ro_after_init

2025-02-26 Thread Sean Christopherson
Now that Xen PV clock and kvmclock explicitly do setup only during init, tag the common PV clock flags/vsyscall variables and their mutators with __init. Signed-off-by: Sean Christopherson --- arch/x86/kernel/pvclock.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a

[PATCH v2 23/38] x86/kvmclock: Refactor handling of PVCLOCK_TSC_STABLE_BIT during kvmclock_init()

2025-02-26 Thread Sean Christopherson
KVM_FEATURE_CLOCKSOURCE_STABLE_BIT is set could very, very theoretically result in a change in behavior. In practice, the kernel only supports a single PV clock. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 15 +++ 1 file changed, 11 insertions(+), 4 deletions

[PATCH v2 22/38] x86/pvclock: WARN if pvclock's valid_flags are overwritten

2025-02-26 Thread Sean Christopherson
WARN if the common PV clock valid_flags are overwritten; all PV clocks expect that they are the one and only PV clock, i.e. don't guard against another PV clock having modified the flags. Signed-off-by: Sean Christopherson --- arch/x86/kernel/pvclock.c | 1 + 1 file changed, 1 inse

[PATCH v2 20/38] x86/xen/time: Mark xen_setup_vsyscall_time_info() as __init

2025-02-26 Thread Sean Christopherson
Annotate xen_setup_vsyscall_time_info() as being used only during kernel initialization; it's called only by xen_time_init(), which is already tagged __init. Signed-off-by: Sean Christopherson --- arch/x86/xen/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arc

[PATCH v2 24/38] timekeeping: Resume clocksources before reading persistent clock

2025-02-26 Thread Sean Christopherson
ource supported by the kernel depends on a persistent clock. Signed-off-by: Sean Christopherson --- kernel/time/timekeeping.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 1e67d076f195..332d053fa9ce 100644

[PATCH v2 25/38] x86/kvmclock: Hook clocksource.suspend/resume when kvmclock isn't sched_clock

2025-02-26 Thread Sean Christopherson
Save/restore kvmclock across suspend/resume via clocksource hooks when kvmclock isn't being used for sched_clock. This will allow using kvmclock as a clocksource (or for wallclock!) without also using it for sched_clock. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c

[PATCH v2 26/38] x86/kvmclock: WARN if wall clock is read while kvmclock is suspended

2025-02-26 Thread Sean Christopherson
WARN if kvmclock is still suspended when its wallclock is read, i.e. when the kernel reads its persistent clock. The wallclock subtly depends on the BSP's kvmclock being enabled, and returns garbage if kvmclock is disabled. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.

[PATCH v2 04/38] x86/sev: Mark TSC as reliable when configuring Secure TSC

2025-02-26 Thread Sean Christopherson
TSC_RELIABLE when overriding the TSC calibration routine. Cc: Tom Lendacky Reviewed-by: Nikunj A Dadhania Signed-off-by: Sean Christopherson --- arch/x86/coco/sev/core.c | 2 ++ arch/x86/mm/mem_encrypt_amd.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86

[PATCH v2 31/38] x86/tsc: Pass KNOWN_FREQ and RELIABLE as params to registration

2025-02-26 Thread Sean Christopherson
rse" routine. As a bonus, the flags also give developers working on new PV code a heads up that they should at least mark the TSC as having a known frequency. Signed-off-by: Sean Christopherson --- arch/x86/coco/sev/core.c | 6 ++ arch/x86/coco/tdx/tdx.c| 7 ++-

[PATCH v2 27/38] x86/kvmclock: Enable kvmclock on APs during onlining if kvmclock isn't sched_clock

2025-02-26 Thread Sean Christopherson
s are invoked depends entirely on when a subsystem is initialized and thus registers its hooks. Opportunsitically make the registration messages more precise to help debug issues where kvmclock is enabled too late. Opportunstically WARN in kvmclock_{suspend,resume}() to harden against future b

[PATCH v2 28/38] x86/paravirt: Mark __paravirt_set_sched_clock() as __init

2025-02-26 Thread Sean Christopherson
igned-off-by: Sean Christopherson --- arch/x86/include/asm/paravirt.h | 9 + arch/x86/kernel/paravirt.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index dc26a3c26527..e6d5e77753c4 100644

[PATCH v2 29/38] x86/paravirt: Plumb a return code into __paravirt_set_sched_clock()

2025-02-26 Thread Sean Christopherson
extra" beyond simply registering itself as sched_clock, i.e. is the only caller that needs to check the new return value. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/paravirt.h | 6 +++--- arch/x86/kernel/kvmclock.c | 7 +-- arch/x86/kernel/paravirt.c | 5 +++-

[PATCH v2 34/38] x86/kvmclock: Get CPU base frequency from CPUID when it's available

2025-02-26 Thread Sean Christopherson
it's nonsensical, especially if the hypervisor explicitly enumerates the CPU frequency. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmcl

[PATCH v2 30/38] x86/paravirt: Don't use a PV sched_clock in CoCo guests with trusted TSC

2025-02-26 Thread Sean Christopherson
TSC on such platforms is faster than any PV clock, and sched_clock is all about speed. Signed-off-by: Sean Christopherson --- arch/x86/kernel/paravirt.c | 9 + 1 file changed, 9 insertions(+) diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index a3a1359cfc26

[PATCH v2 32/38] x86/tsc: Rejects attempts to override TSC calibration with lesser routine

2025-02-26 Thread Sean Christopherson
rusted source of information (hardware/firmware) is being discarded in favor of a less trusted source (hypervisor). Signed-off-by: Sean Christopherson --- arch/x86/kernel/tsc.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index be58df

[PATCH v2 33/38] x86/kvmclock: Mark TSC as reliable when it's constant and nonstop

2025-02-26 Thread Sean Christopherson
ksource is usually emulated in host userspace, i.e. reading the clock incurs a roundtrip cost of thousands of cycles. Marking the TSC reliable addresses a flaw where the TSC will occasionally be marked unstable if the host is under moderate/heavy load. Signed-off-by: Sean Christopherson --- arch/

[PATCH v2 37/38] x86/kvmclock: Use TSC for sched_clock if it's constant and non-stop

2025-02-26 Thread Sean Christopherson
. acknowledging PVCLOCK_GUEST_STOPPED needs to be decoupled from sched_clock() no matter what. Link: https://lore.kernel.org/all/z4hdk27ov7wk5...@google.com Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/

[PATCH v2 38/38] x86/paravirt: kvmclock: Setup kvmclock early iff it's sched_clock

2025-02-26 Thread Sean Christopherson
printk. Rearranging the hook doesn't exactly reduce complexity; arguably it does the opposite. But as-is, it's practically impossible to understand *why* kvmclock needs to do early configuration. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/paravirt.h | 10 --

[PATCH v2 35/38] x86/kvmclock: Get TSC frequency from CPUID when its available

2025-02-26 Thread Sean Christopherson
using CPUID.0x15 will allow stuffing the local APIC timer frequency based on the core crystal frequency, i.e. will allow skipping APIC timer calibration. Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 15 ++- 1 file changed, 10 insertions(+), 5 deletions(-) diff

[PATCH v2 36/38] x86/kvmclock: Stuff local APIC bus period when core crystal freq comes from CPUID

2025-02-26 Thread Sean Christopherson
frequency is enumerated via CPUID.0x15. The APIC timer frequency will be the processor’s bus clock or core crystal clock frequency (when TSC/core crystal clock ratio is enumerated in CPUID leaf 0x15). Signed-off-by: Sean Christopherson --- arch/x86/kernel/kvmclock.c | 12 +++- 1 fi

Re: [PATCH v2 00/38] x86: Try to wrangle PV clocks vs. TSC

2025-03-03 Thread Sean Christopherson
On Fri, Feb 28, 2025, David Woodhouse wrote: > On Wed, 2025-02-26 at 18:18 -0800, Sean Christopherson wrote: > > This... snowballed a bit. > > > > The bulk of the changes are in kvmclock and TSC, but pretty much every > > hypervisor's guest-side code gets touched

Re: [PATCH v2 08/38] clocksource: hyper-v: Register sched_clock save/restore iff it's necessary

2025-03-04 Thread Sean Christopherson
On Tue, Mar 04, 2025, Michael Kelley wrote: > From: Sean Christopherson Sent: Wednesday, February 26, > 2025 6:18 PM > > > > Register the Hyper-V timer callbacks or saving/restoring its PV sched_clock > > s/or/for/ > > > if and only if the timer is ac