Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "axvcpu"
authors = ["aarkegz <aarkegz@gmail.com>"]
version = "0.2.0"
version = "0.2.2"
edition = "2024"
categories = ["virtualization", "no-std"]
description = "Virtual CPU abstraction for ArceOS hypervisor"
Expand All @@ -12,6 +12,6 @@ license = "Apache-2.0"
[dependencies]
axerrno = "0.1.0"
memory_addr = "0.4"
percpu = "0.2.0"
axaddrspace = "0.1"
percpu = "0.2.3-preview.1"
axaddrspace = "0.1.4"
axvisor_api = "0.1"
4 changes: 4 additions & 0 deletions src/percpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub trait AxArchPerCpu: Sized {
fn hardware_enable(&mut self) -> AxResult;
/// Disable hardware virtualization on the current CPU.
fn hardware_disable(&mut self) -> AxResult;
/// Return max guest page table levels used by the architecture.
fn max_guest_page_table_levels(&self) -> usize {
4
}
}

/// Host per-CPU states to run the guest.
Expand Down
6 changes: 5 additions & 1 deletion src/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ static mut CURRENT_VCPU: Option<*mut u8> = None;
///
/// It's guaranteed that each time before a method of [`AxArchVCpu`] is called, the current VCpu is set to the corresponding [`AxVCpu`].
/// So methods of [`AxArchVCpu`] can always get the [`AxVCpu`] containing itself by calling this method.
#[allow(static_mut_refs)]
pub fn get_current_vcpu<'a, A: AxArchVCpu>() -> Option<&'a AxVCpu<A>> {
unsafe {
CURRENT_VCPU
Expand All @@ -327,6 +328,7 @@ pub fn get_current_vcpu<'a, A: AxArchVCpu>() -> Option<&'a AxVCpu<A>> {
/// Get a mutable reference to the current VCpu on the current physical CPU.
///
/// See [`get_current_vcpu`] for more details.
#[allow(static_mut_refs)]
pub fn get_current_vcpu_mut<'a, A: AxArchVCpu>() -> Option<&'a mut AxVCpu<A>> {
unsafe {
CURRENT_VCPU
Expand All @@ -342,6 +344,7 @@ pub fn get_current_vcpu_mut<'a, A: AxArchVCpu>() -> Option<&'a mut AxVCpu<A>> {
/// # Safety
/// This method is marked as unsafe because it may result in unexpected behavior if not used properly.
/// Do not call this method unless you know what you are doing.
#[allow(static_mut_refs)]
pub unsafe fn set_current_vcpu<A: AxArchVCpu>(vcpu: &AxVCpu<A>) {
unsafe {
CURRENT_VCPU
Expand All @@ -354,7 +357,8 @@ pub unsafe fn set_current_vcpu<A: AxArchVCpu>(vcpu: &AxVCpu<A>) {
///
/// # Safety
/// This method is marked as unsafe because it may result in unexpected behavior if not used properly.
/// Do not call this method unless you know what you are doing.
/// Do not call this method unless you know what you are doing.
#[allow(static_mut_refs)]
pub unsafe fn clear_current_vcpu<A: AxArchVCpu>() {
unsafe {
CURRENT_VCPU.current_ref_mut_raw().take();
Expand Down