@@ -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) ?;
0 commit comments