Skip to content

Commit

Permalink
tdx-tdcall: align the additional data of report
Browse files Browse the repository at this point in the history
Add a wrapper struct to hold the additional data to meet the 64B alignment.

Signed-off-by: Jiaqi Gao <[email protected]>
  • Loading branch information
gaojiaqi7 committed Dec 11, 2024
1 parent 820a44d commit 8a97537
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tdx-tdcall/src/tdreport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ impl Default for TdxReport {
#[repr(C, align(1024))]
struct TdxReportBuf(TdxReport);

#[repr(C, align(64))]
struct AdditionalDataBuf([u8; TD_REPORT_ADDITIONAL_DATA_SIZE]);

/// Create a TDREPORT_STRUCT structure that contains the measurements/configuration
/// information of the guest TD, measurements/configuration information of the Intel
/// TDX module and a REPORTMACSTRUCT
Expand All @@ -194,12 +197,13 @@ struct TdxReportBuf(TdxReport);
pub fn tdcall_report(
additional_data: &[u8; TD_REPORT_ADDITIONAL_DATA_SIZE],
) -> Result<TdxReport, TdCallError> {
let mut buf = TdxReportBuf(TdxReport::default());
let mut report_buf = TdxReportBuf(TdxReport::default());
let additional_data_buf = AdditionalDataBuf(*additional_data);

let mut args = TdcallArgs {
rax: TDCALL_TDREPORT,
rcx: &mut buf as *mut _ as u64,
rdx: additional_data.as_ptr() as u64,
rcx: &mut report_buf as *mut _ as u64,
rdx: &additional_data_buf as *const _ as u64,
..Default::default()
};

Expand All @@ -208,7 +212,7 @@ pub fn tdcall_report(
return Err(args.r10.into());
}

Ok(buf.0)
Ok(report_buf.0)
}

#[cfg(test)]
Expand Down

0 comments on commit 8a97537

Please sign in to comment.