Make it possible for an emulator to set the protection of the guest pages. For some reason I had initially concluded that it wasn't doable; verily it is, so let's do it. The reserved 'flags' argument of nvmm_gpa_map() becomes 'prot' and takes mmap-like protection codes.diff -r1.11 -r1.12 src/lib/libnvmm/libnvmm.3
(maxv)
--- src/lib/libnvmm/libnvmm.3 2019/02/05 15:03:35 1.11
+++ src/lib/libnvmm/libnvmm.3 2019/03/21 20:21:40 1.12
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: libnvmm.3,v 1.11 2019/02/05 15:03:35 wiz Exp $ | 1 | .\" $NetBSD: libnvmm.3,v 1.12 2019/03/21 20:21:40 maxv Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 2018, 2019 The NetBSD Foundation, Inc. | 3 | .\" Copyright (c) 2018, 2019 The NetBSD Foundation, Inc. | |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | 6 | .\" This code is derived from software contributed to The NetBSD Foundation | |
7 | .\" by Maxime Villard. | 7 | .\" by Maxime Villard. | |
8 | .\" | 8 | .\" | |
9 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without | |
10 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | 11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | 12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | 13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
@@ -17,27 +17,27 @@ | @@ -17,27 +17,27 @@ | |||
17 | .\" | 17 | .\" | |
18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 18 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 19 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 20 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 21 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | .\" POSSIBILITY OF SUCH DAMAGE. | 28 | .\" POSSIBILITY OF SUCH DAMAGE. | |
29 | .\" | 29 | .\" | |
30 | .Dd February 5, 2019 | 30 | .Dd March 19, 2019 | |
31 | .Dt LIBNVMM 3 | 31 | .Dt LIBNVMM 3 | |
32 | .Os | 32 | .Os | |
33 | .Sh NAME | 33 | .Sh NAME | |
34 | .Nm libnvmm | 34 | .Nm libnvmm | |
35 | .Nd NetBSD Virtualization API | 35 | .Nd NetBSD Virtualization API | |
36 | .Sh LIBRARY | 36 | .Sh LIBRARY | |
37 | .Lb libnvmm | 37 | .Lb libnvmm | |
38 | .Sh SYNOPSIS | 38 | .Sh SYNOPSIS | |
39 | .In nvmm.h | 39 | .In nvmm.h | |
40 | .Ft int | 40 | .Ft int | |
41 | .Fn nvmm_capability "struct nvmm_capability *cap" | 41 | .Fn nvmm_capability "struct nvmm_capability *cap" | |
42 | .Ft int | 42 | .Ft int | |
43 | .Fn nvmm_machine_create "struct nvmm_machine *mach" | 43 | .Fn nvmm_machine_create "struct nvmm_machine *mach" | |
@@ -58,27 +58,27 @@ | @@ -58,27 +58,27 @@ | |||
58 | "void *state" "uint64_t flags" | 58 | "void *state" "uint64_t flags" | |
59 | .Ft int | 59 | .Ft int | |
60 | .Fn nvmm_vcpu_inject "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | 60 | .Fn nvmm_vcpu_inject "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | |
61 | "struct nvmm_event *event" | 61 | "struct nvmm_event *event" | |
62 | .Ft int | 62 | .Ft int | |
63 | .Fn nvmm_vcpu_run "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | 63 | .Fn nvmm_vcpu_run "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | |
64 | "struct nvmm_exit *exit" | 64 | "struct nvmm_exit *exit" | |
65 | .Ft int | 65 | .Ft int | |
66 | .Fn nvmm_hva_map "struct nvmm_machine *mach" "uintptr_t hva" "size_t size" | 66 | .Fn nvmm_hva_map "struct nvmm_machine *mach" "uintptr_t hva" "size_t size" | |
67 | .Ft int | 67 | .Ft int | |
68 | .Fn nvmm_hva_unmap "struct nvmm_machine *mach" "uintptr_t hva" "size_t size" | 68 | .Fn nvmm_hva_unmap "struct nvmm_machine *mach" "uintptr_t hva" "size_t size" | |
69 | .Ft int | 69 | .Ft int | |
70 | .Fn nvmm_gpa_map "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \ | 70 | .Fn nvmm_gpa_map "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \ | |
71 | "size_t size" "int flags" | 71 | "size_t size" "int prot" | |
72 | .Ft int | 72 | .Ft int | |
73 | .Fn nvmm_gpa_unmap "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \ | 73 | .Fn nvmm_gpa_unmap "struct nvmm_machine *mach" "uintptr_t hva" "gpaddr_t gpa" \ | |
74 | "size_t size" | 74 | "size_t size" | |
75 | .Ft int | 75 | .Ft int | |
76 | .Fn nvmm_gva_to_gpa "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | 76 | .Fn nvmm_gva_to_gpa "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | |
77 | "gvaddr_t gva" "gpaddr_t *gpa" "nvmm_prot_t *prot" | 77 | "gvaddr_t gva" "gpaddr_t *gpa" "nvmm_prot_t *prot" | |
78 | .Ft int | 78 | .Ft int | |
79 | .Fn nvmm_gpa_to_hva "struct nvmm_machine *mach" "gpaddr_t gpa" \ | 79 | .Fn nvmm_gpa_to_hva "struct nvmm_machine *mach" "gpaddr_t gpa" \ | |
80 | "uintptr_t *hva" | 80 | "uintptr_t *hva" | |
81 | .Ft void | 81 | .Ft void | |
82 | .Fn nvmm_callbacks_register "const struct nvmm_callbacks *cbs" | 82 | .Fn nvmm_callbacks_register "const struct nvmm_callbacks *cbs" | |
83 | .Ft int | 83 | .Ft int | |
84 | .Fn nvmm_assist_io "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ | 84 | .Fn nvmm_assist_io "struct nvmm_machine *mach" "nvmm_cpuid_t cpuid" \ |
--- src/lib/libnvmm/libnvmm.c 2018/12/27 07:22:31 1.6
+++ src/lib/libnvmm/libnvmm.c 2019/03/21 20:21:40 1.7
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: libnvmm.c,v 1.6 2018/12/27 07:22:31 maxv Exp $ */ | 1 | /* $NetBSD: libnvmm.c,v 1.7 2019/03/21 20:21:40 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -364,44 +364,44 @@ nvmm_vcpu_run(struct nvmm_machine *mach, | @@ -364,44 +364,44 @@ nvmm_vcpu_run(struct nvmm_machine *mach, | |||
364 | memset(&args.exit, 0, sizeof(args.exit)); | 364 | memset(&args.exit, 0, sizeof(args.exit)); | |
365 | 365 | |||
366 | ret = ioctl(nvmm_fd, NVMM_IOC_VCPU_RUN, &args); | 366 | ret = ioctl(nvmm_fd, NVMM_IOC_VCPU_RUN, &args); | |
367 | if (ret == -1) | 367 | if (ret == -1) | |
368 | return -1; | 368 | return -1; | |
369 | 369 | |||
370 | memcpy(exit, &args.exit, sizeof(args.exit)); | 370 | memcpy(exit, &args.exit, sizeof(args.exit)); | |
371 | 371 | |||
372 | return 0; | 372 | return 0; | |
373 | } | 373 | } | |
374 | 374 | |||
375 | int | 375 | int | |
376 | nvmm_gpa_map(struct nvmm_machine *mach, uintptr_t hva, gpaddr_t gpa, | 376 | nvmm_gpa_map(struct nvmm_machine *mach, uintptr_t hva, gpaddr_t gpa, | |
377 | size_t size, int flags) | 377 | size_t size, int prot) | |
378 | { | 378 | { | |
379 | struct nvmm_ioc_gpa_map args; | 379 | struct nvmm_ioc_gpa_map args; | |
380 | int ret; | 380 | int ret; | |
381 | 381 | |||
382 | if (nvmm_init() == -1) { | 382 | if (nvmm_init() == -1) { | |
383 | return -1; | 383 | return -1; | |
384 | } | 384 | } | |
385 | 385 | |||
386 | ret = __area_add(mach, hva, gpa, size); | 386 | ret = __area_add(mach, hva, gpa, size); | |
387 | if (ret == -1) | 387 | if (ret == -1) | |
388 | return -1; | 388 | return -1; | |
389 | 389 | |||
390 | args.machid = mach->machid; | 390 | args.machid = mach->machid; | |
391 | args.hva = hva; | 391 | args.hva = hva; | |
392 | args.gpa = gpa; | 392 | args.gpa = gpa; | |
393 | args.size = size; | 393 | args.size = size; | |
394 | args.flags = flags; | 394 | args.prot = prot; | |
395 | 395 | |||
396 | ret = ioctl(nvmm_fd, NVMM_IOC_GPA_MAP, &args); | 396 | ret = ioctl(nvmm_fd, NVMM_IOC_GPA_MAP, &args); | |
397 | if (ret == -1) { | 397 | if (ret == -1) { | |
398 | /* Can't recover. */ | 398 | /* Can't recover. */ | |
399 | abort(); | 399 | abort(); | |
400 | } | 400 | } | |
401 | 401 | |||
402 | return 0; | 402 | return 0; | |
403 | } | 403 | } | |
404 | 404 | |||
405 | int | 405 | int | |
406 | nvmm_gpa_unmap(struct nvmm_machine *mach, uintptr_t hva, gpaddr_t gpa, | 406 | nvmm_gpa_unmap(struct nvmm_machine *mach, uintptr_t hva, gpaddr_t gpa, | |
407 | size_t size) | 407 | size_t size) |
--- src/sys/dev/nvmm/nvmm.c 2019/03/14 19:10:27 1.10
+++ src/sys/dev/nvmm/nvmm.c 2019/03/21 20:21:40 1.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nvmm.c,v 1.10 2019/03/14 19:10:27 maxv Exp $ */ | 1 | /* $NetBSD: nvmm.c,v 1.11 2019/03/21 20:21:40 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,37 +20,38 @@ | @@ -20,37 +20,38 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.10 2019/03/14 19:10:27 maxv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.11 2019/03/21 20:21:40 maxv Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/systm.h> | 36 | #include <sys/systm.h> | |
37 | #include <sys/kernel.h> | 37 | #include <sys/kernel.h> | |
38 | 38 | |||
39 | #include <sys/cpu.h> | 39 | #include <sys/cpu.h> | |
40 | #include <sys/conf.h> | 40 | #include <sys/conf.h> | |
41 | #include <sys/kmem.h> | 41 | #include <sys/kmem.h> | |
42 | #include <sys/module.h> | 42 | #include <sys/module.h> | |
43 | #include <sys/proc.h> | 43 | #include <sys/proc.h> | |
44 | #include <sys/mman.h> | |||
44 | 45 | |||
45 | #include <uvm/uvm.h> | 46 | #include <uvm/uvm.h> | |
46 | #include <uvm/uvm_page.h> | 47 | #include <uvm/uvm_page.h> | |
47 | 48 | |||
48 | #include "ioconf.h" | 49 | #include "ioconf.h" | |
49 | 50 | |||
50 | #include <dev/nvmm/nvmm.h> | 51 | #include <dev/nvmm/nvmm.h> | |
51 | #include <dev/nvmm/nvmm_internal.h> | 52 | #include <dev/nvmm/nvmm_internal.h> | |
52 | #include <dev/nvmm/nvmm_ioctl.h> | 53 | #include <dev/nvmm/nvmm_ioctl.h> | |
53 | 54 | |||
54 | static struct nvmm_machine machines[NVMM_MAX_MACHINES]; | 55 | static struct nvmm_machine machines[NVMM_MAX_MACHINES]; | |
55 | 56 | |||
56 | static const struct nvmm_impl *nvmm_impl_list[] = { | 57 | static const struct nvmm_impl *nvmm_impl_list[] = { | |
@@ -483,27 +484,27 @@ nvmm_do_vcpu_run(struct nvmm_machine *ma | @@ -483,27 +484,27 @@ nvmm_do_vcpu_run(struct nvmm_machine *ma | |||
483 | struct nvmm_exit *exit) | 484 | struct nvmm_exit *exit) | |
484 | { | 485 | { | |
485 | struct vmspace *vm = mach->vm; | 486 | struct vmspace *vm = mach->vm; | |
486 | 487 | |||
487 | while (1) { | 488 | while (1) { | |
488 | (*nvmm_impl->vcpu_run)(mach, vcpu, exit); | 489 | (*nvmm_impl->vcpu_run)(mach, vcpu, exit); | |
489 | 490 | |||
490 | if (__predict_true(exit->reason != NVMM_EXIT_MEMORY)) { | 491 | if (__predict_true(exit->reason != NVMM_EXIT_MEMORY)) { | |
491 | break; | 492 | break; | |
492 | } | 493 | } | |
493 | if (exit->u.mem.gpa >= mach->gpa_end) { | 494 | if (exit->u.mem.gpa >= mach->gpa_end) { | |
494 | break; | 495 | break; | |
495 | } | 496 | } | |
496 | if (uvm_fault(&vm->vm_map, exit->u.mem.gpa, VM_PROT_ALL)) { | 497 | if (uvm_fault(&vm->vm_map, exit->u.mem.gpa, exit->u.mem.prot)) { | |
497 | break; | 498 | break; | |
498 | } | 499 | } | |
499 | } | 500 | } | |
500 | } | 501 | } | |
501 | 502 | |||
502 | static int | 503 | static int | |
503 | nvmm_vcpu_run(struct nvmm_ioc_vcpu_run *args) | 504 | nvmm_vcpu_run(struct nvmm_ioc_vcpu_run *args) | |
504 | { | 505 | { | |
505 | struct nvmm_machine *mach; | 506 | struct nvmm_machine *mach; | |
506 | struct nvmm_cpu *vcpu; | 507 | struct nvmm_cpu *vcpu; | |
507 | int error; | 508 | int error; | |
508 | 509 | |||
509 | error = nvmm_machine_get(args->machid, &mach, false); | 510 | error = nvmm_machine_get(args->machid, &mach, false); | |
@@ -696,26 +697,31 @@ nvmm_hva_unmap(struct nvmm_ioc_hva_unmap | @@ -696,26 +697,31 @@ nvmm_hva_unmap(struct nvmm_ioc_hva_unmap | |||
696 | static int | 697 | static int | |
697 | nvmm_gpa_map(struct nvmm_ioc_gpa_map *args) | 698 | nvmm_gpa_map(struct nvmm_ioc_gpa_map *args) | |
698 | { | 699 | { | |
699 | struct nvmm_machine *mach; | 700 | struct nvmm_machine *mach; | |
700 | struct uvm_object *uobj; | 701 | struct uvm_object *uobj; | |
701 | gpaddr_t gpa; | 702 | gpaddr_t gpa; | |
702 | size_t off; | 703 | size_t off; | |
703 | int error; | 704 | int error; | |
704 | 705 | |||
705 | error = nvmm_machine_get(args->machid, &mach, false); | 706 | error = nvmm_machine_get(args->machid, &mach, false); | |
706 | if (error) | 707 | if (error) | |
707 | return error; | 708 | return error; | |
708 | 709 | |||
710 | if ((args->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC)) != 0) { | |||
711 | error = EINVAL; | |||
712 | goto out; | |||
713 | } | |||
714 | ||||
709 | if ((args->gpa % PAGE_SIZE) != 0 || (args->size % PAGE_SIZE) != 0 || | 715 | if ((args->gpa % PAGE_SIZE) != 0 || (args->size % PAGE_SIZE) != 0 || | |
710 | (args->hva % PAGE_SIZE) != 0) { | 716 | (args->hva % PAGE_SIZE) != 0) { | |
711 | error = EINVAL; | 717 | error = EINVAL; | |
712 | goto out; | 718 | goto out; | |
713 | } | 719 | } | |
714 | if (args->hva == 0) { | 720 | if (args->hva == 0) { | |
715 | error = EINVAL; | 721 | error = EINVAL; | |
716 | goto out; | 722 | goto out; | |
717 | } | 723 | } | |
718 | if (args->gpa < mach->gpa_begin || args->gpa >= mach->gpa_end) { | 724 | if (args->gpa < mach->gpa_begin || args->gpa >= mach->gpa_end) { | |
719 | error = EINVAL; | 725 | error = EINVAL; | |
720 | goto out; | 726 | goto out; | |
721 | } | 727 | } | |
@@ -730,27 +736,27 @@ nvmm_gpa_map(struct nvmm_ioc_gpa_map *ar | @@ -730,27 +736,27 @@ nvmm_gpa_map(struct nvmm_ioc_gpa_map *ar | |||
730 | gpa = args->gpa; | 736 | gpa = args->gpa; | |
731 | 737 | |||
732 | uobj = nvmm_hmapping_getuobj(mach, args->hva, args->size, &off); | 738 | uobj = nvmm_hmapping_getuobj(mach, args->hva, args->size, &off); | |
733 | if (uobj == NULL) { | 739 | if (uobj == NULL) { | |
734 | error = EINVAL; | 740 | error = EINVAL; | |
735 | goto out; | 741 | goto out; | |
736 | } | 742 | } | |
737 | 743 | |||
738 | /* Take a reference for the machine. */ | 744 | /* Take a reference for the machine. */ | |
739 | uao_reference(uobj); | 745 | uao_reference(uobj); | |
740 | 746 | |||
741 | /* Map the uobj into the machine address space, as pageable. */ | 747 | /* Map the uobj into the machine address space, as pageable. */ | |
742 | error = uvm_map(&mach->vm->vm_map, &gpa, args->size, uobj, off, 0, | 748 | error = uvm_map(&mach->vm->vm_map, &gpa, args->size, uobj, off, 0, | |
743 | UVM_MAPFLAG(UVM_PROT_RWX, UVM_PROT_RWX, UVM_INH_NONE, | 749 | UVM_MAPFLAG(args->prot, UVM_PROT_RWX, UVM_INH_NONE, | |
744 | UVM_ADV_RANDOM, UVM_FLAG_FIXED|UVM_FLAG_UNMAP)); | 750 | UVM_ADV_RANDOM, UVM_FLAG_FIXED|UVM_FLAG_UNMAP)); | |
745 | if (error) { | 751 | if (error) { | |
746 | uao_detach(uobj); | 752 | uao_detach(uobj); | |
747 | goto out; | 753 | goto out; | |
748 | } | 754 | } | |
749 | if (gpa != args->gpa) { | 755 | if (gpa != args->gpa) { | |
750 | uao_detach(uobj); | 756 | uao_detach(uobj); | |
751 | printf("[!] uvm_map problem\n"); | 757 | printf("[!] uvm_map problem\n"); | |
752 | error = EINVAL; | 758 | error = EINVAL; | |
753 | goto out; | 759 | goto out; | |
754 | } | 760 | } | |
755 | 761 | |||
756 | out: | 762 | out: |
--- src/sys/dev/nvmm/nvmm.h 2019/01/26 15:12:20 1.4
+++ src/sys/dev/nvmm/nvmm.h 2019/03/21 20:21:40 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nvmm.h,v 1.4 2019/01/26 15:12:20 maxv Exp $ */ | 1 | /* $NetBSD: nvmm.h,v 1.5 2019/03/21 20:21:40 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -54,34 +54,28 @@ enum nvmm_exit_reason { | @@ -54,34 +54,28 @@ enum nvmm_exit_reason { | |||
54 | NVMM_EXIT_INT_READY = 0x0000000000000004, | 54 | NVMM_EXIT_INT_READY = 0x0000000000000004, | |
55 | NVMM_EXIT_NMI_READY = 0x0000000000000005, | 55 | NVMM_EXIT_NMI_READY = 0x0000000000000005, | |
56 | NVMM_EXIT_HALTED = 0x0000000000000006, | 56 | NVMM_EXIT_HALTED = 0x0000000000000006, | |
57 | NVMM_EXIT_SHUTDOWN = 0x0000000000000007, | 57 | NVMM_EXIT_SHUTDOWN = 0x0000000000000007, | |
58 | 58 | |||
59 | /* Instructions (x86). */ | 59 | /* Instructions (x86). */ | |
60 | NVMM_EXIT_MONITOR = 0x0000000000001000, | 60 | NVMM_EXIT_MONITOR = 0x0000000000001000, | |
61 | NVMM_EXIT_MWAIT = 0x0000000000001001, | 61 | NVMM_EXIT_MWAIT = 0x0000000000001001, | |
62 | NVMM_EXIT_MWAIT_COND = 0x0000000000001002, | 62 | NVMM_EXIT_MWAIT_COND = 0x0000000000001002, | |
63 | 63 | |||
64 | NVMM_EXIT_INVALID = 0xFFFFFFFFFFFFFFFF | 64 | NVMM_EXIT_INVALID = 0xFFFFFFFFFFFFFFFF | |
65 | }; | 65 | }; | |
66 | 66 | |||
67 | enum nvmm_exit_memory_perm { | |||
68 | NVMM_EXIT_MEMORY_READ, | |||
69 | NVMM_EXIT_MEMORY_WRITE, | |||
70 | NVMM_EXIT_MEMORY_EXEC | |||
71 | }; | |||
72 | ||||
73 | struct nvmm_exit_memory { | 67 | struct nvmm_exit_memory { | |
74 | enum nvmm_exit_memory_perm perm; | 68 | int prot; | |
75 | gpaddr_t gpa; | 69 | gpaddr_t gpa; | |
76 | uint8_t inst_len; | 70 | uint8_t inst_len; | |
77 | uint8_t inst_bytes[15]; | 71 | uint8_t inst_bytes[15]; | |
78 | }; | 72 | }; | |
79 | 73 | |||
80 | enum nvmm_exit_io_type { | 74 | enum nvmm_exit_io_type { | |
81 | NVMM_EXIT_IO_IN, | 75 | NVMM_EXIT_IO_IN, | |
82 | NVMM_EXIT_IO_OUT | 76 | NVMM_EXIT_IO_OUT | |
83 | }; | 77 | }; | |
84 | 78 | |||
85 | struct nvmm_exit_io { | 79 | struct nvmm_exit_io { | |
86 | enum nvmm_exit_io_type type; | 80 | enum nvmm_exit_io_type type; | |
87 | uint16_t port; | 81 | uint16_t port; |
--- src/sys/dev/nvmm/nvmm_ioctl.h 2019/01/08 07:29:46 1.3
+++ src/sys/dev/nvmm/nvmm_ioctl.h 2019/03/21 20:21:40 1.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nvmm_ioctl.h,v 1.3 2019/01/08 07:29:46 maxv Exp $ */ | 1 | /* $NetBSD: nvmm_ioctl.h,v 1.4 2019/03/21 20:21:40 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -99,27 +99,27 @@ struct nvmm_ioc_hva_map { | @@ -99,27 +99,27 @@ struct nvmm_ioc_hva_map { | |||
99 | 99 | |||
100 | struct nvmm_ioc_hva_unmap { | 100 | struct nvmm_ioc_hva_unmap { | |
101 | nvmm_machid_t machid; | 101 | nvmm_machid_t machid; | |
102 | uintptr_t hva; | 102 | uintptr_t hva; | |
103 | size_t size; | 103 | size_t size; | |
104 | int flags; | 104 | int flags; | |
105 | }; | 105 | }; | |
106 | 106 | |||
107 | struct nvmm_ioc_gpa_map { | 107 | struct nvmm_ioc_gpa_map { | |
108 | nvmm_machid_t machid; | 108 | nvmm_machid_t machid; | |
109 | uintptr_t hva; | 109 | uintptr_t hva; | |
110 | gpaddr_t gpa; | 110 | gpaddr_t gpa; | |
111 | size_t size; | 111 | size_t size; | |
112 | int flags; | 112 | int prot; | |
113 | }; | 113 | }; | |
114 | 114 | |||
115 | struct nvmm_ioc_gpa_unmap { | 115 | struct nvmm_ioc_gpa_unmap { | |
116 | nvmm_machid_t machid; | 116 | nvmm_machid_t machid; | |
117 | gpaddr_t gpa; | 117 | gpaddr_t gpa; | |
118 | size_t size; | 118 | size_t size; | |
119 | }; | 119 | }; | |
120 | 120 | |||
121 | #define NVMM_IOC_CAPABILITY _IOR ('N', 0, struct nvmm_ioc_capability) | 121 | #define NVMM_IOC_CAPABILITY _IOR ('N', 0, struct nvmm_ioc_capability) | |
122 | #define NVMM_IOC_MACHINE_CREATE _IOWR('N', 1, struct nvmm_ioc_machine_create) | 122 | #define NVMM_IOC_MACHINE_CREATE _IOWR('N', 1, struct nvmm_ioc_machine_create) | |
123 | #define NVMM_IOC_MACHINE_DESTROY _IOW ('N', 2, struct nvmm_ioc_machine_destroy) | 123 | #define NVMM_IOC_MACHINE_DESTROY _IOW ('N', 2, struct nvmm_ioc_machine_destroy) | |
124 | #define NVMM_IOC_MACHINE_CONFIGURE _IOW ('N', 3, struct nvmm_ioc_machine_configure) | 124 | #define NVMM_IOC_MACHINE_CONFIGURE _IOW ('N', 3, struct nvmm_ioc_machine_configure) | |
125 | #define NVMM_IOC_VCPU_CREATE _IOW ('N', 4, struct nvmm_ioc_vcpu_create) | 125 | #define NVMM_IOC_VCPU_CREATE _IOW ('N', 4, struct nvmm_ioc_vcpu_create) |
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c 2019/03/14 19:15:26 1.34
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c 2019/03/21 20:21:41 1.35
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nvmm_x86_svm.c,v 1.34 2019/03/14 19:15:26 maxv Exp $ */ | 1 | /* $NetBSD: nvmm_x86_svm.c,v 1.35 2019/03/21 20:21:41 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,34 +20,35 @@ | @@ -20,34 +20,35 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.34 2019/03/14 19:15:26 maxv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.35 2019/03/21 20:21:41 maxv Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/systm.h> | 36 | #include <sys/systm.h> | |
37 | #include <sys/kernel.h> | 37 | #include <sys/kernel.h> | |
38 | #include <sys/kmem.h> | 38 | #include <sys/kmem.h> | |
39 | #include <sys/cpu.h> | 39 | #include <sys/cpu.h> | |
40 | #include <sys/xcall.h> | 40 | #include <sys/xcall.h> | |
41 | #include <sys/mman.h> | |||
41 | 42 | |||
42 | #include <uvm/uvm.h> | 43 | #include <uvm/uvm.h> | |
43 | #include <uvm/uvm_page.h> | 44 | #include <uvm/uvm_page.h> | |
44 | 45 | |||
45 | #include <x86/cputypes.h> | 46 | #include <x86/cputypes.h> | |
46 | #include <x86/specialreg.h> | 47 | #include <x86/specialreg.h> | |
47 | #include <x86/pmap.h> | 48 | #include <x86/pmap.h> | |
48 | #include <x86/dbregs.h> | 49 | #include <x86/dbregs.h> | |
49 | #include <x86/cpu_counter.h> | 50 | #include <x86/cpu_counter.h> | |
50 | #include <machine/cpuvar.h> | 51 | #include <machine/cpuvar.h> | |
51 | 52 | |||
52 | #include <dev/nvmm/nvmm.h> | 53 | #include <dev/nvmm/nvmm.h> | |
53 | #include <dev/nvmm/nvmm_internal.h> | 54 | #include <dev/nvmm/nvmm_internal.h> | |
@@ -1056,31 +1057,31 @@ svm_exit_msr(struct nvmm_machine *mach, | @@ -1056,31 +1057,31 @@ svm_exit_msr(struct nvmm_machine *mach, | |||
1056 | exit->reason = NVMM_EXIT_MSR; | 1057 | exit->reason = NVMM_EXIT_MSR; | |
1057 | exit->u.msr.npc = cpudata->vmcb->ctrl.nrip; | 1058 | exit->u.msr.npc = cpudata->vmcb->ctrl.nrip; | |
1058 | } | 1059 | } | |
1059 | 1060 | |||
1060 | static void | 1061 | static void | |
1061 | svm_exit_npf(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, | 1062 | svm_exit_npf(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, | |
1062 | struct nvmm_exit *exit) | 1063 | struct nvmm_exit *exit) | |
1063 | { | 1064 | { | |
1064 | struct svm_cpudata *cpudata = vcpu->cpudata; | 1065 | struct svm_cpudata *cpudata = vcpu->cpudata; | |
1065 | gpaddr_t gpa = cpudata->vmcb->ctrl.exitinfo2; | 1066 | gpaddr_t gpa = cpudata->vmcb->ctrl.exitinfo2; | |
1066 | 1067 | |||
1067 | exit->reason = NVMM_EXIT_MEMORY; | 1068 | exit->reason = NVMM_EXIT_MEMORY; | |
1068 | if (cpudata->vmcb->ctrl.exitinfo1 & PGEX_W) | 1069 | if (cpudata->vmcb->ctrl.exitinfo1 & PGEX_W) | |
1069 | exit->u.mem.perm = NVMM_EXIT_MEMORY_WRITE; | 1070 | exit->u.mem.prot = PROT_WRITE; | |
1070 | else if (cpudata->vmcb->ctrl.exitinfo1 & PGEX_X) | 1071 | else if (cpudata->vmcb->ctrl.exitinfo1 & PGEX_X) | |
1071 | exit->u.mem.perm = NVMM_EXIT_MEMORY_EXEC; | 1072 | exit->u.mem.prot = PROT_EXEC; | |
1072 | else | 1073 | else | |
1073 | exit->u.mem.perm = NVMM_EXIT_MEMORY_READ; | 1074 | exit->u.mem.prot = PROT_READ; | |
1074 | exit->u.mem.gpa = gpa; | 1075 | exit->u.mem.gpa = gpa; | |
1075 | exit->u.mem.inst_len = cpudata->vmcb->ctrl.inst_len; | 1076 | exit->u.mem.inst_len = cpudata->vmcb->ctrl.inst_len; | |
1076 | memcpy(exit->u.mem.inst_bytes, cpudata->vmcb->ctrl.inst_bytes, | 1077 | memcpy(exit->u.mem.inst_bytes, cpudata->vmcb->ctrl.inst_bytes, | |
1077 | sizeof(exit->u.mem.inst_bytes)); | 1078 | sizeof(exit->u.mem.inst_bytes)); | |
1078 | } | 1079 | } | |
1079 | 1080 | |||
1080 | static void | 1081 | static void | |
1081 | svm_exit_insn(struct vmcb *vmcb, struct nvmm_exit *exit, uint64_t reason) | 1082 | svm_exit_insn(struct vmcb *vmcb, struct nvmm_exit *exit, uint64_t reason) | |
1082 | { | 1083 | { | |
1083 | exit->u.insn.npc = vmcb->ctrl.nrip; | 1084 | exit->u.insn.npc = vmcb->ctrl.nrip; | |
1084 | exit->reason = reason; | 1085 | exit->reason = reason; | |
1085 | } | 1086 | } | |
1086 | 1087 |
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c 2019/03/14 20:29:53 1.19
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c 2019/03/21 20:21:41 1.20
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nvmm_x86_vmx.c,v 1.19 2019/03/14 20:29:53 maxv Exp $ */ | 1 | /* $NetBSD: nvmm_x86_vmx.c,v 1.20 2019/03/21 20:21:41 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,34 +20,35 @@ | @@ -20,34 +20,35 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.19 2019/03/14 20:29:53 maxv Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.20 2019/03/21 20:21:41 maxv Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/systm.h> | 36 | #include <sys/systm.h> | |
37 | #include <sys/kernel.h> | 37 | #include <sys/kernel.h> | |
38 | #include <sys/kmem.h> | 38 | #include <sys/kmem.h> | |
39 | #include <sys/cpu.h> | 39 | #include <sys/cpu.h> | |
40 | #include <sys/xcall.h> | 40 | #include <sys/xcall.h> | |
41 | #include <sys/mman.h> | |||
41 | 42 | |||
42 | #include <uvm/uvm.h> | 43 | #include <uvm/uvm.h> | |
43 | #include <uvm/uvm_page.h> | 44 | #include <uvm/uvm_page.h> | |
44 | 45 | |||
45 | #include <x86/cputypes.h> | 46 | #include <x86/cputypes.h> | |
46 | #include <x86/specialreg.h> | 47 | #include <x86/specialreg.h> | |
47 | #include <x86/pmap.h> | 48 | #include <x86/pmap.h> | |
48 | #include <x86/dbregs.h> | 49 | #include <x86/dbregs.h> | |
49 | #include <x86/cpu_counter.h> | 50 | #include <x86/cpu_counter.h> | |
50 | #include <machine/cpuvar.h> | 51 | #include <machine/cpuvar.h> | |
51 | 52 | |||
52 | #include <dev/nvmm/nvmm.h> | 53 | #include <dev/nvmm/nvmm.h> | |
53 | #include <dev/nvmm/nvmm_internal.h> | 54 | #include <dev/nvmm/nvmm_internal.h> | |
@@ -1590,31 +1591,31 @@ error: | @@ -1590,31 +1591,31 @@ error: | |||
1590 | 1591 | |||
1591 | static void | 1592 | static void | |
1592 | vmx_exit_epf(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, | 1593 | vmx_exit_epf(struct nvmm_machine *mach, struct nvmm_cpu *vcpu, | |
1593 | struct nvmm_exit *exit) | 1594 | struct nvmm_exit *exit) | |
1594 | { | 1595 | { | |
1595 | uint64_t perm; | 1596 | uint64_t perm; | |
1596 | gpaddr_t gpa; | 1597 | gpaddr_t gpa; | |
1597 | 1598 | |||
1598 | vmx_vmread(VMCS_GUEST_PHYSICAL_ADDRESS, &gpa); | 1599 | vmx_vmread(VMCS_GUEST_PHYSICAL_ADDRESS, &gpa); | |
1599 | 1600 | |||
1600 | exit->reason = NVMM_EXIT_MEMORY; | 1601 | exit->reason = NVMM_EXIT_MEMORY; | |
1601 | vmx_vmread(VMCS_EXIT_QUALIFICATION, &perm); | 1602 | vmx_vmread(VMCS_EXIT_QUALIFICATION, &perm); | |
1602 | if (perm & VMX_EPT_VIOLATION_WRITE) | 1603 | if (perm & VMX_EPT_VIOLATION_WRITE) | |
1603 | exit->u.mem.perm = NVMM_EXIT_MEMORY_WRITE; | 1604 | exit->u.mem.prot = PROT_WRITE; | |
1604 | else if (perm & VMX_EPT_VIOLATION_EXECUTE) | 1605 | else if (perm & VMX_EPT_VIOLATION_EXECUTE) | |
1605 | exit->u.mem.perm = NVMM_EXIT_MEMORY_EXEC; | 1606 | exit->u.mem.prot = PROT_EXEC; | |
1606 | else | 1607 | else | |
1607 | exit->u.mem.perm = NVMM_EXIT_MEMORY_READ; | 1608 | exit->u.mem.prot = PROT_READ; | |
1608 | exit->u.mem.gpa = gpa; | 1609 | exit->u.mem.gpa = gpa; | |
1609 | exit->u.mem.inst_len = 0; | 1610 | exit->u.mem.inst_len = 0; | |
1610 | } | 1611 | } | |
1611 | 1612 | |||
1612 | /* -------------------------------------------------------------------------- */ | 1613 | /* -------------------------------------------------------------------------- */ | |
1613 | 1614 | |||
1614 | static void | 1615 | static void | |
1615 | vmx_vcpu_guest_fpu_enter(struct nvmm_cpu *vcpu) | 1616 | vmx_vcpu_guest_fpu_enter(struct nvmm_cpu *vcpu) | |
1616 | { | 1617 | { | |
1617 | struct vmx_cpudata *cpudata = vcpu->cpudata; | 1618 | struct vmx_cpudata *cpudata = vcpu->cpudata; | |
1618 | 1619 | |||
1619 | cpudata->ts_set = (rcr0() & CR0_TS) != 0; | 1620 | cpudata->ts_set = (rcr0() & CR0_TS) != 0; | |
1620 | 1621 |
--- src/tests/lib/libnvmm/h_io_assist.c 2019/03/19 19:23:39 1.4
+++ src/tests/lib/libnvmm/h_io_assist.c 2019/03/21 20:21:41 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: h_io_assist.c,v 1.4 2019/03/19 19:23:39 maxv Exp $ */ | 1 | /* $NetBSD: h_io_assist.c,v 1.5 2019/03/21 20:21:41 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -116,43 +116,48 @@ reset_machine(struct nvmm_machine *mach) | @@ -116,43 +116,48 @@ reset_machine(struct nvmm_machine *mach) | |||
116 | /* Page tables. */ | 116 | /* Page tables. */ | |
117 | state.crs[NVMM_X64_CR_CR3] = 0x3000; | 117 | state.crs[NVMM_X64_CR_CR3] = 0x3000; | |
118 | 118 | |||
119 | state.gprs[NVMM_X64_GPR_RIP] = 0x2000; | 119 | state.gprs[NVMM_X64_GPR_RIP] = 0x2000; | |
120 | 120 | |||
121 | if (nvmm_vcpu_setstate(mach, 0, &state, NVMM_X64_STATE_ALL) == -1) | 121 | if (nvmm_vcpu_setstate(mach, 0, &state, NVMM_X64_STATE_ALL) == -1) | |
122 | err(errno, "nvmm_vcpu_setstate"); | 122 | err(errno, "nvmm_vcpu_setstate"); | |
123 | } | 123 | } | |
124 | 124 | |||
125 | static void | 125 | static void | |
126 | map_pages(struct nvmm_machine *mach) | 126 | map_pages(struct nvmm_machine *mach) | |
127 | { | 127 | { | |
128 | pt_entry_t *L4, *L3, *L2, *L1; | 128 | pt_entry_t *L4, *L3, *L2, *L1; | |
129 | int ret; | |||
129 | 130 | |||
130 | instbuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 131 | instbuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
131 | -1, 0); | 132 | -1, 0); | |
132 | if (instbuf == MAP_FAILED) | 133 | if (instbuf == MAP_FAILED) | |
133 | err(errno, "mmap"); | 134 | err(errno, "mmap"); | |
134 | databuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 135 | databuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
135 | -1, 0); | 136 | -1, 0); | |
136 | if (databuf == MAP_FAILED) | 137 | if (databuf == MAP_FAILED) | |
137 | err(errno, "mmap"); | 138 | err(errno, "mmap"); | |
138 | 139 | |||
139 | if (nvmm_hva_map(mach, (uintptr_t)instbuf, PAGE_SIZE) == -1) | 140 | if (nvmm_hva_map(mach, (uintptr_t)instbuf, PAGE_SIZE) == -1) | |
140 | err(errno, "nvmm_hva_map"); | 141 | err(errno, "nvmm_hva_map"); | |
141 | if (nvmm_hva_map(mach, (uintptr_t)databuf, PAGE_SIZE) == -1) | 142 | if (nvmm_hva_map(mach, (uintptr_t)databuf, PAGE_SIZE) == -1) | |
142 | err(errno, "nvmm_hva_map"); | 143 | err(errno, "nvmm_hva_map"); | |
143 | if (nvmm_gpa_map(mach, (uintptr_t)instbuf, 0x2000, PAGE_SIZE, 0) == -1) | 144 | ret = nvmm_gpa_map(mach, (uintptr_t)instbuf, 0x2000, PAGE_SIZE, | |
145 | PROT_READ|PROT_EXEC); | |||
146 | if (ret == -1) | |||
144 | err(errno, "nvmm_gpa_map"); | 147 | err(errno, "nvmm_gpa_map"); | |
145 | if (nvmm_gpa_map(mach, (uintptr_t)databuf, 0x1000, PAGE_SIZE, 0) == -1) | 148 | ret = nvmm_gpa_map(mach, (uintptr_t)databuf, 0x1000, PAGE_SIZE, | |
149 | PROT_READ|PROT_WRITE); | |||
150 | if (ret == -1) | |||
146 | err(errno, "nvmm_gpa_map"); | 151 | err(errno, "nvmm_gpa_map"); | |
147 | 152 | |||
148 | L4 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 153 | L4 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
149 | -1, 0); | 154 | -1, 0); | |
150 | if (L4 == MAP_FAILED) | 155 | if (L4 == MAP_FAILED) | |
151 | err(errno, "mmap"); | 156 | err(errno, "mmap"); | |
152 | L3 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 157 | L3 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
153 | -1, 0); | 158 | -1, 0); | |
154 | if (L3 == MAP_FAILED) | 159 | if (L3 == MAP_FAILED) | |
155 | err(errno, "mmap"); | 160 | err(errno, "mmap"); | |
156 | L2 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 161 | L2 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
157 | -1, 0); | 162 | -1, 0); | |
158 | if (L2 == MAP_FAILED) | 163 | if (L2 == MAP_FAILED) | |
@@ -161,33 +166,41 @@ map_pages(struct nvmm_machine *mach) | @@ -161,33 +166,41 @@ map_pages(struct nvmm_machine *mach) | |||
161 | -1, 0); | 166 | -1, 0); | |
162 | if (L1 == MAP_FAILED) | 167 | if (L1 == MAP_FAILED) | |
163 | err(errno, "mmap"); | 168 | err(errno, "mmap"); | |
164 | 169 | |||
165 | if (nvmm_hva_map(mach, (uintptr_t)L4, PAGE_SIZE) == -1) | 170 | if (nvmm_hva_map(mach, (uintptr_t)L4, PAGE_SIZE) == -1) | |
166 | err(errno, "nvmm_hva_map"); | 171 | err(errno, "nvmm_hva_map"); | |
167 | if (nvmm_hva_map(mach, (uintptr_t)L3, PAGE_SIZE) == -1) | 172 | if (nvmm_hva_map(mach, (uintptr_t)L3, PAGE_SIZE) == -1) | |
168 | err(errno, "nvmm_hva_map"); | 173 | err(errno, "nvmm_hva_map"); | |
169 | if (nvmm_hva_map(mach, (uintptr_t)L2, PAGE_SIZE) == -1) | 174 | if (nvmm_hva_map(mach, (uintptr_t)L2, PAGE_SIZE) == -1) | |
170 | err(errno, "nvmm_hva_map"); | 175 | err(errno, "nvmm_hva_map"); | |
171 | if (nvmm_hva_map(mach, (uintptr_t)L1, PAGE_SIZE) == -1) | 176 | if (nvmm_hva_map(mach, (uintptr_t)L1, PAGE_SIZE) == -1) | |
172 | err(errno, "nvmm_hva_map"); | 177 | err(errno, "nvmm_hva_map"); | |
173 | 178 | |||
174 | if (nvmm_gpa_map(mach, (uintptr_t)L4, 0x3000, PAGE_SIZE, 0) == -1) | 179 | ret = nvmm_gpa_map(mach, (uintptr_t)L4, 0x3000, PAGE_SIZE, | |
180 | PROT_READ|PROT_WRITE); | |||
181 | if (ret == -1) | |||
175 | err(errno, "nvmm_gpa_map"); | 182 | err(errno, "nvmm_gpa_map"); | |
176 | if (nvmm_gpa_map(mach, (uintptr_t)L3, 0x4000, PAGE_SIZE, 0) == -1) | 183 | ret = nvmm_gpa_map(mach, (uintptr_t)L3, 0x4000, PAGE_SIZE, | |
184 | PROT_READ|PROT_WRITE); | |||
185 | if (ret == -1) | |||
177 | err(errno, "nvmm_gpa_map"); | 186 | err(errno, "nvmm_gpa_map"); | |
178 | if (nvmm_gpa_map(mach, (uintptr_t)L2, 0x5000, PAGE_SIZE, 0) == -1) | 187 | ret = nvmm_gpa_map(mach, (uintptr_t)L2, 0x5000, PAGE_SIZE, | |
188 | PROT_READ|PROT_WRITE); | |||
189 | if (ret == -1) | |||
179 | err(errno, "nvmm_gpa_map"); | 190 | err(errno, "nvmm_gpa_map"); | |
180 | if (nvmm_gpa_map(mach, (uintptr_t)L1, 0x6000, PAGE_SIZE, 0) == -1) | 191 | ret = nvmm_gpa_map(mach, (uintptr_t)L1, 0x6000, PAGE_SIZE, | |
192 | if (ret == -1) | |||
193 | PROT_READ|PROT_WRITE); | |||
181 | err(errno, "nvmm_gpa_map"); | 194 | err(errno, "nvmm_gpa_map"); | |
182 | 195 | |||
183 | memset(L4, 0, PAGE_SIZE); | 196 | memset(L4, 0, PAGE_SIZE); | |
184 | memset(L3, 0, PAGE_SIZE); | 197 | memset(L3, 0, PAGE_SIZE); | |
185 | memset(L2, 0, PAGE_SIZE); | 198 | memset(L2, 0, PAGE_SIZE); | |
186 | memset(L1, 0, PAGE_SIZE); | 199 | memset(L1, 0, PAGE_SIZE); | |
187 | 200 | |||
188 | L4[0] = PTE_P | PTE_W | 0x4000; | 201 | L4[0] = PTE_P | PTE_W | 0x4000; | |
189 | L3[0] = PTE_P | PTE_W | 0x5000; | 202 | L3[0] = PTE_P | PTE_W | 0x5000; | |
190 | L2[0] = PTE_P | PTE_W | 0x6000; | 203 | L2[0] = PTE_P | PTE_W | 0x6000; | |
191 | L1[0x2000 / PAGE_SIZE] = PTE_P | PTE_W | 0x2000; | 204 | L1[0x2000 / PAGE_SIZE] = PTE_P | PTE_W | 0x2000; | |
192 | L1[0x1000 / PAGE_SIZE] = PTE_P | PTE_W | 0x1000; | 205 | L1[0x1000 / PAGE_SIZE] = PTE_P | PTE_W | 0x1000; | |
193 | } | 206 | } |
--- src/tests/lib/libnvmm/h_mem_assist.c 2019/03/19 19:23:39 1.7
+++ src/tests/lib/libnvmm/h_mem_assist.c 2019/03/21 20:21:41 1.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: h_mem_assist.c,v 1.7 2019/03/19 19:23:39 maxv Exp $ */ | 1 | /* $NetBSD: h_mem_assist.c,v 1.8 2019/03/21 20:21:41 maxv Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -121,27 +121,29 @@ reset_machine(struct nvmm_machine *mach) | @@ -121,27 +121,29 @@ reset_machine(struct nvmm_machine *mach) | |||
121 | 121 | |||
122 | static void | 122 | static void | |
123 | map_pages(struct nvmm_machine *mach) | 123 | map_pages(struct nvmm_machine *mach) | |
124 | { | 124 | { | |
125 | pt_entry_t *L4, *L3, *L2, *L1; | 125 | pt_entry_t *L4, *L3, *L2, *L1; | |
126 | 126 | |||
127 | instbuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 127 | instbuf = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
128 | -1, 0); | 128 | -1, 0); | |
129 | if (instbuf == MAP_FAILED) | 129 | if (instbuf == MAP_FAILED) | |
130 | err(errno, "mmap"); | 130 | err(errno, "mmap"); | |
131 | 131 | |||
132 | if (nvmm_hva_map(mach, (uintptr_t)instbuf, PAGE_SIZE) == -1) | 132 | if (nvmm_hva_map(mach, (uintptr_t)instbuf, PAGE_SIZE) == -1) | |
133 | err(errno, "nvmm_hva_map"); | 133 | err(errno, "nvmm_hva_map"); | |
134 | if (nvmm_gpa_map(mach, (uintptr_t)instbuf, 0x2000, PAGE_SIZE, 0) == -1) | 134 | ret = nvmm_gpa_map(mach, (uintptr_t)instbuf, 0x2000, PAGE_SIZE, | |
135 | PROT_READ|PROT_EXEC); | |||
136 | if (ret == -1) | |||
135 | err(errno, "nvmm_gpa_map"); | 137 | err(errno, "nvmm_gpa_map"); | |
136 | 138 | |||
137 | L4 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 139 | L4 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
138 | -1, 0); | 140 | -1, 0); | |
139 | if (L4 == MAP_FAILED) | 141 | if (L4 == MAP_FAILED) | |
140 | err(errno, "mmap"); | 142 | err(errno, "mmap"); | |
141 | L3 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 143 | L3 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
142 | -1, 0); | 144 | -1, 0); | |
143 | if (L3 == MAP_FAILED) | 145 | if (L3 == MAP_FAILED) | |
144 | err(errno, "mmap"); | 146 | err(errno, "mmap"); | |
145 | L2 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | 147 | L2 = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, | |
146 | -1, 0); | 148 | -1, 0); | |
147 | if (L2 == MAP_FAILED) | 149 | if (L2 == MAP_FAILED) | |
@@ -150,33 +152,41 @@ map_pages(struct nvmm_machine *mach) | @@ -150,33 +152,41 @@ map_pages(struct nvmm_machine *mach) | |||
150 | -1, 0); | 152 | -1, 0); | |
151 | if (L1 == MAP_FAILED) | 153 | if (L1 == MAP_FAILED) | |
152 | err(errno, "mmap"); | 154 | err(errno, "mmap"); | |
153 | 155 | |||
154 | if (nvmm_hva_map(mach, (uintptr_t)L4, PAGE_SIZE) == -1) | 156 | if (nvmm_hva_map(mach, (uintptr_t)L4, PAGE_SIZE) == -1) | |
155 | err(errno, "nvmm_hva_map"); | 157 | err(errno, "nvmm_hva_map"); | |
156 | if (nvmm_hva_map(mach, (uintptr_t)L3, PAGE_SIZE) == -1) | 158 | if (nvmm_hva_map(mach, (uintptr_t)L3, PAGE_SIZE) == -1) | |
157 | err(errno, "nvmm_hva_map"); | 159 | err(errno, "nvmm_hva_map"); | |
158 | if (nvmm_hva_map(mach, (uintptr_t)L2, PAGE_SIZE) == -1) | 160 | if (nvmm_hva_map(mach, (uintptr_t)L2, PAGE_SIZE) == -1) | |
159 | err(errno, "nvmm_hva_map"); | 161 | err(errno, "nvmm_hva_map"); | |
160 | if (nvmm_hva_map(mach, (uintptr_t)L1, PAGE_SIZE) == -1) | 162 | if (nvmm_hva_map(mach, (uintptr_t)L1, PAGE_SIZE) == -1) | |
161 | err(errno, "nvmm_hva_map"); | 163 | err(errno, "nvmm_hva_map"); | |
162 | 164 | |||
163 | if (nvmm_gpa_map(mach, (uintptr_t)L4, 0x3000, PAGE_SIZE, 0) == -1) | 165 | ret = nvmm_gpa_map(mach, (uintptr_t)L4, 0x3000, PAGE_SIZE, | |
166 | PROT_READ|PROT_WRITE); | |||
167 | if (ret == -1) | |||
164 | err(errno, "nvmm_gpa_map"); | 168 | err(errno, "nvmm_gpa_map"); | |
165 | if (nvmm_gpa_map(mach, (uintptr_t)L3, 0x4000, PAGE_SIZE, 0) == -1) | 169 | ret = nvmm_gpa_map(mach, (uintptr_t)L3, 0x4000, PAGE_SIZE, | |
170 | PROT_READ|PROT_WRITE); | |||
171 | if (ret == -1) | |||
166 | err(errno, "nvmm_gpa_map"); | 172 | err(errno, "nvmm_gpa_map"); | |
167 | if (nvmm_gpa_map(mach, (uintptr_t)L2, 0x5000, PAGE_SIZE, 0) == -1) | 173 | ret = nvmm_gpa_map(mach, (uintptr_t)L2, 0x5000, PAGE_SIZE, | |
174 | PROT_READ|PROT_WRITE); | |||
175 | if (ret == -1) | |||
168 | err(errno, "nvmm_gpa_map"); | 176 | err(errno, "nvmm_gpa_map"); | |
169 | if (nvmm_gpa_map(mach, (uintptr_t)L1, 0x6000, PAGE_SIZE, 0) == -1) | 177 | ret = nvmm_gpa_map(mach, (uintptr_t)L1, 0x6000, PAGE_SIZE, | |
178 | PROT_READ|PROT_WRITE); | |||
179 | if (ret == -1) | |||
170 | err(errno, "nvmm_gpa_map"); | 180 | err(errno, "nvmm_gpa_map"); | |
171 | 181 | |||
172 | memset(L4, 0, PAGE_SIZE); | 182 | memset(L4, 0, PAGE_SIZE); | |
173 | memset(L3, 0, PAGE_SIZE); | 183 | memset(L3, 0, PAGE_SIZE); | |
174 | memset(L2, 0, PAGE_SIZE); | 184 | memset(L2, 0, PAGE_SIZE); | |
175 | memset(L1, 0, PAGE_SIZE); | 185 | memset(L1, 0, PAGE_SIZE); | |
176 | 186 | |||
177 | L4[0] = PTE_P | PTE_W | 0x4000; | 187 | L4[0] = PTE_P | PTE_W | 0x4000; | |
178 | L3[0] = PTE_P | PTE_W | 0x5000; | 188 | L3[0] = PTE_P | PTE_W | 0x5000; | |
179 | L2[0] = PTE_P | PTE_W | 0x6000; | 189 | L2[0] = PTE_P | PTE_W | 0x6000; | |
180 | L1[0x2000 / PAGE_SIZE] = PTE_P | PTE_W | 0x2000; | 190 | L1[0x2000 / PAGE_SIZE] = PTE_P | PTE_W | 0x2000; | |
181 | L1[0x1000 / PAGE_SIZE] = PTE_P | PTE_W | 0x1000; | 191 | L1[0x1000 / PAGE_SIZE] = PTE_P | PTE_W | 0x1000; | |
182 | } | 192 | } |