From owner-dev-commits-src-main@freebsd.org Mon Jan 11 15:36:10 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E7DF04DCDC4; Mon, 11 Jan 2021 15:36:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DDyV23plbz3rFk; Mon, 11 Jan 2021 15:36:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 55A2C1CD2E; Mon, 11 Jan 2021 15:36:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10BFaAfO026671; Mon, 11 Jan 2021 15:36:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10BFaAIK026670; Mon, 11 Jan 2021 15:36:10 GMT (envelope-from git) Date: Mon, 11 Jan 2021 15:36:10 GMT Message-Id: <202101111536.10BFaAIK026670@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Roger Pau Monné Subject: git: ed78016d005c - main - xen/privcmd: implement the dm op ioctl MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ed78016d005c9ec97883a33c4468052ca9880c4f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2021 15:36:11 -0000 The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=ed78016d005c9ec97883a33c4468052ca9880c4f commit ed78016d005c9ec97883a33c4468052ca9880c4f Author: Roger Pau Monne AuthorDate: 2020-06-25 16:25:29 +0000 Commit: Roger Pau Monné 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 #include #include +#include #include 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__ */