Skip to content

Commit bd74590

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

File tree

7 files changed

+525
-42
lines changed

7 files changed

+525
-42
lines changed

Cargo.lock

Lines changed: 12 additions & 1 deletion
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: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ 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;
2125
#[cfg(feature = "vmcall-raw")]
2226
use migtd::migration::data::WaitForRequestResponse;
2327
use migtd::migration::session::*;
28+
#[cfg(feature = "vmcall-raw")]
29+
use migtd::migration::logging::*;
2430
use migtd::migration::MigrationResult;
2531
use migtd::{config, event_log, migration};
2632
use spin::Mutex;
@@ -39,6 +45,12 @@ pub extern "C" fn main() {
3945
pub fn runtime_main() {
4046
let _ = td_logger::init();
4147

48+
// Create LogArea per vCPU
49+
#[cfg(feature = "vmcall-raw")]
50+
{
51+
let _ = create_logarea();
52+
}
53+
4254
// Dump basic information of MigTD
4355
basic_info();
4456

@@ -230,28 +242,106 @@ fn handle_pre_mig() {
230242
.await
231243
.map(|_| MigrationResult::Success)
232244
.unwrap_or_else(|e| e);
245+
if status == MigrationResult::Success {
246+
entrylog(
247+
&format!("Successfully completed key exchange\n").into_bytes(),
248+
Level::Trace,
249+
wfr_info.mig_info.mig_request_id,
250+
);
251+
} else {
252+
entrylog(
253+
&format!(
254+
"Failure during key exchange, status code: {:x}\n",
255+
status.clone() as u8
256+
)
257+
.into_bytes(),
258+
Level::Error,
259+
wfr_info.mig_info.mig_request_id,
260+
);
261+
}
233262
let _ = report_status(
234263
status as u8,
235264
wfr_info.mig_info.mig_request_id,
236265
&data,
237266
)
238267
.await;
268+
entrylog(
269+
&format!("ReportStatus for key exchange completed\n").into_bytes(),
270+
Level::Trace,
271+
wfr_info.mig_info.mig_request_id,
272+
);
239273
REQUESTS.lock().remove(&wfr_info.mig_info.mig_request_id);
240274
}
241275
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);
276+
let status = get_tdreport(
277+
&wfr_info.reportdata,
278+
&mut data,
279+
wfr_info.mig_request_id,
280+
)
281+
.await
282+
.map(|_| MigrationResult::Success)
283+
.unwrap_or_else(|e| e);
284+
if status == MigrationResult::Success {
285+
entrylog(
286+
&format!("Successfully completed get TDREPORT\n").into_bytes(),
287+
Level::Trace,
288+
wfr_info.mig_request_id,
289+
);
290+
} else {
291+
entrylog(
292+
&format!(
293+
"Failure during get TDREPORT, status code: {:x}\n",
294+
status.clone() as u8
295+
)
296+
.into_bytes(),
297+
Level::Error,
298+
wfr_info.mig_request_id,
299+
);
300+
}
246301
let _ =
247302
report_status(status as u8, wfr_info.mig_request_id, &data).await;
303+
entrylog(
304+
&format!("ReportStatus for get TDREPORT completed\n").into_bytes(),
305+
Level::Trace,
306+
wfr_info.mig_request_id,
307+
);
248308
REQUESTS.lock().remove(&wfr_info.mig_request_id);
249309
}
250310
WaitForRequestResponse::EnableLogArea(wfr_info) => {
251-
// TODO: support this feature
252-
let status = MigrationResult::UnsupportedOperationError;
311+
let status = enable_logarea(
312+
wfr_info.log_max_level,
313+
wfr_info.mig_request_id,
314+
&mut data,
315+
)
316+
.await
317+
.map(|_| MigrationResult::Success)
318+
.unwrap_or_else(|e| e);
319+
if status == MigrationResult::Success {
320+
entrylog(
321+
&format!("Successfully completed Enable LogArea\n")
322+
.into_bytes(),
323+
Level::Trace,
324+
wfr_info.mig_request_id,
325+
);
326+
} else {
327+
entrylog(
328+
&format!(
329+
"Failure during Enable LogArea, status code: {:x}\n",
330+
status.clone() as u8
331+
)
332+
.into_bytes(),
333+
Level::Error,
334+
wfr_info.mig_request_id,
335+
);
336+
}
253337
let _ =
254338
report_status(status as u8, wfr_info.mig_request_id, &data).await;
339+
entrylog(
340+
&format!("ReportStatus for Enable LogArea completed\n")
341+
.into_bytes(),
342+
Level::Trace,
343+
wfr_info.mig_request_id,
344+
);
255345
REQUESTS.lock().remove(&wfr_info.mig_request_id);
256346
}
257347
}

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),

0 commit comments

Comments
 (0)