underhill_core/emuplat/
firmware.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use cvm_tracing::CVM_ALLOWED;
5#[cfg(guest_arch = "x86_64")]
6use firmware_pcat::PcatEvent;
7#[cfg(guest_arch = "x86_64")]
8use firmware_pcat::PcatLogger;
9use firmware_uefi::platform::logger::UefiEvent;
10use firmware_uefi::platform::logger::UefiLogger;
11use guest_emulation_transport::GuestEmulationTransportClient;
12use guest_emulation_transport::api::EventLogId;
13use std::sync::Weak;
14use virt_mshv_vtl::UhPartition;
15
16/// An Underhill specific logger used to log UEFI and PCAT events.
17#[derive(Debug)]
18pub struct UnderhillLogger {
19    pub get: GuestEmulationTransportClient,
20}
21
22impl UefiLogger for UnderhillLogger {
23    fn log_event(&self, event: UefiEvent) {
24        let log_event_id = match event {
25            UefiEvent::BootSuccess(boot_info) => {
26                if boot_info.secure_boot_succeeded {
27                    EventLogId::BOOT_SUCCESS
28                } else {
29                    EventLogId::BOOT_SUCCESS_SECURE_BOOT_FAILED
30                }
31            }
32            UefiEvent::BootFailure(boot_info) => {
33                if boot_info.secure_boot_succeeded {
34                    EventLogId::BOOT_FAILURE
35                } else {
36                    EventLogId::BOOT_FAILURE_SECURE_BOOT_FAILED
37                }
38            }
39            UefiEvent::NoBootDevice => EventLogId::NO_BOOT_DEVICE,
40        };
41        self.get.event_log(log_event_id);
42    }
43}
44
45#[cfg(guest_arch = "x86_64")]
46impl PcatLogger for UnderhillLogger {
47    fn log_event(&self, event: PcatEvent) {
48        let log_event_id = match event {
49            PcatEvent::BootFailure => EventLogId::BOOT_FAILURE,
50            PcatEvent::BootAttempt => EventLogId::BOOT_ATTEMPT,
51        };
52        self.get.event_log(log_event_id);
53    }
54}
55
56#[derive(Debug)]
57pub struct UnderhillVsmConfig {
58    pub partition: Weak<UhPartition>,
59}
60
61impl firmware_uefi::platform::nvram::VsmConfig for UnderhillVsmConfig {
62    fn revoke_guest_vsm(&self) {
63        if let Some(partition) = self.partition.upgrade() {
64            if let Err(err) = partition.revoke_guest_vsm() {
65                tracing::warn!(
66                    CVM_ALLOWED,
67                    error = &err as &dyn std::error::Error,
68                    "failed to revoke guest vsm"
69                );
70            }
71        }
72    }
73}