Deleted Added
full compact
vmmapi.c (280929) vmmapi.c (282558)
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/lib/libvmmapi/vmmapi.c 280929 2015-04-01 00:15:31Z tychon $
26 * $FreeBSD: head/lib/libvmmapi/vmmapi.c 282558 2015-05-06 16:25:20Z neel $
27 */
28
29#include <sys/cdefs.h>
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/lib/libvmmapi/vmmapi.c 280929 2015-04-01 00:15:31Z tychon $");
30__FBSDID("$FreeBSD: head/lib/libvmmapi/vmmapi.c 282558 2015-05-06 16:25:20Z neel $");
31
32#include <sys/param.h>
33#include <sys/sysctl.h>
34#include <sys/ioctl.h>
35#include <sys/mman.h>
36#include <sys/_iovec.h>
37#include <sys/cpuset.h>
38
39#include <x86/segments.h>
40#include <machine/specialreg.h>
41#include <machine/param.h>
42
31
32#include <sys/param.h>
33#include <sys/sysctl.h>
34#include <sys/ioctl.h>
35#include <sys/mman.h>
36#include <sys/_iovec.h>
37#include <sys/cpuset.h>
38
39#include <x86/segments.h>
40#include <machine/specialreg.h>
41#include <machine/param.h>
42
43#include <errno.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <assert.h>
46#include <string.h>
47#include <fcntl.h>
48#include <unistd.h>
49
50#include <libutil.h>

--- 902 unchanged lines hidden (view full) ---

953
954 bzero(&cap, sizeof(struct vm_hpet_cap));
955 error = ioctl(ctx->fd, VM_GET_HPET_CAPABILITIES, &cap);
956 if (capabilities != NULL)
957 *capabilities = cap.capabilities;
958 return (error);
959}
960
44#include <stdio.h>
45#include <stdlib.h>
46#include <assert.h>
47#include <string.h>
48#include <fcntl.h>
49#include <unistd.h>
50
51#include <libutil.h>

--- 902 unchanged lines hidden (view full) ---

954
955 bzero(&cap, sizeof(struct vm_hpet_cap));
956 error = ioctl(ctx->fd, VM_GET_HPET_CAPABILITIES, &cap);
957 if (capabilities != NULL)
958 *capabilities = cap.capabilities;
959 return (error);
960}
961
961static int
962gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
963 uint64_t gla, int prot, int *fault, uint64_t *gpa)
962int
963vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
964 uint64_t gla, int prot, uint64_t *gpa, int *fault)
964{
965 struct vm_gla2gpa gg;
966 int error;
967
968 bzero(&gg, sizeof(struct vm_gla2gpa));
969 gg.vcpuid = vcpu;
970 gg.prot = prot;
971 gg.gla = gla;
972 gg.paging = *paging;
973
974 error = ioctl(ctx->fd, VM_GLA2GPA, &gg);
975 if (error == 0) {
976 *fault = gg.fault;
977 *gpa = gg.gpa;
978 }
979 return (error);
980}
981
965{
966 struct vm_gla2gpa gg;
967 int error;
968
969 bzero(&gg, sizeof(struct vm_gla2gpa));
970 gg.vcpuid = vcpu;
971 gg.prot = prot;
972 gg.gla = gla;
973 gg.paging = *paging;
974
975 error = ioctl(ctx->fd, VM_GLA2GPA, &gg);
976 if (error == 0) {
977 *fault = gg.fault;
978 *gpa = gg.gpa;
979 }
980 return (error);
981}
982
982int
983vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
984 uint64_t gla, int prot, uint64_t *gpa)
985{
986 int error, fault;
987
988 error = gla2gpa(ctx, vcpu, paging, gla, prot, &fault, gpa);
989 if (fault)
990 error = fault;
991 return (error);
992}
993
994#ifndef min
995#define min(a,b) (((a) < (b)) ? (a) : (b))
996#endif
997
998int
999vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
983#ifndef min
984#define min(a,b) (((a) < (b)) ? (a) : (b))
985#endif
986
987int
988vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging,
1000 uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt)
989 uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt,
990 int *fault)
1001{
1002 void *va;
1003 uint64_t gpa;
991{
992 void *va;
993 uint64_t gpa;
1004 int error, fault, i, n, off;
994 int error, i, n, off;
1005
1006 for (i = 0; i < iovcnt; i++) {
1007 iov[i].iov_base = 0;
1008 iov[i].iov_len = 0;
1009 }
1010
1011 while (len) {
1012 assert(iovcnt > 0);
995
996 for (i = 0; i < iovcnt; i++) {
997 iov[i].iov_base = 0;
998 iov[i].iov_len = 0;
999 }
1000
1001 while (len) {
1002 assert(iovcnt > 0);
1013 error = gla2gpa(ctx, vcpu, paging, gla, prot, &fault, &gpa);
1014 if (error)
1015 return (-1);
1016 if (fault)
1017 return (1);
1003 error = vm_gla2gpa(ctx, vcpu, paging, gla, prot, &gpa, fault);
1004 if (error || *fault)
1005 return (error);
1018
1019 off = gpa & PAGE_MASK;
1020 n = min(len, PAGE_SIZE - off);
1021
1022 va = vm_map_gpa(ctx, gpa, n);
1023 if (va == NULL)
1006
1007 off = gpa & PAGE_MASK;
1008 n = min(len, PAGE_SIZE - off);
1009
1010 va = vm_map_gpa(ctx, gpa, n);
1011 if (va == NULL)
1024 return (-1);
1012 return (EFAULT);
1025
1026 iov->iov_base = va;
1027 iov->iov_len = n;
1028 iov++;
1029 iovcnt--;
1030
1031 gla += n;
1032 len -= n;

--- 181 unchanged lines hidden ---
1013
1014 iov->iov_base = va;
1015 iov->iov_len = n;
1016 iov++;
1017 iovcnt--;
1018
1019 gla += n;
1020 len -= n;

--- 181 unchanged lines hidden ---