-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for arm cca #211
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ authors = ["The Chromium OS Authors"] | |
edition = "2021" | ||
|
||
[features] | ||
default = ["cca"] | ||
cca = [] | ||
tee = [] | ||
amd-sev = [ "tee" ] | ||
efi = [] | ||
|
@@ -18,8 +20,8 @@ smbios = { path = "../smbios" } | |
utils = { path = "../utils" } | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] } | ||
kvm-ioctls = ">=0.17" | ||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" } | ||
kvm-ioctls = { version = ">=0.17", git = "https://github.com/virtee/kvm-ioctls", branch = "cca" } | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make a PR once these branches are ready? I'd like to have the deps be on the main branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to use the main branch rather than the cca? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. I'm going to have to make some changes for my TDX work, so I think we'll need to merge your CCA work and my TDX work into the main branch and then use that here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tylerfanelli Do you think we can merge the cca branches into main for kvm-ioctl/bindings repos? Or, shall we have one branch per flavor? Bear in mind that those repo are temporal until changes are upstreamed. |
||
|
||
[target.'cfg(target_arch = "aarch64")'.dependencies] | ||
vm-fdt = ">= 0.2.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ edition = "2021" | |
vmm-sys-util = ">=0.11" | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] } | ||
kvm-ioctls = ">=0.17" | ||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" } | ||
kvm-ioctls = { version = ">=0.17", git = "https://github.com/virtee/kvm-ioctls", branch = "cca" } | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,7 +5,9 @@ authors = ["The Chromium OS Authors"] | |||||||||
edition = "2021" | ||||||||||
|
||||||||||
[features] | ||||||||||
default = ["cca"] | ||||||||||
tee = [] | ||||||||||
cca = [] | ||||||||||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I not leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should. I think that was a suggestion error. I was trying to suggest just getting rid of |
||||||||||
amd-sev = ["blk", "tee"] | ||||||||||
net = [] | ||||||||||
blk = [] | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,14 @@ snd = [] | |
virgl_resource_map2 = [] | ||
|
||
[dependencies] | ||
vm-memory = { version = ">=0.13", features = ["backend-mmap"] } | ||
crossbeam-channel = "0.5" | ||
env_logger = "0.9.0" | ||
libc = ">=0.2.39" | ||
log = "0.4.0" | ||
once_cell = "1.4.1" | ||
|
||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here |
||
devices = { path = "../devices" } | ||
polly = { path = "../polly" } | ||
utils = { path = "../utils" } | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,13 @@ | ||||||||||||||||||||||||||||
#[macro_use] | ||||||||||||||||||||||||||||
extern crate log; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
use crossbeam_channel::unbounded; | ||||||||||||||||||||||||||||
use kvm_bindings::kvm_memory_attributes; | ||||||||||||||||||||||||||||
use libc::fallocate; | ||||||||||||||||||||||||||||
use libc::madvise; | ||||||||||||||||||||||||||||
use libc::FALLOC_FL_KEEP_SIZE; | ||||||||||||||||||||||||||||
use libc::FALLOC_FL_PUNCH_HOLE; | ||||||||||||||||||||||||||||
use libc::MADV_DONTNEED; | ||||||||||||||||||||||||||||
use std::collections::hash_map::Entry; | ||||||||||||||||||||||||||||
use std::collections::HashMap; | ||||||||||||||||||||||||||||
use std::convert::TryInto; | ||||||||||||||||||||||||||||
|
@@ -11,10 +18,13 @@ use std::ffi::CString; | |||||||||||||||||||||||||||
#[cfg(target_os = "linux")] | ||||||||||||||||||||||||||||
use std::os::fd::AsRawFd; | ||||||||||||||||||||||||||||
use std::os::fd::RawFd; | ||||||||||||||||||||||||||||
use std::os::raw::c_void; | ||||||||||||||||||||||||||||
use std::path::PathBuf; | ||||||||||||||||||||||||||||
use std::slice; | ||||||||||||||||||||||||||||
use std::sync::atomic::{AtomicI32, Ordering}; | ||||||||||||||||||||||||||||
use std::sync::Mutex; | ||||||||||||||||||||||||||||
use vm_memory::GuestMemoryRegion; | ||||||||||||||||||||||||||||
use vm_memory::{Address, GuestMemory}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#[cfg(target_os = "macos")] | ||||||||||||||||||||||||||||
use crossbeam_channel::unbounded; | ||||||||||||||||||||||||||||
|
@@ -1225,9 +1235,12 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 { | |||||||||||||||||||||||||||
#[cfg(target_os = "macos")] | ||||||||||||||||||||||||||||
let (sender, receiver) = unbounded(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let (io_sender, receiver) = unbounded(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let _vmm = match vmm::builder::build_microvm( | ||||||||||||||||||||||||||||
&ctx_cfg.vmr, | ||||||||||||||||||||||||||||
&mut event_manager, | ||||||||||||||||||||||||||||
io_sender, | ||||||||||||||||||||||||||||
ctx_cfg.shutdown_efd, | ||||||||||||||||||||||||||||
Comment on lines
+1238
to
1244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm struggling with the design of this. As is, this would be forcing all flavors of libkrun to have a separate thread waiting to convert memory regions. This should be conditional upon the I need to do something similar for the TDX implementation, and I couldn't have a function signature like vmm::builder::build_microvm(
&ctx_cfg.vmr,
&mut event_manager
#[cfg(feature = "cca")]
io_sender,
ctx_cfg.shutdown_efd,
#[cfg(target_os = "macos")]
sender,
) I'm not sure what the best way to do this is. Maybe make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about the design either. I do not like that all flavors spawn an extra thread so I will change that. Why couldn't you have a function signature as you proposed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC cargo complained about it. I don't remember the exact reason. It very well could have been user error |
||||||||||||||||||||||||||||
#[cfg(target_os = "macos")] | ||||||||||||||||||||||||||||
sender, | ||||||||||||||||||||||||||||
|
@@ -1242,6 +1255,61 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 { | |||||||||||||||||||||||||||
#[cfg(target_os = "macos")] | ||||||||||||||||||||||||||||
let mapper_vmm = _vmm.clone(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
let vm = _vmm.lock().unwrap().kvm_vm().fd.clone(); | ||||||||||||||||||||||||||||
let guest_mem = _vmm.lock().unwrap().guest_memory().clone(); | ||||||||||||||||||||||||||||
let guest_memfd = _vmm.lock().unwrap().guest_memfd_vec.clone(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
std::thread::spawn(move || loop { | ||||||||||||||||||||||||||||
match receiver.recv() { | ||||||||||||||||||||||||||||
Err(e) => error!("Error in receiver: {:?}", e), | ||||||||||||||||||||||||||||
Ok(m) => { | ||||||||||||||||||||||||||||
let _ret = vm | ||||||||||||||||||||||||||||
.lock() | ||||||||||||||||||||||||||||
.unwrap() | ||||||||||||||||||||||||||||
.set_memory_attributes(kvm_memory_attributes { | ||||||||||||||||||||||||||||
address: m.addr, | ||||||||||||||||||||||||||||
size: m.size, | ||||||||||||||||||||||||||||
attributes: m.attributes as u64, | ||||||||||||||||||||||||||||
flags: 0, | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we do this instead of looping through the regions?
Suggested change
|
||||||||||||||||||||||||||||
// from private to shared | ||||||||||||||||||||||||||||
if m.attributes == 0 { | ||||||||||||||||||||||||||||
for (index, region) in guest_mem.iter().enumerate() { | ||||||||||||||||||||||||||||
// this supposes that m.addr + m.size < region.start + region.size | ||||||||||||||||||||||||||||
// which may be false | ||||||||||||||||||||||||||||
if (region.start_addr().raw_value() + region.size() as u64) > m.addr { | ||||||||||||||||||||||||||||
let offset = m.addr - region.start_addr().raw_value(); | ||||||||||||||||||||||||||||
unsafe { | ||||||||||||||||||||||||||||
let _ret = fallocate( | ||||||||||||||||||||||||||||
*guest_memfd.get(index).unwrap(), | ||||||||||||||||||||||||||||
Comment on lines
+1284
to
+1285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check the return value of |
||||||||||||||||||||||||||||
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, | ||||||||||||||||||||||||||||
offset as i64, | ||||||||||||||||||||||||||||
m.size as i64, | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
// from shared to private | ||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||
for (_index, region) in guest_mem.iter().enumerate() { | ||||||||||||||||||||||||||||
if (region.start_addr().raw_value() + region.size() as u64) > m.addr { | ||||||||||||||||||||||||||||
let offset = m.addr - region.start_addr().raw_value(); | ||||||||||||||||||||||||||||
let host_startaddr = m.addr + offset; | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this based on QEMU's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is based on |
||||||||||||||||||||||||||||
unsafe { | ||||||||||||||||||||||||||||
let _ret = madvise( | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check the return value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. How do I handle the error in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how to handle this off the top of my head, but at the very least I think we should probably check if the ret value is < 0 and then log the error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I will check for that condition. |
||||||||||||||||||||||||||||
host_startaddr as *mut c_void, | ||||||||||||||||||||||||||||
m.size.try_into().unwrap(), | ||||||||||||||||||||||||||||
MADV_DONTNEED, | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#[cfg(target_os = "macos")] | ||||||||||||||||||||||||||||
std::thread::Builder::new() | ||||||||||||||||||||||||||||
.name("mapping worker".into()) | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,8 +5,10 @@ authors = ["Amazon Firecracker team <[email protected]>"] | |||||||||||||||
edition = "2021" | ||||||||||||||||
|
||||||||||||||||
[features] | ||||||||||||||||
default = ["cca"] | ||||||||||||||||
tee = [] | ||||||||||||||||
amd-sev = [ "blk", "tee", "codicon", "kbs-types", "procfs", "rdrand", "serde", "serde_json", "sev", "curl" ] | ||||||||||||||||
cca = [] | ||||||||||||||||
Comment on lines
+8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
net = [] | ||||||||||||||||
blk = [] | ||||||||||||||||
efi = [ "blk", "net" ] | ||||||||||||||||
|
@@ -37,12 +39,14 @@ sev = { version = "4.0.0", features = ["openssl"], optional = true } | |||||||||||||||
curl = { version = "0.4", optional = true } | ||||||||||||||||
nix = "0.24.1" | ||||||||||||||||
|
||||||||||||||||
cca = { git = "https://github.com/virtee/cca" } | ||||||||||||||||
|
||||||||||||||||
[target.'cfg(target_arch = "x86_64")'.dependencies] | ||||||||||||||||
cpuid = { path = "../cpuid" } | ||||||||||||||||
|
||||||||||||||||
[target.'cfg(target_os = "linux")'.dependencies] | ||||||||||||||||
kvm-bindings = { version = ">=0.10", features = ["fam-wrappers"] } | ||||||||||||||||
kvm-ioctls = ">=0.17" | ||||||||||||||||
kvm-bindings = { version = ">=0.8", features = ["fam-wrappers"] , git = "https://github.com/virtee/kvm-bindings", branch = "add_bindings_for_realms" } | ||||||||||||||||
kvm-ioctls = { version = ">=0.17", git = "https://github.com/virtee/kvm-ioctls", branch = "cca" } | ||||||||||||||||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same branch comment |
||||||||||||||||
|
||||||||||||||||
[target.'cfg(target_os = "macos")'.dependencies] | ||||||||||||||||
hvf = { path = "../hvf" } | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't make
cca
the default here. IMO, it should follow suit with the othersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, when I compile with cca flag:
The
tee
feature would be enabled. However, most of the code fortee
is not required and I ended up doing this everywhere:Can't
cca
be just a different feature?