Lines Matching +full:gpa +full:- +full:1
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
10 * 1. Redistributions of source code must retain the above copyright
109 return (-1); in vm_ctl_create()
121 return (-1); in vm_create()
128 return (-1); in vm_create()
149 vm = malloc(sizeof(struct vmctx) + strlen(name) + 1); in vm_openf()
152 vm->fd = vm->ctlfd = -1; in vm_openf()
153 vm->memflags = 0; in vm_openf()
154 vm->name = (char *)(vm + 1); in vm_openf()
155 strcpy(vm->name, name); in vm_openf()
156 memset(vm->memsegs, 0, sizeof(vm->memsegs)); in vm_openf()
158 if ((vm->ctlfd = vm_ctl_open()) < 0) in vm_openf()
161 vm->fd = vm_device_open(vm->name); in vm_openf()
162 if (vm->fd < 0 && errno == ENOENT) { in vm_openf()
164 if (vm_ctl_create(vm->name, vm->ctlfd) != 0) in vm_openf()
166 vm->fd = vm_device_open(vm->name); in vm_openf()
170 if (vm->fd < 0) in vm_openf()
192 if (vm->fd >= 0) in vm_close()
193 (void)close(vm->fd); in vm_close()
194 if (vm->ctlfd >= 0) in vm_close()
195 (void)close(vm->ctlfd); in vm_close()
205 (void)strlcpy(vmd.name, vm->name, sizeof(vmd.name)); in vm_destroy()
206 if (ioctl(vm->ctlfd, VMMCTL_VM_DESTROY, &vmd) != 0) in vm_destroy()
218 vcpu->ctx = ctx; in vm_vcpu_open()
219 vcpu->vcpuid = vcpuid; in vm_vcpu_open()
232 return (vcpu->vcpuid); in vcpu_id()
270 ctx->memflags = flags; in vm_set_memflags()
277 return (ctx->memflags); in vm_get_memflags()
281 * Map segment 'segid' starting at 'off' into guest address range [gpa,gpa+len).
284 vm_mmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, int segid, vm_ooffset_t off, in vm_mmap_memseg() argument
290 memmap.gpa = gpa; in vm_mmap_memseg()
297 if (ctx->memflags & VM_MEM_F_WIRED) in vm_mmap_memseg()
304 error = vm_mmap_getnext(ctx, &gpa, &segid, &off, &len, &prot, &flags); in vm_mmap_memseg()
305 if (error == 0 && gpa == memmap.gpa) { in vm_mmap_memseg()
309 return (-1); in vm_mmap_memseg()
315 error = ioctl(ctx->fd, VM_MMAP_MEMSEG, &memmap); in vm_mmap_memseg()
324 *guest_baseaddr = ctx->baseaddr; in vm_get_guestmem_from_ctx()
325 *lowmem_size = ctx->memsegs[VM_MEMSEG_LOW].size; in vm_get_guestmem_from_ctx()
326 *highmem_size = ctx->memsegs[VM_MEMSEG_HIGH].size; in vm_get_guestmem_from_ctx()
331 vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len) in vm_munmap_memseg() argument
336 munmap.gpa = gpa; in vm_munmap_memseg()
339 error = ioctl(ctx->fd, VM_MUNMAP_MEMSEG, &munmap); in vm_munmap_memseg()
344 vm_mmap_getnext(struct vmctx *ctx, vm_paddr_t *gpa, int *segid, in vm_mmap_getnext() argument
351 memmap.gpa = *gpa; in vm_mmap_getnext()
352 error = ioctl(ctx->fd, VM_MMAP_GETNEXT, &memmap); in vm_mmap_getnext()
354 *gpa = memmap.gpa; in vm_mmap_getnext()
365 * Return 0 if the segments are identical and non-zero otherwise.
378 return (-1); in cmpseg()
401 return (-1); in vm_alloc_memseg()
414 return (-1); in vm_alloc_memseg()
418 error = ioctl(ctx->fd, VM_ALLOC_MEMSEG, &memseg); in vm_alloc_memseg()
432 error = ioctl(ctx->fd, VM_GET_MEMSEG, &memseg); in vm_get_memseg()
438 error = -1; in vm_get_memseg()
445 setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char *base) in setup_memory_segment() argument
450 /* Map 'len' bytes starting at 'gpa' in the guest address space */ in setup_memory_segment()
451 error = vm_mmap_memseg(ctx, gpa, VM_SYSMEM, gpa, len, PROT_ALL); in setup_memory_segment()
456 if ((ctx->memflags & VM_MEM_F_INCORE) == 0) in setup_memory_segment()
460 ptr = mmap(base + gpa, len, PROT_RW, flags, ctx->fd, gpa); in setup_memory_segment()
462 return (-1); in setup_memory_segment()
471 vm_paddr_t gpa; in vm_setup_memory() local
482 ctx->memsegs[VM_MEMSEG_LOW].size = VM_LOWMEM_LIMIT; in vm_setup_memory()
483 ctx->memsegs[VM_MEMSEG_HIGH].size = memsize - VM_LOWMEM_LIMIT; in vm_setup_memory()
484 objsize = VM_HIGHMEM_BASE + ctx->memsegs[VM_MEMSEG_HIGH].size; in vm_setup_memory()
486 ctx->memsegs[VM_MEMSEG_LOW].size = memsize; in vm_setup_memory()
487 ctx->memsegs[VM_MEMSEG_HIGH].size = 0; in vm_setup_memory()
500 ptr = mmap(NULL, len, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1, 0); in vm_setup_memory()
502 return (-1); in vm_setup_memory()
505 if (ctx->memsegs[VM_MEMSEG_HIGH].size > 0) { in vm_setup_memory()
506 gpa = VM_HIGHMEM_BASE; in vm_setup_memory()
507 len = ctx->memsegs[VM_MEMSEG_HIGH].size; in vm_setup_memory()
508 error = setup_memory_segment(ctx, gpa, len, baseaddr); in vm_setup_memory()
513 if (ctx->memsegs[VM_MEMSEG_LOW].size > 0) { in vm_setup_memory()
514 gpa = 0; in vm_setup_memory()
515 len = ctx->memsegs[VM_MEMSEG_LOW].size; in vm_setup_memory()
516 error = setup_memory_segment(ctx, gpa, len, baseaddr); in vm_setup_memory()
521 ctx->baseaddr = baseaddr; in vm_setup_memory()
527 * Returns a non-NULL pointer if [gaddr, gaddr+len) is entirely contained in
538 lowsize = ctx->memsegs[VM_MEMSEG_LOW].size; in vm_map_gpa()
541 return (ctx->baseaddr + gaddr); in vm_map_gpa()
544 highsize = ctx->memsegs[VM_MEMSEG_HIGH].size; in vm_map_gpa()
548 return (ctx->baseaddr + gaddr); in vm_map_gpa()
560 offaddr = (char *)addr - ctx->baseaddr; in vm_rev_map_gpa()
562 lowsize = ctx->memsegs[VM_MEMSEG_LOW].size; in vm_rev_map_gpa()
567 highsize = ctx->memsegs[VM_MEMSEG_HIGH].size; in vm_rev_map_gpa()
573 return ((vm_paddr_t)-1); in vm_rev_map_gpa()
580 return (ctx->name); in vm_get_name()
587 return (ctx->memsegs[VM_MEMSEG_LOW].size); in vm_get_lowmem_size()
601 return (ctx->memsegs[VM_MEMSEG_HIGH].size); in vm_get_highmem_size()
612 fd = -1; in vm_create_devmem()
624 strlcat(pathname, ctx->name, sizeof(pathname)); in vm_create_devmem()
637 base = mmap(NULL, len2, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1, in vm_create_devmem()
643 if ((ctx->memflags & VM_MEM_F_INCORE) == 0) in vm_create_devmem()
662 *(int *)arg = vcpu->vcpuid; in vcpu_ioctl()
663 return (ioctl(vcpu->ctx->fd, cmd, arg)); in vcpu_ioctl()
739 return (ioctl(ctx->fd, VM_SUSPEND, &vmsuspend)); in vm_suspend()
746 return (ioctl(ctx->fd, VM_REINIT, 0)); in vm_reinit()
760 return (-1); in vm_capability_name2type()
849 if (ioctl(ctx->fd, VM_STAT_DESC, &statdesc) == 0) in vm_get_stat_desc()
857 vm_get_gpa_pmap(struct vmctx *ctx, uint64_t gpa, uint64_t *pte, int *num) in vm_get_gpa_pmap() argument
863 gpapte.gpa = gpa; in vm_get_gpa_pmap()
865 error = ioctl(ctx->fd, VM_GET_GPA_PMAP, &gpapte); in vm_get_gpa_pmap()
878 uint64_t gla, int prot, uint64_t *gpa, int *fault) in vm_gla2gpa() argument
891 *gpa = gg.gpa; in vm_gla2gpa()
899 uint64_t gla, int prot, uint64_t *gpa, int *fault) in vm_gla2gpa_nofault() argument
912 *gpa = gg.gpa; in vm_gla2gpa_nofault()
928 uint64_t gpa, off; in vm_copy_setup() local
938 error = vm_gla2gpa(vcpu, paging, gla, prot, &gpa, fault); in vm_copy_setup()
942 off = gpa & PAGE_MASK; in vm_copy_setup()
943 n = MIN(len, PAGE_SIZE - off); in vm_copy_setup()
945 va = vm_map_gpa(vcpu->ctx, gpa, n); in vm_copy_setup()
949 iov->iov_base = va; in vm_copy_setup()
950 iov->iov_len = n; in vm_copy_setup()
952 iovcnt--; in vm_copy_setup()
955 len -= n; in vm_copy_setup()
966 * emulation code shared with the kernel. The in-kernel in vm_copy_teardown()
967 * version of this is non-empty. in vm_copy_teardown()
980 assert(iov->iov_len); in vm_copyin()
981 n = min(len, iov->iov_len); in vm_copyin()
982 src = iov->iov_base; in vm_copyin()
987 len -= n; in vm_copyin()
1000 assert(iov->iov_len); in vm_copyout()
1001 n = min(len, iov->iov_len); in vm_copyout()
1002 dst = iov->iov_base; in vm_copyout()
1007 len -= n; in vm_copyout()
1022 error = ioctl(ctx->fd, VM_GET_CPUS, &vm_cpuset); in vm_get_cpus()
1065 ac.vcpuid = -1; in vm_suspend_all_cpus()
1066 error = ioctl(ctx->fd, VM_SUSPEND_CPU, &ac); in vm_suspend_all_cpus()
1099 ac.vcpuid = -1; in vm_resume_all_cpus()
1100 error = ioctl(ctx->fd, VM_RESUME_CPU, &ac); in vm_resume_all_cpus()
1146 if (ioctl(ctx->fd, VM_SNAPSHOT_REQ, meta) == -1) { in vm_snapshot_req()
1149 __func__, meta->dev_name, errno); in vm_snapshot_req()
1151 return (-1); in vm_snapshot_req()
1162 return (ioctl(ctx->fd, VM_RESTORE_TIME, &dummy)); in vm_restore_time()
1177 return (ioctl(ctx->fd, VM_SET_TOPOLOGY, &topology)); in vm_set_topology()
1188 error = ioctl(ctx->fd, VM_GET_TOPOLOGY, &topology); in vm_get_topology()
1204 if (caph_rights_limit(ctx->fd, &rights) != 0) in vm_limit_rights()
1205 return (-1); in vm_limit_rights()
1206 if (caph_ioctls_limit(ctx->fd, vm_ioctl_cmds, vm_ioctl_ncmds) != 0) in vm_limit_rights()
1207 return (-1); in vm_limit_rights()
1219 return (ctx->fd); in vm_get_device_fd()