All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org
Cc: Joao Martins <joao.m.martins@oracle.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	David Vrabel <david.vrabel@citrix.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	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	[thread overview]
Message-ID: <1451339557-24473-3-git-send-email-joao.m.martins@oracle.com> (raw)
In-Reply-To: <1451339557-24473-1-git-send-email-joao.m.martins@oracle.com>

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 <joao.m.martins@oracle.com>
---
 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 <linux/slab.h>
 #include <linux/pvclock_gtod.h>
 #include <linux/timekeeper_internal.h>
+#include <linux/memblock.h>
 
 #include <asm/pvclock.h>
 #include <asm/xen/hypervisor.h>
@@ -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


  parent reply	other threads:[~2015-12-28 21:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-28 21:52 [PATCH RFC 0/3] x86/xen: pvclock vdso support Joao Martins
2015-12-28 21:52 ` [PATCH RFC 1/3] x86/pvclock: add setter for pvclock_pvti_cpu0_va Joao Martins
2015-12-28 23:45   ` Andy Lutomirski
2015-12-28 23:45   ` Andy Lutomirski
2015-12-29 12:50     ` Joao Martins
2015-12-29 12:50     ` Joao Martins
2015-12-29 13:03       ` Andy Lutomirski
2015-12-29 13:03       ` Andy Lutomirski
2015-12-28 21:52 ` Joao Martins
2015-12-28 21:52 ` Joao Martins [this message]
2016-01-04 16:07   ` [PATCH RFC 2/3] x86/xen/time: setup vcpu 0 time info page Boris Ostrovsky
2016-01-04 16:07   ` Boris Ostrovsky
2016-01-04 20:41     ` Joao Martins
2016-01-04 20:41     ` Joao Martins
2016-01-04 21:34       ` Boris Ostrovsky
2016-01-04 21:34       ` Boris Ostrovsky
2016-01-05 12:20         ` Joao Martins
2016-01-05 12:20         ` Joao Martins
2015-12-28 21:52 ` Joao Martins
2015-12-28 21:52 ` [PATCH RFC 3/3] xen/Kconfig: add XEN_TIME_VSYSCALL option Joao Martins
2015-12-28 21:52 ` Joao Martins
2016-01-04 16:12   ` David Vrabel
2016-01-04 16:12   ` [Xen-devel] " David Vrabel
2016-01-04 16:15     ` Boris Ostrovsky
2016-01-04 16:15     ` [Xen-devel] " Boris Ostrovsky
2016-01-04 20:41       ` Joao Martins
2016-01-04 20:41       ` [Xen-devel] " Joao Martins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1451339557-24473-3-git-send-email-joao.m.martins@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=hpa@zytor.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.