multiple corrections to page table setup and fix vcpu structs

This commit is contained in:
Alex Zenla
2024-01-11 23:54:44 -08:00
parent 4b4f22ffcd
commit b79c31e613
5 changed files with 108 additions and 21 deletions

View File

@ -1,9 +1,9 @@
use crate::sys::{
ArchDomainConfig, CreateDomain, DomCtl, DomCtlValue, DomCtlVcpuContext, GetDomainInfo,
HypercallInit, MaxMem, MaxVcpus, VcpuGuestContext, VcpuGuestContextAny, HYPERVISOR_DOMCTL,
XEN_DOMCTL_CREATEDOMAIN, XEN_DOMCTL_DESTROYDOMAIN, XEN_DOMCTL_GETDOMAININFO,
AddressSize, ArchDomainConfig, CreateDomain, DomCtl, DomCtlValue, DomCtlVcpuContext,
GetDomainInfo, HypercallInit, MaxMem, MaxVcpus, VcpuGuestContext, VcpuGuestContextAny,
HYPERVISOR_DOMCTL, XEN_DOMCTL_CREATEDOMAIN, XEN_DOMCTL_DESTROYDOMAIN, XEN_DOMCTL_GETDOMAININFO,
XEN_DOMCTL_HYPERCALL_INIT, XEN_DOMCTL_INTERFACE_VERSION, XEN_DOMCTL_MAX_MEM,
XEN_DOMCTL_MAX_VCPUS, XEN_DOMCTL_SETVCPUCONTEXT,
XEN_DOMCTL_MAX_VCPUS, XEN_DOMCTL_SETVCPUCONTEXT, XEN_DOMCTL_SET_ADDRESS_SIZE,
};
use crate::{XenCall, XenCallError};
use log::trace;
@ -117,6 +117,26 @@ impl DomainControl<'_> {
Ok(())
}
pub fn set_address_size(&self, domid: u32, size: u32) -> Result<(), XenCallError> {
trace!(
"domctl fd={} set_address_size domid={} size={}",
self.call.handle.as_raw_fd(),
domid,
size,
);
let mut domctl = DomCtl {
cmd: XEN_DOMCTL_SET_ADDRESS_SIZE,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
domid,
value: DomCtlValue {
address_size: AddressSize { size },
},
};
self.call
.hypercall1(HYPERVISOR_DOMCTL, addr_of_mut!(domctl) as c_ulong)?;
Ok(())
}
pub fn set_vcpu_context(
&self,
domid: u32,
@ -152,7 +172,7 @@ impl DomainControl<'_> {
pub fn hypercall_init(&self, domid: u32, gmfn: u64) -> Result<(), XenCallError> {
trace!(
"domctl fd={} hypercall_init domid={} max_vcpus={}",
"domctl fd={} hypercall_init domid={} gmfn={}",
self.call.handle.as_raw_fd(),
domid,
gmfn

View File

@ -207,6 +207,12 @@ pub struct DomCtlVcpuContext {
pub ctx: u64,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct AddressSize {
pub size: u32,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union DomCtlValue {
@ -215,8 +221,9 @@ pub union DomCtlValue {
pub max_mem: MaxMem,
pub max_cpus: MaxVcpus,
pub hypercall_init: HypercallInit,
pub pad: [u8; 128],
pub vcpu_context: DomCtlVcpuContext,
pub address_size: AddressSize,
pub pad: [u8; 128],
}
#[repr(C)]
@ -400,7 +407,7 @@ pub struct TrapInfo {
#[derive(Copy, Clone, Debug)]
pub struct VcpuGuestContext {
pub fpu_ctx: VcpuGuestContextFpuCtx,
pub flags: c_ulong,
pub flags: u64,
pub user_regs: CpuUserRegs,
pub trap_ctx: [TrapInfo; 256],
pub ldt_base: u64,
@ -411,6 +418,8 @@ pub struct VcpuGuestContext {
pub kernel_sp: u64,
pub ctrlreg: [u64; 8],
pub debugreg: [u64; 8],
pub event_callback_eip: u64,
pub failsafe_callback_eip: u64,
pub syscall_callback_eip: u64,
pub vm_assist: u64,
pub fs_base: u64,
@ -433,6 +442,8 @@ impl Default for VcpuGuestContext {
kernel_sp: 0,
ctrlreg: [0; 8],
debugreg: [0; 8],
event_callback_eip: 0,
failsafe_callback_eip: 0,
syscall_callback_eip: 0,
vm_assist: 0,
fs_base: 0,