2019-04-04 20:33:47 +03:00
|
|
|
/* $NetBSD: nvmm.h,v 1.7 2019/04/04 17:33:47 maxv Exp $ */
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Maxime Villard.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBNVMM_H_
|
|
|
|
#define _LIBNVMM_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <dev/nvmm/nvmm.h>
|
|
|
|
#include <dev/nvmm/nvmm_ioctl.h>
|
|
|
|
#ifdef __x86_64__
|
|
|
|
#include <dev/nvmm/x86/nvmm_x86.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct nvmm_machine {
|
|
|
|
nvmm_machid_t machid;
|
2018-11-29 22:55:20 +03:00
|
|
|
void *areas; /* opaque */
|
2018-11-10 12:28:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nvmm_io {
|
|
|
|
uint64_t port;
|
|
|
|
bool in;
|
|
|
|
size_t size;
|
Improvements and fixes in NVMM.
Kernel driver:
* Don't take an extra (unneeded) reference to the UAO.
* Provide npc for HLT. I'm not really happy with it right now, will
likely be revisited.
* Add the INT_SHADOW, INT_WINDOW_EXIT and NMI_WINDOW_EXIT states. Provide
them in the exitstate too.
* Don't take the TPR into account when processing INTs. The virtualizer
can do that itself (Qemu already does).
* Provide a hypervisor signature in CPUID, and hide SVM.
* Ignore certain MSRs. One special case is MSR_NB_CFG in which we set
NB_CFG_INITAPICCPUIDLO. Allow reads of MSR_TSC.
* If the LWP has pending signals or softints, leave, rather than waiting
for a rescheduling to happen later. This reduces interrupt processing
time in the guest (Qemu sends a signal to the thread, and now we leave
right away). This could be improved even more by sending an actual IPI
to the CPU, but I'll see later.
Libnvmm:
* Fix the MMU translation of large pages, we need to add the lower bits
too.
* Change the IO and Mem structures to take a pointer rather than a
static array. This provides more flexibility.
* Batch together the str+rep IO transactions. We do one big memory
read/write, and then send the IO commands to the hypervisor all at
once. This considerably increases performance.
* Decode MOVZX.
With these changes in place, Qemu+NVMM works. I can install NetBSD 8.0
in a VM with multiple VCPUs, connect to the network, etc.
2019-01-06 19:10:51 +03:00
|
|
|
uint8_t *data;
|
2018-11-10 12:28:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nvmm_mem {
|
|
|
|
gpaddr_t gpa;
|
|
|
|
bool write;
|
|
|
|
size_t size;
|
Improvements and fixes in NVMM.
Kernel driver:
* Don't take an extra (unneeded) reference to the UAO.
* Provide npc for HLT. I'm not really happy with it right now, will
likely be revisited.
* Add the INT_SHADOW, INT_WINDOW_EXIT and NMI_WINDOW_EXIT states. Provide
them in the exitstate too.
* Don't take the TPR into account when processing INTs. The virtualizer
can do that itself (Qemu already does).
* Provide a hypervisor signature in CPUID, and hide SVM.
* Ignore certain MSRs. One special case is MSR_NB_CFG in which we set
NB_CFG_INITAPICCPUIDLO. Allow reads of MSR_TSC.
* If the LWP has pending signals or softints, leave, rather than waiting
for a rescheduling to happen later. This reduces interrupt processing
time in the guest (Qemu sends a signal to the thread, and now we leave
right away). This could be improved even more by sending an actual IPI
to the CPU, but I'll see later.
Libnvmm:
* Fix the MMU translation of large pages, we need to add the lower bits
too.
* Change the IO and Mem structures to take a pointer rather than a
static array. This provides more flexibility.
* Batch together the str+rep IO transactions. We do one big memory
read/write, and then send the IO commands to the hypervisor all at
once. This considerably increases performance.
* Decode MOVZX.
With these changes in place, Qemu+NVMM works. I can install NetBSD 8.0
in a VM with multiple VCPUs, connect to the network, etc.
2019-01-06 19:10:51 +03:00
|
|
|
uint8_t *data;
|
2018-11-10 12:28:56 +03:00
|
|
|
};
|
|
|
|
|
2018-12-27 10:22:31 +03:00
|
|
|
struct nvmm_callbacks {
|
|
|
|
void (*io)(struct nvmm_io *);
|
|
|
|
void (*mem)(struct nvmm_mem *);
|
|
|
|
};
|
|
|
|
|
2018-11-10 12:28:56 +03:00
|
|
|
#define NVMM_PROT_READ 0x01
|
|
|
|
#define NVMM_PROT_WRITE 0x02
|
|
|
|
#define NVMM_PROT_EXEC 0x04
|
|
|
|
#define NVMM_PROT_USER 0x08
|
|
|
|
#define NVMM_PROT_ALL 0x0F
|
|
|
|
typedef uint64_t nvmm_prot_t;
|
|
|
|
|
|
|
|
int nvmm_capability(struct nvmm_capability *);
|
|
|
|
|
|
|
|
int nvmm_machine_create(struct nvmm_machine *);
|
|
|
|
int nvmm_machine_destroy(struct nvmm_machine *);
|
|
|
|
int nvmm_machine_configure(struct nvmm_machine *, uint64_t, void *);
|
|
|
|
|
|
|
|
int nvmm_vcpu_create(struct nvmm_machine *, nvmm_cpuid_t);
|
|
|
|
int nvmm_vcpu_destroy(struct nvmm_machine *, nvmm_cpuid_t);
|
|
|
|
int nvmm_vcpu_setstate(struct nvmm_machine *, nvmm_cpuid_t, void *, uint64_t);
|
|
|
|
int nvmm_vcpu_getstate(struct nvmm_machine *, nvmm_cpuid_t, void *, uint64_t);
|
|
|
|
int nvmm_vcpu_inject(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_event *);
|
|
|
|
int nvmm_vcpu_run(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_exit *);
|
|
|
|
|
|
|
|
int nvmm_gpa_map(struct nvmm_machine *, uintptr_t, gpaddr_t, size_t, int);
|
|
|
|
int nvmm_gpa_unmap(struct nvmm_machine *, uintptr_t, gpaddr_t, size_t);
|
2018-12-15 16:39:43 +03:00
|
|
|
int nvmm_hva_map(struct nvmm_machine *, uintptr_t, size_t);
|
|
|
|
int nvmm_hva_unmap(struct nvmm_machine *, uintptr_t, size_t);
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
int nvmm_gva_to_gpa(struct nvmm_machine *, nvmm_cpuid_t, gvaddr_t, gpaddr_t *,
|
|
|
|
nvmm_prot_t *);
|
2019-04-04 20:33:47 +03:00
|
|
|
int nvmm_gpa_to_hva(struct nvmm_machine *, gpaddr_t, uintptr_t *,
|
|
|
|
nvmm_prot_t *);
|
2018-11-10 12:28:56 +03:00
|
|
|
|
2018-12-27 10:22:31 +03:00
|
|
|
int nvmm_assist_io(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_exit *);
|
|
|
|
int nvmm_assist_mem(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_exit *);
|
|
|
|
void nvmm_callbacks_register(const struct nvmm_callbacks *);
|
|
|
|
|
|
|
|
int nvmm_vcpu_dump(struct nvmm_machine *, nvmm_cpuid_t);
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
#endif /* _LIBNVMM_H_ */
|