From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752851AbbL1VxZ (ORCPT ); Mon, 28 Dec 2015 16:53:25 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:32773 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752764AbbL1VxQ (ORCPT ); Mon, 28 Dec 2015 16:53:16 -0500 From: Joao Martins To: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org Cc: Joao Martins , Konrad Rzeszutek Wilk , Boris Ostrovsky , David Vrabel , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH RFC 2/3] x86/xen/time: setup vcpu 0 time info page Date: Mon, 28 Dec 2015 21:52:36 +0000 Message-Id: <1451339557-24473-3-git-send-email-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1451339557-24473-1-git-send-email-joao.m.martins@oracle.com> References: <1451339557-24473-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to support pvclock vdso on xen we need to setup the time info page for vcpu 0 and register the page with Xen using the VCPUOP_register_vcpu_time_memory_area hypercall. This hypercall will also forcefully update the pvti which will set some of the necessary flags for vdso. Afterwards we check if it supports the PVCLOCK_TSC_STABLE_BIT flag which is mandatory for having vdso/vsyscall support. And if so, it will set the cpu 0 pvti that will be later on used when mapping the vdso image. The xen headers are also updated to include the new hypercall for registering the secondary vcpu_time_info copy. Signed-off-by: Joao Martins --- arch/x86/xen/time.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ include/xen/interface/vcpu.h | 28 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index a0a4e55..c17b1b2 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -403,6 +404,69 @@ static const struct pv_time_ops xen_time_ops __initconst = { .sched_clock = xen_clocksource_read, }; +#ifdef CONFIG_XEN_TIME_VSYSCALL +static struct pvclock_vsyscall_time_info *xen_clock __read_mostly; + +static int xen_setup_vsyscall_time_info(int cpu) +{ + struct pvclock_vsyscall_time_info *ti; + struct vcpu_register_time_memory_area t; + struct pvclock_vcpu_time_info *pvti; + unsigned long mem; + int ret, size; + u8 flags; + + ret = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, + cpu, NULL); + if (ret == -ENOSYS) { + pr_debug("xen: vcpu_time_info placement not supported\n"); + return -ENOTSUPP; + } + + size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)); + mem = memblock_alloc(size, PAGE_SIZE); + if (!mem) + return -ENOMEM; + + ti = __va(mem); + memset(ti, 0, size); + + t.addr.v = &ti[cpu].pvti; + + ret = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_time_memory_area, + cpu, &t); + + if (ret) { + pr_debug("xen: cannot register vcpu_time_info err %d\n", ret); + memblock_free(mem, size); + return ret; + } + + pvti = &ti[cpu].pvti; + flags = pvti->flags; + + if (!(flags & PVCLOCK_TSC_STABLE_BIT)) { + pr_debug("xen: VCLOCK_PVCLOCK not supported\n"); + memblock_free(mem, size); + return -ENOTSUPP; + } + + xen_clock = ti; + pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT); + pvclock_set_pvti_cpu0_va(xen_clock); + + xen_clocksource.archdata.vclock_mode = VCLOCK_PVCLOCK; + + return 0; +} +#else +static int xen_setup_vsyscall_time_info(int cpu) +{ + return -1; +} + +#endif /* CONFIG_XEN_TIME_VSYSCALL */ + static void __init xen_time_init(void) { int cpu = smp_processor_id(); @@ -431,6 +495,8 @@ static void __init xen_time_init(void) xen_setup_timer(cpu); xen_setup_cpu_clockevents(); + xen_setup_vsyscall_time_info(cpu); + if (xen_initial_domain()) pvclock_gtod_register_notifier(&xen_pvclock_gtod_notifier); } diff --git a/include/xen/interface/vcpu.h b/include/xen/interface/vcpu.h index b05288c..902b59e 100644 --- a/include/xen/interface/vcpu.h +++ b/include/xen/interface/vcpu.h @@ -172,4 +172,32 @@ DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_vcpu_info); /* Send an NMI to the specified VCPU. @extra_arg == NULL. */ #define VCPUOP_send_nmi 11 + +/* + * Register a memory location to get a secondary copy of the vcpu time + * parameters. The master copy still exists as part of the vcpu shared + * memory area, and this secondary copy is updated whenever the master copy + * is updated (and using the same versioning scheme for synchronisation). + * + * The intent is that this copy may be mapped (RO) into userspace so + * that usermode can compute system time using the time info and the + * tsc. Usermode will see an array of vcpu_time_info structures, one + * for each vcpu, and choose the right one by an existing mechanism + * which allows it to get the current vcpu number (such as via a + * segment limit). It can then apply the normal algorithm to compute + * system time from the tsc. + * + * @extra_arg == pointer to vcpu_register_time_info_memory_area structure. + */ +#define VCPUOP_register_vcpu_time_memory_area 13 +DEFINE_GUEST_HANDLE_STRUCT(vcpu_time_info_t); +struct vcpu_register_time_memory_area { + union { + GUEST_HANDLE(vcpu_time_info_t) h; + struct pvclock_vcpu_time_info *v; + uint64_t p; + } addr; +}; +DEFINE_GUEST_HANDLE_STRUCT(vcpu_register_time_memory_area_t); + #endif /* __XEN_PUBLIC_VCPU_H__ */ -- 2.1.4