Skip to content

Commit d8d5249

Browse files
authored
update deps version (#34)
* update deps version * fix:将 `naked` 属性更改为 `unsafe(naked)` * fix: clippy warnings * fix:更新目标架构,移除不必要的 `aarch64-unknown-none`
1 parent 3a40611 commit d8d5249

File tree

6 files changed

+51
-60
lines changed

6 files changed

+51
-60
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
rust-toolchain: [nightly-2024-12-25, nightly]
11+
rust-toolchain: [nightly-2025-05-20, nightly]
1212
targets: [aarch64-unknown-none-softfloat]
1313
steps:
1414
- uses: actions/checkout@v4

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[package]
2+
edition = "2024"
23
name = "arm_vcpu"
34
version = "0.1.0"
4-
edition = "2024"
55

66
[dependencies]
7-
log = "0.4.21"
8-
spin = "0.9"
7+
log = "0.4"
8+
spin = "0.10"
99

1010
aarch64-cpu = "10.0"
11-
tock-registers = "0.9"
1211
numeric-enum-macro = "0.2"
12+
tock-registers = "0.9"
1313

1414
axerrno = "0.1.0"
15-
percpu = { version = "0.2.0", features = ["arm-el2"] }
15+
percpu = {version = "0.2.0", features = ["arm-el2"]}
1616

17-
axaddrspace = { git = "https://github.com/arceos-hypervisor/axaddrspace.git" }
18-
axvcpu = { git = "https://github.com/arceos-hypervisor/axvcpu.git" }
19-
axdevice_base = { git = "https://github.com/arceos-hypervisor/axdevice_crates.git" }
20-
axvisor_api = { git = "https://github.com/arceos-hypervisor/axvisor_api.git" }
17+
axaddrspace = {git = "https://github.com/arceos-hypervisor/axaddrspace.git"}
18+
axdevice_base = {git = "https://github.com/arceos-hypervisor/axdevice_crates.git"}
19+
axvcpu = {git = "https://github.com/arceos-hypervisor/axvcpu.git"}
20+
axvisor_api = {git = "https://github.com/arceos-hypervisor/axvisor_api.git"}

rust-toolchain.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[toolchain]
22
profile = "minimal"
3-
channel = "nightly-2024-12-25"
3+
channel = "nightly-2025-05-20"
44
components = ["rust-src", "llvm-tools", "rustfmt", "clippy"]
55
targets = [
6-
"aarch64-unknown-none",
76
"aarch64-unknown-none-softfloat",
87
]

src/exception.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ core::arch::global_asm!(
5858
///
5959
/// # Arguments
6060
///
61-
/// * `ctx` - A mutable reference to the `TrapFrame`, which contains the saved state of the
62-
/// guest VM's CPU registers at the time of the exception.
61+
/// * `ctx` - A mutable reference to the `TrapFrame`, which contains the saved state of the guest VM's CPU registers at the time of the exception.
6362
///
6463
/// # Returns
6564
///
@@ -295,8 +294,8 @@ fn current_el_sync_handler(tf: &mut TrapFrame) {
295294
let iss = ESR_EL2.read(ESR_EL2::ISS);
296295

297296
error!("ESR_EL2: {:#x}", esr.get());
298-
error!("Exception Class: {:#x}", ec);
299-
error!("Instruction Specific Syndrome: {:#x}", iss);
297+
error!("Exception Class: {ec:#x}");
298+
error!("Instruction Specific Syndrome: {iss:#x}");
300299

301300
panic!(
302301
"Unhandled synchronous exception from current EL: {:#x?}",
@@ -339,20 +338,18 @@ fn current_el_sync_handler(tf: &mut TrapFrame) {
339338
///
340339
/// - This function is not typically called directly from Rust code. Instead, it is
341340
/// invoked as part of the low-level hypervisor or VM exit handling routines.
342-
#[naked]
341+
#[unsafe(naked)]
343342
#[unsafe(no_mangle)]
344343
unsafe extern "C" fn vmexit_trampoline() -> ! {
345-
unsafe {
346-
core::arch::naked_asm!(
347-
// Curretly `sp` points to the base address of `Aarch64VCpu.ctx`, which stores guest's `TrapFrame`.
348-
"add x9, sp, 34 * 8", // Skip the exception frame.
349-
// Currently `x9` points to `&Aarch64VCpu.host_stack_top`, see `run_guest()` in vcpu.rs.
350-
"ldr x10, [x9]", // Get `host_stack_top` value from `&Aarch64VCpu.host_stack_top`.
351-
"mov sp, x10", // Set `sp` as the host stack top.
352-
restore_regs_from_stack!(), // Restore host function context frame.
353-
"ret", // Control flow is handed back to Aarch64VCpu.run(), simulating the normal return of the `run_guest` function.
354-
)
355-
}
344+
core::arch::naked_asm!(
345+
// Curretly `sp` points to the base address of `Aarch64VCpu.ctx`, which stores guest's `TrapFrame`.
346+
"add x9, sp, 34 * 8", // Skip the exception frame.
347+
// Currently `x9` points to `&Aarch64VCpu.host_stack_top`, see `run_guest()` in vcpu.rs.
348+
"ldr x10, [x9]", // Get `host_stack_top` value from `&Aarch64VCpu.host_stack_top`.
349+
"mov sp, x10", // Set `sp` as the host stack top.
350+
restore_regs_from_stack!(), // Restore host function context frame.
351+
"ret", // Control flow is handed back to Aarch64VCpu.run(), simulating the normal return of the `run_guest` function.
352+
)
356353
}
357354

358355
/// Deal with invalid aarch64 exception.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![feature(naked_functions)]
32
#![feature(doc_cfg)]
43
#![doc = include_str!("../README.md")]
54

src/vcpu.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use core::marker::PhantomData;
22

3-
use aarch64_cpu::registers::{CNTHCTL_EL2, HCR_EL2, SP_EL0, SPSR_EL1, VTCR_EL2};
3+
use aarch64_cpu::registers::*;
44
use axaddrspace::{GuestPhysAddr, HostPhysAddr, device::SysRegAddr};
55
use axerrno::AxResult;
66
use axvcpu::{AxArchVCpu, AxVCpuExitReason, AxVCpuHal};
7-
use tock_registers::interfaces::{ReadWriteable, Readable, Writeable};
87

98
use crate::TrapFrame;
109
use crate::context_frame::GuestSystemRegisters;
@@ -75,7 +74,7 @@ impl<H: AxVCpuHal> axvcpu::AxArchVCpu for Aarch64VCpu<H> {
7574

7675
type SetupConfig = Aarch64VCpuSetupConfig;
7776

78-
fn new(vm_id: usize, vcpu_id: usize, config: Self::CreateConfig) -> AxResult<Self> {
77+
fn new(_vm_id: usize, _vcpu_id: usize, config: Self::CreateConfig) -> AxResult<Self> {
7978
let mut ctx = TrapFrame::default();
8079
ctx.set_argument(config.dtb_addr);
8180

@@ -94,13 +93,13 @@ impl<H: AxVCpuHal> axvcpu::AxArchVCpu for Aarch64VCpu<H> {
9493
}
9594

9695
fn set_entry(&mut self, entry: GuestPhysAddr) -> AxResult {
97-
debug!("set vcpu entry:{:?}", entry);
96+
debug!("set vcpu entry:{entry:?}");
9897
self.set_elr(entry.as_usize());
9998
Ok(())
10099
}
101100

102101
fn set_ept_root(&mut self, ept_root: HostPhysAddr) -> AxResult {
103-
debug!("set vcpu ept root:{:#x}", ept_root);
102+
debug!("set vcpu ept root:{ept_root:#x}");
104103
self.guest_system_regs.vttbr_el2 = ept_root.as_usize() as u64;
105104
Ok(())
106105
}
@@ -237,7 +236,7 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
237236
///
238237
/// When a VM-Exit happens when guest's vCpu is running,
239238
/// the control flow will be redirected to this function through `return_run_guest`.
240-
#[naked]
239+
#[unsafe(naked)]
241240
unsafe extern "C" fn run_guest(&mut self) -> usize {
242241
// Fixes: https://github.com/arceos-hypervisor/arm_vcpu/issues/22
243242
//
@@ -246,25 +245,23 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
246245
// original `run_guest` with the current naked one, we eliminate the dummy code path of the
247246
// original version, and ensure that the compiler does not perform any unexpected return
248247
// value optimization.
249-
unsafe {
250-
core::arch::naked_asm!(
251-
// Save host context.
252-
save_regs_to_stack!(),
253-
// Save current host stack top to `self.host_stack_top`.
254-
//
255-
// 'extern "C"' here specifies the aapcs64 calling convention, according to which
256-
// the first and only parameter, the pointer of self, should be in x0:
257-
"mov x9, sp",
258-
"add x0, x0, {host_stack_top_offset}",
259-
"str x9, [x0]",
260-
// Go to `context_vm_entry`.
261-
"b context_vm_entry",
262-
// Panic if the control flow comes back here, which should never happen.
263-
"b {run_guest_panic}",
264-
host_stack_top_offset = const core::mem::size_of::<TrapFrame>(),
265-
run_guest_panic = sym Self::run_guest_panic,
266-
);
267-
}
248+
core::arch::naked_asm!(
249+
// Save host context.
250+
save_regs_to_stack!(),
251+
// Save current host stack top to `self.host_stack_top`.
252+
//
253+
// 'extern "C"' here specifies the aapcs64 calling convention, according to which
254+
// the first and only parameter, the pointer of self, should be in x0:
255+
"mov x9, sp",
256+
"add x0, x0, {host_stack_top_offset}",
257+
"str x9, [x0]",
258+
// Go to `context_vm_entry`.
259+
"b context_vm_entry",
260+
// Panic if the control flow comes back here, which should never happen.
261+
"b {run_guest_panic}",
262+
host_stack_top_offset = const core::mem::size_of::<TrapFrame>(),
263+
run_guest_panic = sym Self::run_guest_panic,
264+
);
268265
}
269266

270267
/// This function is called when the control flow comes back to `run_guest`. To provide a error
@@ -342,7 +339,7 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
342339
return Ok(exit_reason);
343340
}
344341

345-
return result;
342+
result
346343
}
347344
Ok(AxVCpuExitReason::SysRegWrite { addr, value }) => {
348345
if let Some(exit_reason) =
@@ -351,9 +348,9 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
351348
return Ok(exit_reason);
352349
}
353350

354-
return result;
351+
result
355352
}
356-
r => return r,
353+
r => r,
357354
}
358355
}
359356

@@ -371,7 +368,7 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
371368

372369
match (addr, write) {
373370
(SYSREG_ICC_SGI1R_EL1, true) => {
374-
debug!("arm_vcpu ICC_SGI1R_EL1 write: {:#x}", value);
371+
debug!("arm_vcpu ICC_SGI1R_EL1 write: {value:#x}");
375372

376373
// TODO: support RangeSelector
377374

@@ -397,8 +394,7 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
397394
let target_list = value & 0xffff;
398395

399396
debug!(
400-
"arm_vcpu ICC_SGI1R_EL1 write: aff3:{:#x} aff2:{:#x} aff1:{:#x} intid:{:#x} target_list:{:#x}",
401-
aff3, aff2, aff1, intid, target_list
397+
"arm_vcpu ICC_SGI1R_EL1 write: aff3:{aff3:#x} aff2:{aff2:#x} aff1:{aff1:#x} intid:{intid:#x} target_list:{target_list:#x}"
402398
);
403399

404400
Ok(Some(AxVCpuExitReason::SendIPI {

0 commit comments

Comments
 (0)