-
Notifications
You must be signed in to change notification settings - Fork 265
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
Implement enclave memory management #436
base: emm-dev
Are you sure you want to change the base?
Conversation
sgx_trts/src/sync/remutex.rs
Outdated
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; | ||
use sgx_types::marker::ContiguousMemory; | ||
|
||
pub struct ReentrantMutex<T: ?Sized> { |
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.
Suggest name change to SpinReentrantMutex
sgx_trts/src/sync/remutex.rs
Outdated
} | ||
} | ||
|
||
pub struct ReentrantMutexGuard<'a, T: 'a + ?Sized> { |
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.
pub struct SpinReentrantMutexGuard<'a, T: 'a + ?Sized> {
lock: &'a SpinReentrantMutex<T>,
}
sgx_trts/src/sync/remutex.rs
Outdated
} | ||
|
||
#[inline] | ||
fn acquire_lock(&self) { |
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.
fn acquire_lock(&self) {
while self
.lock
.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed)
.is_err()
{
while self.is_locked() {
spin_loop();
}
}
}
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.
Done
e9588a9
to
60caea5
Compare
059718f
to
c88e2bb
Compare
sgx_trts/src/emm/page.rs
Outdated
use sgx_types::marker::ContiguousMemory; | ||
|
||
bitflags! { |
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.
Please use impl_bitflags!
instead of bitflags!
.
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.
Done
sgx_trts/src/emm/init.rs
Outdated
if #[cfg(not(any(feature = "sim", feature = "hyper")))] { | ||
pub use hw::*; | ||
} else { | ||
pub use sw::*; |
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.
sw mod is not defined
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.
Done, sw is removed.
// Free block for allocating memory with exact size | ||
#[repr(C)] | ||
#[derive(Debug)] | ||
struct BlockFree { |
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.
struct Payload {
ptr: Option<NonNull<u8>>,
}
union BlockPtr {
link: Link,
payload: Payload,
}
struct Block {
size: usize,
ptr: BlockPtr
}
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.
Done
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.
Here we use From
trait to refactor code.
} | ||
|
||
let mut cursor_next = cursor.peek_next(); | ||
while !cursor_next.is_null() { |
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.
Why do we need to traverse the linked list twice?
sgx_trts/src/emm/alloc.rs
Outdated
for block in &mut exact_blocks { | ||
block.write(SinglyLinkedList::new(BlockFreeAda::new())); | ||
} | ||
unsafe { transmute(exact_blocks) } |
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.
unsafe { MaybeUninit::array_assume_init(exact_blocks)}
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.
Done, nice suggestion!
sgx_trts/src/emm/bitmap.rs
Outdated
}; | ||
} | ||
|
||
#[repr(C)] |
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.
remove #[repr(C)]
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.
Done
|
||
#[repr(C)] | ||
#[derive(Debug)] | ||
pub struct BitArray { |
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.
pub struct BitArray<'a> {
bits: usize,
data: Box<[u8], &'a dyn Allocator>,
}
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.
Excellent! I wasn't previously aware of the unsafe impl<A> Allocator for &A
implementation.
sgx_trts/src/emm/ema.rs
Outdated
impl Ema { | ||
/// Initialize Emanode with null eaccept map, | ||
/// and start address must be page aligned | ||
pub fn new( |
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.
impl Clone for Ema {
}
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.
Initially, I contemplated utilizing the Clone trait, but upon deeper analysis, I've come to realize that its semantics diverge from our implementation. The inherent implication of the default Clone is that it performs a "field-by-field clone using the default allocator." In contrast, within the context of our split()
function, our objective is to "clone all fields, excluding the bitmap, utilizing the inner allocator." This distinction in behavior necessitates a more tailored approach to suit our specific cloning needs.
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.
If we were to implement the Clone trait according to our specific semantics, there's a heightened risk that developers might inadvertently misuse the clone() method.
sgx_trts/src/emm/ema.rs
Outdated
} | ||
} | ||
|
||
pub fn new_options(options: &EmaOptions) -> OsResult<Self> { |
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.
new_options
rename to new
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.
Done
/// Split current bit array at specified position, return a new allocated bit array | ||
/// corresponding to the bits at the range of [pos, end). | ||
/// And the current bit array manages the bits at the range of [0, pos). | ||
pub fn split(&mut self, pos: usize) -> OsResult<BitArray> { |
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.
There is a waste of memory
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.
Yes, it is a temporary but convenient solution.
@ClawSeven
|
Is upgrading Intel SGX SDK to 2.21 to enable EDMM? |
Thanks a lot for your reply, we are using SGX2 on 3rd Gen Xeon Scalable Processor with MKTME, and we will need large dynamic heap allocations. We are now using v1.1.6 with Intel SGX SDK 2.21. We are trying to upgrade to v2.0.0 with support to the later Rust toolchain. |
The second issue has an easy fix, essentially, all problems are due to the alignment checks in dereference of raw pointers. We just need to use I also fixed the first issue. |
@yangfh2004 , Hi, thanks for your two issue.
|
@yangfh2004 Btw, I have tested the |
@ClawSeven Hi, our team is using your emm branch, which works OK. But we want to request some supports to the simulation mode (SW mode) so that we can build and run our enclave without sgx drivers. Do you have a chance to add SW supports to your branch? Thanks |
@yangfh2004 Hello, I'm pleased to know that the EDMM feature has been integrated into your project. Unfortunately, the simulation mode (SW mode) for EDMM is not on our current roadmap, primarily because Intel does not offer support for EDMM in SW mode, and I am currently at full capacity, preventing me from undertaking the implementation of this feature. However, conceptually speaking, I believe the SW mode could be relatively straightforward to implement using system calls like mmap and munmap. |
No description provided.