Skip to content

Commit 4c36234

Browse files
authored
chore: Increase graceful shutdown timeout of SEV VMs (#11538)
1 parent 763d0e5 commit 4c36234

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

ic-os/components/hostos/guestos/guestos@.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ ExecStart=/opt/ic/bin/guest_vm_runner run --slot %i
1414
ExecStartPost=/opt/ic/bin/manageboot.sh hostos confirm
1515
Restart=always
1616
RestartSec=60
17-
TimeoutStopSec=130s
17+
TimeoutStopSec=660s

ic-os/components/hostos/guestos/upgrade-guestos.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Type=notify
1010
ExecStart=/opt/ic/bin/guest_vm_runner run --type=upgrade
1111
Restart=no
1212
RestartSec=20
13-
TimeoutStopSec=130s
13+
TimeoutStopSec=660s

rs/ic_os/os_tools/guest_vm_runner/src/main.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const STUCK_STATE_TIMEOUT: Duration = Duration::from_secs(5 * 60);
7777
#[cfg(test)]
7878
const 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.
8185
const GUESTOS_BOOT_SUCCESS_MARKER: &str = "GUESTOS BOOT SUCCESS";
8286
const 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

Comments
 (0)