2020-09-05 10:22:25 +03:00
|
|
|
/* $NetBSD: nvmm.h,v 1.18 2020/09/05 07:22:25 maxv Exp $ */
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
/*
|
2020-09-05 10:22:25 +03:00
|
|
|
* Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
|
2018-11-10 12:28:56 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2020-09-05 10:22:25 +03:00
|
|
|
* This code is part of the NVMM hypervisor.
|
2018-11-10 12:28:56 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2020-09-05 10:22:25 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
2018-11-10 12:28:56 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBNVMM_H_
|
|
|
|
#define _LIBNVMM_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <dev/nvmm/nvmm.h>
|
|
|
|
#include <dev/nvmm/nvmm_ioctl.h>
|
|
|
|
|
Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.
- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.
- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().
- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.
- Slightly reorganize the MI/MD definitions, for internal clarity.
- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.
- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t
- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.
- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.
- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.
- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.
2019-10-23 10:01:11 +03:00
|
|
|
#define NVMM_USER_VERSION 1
|
|
|
|
|
2019-10-23 15:02:55 +03:00
|
|
|
struct nvmm_io;
|
|
|
|
struct nvmm_mem;
|
2018-11-10 12:28:56 +03:00
|
|
|
|
2019-10-23 15:02:55 +03:00
|
|
|
struct nvmm_assist_callbacks {
|
2018-12-27 10:22:31 +03:00
|
|
|
void (*io)(struct nvmm_io *);
|
|
|
|
void (*mem)(struct nvmm_mem *);
|
|
|
|
};
|
|
|
|
|
2019-05-11 10:31:56 +03:00
|
|
|
struct nvmm_machine {
|
|
|
|
nvmm_machid_t machid;
|
|
|
|
struct nvmm_comm_page **pages;
|
|
|
|
void *areas; /* opaque */
|
|
|
|
};
|
|
|
|
|
2019-06-08 10:27:44 +03:00
|
|
|
struct nvmm_vcpu {
|
|
|
|
nvmm_cpuid_t cpuid;
|
2019-10-23 15:02:55 +03:00
|
|
|
struct nvmm_assist_callbacks cbs;
|
2019-06-08 10:27:44 +03:00
|
|
|
struct nvmm_vcpu_state *state;
|
Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.
- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.
- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().
- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.
- Slightly reorganize the MI/MD definitions, for internal clarity.
- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.
- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t
- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.
- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.
- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.
- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.
2019-10-23 10:01:11 +03:00
|
|
|
struct nvmm_vcpu_event *event;
|
|
|
|
struct nvmm_vcpu_exit *exit;
|
2019-06-08 10:27:44 +03:00
|
|
|
};
|
|
|
|
|
2019-10-23 15:02:55 +03:00
|
|
|
struct nvmm_io {
|
|
|
|
struct nvmm_machine *mach;
|
|
|
|
struct nvmm_vcpu *vcpu;
|
2019-10-28 11:30:49 +03:00
|
|
|
uint16_t port;
|
2019-10-23 15:02:55 +03:00
|
|
|
bool in;
|
|
|
|
size_t size;
|
|
|
|
uint8_t *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvmm_mem {
|
|
|
|
struct nvmm_machine *mach;
|
|
|
|
struct nvmm_vcpu *vcpu;
|
|
|
|
gpaddr_t gpa;
|
|
|
|
bool write;
|
|
|
|
size_t size;
|
|
|
|
uint8_t *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NVMM_VCPU_CONF_CALLBACKS NVMM_VCPU_CONF_LIBNVMM_BEGIN
|
2019-05-11 10:31:56 +03:00
|
|
|
|
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;
|
|
|
|
|
2019-10-27 10:08:15 +03:00
|
|
|
int nvmm_init(void);
|
2019-10-27 23:17:36 +03:00
|
|
|
int nvmm_root_init(void);
|
2019-10-27 10:08:15 +03:00
|
|
|
|
2018-11-10 12:28:56 +03:00
|
|
|
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 *);
|
|
|
|
|
2019-06-08 10:27:44 +03:00
|
|
|
int nvmm_vcpu_create(struct nvmm_machine *, nvmm_cpuid_t, struct nvmm_vcpu *);
|
|
|
|
int nvmm_vcpu_destroy(struct nvmm_machine *, struct nvmm_vcpu *);
|
Miscellaneous changes in NVMM, to address several inconsistencies and
issues in the libnvmm API.
- Rename NVMM_CAPABILITY_VERSION to NVMM_KERN_VERSION, and check it in
libnvmm. Introduce NVMM_USER_VERSION, for future use.
- In libnvmm, open "/dev/nvmm" as read-only and with O_CLOEXEC. This is to
avoid sharing the VMs with the children if the process forks. In the
NVMM driver, force O_CLOEXEC on open().
- Rename the following things for consistency:
nvmm_exit* -> nvmm_vcpu_exit*
nvmm_event* -> nvmm_vcpu_event*
NVMM_EXIT_* -> NVMM_VCPU_EXIT_*
NVMM_EVENT_INTERRUPT_HW -> NVMM_VCPU_EVENT_INTR
NVMM_EVENT_EXCEPTION -> NVMM_VCPU_EVENT_EXCP
Delete NVMM_EVENT_INTERRUPT_SW, unused already.
- Slightly reorganize the MI/MD definitions, for internal clarity.
- Split NVMM_VCPU_EXIT_MSR in two: NVMM_VCPU_EXIT_{RD,WR}MSR. Also provide
separate u.rdmsr and u.wrmsr fields. This is more consistent with the
other exit reasons.
- Change the types of several variables:
event.type enum -> u_int
event.vector uint64_t -> uint8_t
exit.u.*msr.msr: uint64_t -> uint32_t
exit.u.io.type: enum -> bool
exit.u.io.seg: int -> int8_t
cap.arch.mxcsr_mask: uint64_t -> uint32_t
cap.arch.conf_cpuid_maxops: uint64_t -> uint32_t
- Delete NVMM_VCPU_EXIT_MWAIT_COND, it is AMD-only and confusing, and we
already intercept 'monitor' so it is never armed.
- Introduce vmx_exit_insn() for NVMM-Intel, similar to svm_exit_insn().
The 'npc' field wasn't getting filled properly during certain VMEXITs.
- Introduce nvmm_vcpu_configure(). Similar to nvmm_machine_configure(),
but as its name indicates, the configuration is per-VCPU and not per-VM.
Migrate and rename NVMM_MACH_CONF_X86_CPUID to NVMM_VCPU_CONF_CPUID.
This becomes per-VCPU, which makes more sense than per-VM.
- Extend the NVMM_VCPU_CONF_CPUID conf to allow triggering VMEXITs on
specific leaves. Until now we could only mask the leaves. An uint32_t
is added in the structure:
uint32_t mask:1;
uint32_t exit:1;
uint32_t rsvd:30;
The two first bits select the desired behavior on the leaf. Specifying
zero on both resets the leaf to the default behavior. The new
NVMM_VCPU_EXIT_CPUID exit reason is added.
2019-10-23 10:01:11 +03:00
|
|
|
int nvmm_vcpu_configure(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t,
|
|
|
|
void *);
|
2019-06-08 10:27:44 +03:00
|
|
|
int nvmm_vcpu_setstate(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t);
|
|
|
|
int nvmm_vcpu_getstate(struct nvmm_machine *, struct nvmm_vcpu *, uint64_t);
|
|
|
|
int nvmm_vcpu_inject(struct nvmm_machine *, struct nvmm_vcpu *);
|
|
|
|
int nvmm_vcpu_run(struct nvmm_machine *, struct nvmm_vcpu *);
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-08 10:27:44 +03:00
|
|
|
int nvmm_gva_to_gpa(struct nvmm_machine *, struct nvmm_vcpu *, gvaddr_t, gpaddr_t *,
|
2018-11-10 12:28:56 +03:00
|
|
|
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
|
|
|
|
2019-06-08 10:27:44 +03:00
|
|
|
int nvmm_assist_io(struct nvmm_machine *, struct nvmm_vcpu *);
|
|
|
|
int nvmm_assist_mem(struct nvmm_machine *, struct nvmm_vcpu *);
|
2018-12-27 10:22:31 +03:00
|
|
|
|
2019-04-10 21:49:04 +03:00
|
|
|
int nvmm_ctl(int, void *, size_t);
|
|
|
|
|
2019-06-08 10:27:44 +03:00
|
|
|
int nvmm_vcpu_dump(struct nvmm_machine *, struct nvmm_vcpu *);
|
2018-11-10 12:28:56 +03:00
|
|
|
|
|
|
|
#endif /* _LIBNVMM_H_ */
|