@@ -18,7 +18,7 @@ use std::os::unix::io::AsRawFd;
1818use std:: path:: Path ;
1919use std:: sync:: Mutex ;
2020use std:: thread;
21- use std:: time:: Duration ;
21+ use std:: time:: { Duration , Instant } ;
2222
2323use thiserror:: Error ;
2424
@@ -53,6 +53,10 @@ const QGS_MSG_GET_QUOTE_RESP: u32 = 1;
5353const QGS_MSG_VERSION_MAJOR : u16 = 1 ;
5454const QGS_MSG_VERSION_MINOR : u16 = 0 ;
5555
56+ // ConfigFS generation wait parameters
57+ const CONFIGFS_GEN_WAIT_TIMEOUT_SECS : u64 = 5 ;
58+ const CONFIGFS_GEN_POLL_INTERVAL_MS : u64 = 10 ;
59+
5660// ============================================================================
5761// ioctl definitions for /dev/tdx_guest
5862// ============================================================================
@@ -431,12 +435,19 @@ fn write_inblob_with_retry(path: &str, data: &TdxReportData) -> Result<()> {
431435}
432436
433437fn wait_for_generation_change ( path : & str , current : i64 ) -> Result < i64 > {
438+ let deadline = Instant :: now ( ) + Duration :: from_secs ( CONFIGFS_GEN_WAIT_TIMEOUT_SECS ) ;
439+
434440 loop {
435441 let gen = read_generation ( path) ?;
436442 if gen != current {
437443 return Ok ( gen) ;
438444 }
439- thread:: sleep ( Duration :: from_micros ( 1 ) ) ;
445+ if Instant :: now ( ) >= deadline {
446+ return Err ( TdxAttestError :: QuoteFailure (
447+ "timed out waiting for configfs generation to advance" . to_string ( ) ,
448+ ) ) ;
449+ }
450+ thread:: sleep ( Duration :: from_millis ( CONFIGFS_GEN_POLL_INTERVAL_MS ) ) ;
440451 }
441452}
442453
0 commit comments