Skip to content

Commit d9c6282

Browse files
agokarnjyao1
authored andcommitted
Add log::error to ghci.rs.
Revert "Add log::error to ghci.rs." This reverts commit 35a7e96. modified: src/attestation/src/ghci.rs pick 35a7e96 Add log::error to ghci.rs. squash 5b53cf3 Revert "Add log::error to ghci.rs." squash 5a1fe67 Add log::error to ghci.rs. Add log::error to ghci.rs. modified: src/attestation/src/ghci.rs
1 parent 9bce63b commit d9c6282

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

src/attestation/src/ghci.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ pub static NOTIFIER: AtomicU8 = AtomicU8::new(0);
2424
#[no_mangle]
2525
pub extern "C" fn servtd_get_quote(tdquote_req_buf: *mut c_void, len: u64) -> i32 {
2626
if tdquote_req_buf.is_null() || len > GET_QUOTE_MAX_SIZE {
27+
log::error!(
28+
"Invalid parameters: tdquote_req_buf.is_null() is {} or len is {}\n",
29+
tdquote_req_buf.is_null(),
30+
len
31+
);
2732
return AttestLibError::InvalidParameter as i32;
2833
}
2934

@@ -32,17 +37,20 @@ pub extern "C" fn servtd_get_quote(tdquote_req_buf: *mut c_void, len: u64) -> i3
3237
let mut shared = if let Some(shared) = SharedMemory::new(len as usize / 0x1000) {
3338
shared
3439
} else {
40+
log::error!("Failed to allocate shared memory of size {}\n", len);
3541
return AttestLibError::OutOfMemory as i32;
3642
};
3743
shared.as_mut_bytes()[..len as usize].copy_from_slice(input);
3844

3945
let notify_registered = set_vmm_notification();
4046

41-
if tdvmcall_get_quote(shared.as_mut_bytes()).is_err() {
47+
let _ = tdvmcall_get_quote(shared.as_mut_bytes()).map_err(|e| {
48+
log::error!("tdvmcall_get_quote failed with error: {:?}\n", e);
4249
return AttestLibError::QuoteFailure as i32;
43-
}
50+
});
4451

4552
if let Err(err) = wait_for_quote_completion(notify_registered, shared.as_bytes()) {
53+
log::error!("wait_for_quote_completion failed: {:?}\n", err);
4654
return err as i32;
4755
}
4856
input.copy_from_slice(&shared.as_bytes()[..len as usize]);
@@ -57,17 +65,22 @@ fn vmm_notification(_: &mut InterruptStack) {
5765

5866
fn set_vmm_notification() -> bool {
5967
// Setup interrupt handler
60-
if register_interrupt_callback(
68+
_ = register_interrupt_callback(
6169
NOTIFY_VECTOR as usize,
6270
InterruptCallback::new(vmm_notification),
6371
)
64-
.is_err()
65-
{
66-
panic!("Fail to setup interrupt callback for VMM notify\n");
67-
}
72+
.map_err(|e| {
73+
log::error!("Fail to setup interrupt callback for VMM notify\n");
74+
return false;
75+
});
6876

6977
// Setup event notifier
70-
tdx_tdcall::tdx::tdvmcall_setup_event_notify(NOTIFY_VECTOR as u64).is_ok()
78+
_ = tdx_tdcall::tdx::tdvmcall_setup_event_notify(NOTIFY_VECTOR as u64).map_err(|e| {
79+
log::error!("Fail to setup event notify for VMM: {:?}\n", e);
80+
return false;
81+
});
82+
83+
true
7184
}
7285

7386
fn wait_for_quote_completion(notify_registered: bool, buffer: &[u8]) -> Result<(), AttestLibError> {
@@ -81,13 +94,17 @@ fn wait_for_quote_completion(notify_registered: bool, buffer: &[u8]) -> Result<(
8194
while status_code == GET_QUOTE_STATUS_IN_FLIGHT {
8295
status_code = match buffer.get(GET_QUOTE_STATUS_FIELD) {
8396
Some(bytes) => u64::from_le_bytes(bytes.try_into().unwrap()),
84-
None => return Err(AttestLibError::InvalidParameter),
97+
None => {
98+
log::error!("Failed to get quote status from buffer\n");
99+
return Err(AttestLibError::InvalidParameter);
100+
}
85101
};
86102
}
87103

88104
if status_code == GET_QUOTE_STATUS_SUCCESS {
89105
Ok(())
90106
} else {
107+
log::error!("Quote status indicates failure: {:#x}\n", status_code);
91108
Err(AttestLibError::QuoteFailure)
92109
}
93110
}

0 commit comments

Comments
 (0)