Skip to content

Commit d14816d

Browse files
jgross1gregkh
authored andcommitted
xen: Fix x86 sched_clock() interface for xen
commit 867cefb upstream. Commit f94c8d1 ("sched/clock, x86/tsc: Rework the x86 'unstable' sched_clock() interface") broke Xen guest time handling across migration: [ 187.249951] Freezing user space processes ... (elapsed 0.001 seconds) done. [ 187.251137] OOM killer disabled. [ 187.251137] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. [ 187.252299] suspending xenstore... [ 187.266987] xen:grant_table: Grant tables using version 1 layout [18446743811.706476] OOM killer enabled. [18446743811.706478] Restarting tasks ... done. [18446743811.720505] Setting capacity to 16777216 Fix that by setting xen_sched_clock_offset at resume time to ensure a monotonic clock value. [boris: replaced pr_info() with pr_info_once() in xen_callback_vector() to avoid printing with incorrect timestamp during resume (as we haven't re-adjusted the clock yet)] Fixes: f94c8d1 ("sched/clock, x86/tsc: Rework the x86 'unstable' sched_clock() interface") Cc: <[email protected]> # 4.11 Reported-by: Hans van Kranenburg <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Tested-by: Hans van Kranenburg <[email protected]> Signed-off-by: Boris Ostrovsky <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent b7984d4 commit d14816d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

arch/x86/xen/time.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ void xen_timer_resume(void)
361361
{
362362
int cpu;
363363

364-
pvclock_resume();
365-
366364
if (xen_clockevent != &xen_vcpuop_clockevent)
367365
return;
368366

@@ -379,12 +377,15 @@ static const struct pv_time_ops xen_time_ops __initconst = {
379377
};
380378

381379
static struct pvclock_vsyscall_time_info *xen_clock __read_mostly;
380+
static u64 xen_clock_value_saved;
382381

383382
void xen_save_time_memory_area(void)
384383
{
385384
struct vcpu_register_time_memory_area t;
386385
int ret;
387386

387+
xen_clock_value_saved = xen_clocksource_read() - xen_sched_clock_offset;
388+
388389
if (!xen_clock)
389390
return;
390391

@@ -404,7 +405,7 @@ void xen_restore_time_memory_area(void)
404405
int ret;
405406

406407
if (!xen_clock)
407-
return;
408+
goto out;
408409

409410
t.addr.v = &xen_clock->pvti;
410411

@@ -421,6 +422,11 @@ void xen_restore_time_memory_area(void)
421422
if (ret != 0)
422423
pr_notice("Cannot restore secondary vcpu_time_info (err %d)",
423424
ret);
425+
426+
out:
427+
/* Need pvclock_resume() before using xen_clocksource_read(). */
428+
pvclock_resume();
429+
xen_sched_clock_offset = xen_clocksource_read() - xen_clock_value_saved;
424430
}
425431

426432
static void xen_setup_vsyscall_time_info(void)

drivers/xen/events/events_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ void xen_callback_vector(void)
16501650
xen_have_vector_callback = 0;
16511651
return;
16521652
}
1653-
pr_info("Xen HVM callback vector for event delivery is enabled\n");
1653+
pr_info_once("Xen HVM callback vector for event delivery is enabled\n");
16541654
alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,
16551655
xen_hvm_callback_vector);
16561656
}

0 commit comments

Comments
 (0)