Skip to content

Commit

Permalink
Upgrade to Rust-1.82 (#4)
Browse files Browse the repository at this point in the history
* Upgrade verus to support v1.82.

* Cleanup build.rs
* Set verus lib and tool to the rev supporting v1.82

Signed-off-by: Ziqiao Zhou <[email protected]>

* Move vstd.verus.rs to verus vstd & mark memory-related as external

* memory related verification needs to add a memory permission and will
  do it later

Signed-off-by: Ziqiao Zhou <[email protected]>

* Revert unnecessary change after verus upgrade

* revert rust version
* revert some code due to version change

Signed-off-by: Ziqiao Zhou <[email protected]>

* fmt

---------

Signed-off-by: Ziqiao Zhou <[email protected]>
  • Loading branch information
ziqiaozhou authored Oct 30, 2024
1 parent 9880bdf commit c74be0a
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 112 deletions.
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ zerocopy = { version = "0.8.2", features = ["alloc", "derive"] }
packit = { git = "https://github.com/coconut-svsm/packit", version = "0.1.1" }

# Verus repos
builtin = { git = "https://github.com/verus-lang/verus", rev ="2776465", default-features = false }
builtin_macros = { git = "https://github.com/verus-lang/verus", rev ="2776465", default-features = false }
vstd = { git = "https://github.com/verus-lang/verus", rev ="2776465", features = ["alloc"], default-features = false }
builtin = { git = "https://github.com/verus-lang/verus", rev ="31a272f", default-features = false }
builtin_macros = { git = "https://github.com/verus-lang/verus", rev ="31a272f", default-features = false }
vstd = { git = "https://github.com/verus-lang/verus", rev ="31a272f", features = ["alloc"], default-features = false }

# Verification libs
verify_proof = { path = "verify_proof", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "svsm"
version = "0.1.0"
edition = "2021"
rust-version = "1.77.0"
rust-version = "1.82.0"

[[bin]]
name = "stage2"
Expand Down
28 changes: 9 additions & 19 deletions kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,17 @@
//
// Author: Joerg Roedel <[email protected]>

use rustc_version::{Channel, Version};

fn main() {
let rust_version = rustc_version::version_meta().unwrap();
// Check if the version is nightly and higher than 1.78.0
let is_expected_version = rust_version.semver >= Version::new(1, 78, 0);
if !is_expected_version {
if rust_version.channel == Channel::Nightly {
// Print the cargo:rustc-cfg directive to enable the feature
println!("cargo:rustc-cfg=RUST_BEFORE_1_78");
} else {
// Optionally handle the case for non-nightly versions
panic!("Requires the nightly version or stable version >= 1.78.");
}
} else {
// Extra cfgs
println!("cargo::rustc-check-cfg=cfg(fuzzing)");
println!("cargo::rustc-check-cfg=cfg(test_in_svsm)");
println!("cargo::rustc-check-cfg=cfg(verus_keep_ghost)");
println!("cargo::rustc-check-cfg=cfg(RUST_BEFORE_1_78)");
// Verification tool only support rust version lower than 1.82
// If new features are used, may need to disable them until verus is upraded.
if rustc_version::version_meta().unwrap().semver > rustc_version::Version::new(1, 80, 2) {
println!("cargo:rustc-cfg=RUST_VERSION_AFTER_VERUS");
}
// Extra cfgs
println!("cargo::rustc-check-cfg=cfg(fuzzing)");
println!("cargo::rustc-check-cfg=cfg(test_in_svsm)");
println!("cargo::rustc-check-cfg=cfg(verus_keep_ghost)");
println!("cargo::rustc-check-cfg=cfg(RUST_VERSION_AFTER_VERUS)");

// Stage 2
println!("cargo:rustc-link-arg-bin=stage2=-nostdlib");
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ impl VirtAddr {
}

#[inline]
#[verus_verify(external_body)]
pub fn as_ptr<T>(&self) -> *const T {
self.0 as *const T
}

#[inline]
#[verus_verify(external_body)]
pub fn as_mut_ptr<T>(&self) -> *mut T {
self.0 as *mut T
}
Expand All @@ -285,6 +287,7 @@ impl VirtAddr {
/// All safety requirements for pointers apply, minus alignment and NULL
/// checks, which this function already does.
#[inline]
#[verus_verify(external_body)]
pub unsafe fn aligned_ref<'a, T>(&self) -> Option<&'a T> {
self.is_aligned_to::<T>()
.then(|| self.as_ptr::<T>().as_ref())
Expand All @@ -299,6 +302,7 @@ impl VirtAddr {
/// All safety requirements for pointers apply, minus alignment and NULL
/// checks, which this function already does.
#[inline]
#[verus_verify(external)]
pub unsafe fn aligned_mut<'a, T>(&self) -> Option<&'a mut T> {
self.is_aligned_to::<T>()
.then(|| self.as_mut_ptr::<T>().as_mut())
Expand Down Expand Up @@ -327,6 +331,7 @@ impl VirtAddr {
///
/// All Safety requirements from [`core::slice::from_raw_parts`] for the
/// data pointed to by the `VirtAddr` apply here as well.
#[verus_verify(external_body)]
pub unsafe fn to_slice<T>(&self, len: usize) -> &[T] {
slice::from_raw_parts::<T>(self.as_ptr::<T>(), len)
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/address.verus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ broadcast group vaddr_impl_proof {
}

broadcast use vaddr_impl_proof;

/// Define a broadcast function and its related spec function calls in a inner
/// module to avoid cyclic self-reference

mod address_spec { include!("address_inner.verus.rs"); }

#[cfg(verus_keep_ghost)]
Expand Down
2 changes: 0 additions & 2 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Author: Nicolai Stange <[email protected]>

#![no_std]
#![cfg_attr(RUST_BEFORE_1_78, feature(offset_of))] // stable feature after v1.78 but nightly feature in v1.77
#![cfg_attr(RUST_BEFORE_1_78, feature(inline_const))] // stable feature in v1.78 but nightly feature in v1.77
#![cfg_attr(all(test, test_in_svsm), no_main)]
#![cfg_attr(all(test, test_in_svsm), feature(custom_test_frameworks))]
#![cfg_attr(all(test, test_in_svsm), test_runner(crate::testing::svsm_test_runner))]
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/mm/page_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<T> SharedBox<T> {
copy_bytes(
self.ptr.as_ptr() as usize,
out as *const T as usize,
core::mem::size_of::<T>(),
size_of::<T>(),
);
}
}
Expand All @@ -150,7 +150,7 @@ impl<T> SharedBox<T> {
copy_bytes(
value as *const T as usize,
self.ptr.as_ptr() as usize,
core::mem::size_of::<T>(),
size_of::<T>(),
);
}
}
Expand All @@ -175,7 +175,7 @@ impl<T, const N: usize> SharedBox<[T; N]> {

unsafe {
// SAFETY: `self.ptr` is valid and we did a bounds check on `n`.
write_bytes(self.ptr.as_ptr() as usize, core::mem::size_of::<T>() * n, 0);
write_bytes(self.ptr.as_ptr() as usize, size_of::<T>() * n, 0);
}

Ok(())
Expand Down Expand Up @@ -210,7 +210,7 @@ unsafe impl<T> Sync for SharedBox<T> where T: Sync {}
impl<T> Drop for SharedBox<T> {
fn drop(&mut self) {
// Re-encrypt the pages.
let res = (0..core::mem::size_of::<Self>())
let res = (0..size_of::<Self>())
.step_by(PAGE_SIZE)
.try_for_each(|offset| unsafe { make_page_private(self.addr() + offset) });

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ global_asm!(
static CPUID_PAGE: ImmutAfterInitCell<SnpCpuidTable> = ImmutAfterInitCell::uninit();
static LAUNCH_INFO: ImmutAfterInitCell<KernelLaunchInfo> = ImmutAfterInitCell::uninit();

const _: () = assert!(core::mem::size_of::<SnpCpuidTable>() <= PAGE_SIZE);
const _: () = assert!(size_of::<SnpCpuidTable>() <= PAGE_SIZE);

fn copy_cpuid_table_to_fw(fw_addr: PhysAddr) -> Result<(), SvsmError> {
let guard = PerCPUPageMappingGuard::create_4k(fw_addr)?;
Expand Down
Loading

0 comments on commit c74be0a

Please sign in to comment.