Skip to content

Commit 1657771

Browse files
committed
Support Logging for vmcall-raw feature
Signed-off-by: Gudaram, Meghana <[email protected]>
1 parent 7a6bf8c commit 1657771

File tree

6 files changed

+511
-39
lines changed

6 files changed

+511
-39
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/migtd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ x86 = "0.47.0"
4444
x86_64 = { version = "0.14", default-features = false, features = ["instructions"] }
4545
zerocopy = { version = "0.7", features = ["derive"] }
4646
bitfield-struct = "0.11"
47+
raw-cpuid = "11.6.0"
4748

4849
minicov = { version = "0.2", default-features = false, optional = true }
4950
td-benchmark = { path = "../../deps/td-shim/devtools/td-benchmark", default-features = false, optional = true }

src/migtd/src/bin/migtd/main.rs

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ extern crate alloc;
1010
use core::future::poll_fn;
1111
use core::task::Poll;
1212

13+
#[cfg(feature = "vmcall-raw")]
14+
use alloc::format;
1315
#[cfg(feature = "policy_v2")]
1416
use alloc::string::String;
1517
#[cfg(feature = "vmcall-raw")]
1618
use alloc::vec::Vec;
1719
use log::info;
20+
#[cfg(feature = "vmcall-raw")]
21+
use log::Level;
1822
use migtd::event_log::*;
1923
#[cfg(not(feature = "vmcall-raw"))]
2024
use migtd::migration::data::MigrationInformation;
@@ -39,6 +43,12 @@ pub extern "C" fn main() {
3943
pub fn runtime_main() {
4044
let _ = td_logger::init();
4145

46+
// Create LogArea per vCPU
47+
#[cfg(feature = "vmcall-raw")]
48+
{
49+
let _ = create_logarea();
50+
}
51+
4252
// Dump basic information of MigTD
4353
basic_info();
4454

@@ -230,28 +240,106 @@ fn handle_pre_mig() {
230240
.await
231241
.map(|_| MigrationResult::Success)
232242
.unwrap_or_else(|e| e);
243+
if status == MigrationResult::Success {
244+
entrylog(
245+
&format!("Successfully completed key exchange\n").into_bytes(),
246+
Level::Trace,
247+
wfr_info.mig_info.mig_request_id,
248+
);
249+
} else {
250+
entrylog(
251+
&format!(
252+
"Failure during key exchange, status code: {:x}\n",
253+
status.clone() as u8
254+
)
255+
.into_bytes(),
256+
Level::Error,
257+
wfr_info.mig_info.mig_request_id,
258+
);
259+
}
233260
let _ = report_status(
234261
status as u8,
235262
wfr_info.mig_info.mig_request_id,
236263
&data,
237264
)
238265
.await;
266+
entrylog(
267+
&format!("ReportStatus for key exchange completed\n").into_bytes(),
268+
Level::Trace,
269+
wfr_info.mig_info.mig_request_id,
270+
);
239271
REQUESTS.lock().remove(&wfr_info.mig_info.mig_request_id);
240272
}
241273
WaitForRequestResponse::GetTdReport(wfr_info) => {
242-
let status = get_tdreport(&wfr_info.reportdata, &mut data)
243-
.await
244-
.map(|_| MigrationResult::Success)
245-
.unwrap_or_else(|e| e);
274+
let status = get_tdreport(
275+
&wfr_info.reportdata,
276+
&mut data,
277+
wfr_info.mig_request_id,
278+
)
279+
.await
280+
.map(|_| MigrationResult::Success)
281+
.unwrap_or_else(|e| e);
282+
if status == MigrationResult::Success {
283+
entrylog(
284+
&format!("Successfully completed get TDREPORT\n").into_bytes(),
285+
Level::Trace,
286+
wfr_info.mig_request_id,
287+
);
288+
} else {
289+
entrylog(
290+
&format!(
291+
"Failure during get TDREPORT, status code: {:x}\n",
292+
status.clone() as u8
293+
)
294+
.into_bytes(),
295+
Level::Error,
296+
wfr_info.mig_request_id,
297+
);
298+
}
246299
let _ =
247300
report_status(status as u8, wfr_info.mig_request_id, &data).await;
301+
entrylog(
302+
&format!("ReportStatus for get TDREPORT completed\n").into_bytes(),
303+
Level::Trace,
304+
wfr_info.mig_request_id,
305+
);
248306
REQUESTS.lock().remove(&wfr_info.mig_request_id);
249307
}
250308
WaitForRequestResponse::EnableLogArea(wfr_info) => {
251-
// TODO: support this feature
252-
let status = MigrationResult::UnsupportedOperationError;
309+
let status = enable_logarea(
310+
wfr_info.log_max_level,
311+
wfr_info.mig_request_id,
312+
&mut data,
313+
)
314+
.await
315+
.map(|_| MigrationResult::Success)
316+
.unwrap_or_else(|e| e);
317+
if status == MigrationResult::Success {
318+
entrylog(
319+
&format!("Successfully completed Enable LogArea\n")
320+
.into_bytes(),
321+
Level::Trace,
322+
wfr_info.mig_request_id,
323+
);
324+
} else {
325+
entrylog(
326+
&format!(
327+
"Failure during Enable LogArea, status code: {:x}\n",
328+
status.clone() as u8
329+
)
330+
.into_bytes(),
331+
Level::Error,
332+
wfr_info.mig_request_id,
333+
);
334+
}
253335
let _ =
254336
report_status(status as u8, wfr_info.mig_request_id, &data).await;
337+
entrylog(
338+
&format!("ReportStatus for Enable LogArea completed\n")
339+
.into_bytes(),
340+
Level::Trace,
341+
wfr_info.mig_request_id,
342+
);
255343
REQUESTS.lock().remove(&wfr_info.mig_request_id);
256344
}
257345
}

src/migtd/src/migration/data.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ pub struct ReportStatusResponse {
239239
pub reserved: u64,
240240
}
241241

242+
#[cfg(feature = "vmcall-raw")]
243+
#[derive(AsBytes, FromBytes, FromZeroes, Debug)]
244+
#[repr(C, packed)]
245+
pub struct RequestDataBufferHeader {
246+
pub datastatus: u64,
247+
pub length: u32,
248+
}
249+
250+
#[cfg(feature = "vmcall-raw")]
251+
pub struct RequestDataBuffer<'a> {
252+
pub header: RequestDataBufferHeader,
253+
pub data: &'a [u8],
254+
}
255+
242256
#[cfg(feature = "vmcall-raw")]
243257
pub enum WaitForRequestResponse {
244258
StartMigration(MigrationInformation),

src/migtd/src/migration/mod.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use tdx_tdcall::TdVmcallError;
2424
use virtio_serial::VirtioSerialError;
2525
#[cfg(any(feature = "virtio-vsock", feature = "vmcall-vsock"))]
2626
use vsock::VsockError;
27+
#[cfg(feature = "vmcall-raw")]
28+
use zerocopy::{AsBytes, FromBytes, FromZeroes};
2729

2830
pub const VMCALL_SERVICE_COMMON_GUID: Guid = Guid::from_fields(
2931
0xfb6fc5e1,
@@ -118,6 +120,45 @@ pub struct EnableLogAreaInfo {
118120
pub reserved: [u8; 7],
119121
}
120122

123+
#[cfg(feature = "vmcall-raw")]
124+
pub const LOGAREA_SIGNATURE: [u8; 16] = [
125+
0x4d, 0x69, 0x67, 0x54, 0x44, 0x20, 0x4c, 0x6f, 0x67, 0x41, 0x72, 0x65, 0x61, 0x20, 0x31, 0x00,
126+
];
127+
128+
#[repr(C, packed)]
129+
#[derive(AsBytes, FromBytes, FromZeroes, Debug)]
130+
#[cfg(feature = "vmcall-raw")]
131+
pub struct LogAreaBufferHeader {
132+
pub signature: [u8; 16],
133+
pub vcpuindex: u32,
134+
pub reserved: u32,
135+
pub startoffset: u64,
136+
pub endoffset: u64,
137+
}
138+
139+
#[cfg(feature = "vmcall-raw")]
140+
pub struct LogAreaBuffer<'a> {
141+
pub header: LogAreaBufferHeader,
142+
pub logdata: &'a [u8],
143+
}
144+
145+
#[repr(C, packed)]
146+
#[derive(AsBytes, FromBytes, FromZeroes, Debug)]
147+
#[cfg(feature = "vmcall-raw")]
148+
pub struct LogEntryHeader {
149+
pub log_entry_id: u64,
150+
pub mig_request_id: u64,
151+
pub loglevel: u8,
152+
pub reserved: [u8; 3],
153+
pub length: u32,
154+
}
155+
156+
#[cfg(feature = "vmcall-raw")]
157+
pub struct LogEntry<'a> {
158+
pub header: LogEntryHeader,
159+
pub value: &'a [u8],
160+
}
161+
121162
#[repr(C)]
122163
#[derive(Debug, Pread, Pwrite)]
123164
pub struct MigtdStreamSocketInfo {
@@ -155,7 +196,7 @@ pub struct MigtdMigpolicy {
155196
}
156197

157198
#[repr(u8)]
158-
#[derive(PartialEq)]
199+
#[derive(PartialEq, Clone)]
159200
pub enum MigrationResult {
160201
Success = 0,
161202
InvalidParameter = 1,

0 commit comments

Comments
 (0)