aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorRoger Pau Monne <roger.pau@citrix.com>2020-06-25 16:25:29 +0000
committerRoger Pau Monné <royger@FreeBSD.org>2021-01-11 15:33:27 +0000
commited78016d005c9ec97883a33c4468052ca9880c4f (patch)
tree54cb5e155fd525947bd4bb49b04ccd3376ee309f /sys
parent658860e2d07065b4203bb3e7779bee0512c65c92 (diff)
downloadsrc-ed78016d005c9ec97883a33c4468052ca9880c4f.tar.gz
src-ed78016d005c9ec97883a33c4468052ca9880c4f.zip
xen/privcmd: implement the dm op ioctl
Use an interface compatible with the Linux one so that the user-space libraries already using the Linux interface can be used without much modifications. This allows user-space to make use of the dm_op family of hypercalls, which are used by device models. Sponsored by: Citrix Systems R&D
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/include/xen/hypercall.h7
-rw-r--r--sys/dev/xen/privcmd/privcmd.c49
-rw-r--r--sys/i386/include/xen/hypercall.h7
-rw-r--r--sys/xen/hypervisor.h1
-rw-r--r--sys/xen/privcmd.h13
5 files changed, 77 insertions, 0 deletions
diff --git a/sys/amd64/include/xen/hypercall.h b/sys/amd64/include/xen/hypercall.h
index e427bbf4d43f..6d00d4a6ebd8 100644
--- a/sys/amd64/include/xen/hypercall.h
+++ b/sys/amd64/include/xen/hypercall.h
@@ -427,6 +427,13 @@ HYPERVISOR_kexec_op(
return _hypercall2(int, kexec_op, op, args);
}
+static inline int __must_check
+HYPERVISOR_dm_op(
+ domid_t domid, unsigned int nr_bufs, const void *bufs)
+{
+ return _hypercall3(int, dm_op, domid, nr_bufs, bufs);
+}
+
#undef __must_check
#endif /* __MACHINE_XEN_HYPERCALL_H__ */
diff --git a/sys/dev/xen/privcmd/privcmd.c b/sys/dev/xen/privcmd/privcmd.c
index c31c31bcfe41..d9f11aa0fe7a 100644
--- a/sys/dev/xen/privcmd/privcmd.c
+++ b/sys/dev/xen/privcmd/privcmd.c
@@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
MALLOC_DEFINE(M_PRIVCMD, "privcmd_dev", "Xen privcmd user-space device");
+#define MAX_DMOP_BUFFERS 16
+
struct privcmd_map {
vm_object_t mem;
vm_size_t size;
@@ -425,6 +427,53 @@ mmap_out:
break;
}
+ case IOCTL_PRIVCMD_DM_OP: {
+ const struct ioctl_privcmd_dmop *dmop;
+ struct privcmd_dmop_buf *bufs;
+ struct xen_dm_op_buf *hbufs;
+
+ dmop = (struct ioctl_privcmd_dmop *)arg;
+
+ if (dmop->num == 0)
+ break;
+
+ if (dmop->num > MAX_DMOP_BUFFERS) {
+ error = E2BIG;
+ break;
+ }
+
+ bufs = malloc(sizeof(*bufs) * dmop->num, M_PRIVCMD, M_WAITOK);
+
+ error = copyin(dmop->ubufs, bufs, sizeof(*bufs) * dmop->num);
+ if (error != 0) {
+ free(bufs, M_PRIVCMD);
+ break;
+ }
+
+ hbufs = malloc(sizeof(*hbufs) * dmop->num, M_PRIVCMD, M_WAITOK);
+ for (i = 0; i < dmop->num; i++) {
+ set_xen_guest_handle(hbufs[i].h, bufs[i].uptr);
+ hbufs[i].size = bufs[i].size;
+ }
+
+#ifdef __amd64__
+ if (cpu_stdext_feature & CPUID_STDEXT_SMAP)
+ stac();
+#endif
+ error = HYPERVISOR_dm_op(dmop->dom, dmop->num, hbufs);
+#ifdef __amd64__
+ if (cpu_stdext_feature & CPUID_STDEXT_SMAP)
+ clac();
+#endif
+ if (error != 0)
+ error = xen_translate_error(error);
+
+ free(bufs, M_PRIVCMD);
+ free(hbufs, M_PRIVCMD);
+
+
+ break;
+ }
default:
error = ENOSYS;
break;
diff --git a/sys/i386/include/xen/hypercall.h b/sys/i386/include/xen/hypercall.h
index d0cd9179665c..78052fac9355 100644
--- a/sys/i386/include/xen/hypercall.h
+++ b/sys/i386/include/xen/hypercall.h
@@ -404,6 +404,13 @@ HYPERVISOR_kexec_op(
{
return _hypercall2(int, kexec_op, op, args);
}
+
+static inline int
+HYPERVISOR_dm_op(
+ domid_t domid, unsigned int nr_bufs, const void *bufs)
+{
+ return _hypercall3(int, dm_op, domid, nr_bufs, bufs);
+}
#endif /* __HYPERCALL_H__ */
/*
diff --git a/sys/xen/hypervisor.h b/sys/xen/hypervisor.h
index d613e67c5a3b..2be61597fc18 100644
--- a/sys/xen/hypervisor.h
+++ b/sys/xen/hypervisor.h
@@ -20,6 +20,7 @@
#include <xen/interface/sched.h>
#include <xen/interface/callback.h>
#include <xen/interface/memory.h>
+#include <xen/interface/hvm/dm_op.h>
#include <machine/xen/hypercall.h>
extern uint64_t get_system_time(int ticks);
diff --git a/sys/xen/privcmd.h b/sys/xen/privcmd.h
index ac2d0c00b845..cd0bc7d550d9 100644
--- a/sys/xen/privcmd.h
+++ b/sys/xen/privcmd.h
@@ -63,11 +63,24 @@ struct ioctl_privcmd_mmapresource {
*/
};
+struct privcmd_dmop_buf {
+ void *uptr; /* pointer to memory (in calling process) */
+ size_t size; /* size of the buffer */
+};
+
+struct ioctl_privcmd_dmop {
+ domid_t dom; /* target domain */
+ unsigned int num; /* num of buffers */
+ const struct privcmd_dmop_buf *ubufs; /* array of buffers */
+};
+
#define IOCTL_PRIVCMD_HYPERCALL \
_IOWR('E', 0, struct ioctl_privcmd_hypercall)
#define IOCTL_PRIVCMD_MMAPBATCH \
_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
#define IOCTL_PRIVCMD_MMAP_RESOURCE \
_IOW('E', 2, struct ioctl_privcmd_mmapresource)
+#define IOCTL_PRIVCMD_DM_OP \
+ _IOW('E', 3, struct ioctl_privcmd_dmop)
#endif /* !__XEN_PRIVCMD_H__ */