mirror of
https://git.freebsd.org/src.git
synced 2026-01-16 23:02:24 +00:00
vmm: Move common accessors and vm_eventinfo into sys/dev/vmm
Now that struct vm and struct vcpu are defined in headers, provide inline accessors. We could just remove the accessors outright, but they don't hurt and it would result in unneeded churn. As a part of this, consolidate definitions related to struct vm_eventinfo as well. I'm not sure if struct vm_eventinfo is really needed anymore, now that vmmops_run implementations can directly access vm and vcpu fields, but this can be resolved later. No functional change intended. MFC after: 2 months Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53586
This commit is contained in:
parent
ed85203fb7
commit
5f13d6b607
12 changed files with 78 additions and 211 deletions
|
|
@ -160,17 +160,12 @@ struct vhpet;
|
|||
struct vioapic;
|
||||
struct vlapic;
|
||||
struct vmspace;
|
||||
struct vm_eventinfo;
|
||||
struct vm_object;
|
||||
struct vm_guest_paging;
|
||||
struct pmap;
|
||||
enum snapshot_req;
|
||||
|
||||
struct vm_eventinfo {
|
||||
cpuset_t *rptr; /* rendezvous cookie */
|
||||
int *sptr; /* suspend cookie */
|
||||
int *iptr; /* reqidle cookie */
|
||||
};
|
||||
|
||||
#define DECLARE_VMMOPS_FUNC(ret_type, opname, args) \
|
||||
typedef ret_type (*vmmops_##opname##_t) args; \
|
||||
ret_type vmmops_##opname args
|
||||
|
|
@ -233,8 +228,6 @@ struct vmm_ops {
|
|||
extern const struct vmm_ops vmm_ops_intel;
|
||||
extern const struct vmm_ops vmm_ops_amd;
|
||||
|
||||
const char *vm_name(struct vm *vm);
|
||||
|
||||
int vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
|
||||
int vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len);
|
||||
int vm_assign_pptdev(struct vm *vm, int bus, int slot, int func);
|
||||
|
|
@ -253,9 +246,6 @@ void vm_nmi_clear(struct vcpu *vcpu);
|
|||
int vm_inject_extint(struct vcpu *vcpu);
|
||||
int vm_extint_pending(struct vcpu *vcpu);
|
||||
void vm_extint_clear(struct vcpu *vcpu);
|
||||
int vcpu_vcpuid(struct vcpu *vcpu);
|
||||
struct vm *vcpu_vm(struct vcpu *vcpu);
|
||||
struct vcpu *vm_vcpu(struct vm *vm, int cpu);
|
||||
struct vlapic *vm_lapic(struct vcpu *vcpu);
|
||||
struct vioapic *vm_ioapic(struct vm *vm);
|
||||
struct vhpet *vm_hpet(struct vm *vm);
|
||||
|
|
@ -280,33 +270,6 @@ cpuset_t vm_start_cpus(struct vm *vm, const cpuset_t *tostart);
|
|||
void vm_await_start(struct vm *vm, const cpuset_t *waiting);
|
||||
#endif /* _SYS__CPUSET_H_ */
|
||||
|
||||
static __inline int
|
||||
vcpu_rendezvous_pending(struct vcpu *vcpu, struct vm_eventinfo *info)
|
||||
{
|
||||
/*
|
||||
* This check isn't done with atomic operations or under a lock because
|
||||
* there's no need to. If the vcpuid bit is set, the vcpu is part of a
|
||||
* rendezvous and the bit won't be cleared until the vcpu enters the
|
||||
* rendezvous. On rendezvous exit, the cpuset is cleared and the vcpu
|
||||
* will see an empty cpuset. So, the races are harmless.
|
||||
*/
|
||||
return (CPU_ISSET(vcpu_vcpuid(vcpu), info->rptr));
|
||||
}
|
||||
|
||||
static __inline int
|
||||
vcpu_suspended(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*info->sptr);
|
||||
}
|
||||
|
||||
static __inline int
|
||||
vcpu_reqidle(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*info->iptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if device indicated by bus/slot/func is supposed to be a
|
||||
* pci passthrough device.
|
||||
|
|
@ -317,9 +280,7 @@ bool vmm_is_pptdev(int bus, int slot, int func);
|
|||
|
||||
void *vm_iommu_domain(struct vm *vm);
|
||||
|
||||
void *vcpu_stats(struct vcpu *vcpu);
|
||||
void vcpu_notify_lapic(struct vcpu *vcpu);
|
||||
struct vm_mem *vm_mem(struct vm *vm);
|
||||
struct vatpic *vm_atpic(struct vm *vm);
|
||||
struct vatpit *vm_atpit(struct vm *vm);
|
||||
struct vpmtmr *vm_pmtmr(struct vm *vm);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
#include <dev/vmm/vmm_dev.h>
|
||||
#include <dev/vmm/vmm_ktr.h>
|
||||
#include <dev/vmm/vmm_vm.h>
|
||||
|
||||
#include "vmm_lapic.h"
|
||||
#include "vatpic.h"
|
||||
|
|
|
|||
|
|
@ -470,12 +470,6 @@ vm_reset(struct vm *vm)
|
|||
vm_init(vm, false);
|
||||
}
|
||||
|
||||
const char *
|
||||
vm_name(struct vm *vm)
|
||||
{
|
||||
return (vm->name);
|
||||
}
|
||||
|
||||
int
|
||||
vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa)
|
||||
{
|
||||
|
|
@ -1621,24 +1615,6 @@ vm_set_capability(struct vcpu *vcpu, int type, int val)
|
|||
return (vmmops_setcap(vcpu->cookie, type, val));
|
||||
}
|
||||
|
||||
struct vm *
|
||||
vcpu_vm(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vm);
|
||||
}
|
||||
|
||||
int
|
||||
vcpu_vcpuid(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vcpuid);
|
||||
}
|
||||
|
||||
struct vcpu *
|
||||
vm_vcpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
return (vm->vcpu[vcpuid]);
|
||||
}
|
||||
|
||||
struct vlapic *
|
||||
vm_lapic(struct vcpu *vcpu)
|
||||
{
|
||||
|
|
@ -1732,13 +1708,6 @@ vm_await_start(struct vm *vm, const cpuset_t *waiting)
|
|||
mtx_unlock(&vm->rendezvous_mtx);
|
||||
}
|
||||
|
||||
void *
|
||||
vcpu_stats(struct vcpu *vcpu)
|
||||
{
|
||||
|
||||
return (vcpu->stats);
|
||||
}
|
||||
|
||||
int
|
||||
vm_get_x2apic_state(struct vcpu *vcpu, enum x2apic_state *state)
|
||||
{
|
||||
|
|
@ -1771,12 +1740,6 @@ vcpu_notify_lapic(struct vcpu *vcpu)
|
|||
vcpu_unlock(vcpu);
|
||||
}
|
||||
|
||||
struct vm_mem *
|
||||
vm_mem(struct vm *vm)
|
||||
{
|
||||
return (&vm->mem);
|
||||
}
|
||||
|
||||
int
|
||||
vm_apicid2vcpuid(struct vm *vm, int apicid)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <machine/vmm_instruction_emul.h>
|
||||
|
||||
#include <dev/vmm/vmm_ktr.h>
|
||||
#include <dev/vmm/vmm_vm.h>
|
||||
|
||||
#include "vatpic.h"
|
||||
#include "vatpit.h"
|
||||
|
|
|
|||
|
|
@ -135,16 +135,11 @@ struct vmm_special_reg {
|
|||
};
|
||||
#define VM_MAX_SPECIAL_REGS 16
|
||||
|
||||
struct vm_eventinfo {
|
||||
void *rptr; /* rendezvous cookie */
|
||||
int *sptr; /* suspend cookie */
|
||||
int *iptr; /* reqidle cookie */
|
||||
};
|
||||
|
||||
#define DECLARE_VMMOPS_FUNC(ret_type, opname, args) \
|
||||
ret_type vmmops_##opname args
|
||||
|
||||
struct vm;
|
||||
struct vm_eventinfo;
|
||||
struct vm_exception;
|
||||
struct vm_exit;
|
||||
struct vm_run;
|
||||
|
|
@ -181,16 +176,11 @@ DECLARE_VMMOPS_FUNC(int, restore_tsc, (void *vcpui, uint64_t now));
|
|||
#endif
|
||||
#endif
|
||||
|
||||
const char *vm_name(struct vm *vm);
|
||||
|
||||
int vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval);
|
||||
int vm_set_register(struct vcpu *vcpu, int reg, uint64_t val);
|
||||
int vm_run(struct vcpu *vcpu);
|
||||
void* vm_get_cookie(struct vm *vm);
|
||||
int vcpu_vcpuid(struct vcpu *vcpu);
|
||||
void *vcpu_get_cookie(struct vcpu *vcpu);
|
||||
struct vm *vcpu_vm(struct vcpu *vcpu);
|
||||
struct vcpu *vm_vcpu(struct vm *vm, int cpu);
|
||||
int vm_get_capability(struct vcpu *vcpu, int type, int *val);
|
||||
int vm_set_capability(struct vcpu *vcpu, int type, int val);
|
||||
int vm_inject_exception(struct vcpu *vcpu, uint64_t esr, uint64_t far);
|
||||
|
|
@ -204,23 +194,6 @@ void vm_exit_suspended(struct vcpu *vcpu, uint64_t pc);
|
|||
void vm_exit_debug(struct vcpu *vcpu, uint64_t pc);
|
||||
void vm_exit_astpending(struct vcpu *vcpu, uint64_t pc);
|
||||
|
||||
static __inline int
|
||||
vcpu_rendezvous_pending(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*((uintptr_t *)(info->rptr)) != 0);
|
||||
}
|
||||
|
||||
static __inline int
|
||||
vcpu_suspended(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*info->sptr);
|
||||
}
|
||||
|
||||
void *vcpu_stats(struct vcpu *vcpu);
|
||||
struct vm_mem *vm_mem(struct vm *vm);
|
||||
|
||||
struct vm_copyinfo {
|
||||
uint64_t gpa;
|
||||
size_t len;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@
|
|||
|
||||
#include <arm64/vmm/arm64.h>
|
||||
|
||||
#include <dev/vmm/vmm_vm.h>
|
||||
|
||||
#include "vgic.h"
|
||||
#include "vtimer.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -399,12 +399,6 @@ vm_reset(struct vm *vm)
|
|||
vm_init(vm, false);
|
||||
}
|
||||
|
||||
const char *
|
||||
vm_name(struct vm *vm)
|
||||
{
|
||||
return (vm->name);
|
||||
}
|
||||
|
||||
int
|
||||
vm_gla2gpa_nofault(struct vcpu *vcpu, struct vm_guest_paging *paging,
|
||||
uint64_t gla, int prot, uint64_t *gpa, int *is_fault)
|
||||
|
|
@ -720,19 +714,6 @@ vm_exit_debug(struct vcpu *vcpu, uint64_t pc)
|
|||
vmexit->exitcode = VM_EXITCODE_DEBUG;
|
||||
}
|
||||
|
||||
void *
|
||||
vcpu_stats(struct vcpu *vcpu)
|
||||
{
|
||||
|
||||
return (vcpu->stats);
|
||||
}
|
||||
|
||||
struct vm_mem *
|
||||
vm_mem(struct vm *vm)
|
||||
{
|
||||
return (&vm->mem);
|
||||
}
|
||||
|
||||
static void
|
||||
restore_guest_fpustate(struct vcpu *vcpu)
|
||||
{
|
||||
|
|
@ -805,30 +786,12 @@ vm_set_capability(struct vcpu *vcpu, int type, int val)
|
|||
return (vmmops_setcap(vcpu->cookie, type, val));
|
||||
}
|
||||
|
||||
struct vm *
|
||||
vcpu_vm(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vm);
|
||||
}
|
||||
|
||||
int
|
||||
vcpu_vcpuid(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vcpuid);
|
||||
}
|
||||
|
||||
void *
|
||||
vcpu_get_cookie(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->cookie);
|
||||
}
|
||||
|
||||
struct vcpu *
|
||||
vm_vcpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
return (vm->vcpu[vcpuid]);
|
||||
}
|
||||
|
||||
int
|
||||
vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@
|
|||
#include <machine/cpu.h>
|
||||
#include <machine/hypervisor.h>
|
||||
|
||||
#include <dev/vmm/vmm_vm.h>
|
||||
|
||||
#include "arm64.h"
|
||||
#include "reset.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@
|
|||
#ifndef _DEV_VMM_STAT_H_
|
||||
#define _DEV_VMM_STAT_H_
|
||||
|
||||
#include <dev/vmm/vmm_vm.h>
|
||||
|
||||
struct vm;
|
||||
|
||||
#define MAX_VMM_STAT_ELEMS 64 /* arbitrary */
|
||||
|
|
|
|||
|
|
@ -62,6 +62,24 @@ void vcpu_notify_event(struct vcpu *vcpu);
|
|||
void vcpu_notify_event_locked(struct vcpu *vcpu);
|
||||
int vcpu_debugged(struct vcpu *vcpu);
|
||||
|
||||
static inline void *
|
||||
vcpu_stats(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->stats);
|
||||
}
|
||||
|
||||
static inline struct vm *
|
||||
vcpu_vm(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vm);
|
||||
}
|
||||
|
||||
static inline int
|
||||
vcpu_vcpuid(struct vcpu *vcpu)
|
||||
{
|
||||
return (vcpu->vcpuid);
|
||||
}
|
||||
|
||||
static int __inline
|
||||
vcpu_is_running(struct vcpu *vcpu, int *hostcpu)
|
||||
{
|
||||
|
|
@ -161,6 +179,55 @@ void vm_get_topology(struct vm *vm, uint16_t *sockets, uint16_t *cores,
|
|||
uint16_t *threads, uint16_t *maxcpus);
|
||||
int vm_set_topology(struct vm *vm, uint16_t sockets, uint16_t cores,
|
||||
uint16_t threads, uint16_t maxcpus);
|
||||
|
||||
static inline const char *
|
||||
vm_name(struct vm *vm)
|
||||
{
|
||||
return (vm->name);
|
||||
}
|
||||
|
||||
static inline struct vm_mem *
|
||||
vm_mem(struct vm *vm)
|
||||
{
|
||||
return (&vm->mem);
|
||||
}
|
||||
|
||||
static inline struct vcpu *
|
||||
vm_vcpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
return (vm->vcpu[vcpuid]);
|
||||
}
|
||||
|
||||
struct vm_eventinfo {
|
||||
cpuset_t *rptr; /* rendezvous cookie */
|
||||
int *sptr; /* suspend cookie */
|
||||
int *iptr; /* reqidle cookie */
|
||||
};
|
||||
|
||||
static inline int
|
||||
vcpu_rendezvous_pending(struct vcpu *vcpu, struct vm_eventinfo *info)
|
||||
{
|
||||
/*
|
||||
* This check isn't done with atomic operations or under a lock because
|
||||
* there's no need to. If the vcpuid bit is set, the vcpu is part of a
|
||||
* rendezvous and the bit won't be cleared until the vcpu enters the
|
||||
* rendezvous. On rendezvous exit, the cpuset is cleared and the vcpu
|
||||
* will see an empty cpuset. So, the races are harmless.
|
||||
*/
|
||||
return (CPU_ISSET(vcpu_vcpuid(vcpu), info->rptr));
|
||||
}
|
||||
|
||||
static inline int
|
||||
vcpu_suspended(struct vm_eventinfo *info)
|
||||
{
|
||||
return (*info->sptr);
|
||||
}
|
||||
|
||||
static inline int
|
||||
vcpu_reqidle(struct vm_eventinfo *info)
|
||||
{
|
||||
return (*info->iptr);
|
||||
}
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* !_DEV_VMM_VM_H_ */
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ enum vm_reg_name {
|
|||
struct vmm_mmio_region mmio_region[VM_MAX_MMIO_REGIONS]
|
||||
|
||||
struct vm;
|
||||
struct vm_eventinfo;
|
||||
struct vm_exception;
|
||||
struct vm_exit;
|
||||
struct vm_run;
|
||||
|
|
@ -131,12 +132,6 @@ struct vmm_mmio_region {
|
|||
};
|
||||
#define VM_MAX_MMIO_REGIONS 4
|
||||
|
||||
struct vm_eventinfo {
|
||||
void *rptr; /* rendezvous cookie */
|
||||
int *sptr; /* suspend cookie */
|
||||
int *iptr; /* reqidle cookie */
|
||||
};
|
||||
|
||||
#define DECLARE_VMMOPS_FUNC(ret_type, opname, args) \
|
||||
ret_type vmmops_##opname args
|
||||
|
||||
|
|
@ -160,16 +155,11 @@ DECLARE_VMMOPS_FUNC(struct vmspace *, vmspace_alloc, (vm_offset_t min,
|
|||
vm_offset_t max));
|
||||
DECLARE_VMMOPS_FUNC(void, vmspace_free, (struct vmspace *vmspace));
|
||||
|
||||
const char *vm_name(struct vm *vm);
|
||||
|
||||
int vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval);
|
||||
int vm_set_register(struct vcpu *vcpu, int reg, uint64_t val);
|
||||
int vm_run(struct vcpu *vcpu);
|
||||
void *vm_get_cookie(struct vm *vm);
|
||||
int vcpu_vcpuid(struct vcpu *vcpu);
|
||||
void *vcpu_get_cookie(struct vcpu *vcpu);
|
||||
struct vm *vcpu_vm(struct vcpu *vcpu);
|
||||
struct vcpu *vm_vcpu(struct vm *vm, int cpu);
|
||||
int vm_get_capability(struct vcpu *vcpu, int type, int *val);
|
||||
int vm_set_capability(struct vcpu *vcpu, int type, int val);
|
||||
int vm_inject_exception(struct vcpu *vcpu, uint64_t scause);
|
||||
|
|
@ -182,24 +172,6 @@ struct vm_exit *vm_exitinfo(struct vcpu *vcpu);
|
|||
void vm_exit_suspended(struct vcpu *vcpu, uint64_t pc);
|
||||
void vm_exit_debug(struct vcpu *vcpu, uint64_t pc);
|
||||
void vm_exit_astpending(struct vcpu *vcpu, uint64_t pc);
|
||||
|
||||
static __inline int
|
||||
vcpu_rendezvous_pending(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*((uintptr_t *)(info->rptr)) != 0);
|
||||
}
|
||||
|
||||
static __inline int
|
||||
vcpu_suspended(struct vm_eventinfo *info)
|
||||
{
|
||||
|
||||
return (*info->sptr);
|
||||
}
|
||||
|
||||
void *vcpu_stats(struct vcpu *vcpu);
|
||||
struct vm_mem *vm_mem(struct vm *vm);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#define VM_DIR_READ 0
|
||||
|
|
|
|||
|
|
@ -272,12 +272,6 @@ vm_reset(struct vm *vm)
|
|||
vm_init(vm, false);
|
||||
}
|
||||
|
||||
const char *
|
||||
vm_name(struct vm *vm)
|
||||
{
|
||||
return (vm->name);
|
||||
}
|
||||
|
||||
int
|
||||
vm_gla2gpa_nofault(struct vcpu *vcpu, struct vm_guest_paging *paging,
|
||||
uint64_t gla, int prot, uint64_t *gpa, int *is_fault)
|
||||
|
|
@ -393,19 +387,6 @@ vm_exit_debug(struct vcpu *vcpu, uint64_t pc)
|
|||
vmexit->exitcode = VM_EXITCODE_DEBUG;
|
||||
}
|
||||
|
||||
void *
|
||||
vcpu_stats(struct vcpu *vcpu)
|
||||
{
|
||||
|
||||
return (vcpu->stats);
|
||||
}
|
||||
|
||||
struct vm_mem *
|
||||
vm_mem(struct vm *vm)
|
||||
{
|
||||
return (&vm->mem);
|
||||
}
|
||||
|
||||
static void
|
||||
restore_guest_fpustate(struct vcpu *vcpu)
|
||||
{
|
||||
|
|
@ -478,20 +459,6 @@ vm_set_capability(struct vcpu *vcpu, int type, int val)
|
|||
return (vmmops_setcap(vcpu->cookie, type, val));
|
||||
}
|
||||
|
||||
struct vm *
|
||||
vcpu_vm(struct vcpu *vcpu)
|
||||
{
|
||||
|
||||
return (vcpu->vm);
|
||||
}
|
||||
|
||||
int
|
||||
vcpu_vcpuid(struct vcpu *vcpu)
|
||||
{
|
||||
|
||||
return (vcpu->vcpuid);
|
||||
}
|
||||
|
||||
void *
|
||||
vcpu_get_cookie(struct vcpu *vcpu)
|
||||
{
|
||||
|
|
@ -499,13 +466,6 @@ vcpu_get_cookie(struct vcpu *vcpu)
|
|||
return (vcpu->cookie);
|
||||
}
|
||||
|
||||
struct vcpu *
|
||||
vm_vcpu(struct vm *vm, int vcpuid)
|
||||
{
|
||||
|
||||
return (vm->vcpu[vcpuid]);
|
||||
}
|
||||
|
||||
int
|
||||
vm_get_register(struct vcpu *vcpu, int reg, uint64_t *retval)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue