From 4ccefbe597392d2914cf7ad904e33c734972681d Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Thu, 5 Nov 2015 15:15:07 +0000 Subject: xen: move xen_setup_runstate_info and get_runstate_snapshot to drivers/xen/time.c Signed-off-by: Stefano Stabellini Acked-by: Ian Campbell Reviewed-by: Konrad Rzeszutek Wilk --- arch/x86/xen/time.c | 76 +---------------------------------------------------- 1 file changed, 1 insertion(+), 75 deletions(-) (limited to 'arch/x86') diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index f1ba6a092854..041d4cda3939 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -32,86 +32,12 @@ #define TIMER_SLOP 100000 #define NS_PER_TICK (1000000000LL / HZ) -/* runstate info updated by Xen */ -static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate); - /* snapshots of runstate info */ static DEFINE_PER_CPU(struct vcpu_runstate_info, xen_runstate_snapshot); /* unused ns of stolen time */ static DEFINE_PER_CPU(u64, xen_residual_stolen); -/* return an consistent snapshot of 64-bit time/counter value */ -static u64 get64(const u64 *p) -{ - u64 ret; - - if (BITS_PER_LONG < 64) { - u32 *p32 = (u32 *)p; - u32 h, l; - - /* - * Read high then low, and then make sure high is - * still the same; this will only loop if low wraps - * and carries into high. - * XXX some clean way to make this endian-proof? - */ - do { - h = p32[1]; - barrier(); - l = p32[0]; - barrier(); - } while (p32[1] != h); - - ret = (((u64)h) << 32) | l; - } else - ret = *p; - - return ret; -} - -/* - * Runstate accounting - */ -static void get_runstate_snapshot(struct vcpu_runstate_info *res) -{ - u64 state_time; - struct vcpu_runstate_info *state; - - BUG_ON(preemptible()); - - state = this_cpu_ptr(&xen_runstate); - - /* - * The runstate info is always updated by the hypervisor on - * the current CPU, so there's no need to use anything - * stronger than a compiler barrier when fetching it. - */ - do { - state_time = get64(&state->state_entry_time); - barrier(); - *res = *state; - barrier(); - } while (get64(&state->state_entry_time) != state_time); -} - -/* return true when a vcpu could run but has no real cpu to run on */ -bool xen_vcpu_stolen(int vcpu) -{ - return per_cpu(xen_runstate, vcpu).state == RUNSTATE_runnable; -} - -void xen_setup_runstate_info(int cpu) -{ - struct vcpu_register_runstate_memory_area area; - - area.addr.v = &per_cpu(xen_runstate, cpu); - - if (HYPERVISOR_vcpu_op(VCPUOP_register_runstate_memory_area, - cpu, &area)) - BUG(); -} - static void do_stolen_accounting(void) { struct vcpu_runstate_info state; @@ -119,7 +45,7 @@ static void do_stolen_accounting(void) s64 runnable, offline, stolen; cputime_t ticks; - get_runstate_snapshot(&state); + xen_get_runstate_snapshot(&state); WARN_ON(state.state != RUNSTATE_running); -- cgit v1.2.1 From cfafae940381207d48b11a73a211142dba5947d3 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 23 Nov 2015 10:36:12 +0000 Subject: xen: rename dom0_op to platform_op The dom0_op hypercall has been renamed to platform_op since Xen 3.2, which is ancient, and modern upstream Linux kernels cannot run as dom0 and it anymore anyway. Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky --- arch/x86/include/asm/xen/hypercall.h | 6 +++--- arch/x86/xen/apic.c | 2 +- arch/x86/xen/enlighten.c | 8 ++++---- arch/x86/xen/time.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'arch/x86') diff --git a/arch/x86/include/asm/xen/hypercall.h b/arch/x86/include/asm/xen/hypercall.h index 4c20dd333412..3bcdcc84259d 100644 --- a/arch/x86/include/asm/xen/hypercall.h +++ b/arch/x86/include/asm/xen/hypercall.h @@ -310,10 +310,10 @@ HYPERVISOR_mca(struct xen_mc *mc_op) } static inline int -HYPERVISOR_dom0_op(struct xen_platform_op *platform_op) +HYPERVISOR_platform_op(struct xen_platform_op *op) { - platform_op->interface_version = XENPF_INTERFACE_VERSION; - return _hypercall1(int, dom0_op, platform_op); + op->interface_version = XENPF_INTERFACE_VERSION; + return _hypercall1(int, platform_op, op); } static inline int diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c index acda713ab5be..abf4901c917b 100644 --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -64,7 +64,7 @@ static u32 xen_apic_read(u32 reg) if (reg != APIC_ID) return 0; - ret = HYPERVISOR_dom0_op(&op); + ret = HYPERVISOR_platform_op(&op); if (ret) return 0; diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 5774800ff583..f963c40fae01 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -415,7 +415,7 @@ static bool __init xen_check_mwait(void) set_xen_guest_handle(op.u.set_pminfo.pdc, buf); - if ((HYPERVISOR_dom0_op(&op) == 0) && + if ((HYPERVISOR_platform_op(&op) == 0) && (buf[2] & (ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH))) { cpuid_leaf5_ecx_val = cx; cpuid_leaf5_edx_val = dx; @@ -1374,7 +1374,7 @@ static void __init xen_boot_params_init_edd(void) info->params.length = sizeof(info->params); set_xen_guest_handle(op.u.firmware_info.u.disk_info.edd_params, &info->params); - ret = HYPERVISOR_dom0_op(&op); + ret = HYPERVISOR_platform_op(&op); if (ret) break; @@ -1392,7 +1392,7 @@ static void __init xen_boot_params_init_edd(void) op.u.firmware_info.type = XEN_FW_DISK_MBR_SIGNATURE; for (nr = 0; nr < EDD_MBR_SIG_MAX; nr++) { op.u.firmware_info.index = nr; - ret = HYPERVISOR_dom0_op(&op); + ret = HYPERVISOR_platform_op(&op); if (ret) break; mbr_signature[nr] = op.u.firmware_info.u.disk_mbr_signature.mbr_signature; @@ -1698,7 +1698,7 @@ asmlinkage __visible void __init xen_start_kernel(void) xen_start_info->console.domU.mfn = 0; xen_start_info->console.domU.evtchn = 0; - if (HYPERVISOR_dom0_op(&op) == 0) + if (HYPERVISOR_platform_op(&op) == 0) boot_params.kbd_status = op.u.firmware_info.u.kbd_shift_flags; /* Make sure ACS will be enabled */ diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 041d4cda3939..663c2ea449c7 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -139,7 +139,7 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, op.u.settime.nsecs = now.tv_nsec; op.u.settime.system_time = xen_clocksource_read(); - (void)HYPERVISOR_dom0_op(&op); + (void)HYPERVISOR_platform_op(&op); /* * Move the next drift compensation time 11 minutes -- cgit v1.2.1 From f3d6027ee0568b5442077120beeb5d9d17c2d0da Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 23 Nov 2015 10:38:12 +0000 Subject: xen: introduce XENPF_settime64 Rename the current XENPF_settime hypercall and related struct to XENPF_settime32. Signed-off-by: Stefano Stabellini Acked-by: Arnd Bergmann Reviewed-by: Boris Ostrovsky --- arch/x86/xen/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'arch/x86') diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 663c2ea449c7..3bbd377e1657 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -134,10 +134,10 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, if (!was_set && timespec_compare(&now, &next_sync) < 0) return NOTIFY_OK; - op.cmd = XENPF_settime; - op.u.settime.secs = now.tv_sec; - op.u.settime.nsecs = now.tv_nsec; - op.u.settime.system_time = xen_clocksource_read(); + op.cmd = XENPF_settime32; + op.u.settime32.secs = now.tv_sec; + op.u.settime32.nsecs = now.tv_nsec; + op.u.settime32.system_time = xen_clocksource_read(); (void)HYPERVISOR_platform_op(&op); -- cgit v1.2.1 From 760968631323f710ea0824369bbd65f812c82f08 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Mon, 23 Nov 2015 10:42:12 +0000 Subject: xen/x86: support XENPF_settime64 Try XENPF_settime64 first, if it is not available fall back to XENPF_settime32. No need to call __current_kernel_time() when all the info needed are already passed via the struct timekeeper * argument. Return NOTIFY_BAD in case of errors. Signed-off-by: Stefano Stabellini Acked-by: Arnd Bergmann Reviewed-by: Boris Ostrovsky --- arch/x86/xen/time.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'arch/x86') diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 3bbd377e1657..4b8af45b211a 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -123,9 +124,13 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, static struct timespec next_sync; struct xen_platform_op op; - struct timespec now; + struct timespec64 now; + struct timekeeper *tk = priv; + static bool settime64_supported = true; + int ret; - now = __current_kernel_time(); + now.tv_sec = tk->xtime_sec; + now.tv_nsec = (long)(tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift); /* * We only take the expensive HV call when the clock was set @@ -134,12 +139,28 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, if (!was_set && timespec_compare(&now, &next_sync) < 0) return NOTIFY_OK; - op.cmd = XENPF_settime32; - op.u.settime32.secs = now.tv_sec; - op.u.settime32.nsecs = now.tv_nsec; - op.u.settime32.system_time = xen_clocksource_read(); +again: + if (settime64_supported) { + op.cmd = XENPF_settime64; + op.u.settime64.mbz = 0; + op.u.settime64.secs = now.tv_sec; + op.u.settime64.nsecs = now.tv_nsec; + op.u.settime64.system_time = xen_clocksource_read(); + } else { + op.cmd = XENPF_settime32; + op.u.settime32.secs = now.tv_sec; + op.u.settime32.nsecs = now.tv_nsec; + op.u.settime32.system_time = xen_clocksource_read(); + } + + ret = HYPERVISOR_platform_op(&op); - (void)HYPERVISOR_platform_op(&op); + if (ret == -ENOSYS && settime64_supported) { + settime64_supported = false; + goto again; + } + if (ret < 0) + return NOTIFY_BAD; /* * Move the next drift compensation time 11 minutes -- cgit v1.2.1 From 187b26a97244b1083d573175650f41b2267ac635 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Tue, 24 Nov 2015 14:53:02 +0000 Subject: xen/x86: convert remaining timespec to timespec64 in xen_pvclock_gtod_notify Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky --- arch/x86/xen/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arch/x86') diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 4b8af45b211a..a0a4e554c6f1 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -121,7 +121,7 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, unsigned long was_set, void *priv) { /* Protected by the calling core code serialization */ - static struct timespec next_sync; + static struct timespec64 next_sync; struct xen_platform_op op; struct timespec64 now; @@ -136,7 +136,7 @@ static int xen_pvclock_gtod_notify(struct notifier_block *nb, * We only take the expensive HV call when the clock was set * or when the 11 minutes RTC synchronization time elapsed. */ - if (!was_set && timespec_compare(&now, &next_sync) < 0) + if (!was_set && timespec64_compare(&now, &next_sync) < 0) return NOTIFY_OK; again: -- cgit v1.2.1 From 6a1f513776b78c994045287073e55bae44ed9f8c Mon Sep 17 00:00:00 2001 From: "Ouyang Zhaowei (Charles)" Date: Wed, 6 May 2015 09:47:04 +0800 Subject: x86/xen: don't reset vcpu_info on a cancelled suspend On a cancelled suspend the vcpu_info location does not change (it's still in the per-cpu area registered by xen_vcpu_setup()). So do not call xen_hvm_init_shared_info() which would make the kernel think its back in the shared info. With the wrong vcpu_info, events cannot be received and the domain will hang after a cancelled suspend. Signed-off-by: Charles Ouyang Reviewed-by: Boris Ostrovsky Cc: Signed-off-by: David Vrabel --- arch/x86/xen/suspend.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'arch/x86') diff --git a/arch/x86/xen/suspend.c b/arch/x86/xen/suspend.c index 3705eabd7e22..5df55833b529 100644 --- a/arch/x86/xen/suspend.c +++ b/arch/x86/xen/suspend.c @@ -33,7 +33,8 @@ static void xen_hvm_post_suspend(int suspend_cancelled) { #ifdef CONFIG_XEN_PVHVM int cpu; - xen_hvm_init_shared_info(); + if (!suspend_cancelled) + xen_hvm_init_shared_info(); xen_callback_vector(); xen_unplug_emulated_devices(); if (xen_feature(XENFEAT_hvm_safe_pvclock)) { -- cgit v1.2.1