@@ -77,6 +77,10 @@ const STUCK_STATE_TIMEOUT: Duration = Duration::from_secs(5 * 60);
7777#[ cfg( test) ]
7878const STUCK_STATE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
7979
80+ /// With SEV enabled, QEMU needs several minutes after the GuestOS powered off to release the
81+ /// encrypted guest RAM.
82+ const SEV_GRACEFUL_SHUTDOWN_TIMEOUT : Duration = Duration :: from_secs ( 10 * 60 ) ;
83+
8084/// The GuestOS will log one of these marker texts on the serial output.
8185const GUESTOS_BOOT_SUCCESS_MARKER : & str = "GUESTOS BOOT SUCCESS" ;
8286const GUESTOS_BOOT_FAILURE_MARKER : & str = "GUESTOS BOOT FAILURE" ;
@@ -313,9 +317,9 @@ impl VirtualMachine {
313317 }
314318
315319 /// Sends an ACPI power-off signal to the GuestOS and waits for it to stop cleanly.
316- /// If the GuestOS does not stop within `GRACEFUL_SHUTDOWN_TIMEOUT` , this returns and the
320+ /// If the GuestOS does not stop within the given timeout , this returns and the
317321 /// `Drop` impl will force-destroy the domain as a fallback.
318- async fn shutdown_gracefully ( & self ) {
322+ async fn shutdown_gracefully ( & self , graceful_shutdown_timeout : Duration ) {
319323 match self . get_domain ( ) {
320324 Ok ( domain) => {
321325 if let Err ( e) = domain. shutdown ( ) {
@@ -330,11 +334,11 @@ impl VirtualMachine {
330334 }
331335 }
332336
333- match tokio:: time:: timeout ( GRACEFUL_SHUTDOWN_TIMEOUT , self . wait_for_shutdown ( ) ) . await {
337+ match tokio:: time:: timeout ( graceful_shutdown_timeout , self . wait_for_shutdown ( ) ) . await {
334338 Ok ( ( ) ) => info ! ( "GuestOS shut down gracefully" ) ,
335339 Err ( _) => warn ! (
336340 "GuestOS did not shut down within {:?}, proceeding with force shutdown" ,
337- GRACEFUL_SHUTDOWN_TIMEOUT
341+ graceful_shutdown_timeout
338342 ) ,
339343 }
340344 }
@@ -805,12 +809,22 @@ impl GuestVmService {
805809 vm : & VirtualMachine ,
806810 termination_token : CancellationToken ,
807811 ) -> Result < ( ) , GuestVmServiceError > {
812+ let graceful_shutdown_timeout = if self
813+ . hostos_config
814+ . icos_settings
815+ . enable_trusted_execution_environment
816+ {
817+ SEV_GRACEFUL_SHUTDOWN_TIMEOUT
818+ } else {
819+ GRACEFUL_SHUTDOWN_TIMEOUT
820+ } ;
821+
808822 tokio:: select! {
809823 biased;
810824 // Wait for either VM shutdown event or stop signal
811825 _ = termination_token. cancelled( ) => {
812826 info!( "Shutting down VM gracefully" ) ;
813- vm. shutdown_gracefully( ) . await ;
827+ vm. shutdown_gracefully( graceful_shutdown_timeout ) . await ;
814828 Ok ( ( ) )
815829 } ,
816830 _ = vm. wait_for_shutdown( ) => {
0 commit comments