Skip to content

Commit b4030cf

Browse files
gaojiaqi7jyao1
authored andcommitted
tdx-tdcall: align the additional data of report
Add a wrapper struct to hold the additional data to meet the 64B alignment. Signed-off-by: Jiaqi Gao <[email protected]>
1 parent e9820ee commit b4030cf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tdx-tdcall/src/tdreport.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ impl Default for TdxReport {
186186
#[repr(C, align(1024))]
187187
struct TdxReportBuf(TdxReport);
188188

189+
#[repr(C, align(64))]
190+
struct AdditionalDataBuf([u8; TD_REPORT_ADDITIONAL_DATA_SIZE]);
191+
189192
/// Create a TDREPORT_STRUCT structure that contains the measurements/configuration
190193
/// information of the guest TD, measurements/configuration information of the Intel
191194
/// TDX module and a REPORTMACSTRUCT
@@ -194,12 +197,13 @@ struct TdxReportBuf(TdxReport);
194197
pub fn tdcall_report(
195198
additional_data: &[u8; TD_REPORT_ADDITIONAL_DATA_SIZE],
196199
) -> Result<TdxReport, TdCallError> {
197-
let mut buf = TdxReportBuf(TdxReport::default());
200+
let mut report_buf = TdxReportBuf(TdxReport::default());
201+
let additional_data_buf = AdditionalDataBuf(*additional_data);
198202

199203
let mut args = TdcallArgs {
200204
rax: TDCALL_TDREPORT,
201-
rcx: &mut buf as *mut _ as u64,
202-
rdx: additional_data.as_ptr() as u64,
205+
rcx: &mut report_buf as *mut _ as u64,
206+
rdx: &additional_data_buf as *const _ as u64,
203207
..Default::default()
204208
};
205209

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

211-
Ok(buf.0)
215+
Ok(report_buf.0)
212216
}
213217

214218
#[cfg(test)]

0 commit comments

Comments
 (0)