mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-24 11:29:10 +00:00
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
This commit is contained in:
parent
658860e2d0
commit
ed78016d00
@ -427,6 +427,13 @@ HYPERVISOR_kexec_op(
|
|||||||
return _hypercall2(int, kexec_op, op, args);
|
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
|
#undef __must_check
|
||||||
|
|
||||||
#endif /* __MACHINE_XEN_HYPERCALL_H__ */
|
#endif /* __MACHINE_XEN_HYPERCALL_H__ */
|
||||||
|
@ -65,6 +65,8 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
MALLOC_DEFINE(M_PRIVCMD, "privcmd_dev", "Xen privcmd user-space device");
|
MALLOC_DEFINE(M_PRIVCMD, "privcmd_dev", "Xen privcmd user-space device");
|
||||||
|
|
||||||
|
#define MAX_DMOP_BUFFERS 16
|
||||||
|
|
||||||
struct privcmd_map {
|
struct privcmd_map {
|
||||||
vm_object_t mem;
|
vm_object_t mem;
|
||||||
vm_size_t size;
|
vm_size_t size;
|
||||||
@ -423,6 +425,53 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg,
|
|||||||
if (!umap->mapped)
|
if (!umap->mapped)
|
||||||
free(umap->err, M_PRIVCMD);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -404,6 +404,13 @@ HYPERVISOR_kexec_op(
|
|||||||
{
|
{
|
||||||
return _hypercall2(int, kexec_op, op, args);
|
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__ */
|
#endif /* __HYPERCALL_H__ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <xen/interface/sched.h>
|
#include <xen/interface/sched.h>
|
||||||
#include <xen/interface/callback.h>
|
#include <xen/interface/callback.h>
|
||||||
#include <xen/interface/memory.h>
|
#include <xen/interface/memory.h>
|
||||||
|
#include <xen/interface/hvm/dm_op.h>
|
||||||
#include <machine/xen/hypercall.h>
|
#include <machine/xen/hypercall.h>
|
||||||
|
|
||||||
extern uint64_t get_system_time(int ticks);
|
extern uint64_t get_system_time(int ticks);
|
||||||
|
@ -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 \
|
#define IOCTL_PRIVCMD_HYPERCALL \
|
||||||
_IOWR('E', 0, struct ioctl_privcmd_hypercall)
|
_IOWR('E', 0, struct ioctl_privcmd_hypercall)
|
||||||
#define IOCTL_PRIVCMD_MMAPBATCH \
|
#define IOCTL_PRIVCMD_MMAPBATCH \
|
||||||
_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
|
_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
|
||||||
#define IOCTL_PRIVCMD_MMAP_RESOURCE \
|
#define IOCTL_PRIVCMD_MMAP_RESOURCE \
|
||||||
_IOW('E', 2, struct ioctl_privcmd_mmapresource)
|
_IOW('E', 2, struct ioctl_privcmd_mmapresource)
|
||||||
|
#define IOCTL_PRIVCMD_DM_OP \
|
||||||
|
_IOW('E', 3, struct ioctl_privcmd_dmop)
|
||||||
|
|
||||||
#endif /* !__XEN_PRIVCMD_H__ */
|
#endif /* !__XEN_PRIVCMD_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user