Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jan 2021 15:36:07 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: 147e593921d7 - main - xen/privcmd: split setup of virtual address range into helper
Message-ID:  <202101111536.10BFa76D026624@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=147e593921d7b9a6697a92a512ab7bd777f9a6b1

commit 147e593921d7b9a6697a92a512ab7bd777f9a6b1
Author:     Roger Pau Monné <royger@FreeBSD.org>
AuthorDate: 2021-01-04 17:59:14 +0000
Commit:     Roger Pau Monné <royger@FreeBSD.org>
CommitDate: 2021-01-11 15:14:59 +0000

    xen/privcmd: split setup of virtual address range into helper
    
    Preparatory change for further additions that will also make use of
    the same code. No functional change.
    
    Sponsored by:   Citrix Systems R&D
---
 sys/dev/xen/privcmd/privcmd.c | 69 ++++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/sys/dev/xen/privcmd/privcmd.c b/sys/dev/xen/privcmd/privcmd.c
index 24bce97e9b3d..78fb32444931 100644
--- a/sys/dev/xen/privcmd/privcmd.c
+++ b/sys/dev/xen/privcmd/privcmd.c
@@ -217,6 +217,40 @@ privcmd_mmap_single(struct cdev *cdev, vm_ooffset_t *offset, vm_size_t size,
 	return (0);
 }
 
+static struct privcmd_map *
+setup_virtual_area(struct thread *td, unsigned long addr, unsigned long num)
+{
+	vm_map_t map;
+	vm_map_entry_t entry;
+	vm_object_t mem;
+	vm_pindex_t pindex;
+	vm_prot_t prot;
+	boolean_t wired;
+	struct privcmd_map *umap;
+	int error;
+
+	if ((num == 0) || ((addr & PAGE_MASK) != 0))
+		return NULL;
+
+	map = &td->td_proc->p_vmspace->vm_map;
+	error = vm_map_lookup(&map, addr, VM_PROT_NONE, &entry, &mem, &pindex,
+	    &prot, &wired);
+	if (error != KERN_SUCCESS || (entry->start != addr) ||
+	    (entry->end != addr + (num * PAGE_SIZE)))
+		return NULL;
+
+	vm_map_lookup_done(map, entry);
+	if ((mem->type != OBJT_MGTDEVICE) ||
+	    (mem->un_pager.devp.ops != &privcmd_pg_ops))
+		return NULL;
+
+	umap = mem->handle;
+	/* Allocate a bitset to store broken page mappings. */
+	umap->err = BITSET_ALLOC(num, M_PRIVCMD, M_WAITOK | M_ZERO);
+
+	return umap;
+}
+
 static int
 privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg,
 	      int mode, struct thread *td)
@@ -255,12 +289,6 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg,
 	}
 	case IOCTL_PRIVCMD_MMAPBATCH: {
 		struct ioctl_privcmd_mmapbatch *mmap;
-		vm_map_t map;
-		vm_map_entry_t entry;
-		vm_object_t mem;
-		vm_pindex_t pindex;
-		vm_prot_t prot;
-		boolean_t wired;
 		struct xen_add_to_physmap_range add;
 		xen_ulong_t *idxs;
 		xen_pfn_t *gpfns;
@@ -271,33 +299,12 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg,
 
 		mmap = (struct ioctl_privcmd_mmapbatch *)arg;
 
-		if ((mmap->num == 0) ||
-		    ((mmap->addr & PAGE_MASK) != 0)) {
+		umap = setup_virtual_area(td, mmap->addr, mmap->num);
+		if (umap == NULL) {
 			error = EINVAL;
 			break;
 		}
 
-		map = &td->td_proc->p_vmspace->vm_map;
-		error = vm_map_lookup(&map, mmap->addr, VM_PROT_NONE, &entry,
-		    &mem, &pindex, &prot, &wired);
-		if (error != KERN_SUCCESS) {
-			error = EINVAL;
-			break;
-		}
-		if ((entry->start != mmap->addr) ||
-		    (entry->end != mmap->addr + (mmap->num * PAGE_SIZE))) {
-			vm_map_lookup_done(map, entry);
-			error = EINVAL;
-			break;
-		}
-		vm_map_lookup_done(map, entry);
-		if ((mem->type != OBJT_MGTDEVICE) ||
-		    (mem->un_pager.devp.ops != &privcmd_pg_ops)) {
-			error = EINVAL;
-			break;
-		}
-		umap = mem->handle;
-
 		add.domid = DOMID_SELF;
 		add.space = XENMAPSPACE_gmfn_foreign;
 		add.foreign_domid = mmap->dom;
@@ -316,10 +323,6 @@ privcmd_ioctl(struct cdev *dev, unsigned long cmd, caddr_t arg,
 		set_xen_guest_handle(add.gpfns, gpfns);
 		set_xen_guest_handle(add.errs, errs);
 
-		/* Allocate a bitset to store broken page mappings. */
-		umap->err = BITSET_ALLOC(mmap->num, M_PRIVCMD,
-		    M_WAITOK | M_ZERO);
-
 		for (index = 0; index < mmap->num; index += num) {
 			num = MIN(mmap->num - index, UINT16_MAX);
 			add.size = num;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101111536.10BFa76D026624>