Skip to content

Commit

Permalink
xen: Fix x86 sched_clock() interface for xen
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jgross1 authored and Boris Ostrovsky committed Jan 16, 2019
1 parent b471109 commit 867cefb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions arch/x86/xen/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ void xen_timer_resume(void)
{
int cpu;

pvclock_resume();

if (xen_clockevent != &xen_vcpuop_clockevent)
return;

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

static struct pvclock_vsyscall_time_info *xen_clock __read_mostly;
static u64 xen_clock_value_saved;

void xen_save_time_memory_area(void)
{
struct vcpu_register_time_memory_area t;
int ret;

xen_clock_value_saved = xen_clocksource_read() - xen_sched_clock_offset;

if (!xen_clock)
return;

Expand All @@ -404,7 +405,7 @@ void xen_restore_time_memory_area(void)
int ret;

if (!xen_clock)
return;
goto out;

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

Expand All @@ -421,6 +422,11 @@ void xen_restore_time_memory_area(void)
if (ret != 0)
pr_notice("Cannot restore secondary vcpu_time_info (err %d)",
ret);

out:
/* Need pvclock_resume() before using xen_clocksource_read(). */
pvclock_resume();
xen_sched_clock_offset = xen_clocksource_read() - xen_clock_value_saved;
}

static void xen_setup_vsyscall_time_info(void)
Expand Down
2 changes: 1 addition & 1 deletion drivers/xen/events/events_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ void xen_callback_vector(void)
xen_have_vector_callback = 0;
return;
}
pr_info("Xen HVM callback vector for event delivery is enabled\n");
pr_info_once("Xen HVM callback vector for event delivery is enabled\n");
alloc_intr_gate(HYPERVISOR_CALLBACK_VECTOR,
xen_hvm_callback_vector);
}
Expand Down

0 comments on commit 867cefb

Please sign in to comment.