diff mbox

Implement new hypercall to return domain id

Message ID 20170329180739.949-1-eggi.innovations@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felix Schmoll March 29, 2017, 6:07 p.m. UTC
Minimal implementation of a new hypercall that returns the domain
id of the invoking domain with adjustments in libxc.

Signed-off-by: Felix Schmoll <eggi.innovations@gmail.com>
---
 tools/libxc/include/xenctrl.h | 1 +
 tools/libxc/xc_private.c      | 6 ++++++
 xen/arch/arm/traps.c          | 1 +
 xen/arch/x86/hvm/hypercall.c  | 1 +
 xen/arch/x86/hypercall.c      | 1 +
 xen/arch/x86/pv/hypercall.c   | 1 +
 xen/common/kernel.c           | 6 ++++++
 xen/include/public/xen.h      | 1 +
 xen/include/xen/hypercall.h   | 3 +++
 9 files changed, 21 insertions(+)

Comments

Wei Liu March 29, 2017, 6:27 p.m. UTC | #1
For all other people who happen to see this patch: this isn't meant to
be applied.

Cc Juergen as well.

On Wed, Mar 29, 2017 at 08:07:39PM +0200, Felix Schmoll wrote:
> Minimal implementation of a new hypercall that returns the domain
> id of the invoking domain with adjustments in libxc.
> 

I think this patch looks good.

If you feel like it, a more advanced challenge would be to pass a
userspace buffer down to Xen and have the hypervisor write something
back. Some new APIs are needed but there is plenty of examples in libxc.

You don't have to do it, and you don't need to post patch. It's just
something you might be interested in trying in case you have time.

Wei.
diff mbox

Patch

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 2d97d36c38..1e152c8a07 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1569,6 +1569,7 @@  int xc_domctl(xc_interface *xch, struct xen_domctl *domctl);
 int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl);
 
 int xc_version(xc_interface *xch, int cmd, void *arg);
+int xc_domid(xc_interface *xch);
 
 int xc_flask_op(xc_interface *xch, xen_flask_op_t *op);
 
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index 72e6242417..37b11e41a9 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -530,6 +530,12 @@  int xc_version(xc_interface *xch, int cmd, void *arg)
     return rc;
 }
 
+int xc_domid(xc_interface *xch)
+{
+    return xencall0(xch->xcall, __HYPERVISOR_domain_id);
+}
+
+
 unsigned long xc_make_page_below_4G(
     xc_interface *xch, uint32_t domid, unsigned long mfn)
 {
diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 614501f761..eddb264f2d 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -1297,6 +1297,7 @@  static arm_hypercall_t arm_hypercall_table[] = {
     HYPERCALL(platform_op, 1),
     HYPERCALL_ARM(vcpu_op, 3),
     HYPERCALL(vm_assist, 2),
+    HYPERCALL(domain_id, 0),
 };
 
 #ifndef NDEBUG
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index e7238ce293..3d541e01e1 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -132,6 +132,7 @@  static const hypercall_table_t hvm_hypercall_table[] = {
     COMPAT_CALL(mmuext_op),
     HYPERCALL(xenpmu_op),
     COMPAT_CALL(dm_op),
+    HYPERCALL(domain_id),
     HYPERCALL(arch_1)
 };
 
diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c
index e30181817a..184741bf16 100644
--- a/xen/arch/x86/hypercall.c
+++ b/xen/arch/x86/hypercall.c
@@ -67,6 +67,7 @@  const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(tmem_op, 1),
     ARGS(xenpmu_op, 2),
     ARGS(dm_op, 3),
+    ARGS(domain_id, 0),
     ARGS(mca, 1),
     ARGS(arch_1, 1),
 };
diff --git a/xen/arch/x86/pv/hypercall.c b/xen/arch/x86/pv/hypercall.c
index 9d29d2f088..f12314b5ca 100644
--- a/xen/arch/x86/pv/hypercall.c
+++ b/xen/arch/x86/pv/hypercall.c
@@ -79,6 +79,7 @@  static const hypercall_table_t pv_hypercall_table[] = {
 #endif
     HYPERCALL(xenpmu_op),
     COMPAT_CALL(dm_op),
+    HYPERCALL(domain_id),
     HYPERCALL(mca),
     HYPERCALL(arch_1),
 };
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 84618715dc..5107aacd06 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -431,6 +431,12 @@  DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return -ENOSYS;
 }
 
+DO(domain_id)(void)
+{
+    struct domain *d = current->domain;
+    return d->domain_id;
+}
+
 DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     struct xennmi_callback cb;
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 91ba8bb48e..3a8c4af281 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -121,6 +121,7 @@  DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
 #define __HYPERVISOR_xenpmu_op            40
 #define __HYPERVISOR_dm_op                41
+#define __HYPERVISOR_domain_id            42
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h
index cc99aea57d..5c7bc6233e 100644
--- a/xen/include/xen/hypercall.h
+++ b/xen/include/xen/hypercall.h
@@ -83,6 +83,9 @@  do_xen_version(
     XEN_GUEST_HANDLE_PARAM(void) arg);
 
 extern long
+do_domain_id(void);
+
+extern long
 do_console_io(
     int cmd,
     int count,