Skip to content

Commit be197ed

Browse files
mgudaramjyao1
authored andcommitted
changes to support GHCI failure message handling
Signed-off-by: Gudaram, Meghana <[email protected]>
1 parent db6b461 commit be197ed

File tree

5 files changed

+99
-13
lines changed

5 files changed

+99
-13
lines changed

src/migtd/src/bin/migtd/cvmemu.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use std::env;
1111
use std::process;
1212

13+
use alloc::vec::Vec;
1314
use migtd;
1415
use migtd::migration::event;
1516
use migtd::migration::logging::{create_logarea, enable_logarea};
@@ -439,9 +440,10 @@ fn handle_pre_mig_emu() -> i32 {
439440
}
440441
WaitForRequestResponse::StartMigration(req) => {
441442
log::info!("Processing StartMigration request\n");
443+
let mut data = Vec::new();
442444

443445
// Call exchange_msk() and log its immediate outcome
444-
let res = exchange_msk(&req).await;
446+
let res = exchange_msk(&req, &mut data).await;
445447
match &res {
446448
Ok(_) => log::info!("exchange_msk() returned Ok\n"),
447449
Err(e) => {

src/migtd/src/bin/migtd/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use core::task::Poll;
1414
use alloc::format;
1515
#[cfg(feature = "policy_v2")]
1616
use alloc::string::String;
17-
#[cfg(feature = "vmcall-raw")]
1817
use alloc::vec::Vec;
1918
use log::info;
2019
#[cfg(feature = "vmcall-raw")]
@@ -283,6 +282,7 @@ fn handle_pre_mig() {
283282
loop {
284283
// Poll the async runtime to execute tasks
285284
let _ = async_runtime::poll_tasks();
285+
let mut data: Vec<u8> = Vec::new();
286286

287287
// The async task waiting for VMM response is always in the queue
288288
let new_request = PENDING_REQUEST.lock().take();
@@ -291,7 +291,7 @@ fn handle_pre_mig() {
291291
async_runtime::add_task(async move {
292292
#[cfg(not(feature = "vmcall-raw"))]
293293
{
294-
let status = exchange_msk(&request)
294+
let status = exchange_msk(&request, &mut data)
295295
.await
296296
.map(|_| MigrationResult::Success)
297297
.unwrap_or_else(|e| e);
@@ -301,10 +301,9 @@ fn handle_pre_mig() {
301301
}
302302
#[cfg(feature = "vmcall-raw")]
303303
{
304-
let mut data: Vec<u8> = Vec::new();
305304
match request {
306305
WaitForRequestResponse::StartMigration(wfr_info) => {
307-
let status = exchange_msk(&wfr_info)
306+
let status = exchange_msk(&wfr_info, &mut data)
308307
.await
309308
.map(|_| MigrationResult::Success)
310309
.unwrap_or_else(|e| e);

src/migtd/src/migration/logging.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ pub async fn enable_logarea(log_max_level: u8, request_id: u64, data: &mut Vec<u
154154
.load(Ordering::SeqCst);
155155

156156
if !logarea_created {
157+
data.extend_from_slice(
158+
&format!("Error: LogArea has not been successfuly created by create_logarea()\n")
159+
.into_bytes(),
160+
);
157161
return Err(MigrationResult::UnsupportedOperationError);
158162
}
159163

@@ -235,6 +239,13 @@ pub async fn enable_logarea(log_max_level: u8, request_id: u64, data: &mut Vec<u
235239
Level::Error,
236240
request_id,
237241
);
242+
data.extend_from_slice(
243+
&format!(
244+
"Error: enable_logarea(): Invalid MaxLogLevel: {:x} requested\n",
245+
log_max_level
246+
)
247+
.into_bytes(),
248+
);
238249
return Err(MigrationResult::InvalidParameter);
239250
}
240251
}

src/migtd/src/migration/session.rs

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ pub async fn get_tdreport(
475475
Level::Debug,
476476
request_id,
477477
);
478+
data.extend_from_slice(
479+
&format!("Error: get_tdreport(): TDG.MR.REPORT failure {:x}\n", ret).into_bytes(),
480+
);
478481
return Err(MigrationResult::TdxModuleError);
479482
}
480483

@@ -490,6 +493,11 @@ pub async fn get_tdreport(
490493
Level::Debug,
491494
request_id,
492495
);
496+
data.extend_from_slice(&format!(
497+
"Error: get_tdreport(): tdreport incorrect data length - expected {:x} actual {:x}\n",
498+
tdreportsize,
499+
data.len()
500+
).into_bytes());
493501
return Err(MigrationResult::InvalidParameter);
494502
}
495503
Ok(())
@@ -776,7 +784,9 @@ async fn pre_session_data_exchange<T: AsyncRead + AsyncWrite + Unpin>(
776784
}
777785

778786
#[cfg(feature = "main")]
779-
pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
787+
pub async fn exchange_msk(info: &MigrationInformation, data: &mut Vec<u8>) -> Result<()> {
788+
#[cfg(not(feature = "vmcall-raw"))]
789+
let _ = data;
780790
#[cfg(feature = "policy_v2")]
781791
let mut transport;
782792
#[cfg(not(feature = "policy_v2"))]
@@ -786,12 +796,18 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
786796
{
787797
use vmcall_raw::stream::VmcallRaw;
788798
let mut vmcall_raw_instance = VmcallRaw::new_with_mid(info.mig_info.mig_request_id)
789-
.map_err(|_e| MigrationResult::InvalidParameter)?;
799+
.map_err(|e| {
800+
data.extend_from_slice(&format!("Error: exchange_msk(): Failed to create vmcall_raw_instance with Migration ID: {:x} errorcode: {}\n", info.mig_info.mig_request_id, e).into_bytes());
801+
MigrationResult::InvalidParameter
802+
})?;
790803

791804
vmcall_raw_instance
792805
.connect()
793806
.await
794-
.map_err(|_e| MigrationResult::InvalidParameter)?;
807+
.map_err(|e| {
808+
data.extend_from_slice(&format!("Error: exchange_msk(): Failed to connect vmcall_raw_instance with Migration ID: {:x} errorcode: {}\n", info.mig_info.mig_request_id, e).into_bytes());
809+
MigrationResult::InvalidParameter
810+
})?;
795811
transport = vmcall_raw_instance;
796812
}
797813

@@ -849,8 +865,20 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
849865
transport,
850866
#[cfg(feature = "policy_v2")]
851867
remote_policy,
868+
#[cfg(feature = "vmcall-raw")]
869+
data,
852870
)
853-
.map_err(|_| MigrationResult::SecureSessionError)?;
871+
.map_err(|_| {
872+
#[cfg(feature = "vmcall-raw")]
873+
data.extend_from_slice(
874+
&format!(
875+
"Error: exchange_msk(): Failed in ratls transport. Migration ID: {:x}\n",
876+
info.mig_info.mig_request_id
877+
)
878+
.into_bytes(),
879+
);
880+
MigrationResult::SecureSessionError
881+
})?;
854882

855883
// MigTD-S send Migration Session Forward key to peer
856884
with_timeout(
@@ -864,6 +892,16 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
864892
)
865893
.await??;
866894
if size < size_of::<ExchangeInformation>() {
895+
#[cfg(feature = "vmcall-raw")]
896+
data.extend_from_slice(
897+
&format!(
898+
"Error: exchange_msk(): Incorrect ExchangeInformation size Migration ID: {:x}. Size - Expected: {:x} Actual: {:x}\n",
899+
info.mig_info.mig_request_id,
900+
size_of::<ExchangeInformation>(),
901+
size
902+
)
903+
.into_bytes(),
904+
);
867905
return Err(MigrationResult::NetworkError);
868906
}
869907
#[cfg(all(not(feature = "virtio-serial"), not(feature = "vmcall-raw")))]
@@ -874,15 +912,35 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
874912
.transport_mut()
875913
.shutdown()
876914
.await
877-
.map_err(|_e| MigrationResult::InvalidParameter)?;
915+
.map_err(|e| {
916+
data.extend_from_slice(
917+
&format!(
918+
"Error: exchange_msk(): Failed to transport in vmcall_raw_instance with Migration ID: {:x} errorcode: {}\n",
919+
info.mig_info.mig_request_id,
920+
e
921+
)
922+
.into_bytes(),
923+
);
924+
MigrationResult::InvalidParameter
925+
})?;
878926
} else {
879927
// TLS server
880928
let mut ratls_server = ratls::server(
881929
transport,
882930
#[cfg(feature = "policy_v2")]
883931
remote_policy,
884932
)
885-
.map_err(|_| MigrationResult::SecureSessionError)?;
933+
.map_err(|_| {
934+
#[cfg(feature = "vmcall-raw")]
935+
data.extend_from_slice(
936+
&format!(
937+
"Error: exchange_msk(): Failed in ratls transport. Migration ID: {:x}\n",
938+
info.mig_info.mig_request_id
939+
)
940+
.into_bytes(),
941+
);
942+
MigrationResult::SecureSessionError
943+
})?;
886944

887945
with_timeout(
888946
TLS_TIMEOUT,
@@ -895,6 +953,8 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
895953
)
896954
.await??;
897955
if size < size_of::<ExchangeInformation>() {
956+
#[cfg(feature = "vmcall-raw")]
957+
data.extend_from_slice(&format!("Error: exchange_msk(): Incorrect ExchangeInformation size Migration ID: {:x}. Size - Expected: {:x} Actual: {:x}\n", info.mig_info.mig_request_id, size_of::<ExchangeInformation>(), size).into_bytes());
898958
return Err(MigrationResult::NetworkError);
899959
}
900960
#[cfg(all(not(feature = "virtio-serial"), not(feature = "vmcall-raw")))]
@@ -905,7 +965,10 @@ pub async fn exchange_msk(info: &MigrationInformation) -> Result<()> {
905965
.transport_mut()
906966
.shutdown()
907967
.await
908-
.map_err(|_e| MigrationResult::InvalidParameter)?;
968+
.map_err(|e| {
969+
data.extend_from_slice(&format!("Error: exchange_msk(): Failed to transport in vmcall_raw_instance with Migration ID: {:x} errorcode: {}\n", info.mig_info.mig_request_id, e).into_bytes());
970+
MigrationResult::InvalidParameter
971+
})?;
909972
}
910973

911974
let mig_ver = cal_mig_version(info.is_src(), &exchange_information, &remote_information)?;

src/migtd/src/ratls/server_client.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn server<T: AsyncRead + AsyncWrite + Unpin>(
4545
pub fn client<T: AsyncRead + AsyncWrite + Unpin>(
4646
stream: T,
4747
#[cfg(feature = "policy_v2")] remote_policy: Vec<u8>,
48+
#[cfg(feature = "vmcall-raw")] data: &mut Vec<u8>,
4849
) -> Result<SecureChannel<T>> {
4950
let signing_key = EcdsaPk::new()?;
5051
let (certs, quote) = gen_cert(&signing_key)?;
@@ -58,7 +59,17 @@ pub fn client<T: AsyncRead + AsyncWrite + Unpin>(
5859
let config = TlsConfig::new(certs, signing_key, verify_server_cert, quote)?;
5960
#[cfg(feature = "policy_v2")]
6061
let config = TlsConfig::new(certs, signing_key, verify_server_cert, remote_policy)?;
61-
config.tls_client(stream).map_err(|e| e.into())
62+
config.tls_client(stream).map_err(|e| {
63+
#[cfg(feature = "vmcall-raw")]
64+
data.extend_from_slice(
65+
&format!(
66+
"Error: server_client client(): Failure in tls_client() error: {:?}\n",
67+
e
68+
)
69+
.into_bytes(),
70+
);
71+
e.into()
72+
})
6273
}
6374

6475
fn gen_cert(signing_key: &EcdsaPk) -> Result<(Vec<u8>, Vec<u8>)> {

0 commit comments

Comments
 (0)