Date: Mon, 11 Jan 2021 15:36:10 GMT From: Roger Pau Monné <royger@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: ed78016d005c - main - xen/privcmd: implement the dm op ioctl Message-ID: <202101111536.10BFaAIK026670@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=ed78016d005c9ec97883a33c4468052ca9880c4f commit ed78016d005c9ec97883a33c4468052ca9880c4f Author: Roger Pau Monne <roger.pau@citrix.com> AuthorDate: 2020-06-25 16:25:29 +0000 Commit: Roger Pau Monné <royger@FreeBSD.org> CommitDate: 2021-01-11 15:33:27 +0000 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 --- sys/amd64/include/xen/hypercall.h | 7 ++++++ sys/dev/xen/privcmd/privcmd.c | 49 +++++++++++++++++++++++++++++++++++++++ sys/i386/include/xen/hypercall.h | 7 ++++++ sys/xen/hypervisor.h | 1 + sys/xen/privcmd.h | 13 +++++++++++ 5 files changed, 77 insertions(+) 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; @@ -423,6 +425,53 @@ mmap_out: if (!umap->mapped) free(umap->err, M_PRIVCMD); + 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: 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__ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101111536.10BFaAIK026670>