From owner-dev-commits-src-main@freebsd.org Mon Jan 11 15:36:09 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 BF6854DC86F; Mon, 11 Jan 2021 15:36:09 +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 4DDyV13cp7z3rYr; Mon, 11 Jan 2021 15:36:09 +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 3EA951CD2D; Mon, 11 Jan 2021 15:36:09 +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 10BFa9Cb026649; Mon, 11 Jan 2021 15:36:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10BFa9Mk026648; Mon, 11 Jan 2021 15:36:09 GMT (envelope-from git) Date: Mon, 11 Jan 2021 15:36:09 GMT Message-Id: <202101111536.10BFa9Mk026648@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: 658860e2d070 - main - xen/privcmd: implement the map resource 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: 658860e2d07065b4203bb3e7779bee0512c65c92 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:10 -0000 The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=658860e2d07065b4203bb3e7779bee0512c65c92 commit 658860e2d07065b4203bb3e7779bee0512c65c92 Author: Roger Pau Monne AuthorDate: 2020-06-23 09:36:19 +0000 Commit: Roger Pau Monné CommitDate: 2021-01-11 15:15:00 +0000 xen/privcmd: implement the map resource ioctl The interface is mostly the same as the Linux ioctl, so that we don't need to modify the user-space libraries that make use of it. The ioctl is just a proxy for the XENMEM_acquire_resource hypercall. Sponsored by: Citrix Systems R&D --- sys/dev/xen/privcmd/privcmd.c | 52 +++++++++++++++++++++++++++++++++++++++++++ sys/xen/privcmd.h | 15 +++++++++++++ 2 files changed, 67 insertions(+) diff --git a/sys/dev/xen/privcmd/privcmd.c b/sys/dev/xen/privcmd/privcmd.c index 78fb32444931..c31c31bcfe41 100644 --- a/sys/dev/xen/privcmd/privcmd.c +++ b/sys/dev/xen/privcmd/privcmd.c @@ -372,7 +372,59 @@ mmap_out: break; } + case IOCTL_PRIVCMD_MMAP_RESOURCE: { + struct ioctl_privcmd_mmapresource *mmap; + struct xen_mem_acquire_resource adq; + xen_pfn_t *gpfns; + struct privcmd_map *umap; + + mmap = (struct ioctl_privcmd_mmapresource *)arg; + + bzero(&adq, sizeof(adq)); + + adq.domid = mmap->dom; + adq.type = mmap->type; + adq.id = mmap->id; + + /* Shortcut for getting the resource size. */ + if (mmap->addr == 0 && mmap->num == 0) { + error = HYPERVISOR_memory_op(XENMEM_acquire_resource, + &adq); + if (error != 0) { + error = xen_translate_error(error); + break; + } + error = copyout(&adq.nr_frames, &mmap->num, + sizeof(mmap->num)); + break; + } + umap = setup_virtual_area(td, mmap->addr, mmap->num); + if (umap == NULL) { + error = EINVAL; + break; + } + + adq.nr_frames = mmap->num; + adq.frame = mmap->idx; + + gpfns = malloc(sizeof(*gpfns) * mmap->num, M_PRIVCMD, M_WAITOK); + for (i = 0; i < mmap->num; i++) + gpfns[i] = atop(umap->phys_base_addr) + i; + set_xen_guest_handle(adq.frame_list, gpfns); + + error = HYPERVISOR_memory_op(XENMEM_acquire_resource, &adq); + if (error != 0) + error = xen_translate_error(error); + else + umap->mapped = true; + + free(gpfns, M_PRIVCMD); + if (!umap->mapped) + free(umap->err, M_PRIVCMD); + + break; + } default: error = ENOSYS; break; diff --git a/sys/xen/privcmd.h b/sys/xen/privcmd.h index a3cc4e110e41..ac2d0c00b845 100644 --- a/sys/xen/privcmd.h +++ b/sys/xen/privcmd.h @@ -50,9 +50,24 @@ struct ioctl_privcmd_mmapbatch { int *err; /* array of error codes */ }; +struct ioctl_privcmd_mmapresource { + domid_t dom; /* target domain */ + unsigned int type; /* type of resource to map */ + unsigned int id; /* type-specific resource identifier */ + unsigned int idx; /* the index of the initial frame to be mapped */ + unsigned long num; /* number of frames of the resource to be mapped */ + unsigned long addr; /* physical address to map into */ + /* + * Note: issuing an ioctl with num = addr = 0 will return the size of + * the resource. + */ +}; + #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) #endif /* !__XEN_PRIVCMD_H__ */