-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Early support for the SBI HSM extension
Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
- Loading branch information
1 parent
14884b4
commit 1abf129
Showing
35 changed files
with
397 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
security-monitor/src/confidential_flow/handlers/sbi_hsm_hart_stop.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::confidential_flow::ConfidentialFlow; | ||
use crate::core::architecture::HartLifecycleStateTransition; | ||
use crate::core::transformations::{ExposeToHypervisor, SbiRequest}; | ||
|
||
/// Stops the confidential hart as defined in the HSM extension of SBI. Error is returned to the confidential hart if | ||
/// the security monitor cannot stop it, for example, because it is not in the started state. | ||
/// | ||
/// The request to stop the confidential hart comes from the confidential hart itself. The security monitor stops the | ||
/// hart and informs the hypervisor that the hart has been stopped. The hypervisor should not resume execution of a | ||
/// stopped confidential hart. Only another confidential hart of the confidential VM can start the confidential hart. | ||
pub fn handle(mut confidential_flow: ConfidentialFlow) -> ! { | ||
match confidential_flow.transit_hart_lifecycle(HartLifecycleStateTransition::StartedToStopped()) { | ||
Ok(_) => confidential_flow | ||
.into_non_confidential_flow() | ||
.exit_to_hypervisor(ExposeToHypervisor::SbiRequest(SbiRequest::kvm_hsm_hart_stop())), | ||
Err(error) => confidential_flow.exit_to_confidential_vm(error.into_confidential_transformation()), | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
security-monitor/src/confidential_flow/handlers/sbi_hsm_hart_suspend.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::confidential_flow::ConfidentialFlow; | ||
use crate::core::architecture::HartLifecycleStateTransition; | ||
use crate::core::transformations::{ExposeToHypervisor, SbiHsmHartSuspend, SbiRequest}; | ||
|
||
/// Suspends a confidential hart that made this request. This is an implementation of the HartSuspend function from the | ||
/// HSM extension of SBI. | ||
/// | ||
/// The request to suspend the confidential hart comes frmo the confidential hart itself. The security monitor suspends | ||
/// the confidential hart and informs about it the hypervisor. This functions returns an error to the calling | ||
/// confidential hart if this confidential hart cannot be suspended, for example, because it is not in the started | ||
/// state. | ||
pub fn handle(request: SbiHsmHartSuspend, mut confidential_flow: ConfidentialFlow) -> ! { | ||
match confidential_flow.transit_hart_lifecycle(HartLifecycleStateTransition::StartedToSuspended(request)) { | ||
Ok(_) => confidential_flow | ||
.into_non_confidential_flow() | ||
.exit_to_hypervisor(ExposeToHypervisor::SbiRequest(SbiRequest::kvm_hsm_hart_suspend())), | ||
Err(error) => confidential_flow.exit_to_confidential_vm(error.into_confidential_transformation()), | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
security-monitor/src/confidential_flow/handlers/sbi_srst.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::confidential_flow::ConfidentialFlow; | ||
use crate::core::control_data::ControlData; | ||
use crate::core::transformations::{ExposeToHypervisor, SbiRequest}; | ||
|
||
pub fn handle(request: SbiRequest, confidential_flow: ConfidentialFlow) -> ! { | ||
let confidential_vm_id = confidential_flow.confidential_vm_id(); | ||
match ControlData::try_write(|control_data| control_data.remove_confidential_vm(confidential_vm_id)) { | ||
Ok(_) => { | ||
confidential_flow.into_non_confidential_flow().exit_to_hypervisor(ExposeToHypervisor::SbiRequest(request)) | ||
} | ||
Err(error) => confidential_flow.exit_to_confidential_vm(error.into_confidential_transformation()), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
security-monitor/src/core/architecture/riscv/hart_lifecycle_state.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/// Hart lifecycle states as documented in the SBI specification of the HSM extension. | ||
#[derive(PartialEq)] | ||
pub enum HartLifecycleState { | ||
Started, | ||
Stopped, | ||
StartPending, | ||
// | ||
// StopPending is never used because the security monitor stops the hart directly and only informs a hypervisor | ||
// about it for the bookkeeping pourposes. | ||
// StopPending, | ||
Suspended, | ||
// | ||
// SuspendPending is never used because the security monitor stops the hart directly and only informs a hypervisor | ||
// about it for the bookkeeping pourposes. | ||
// SuspendPending, | ||
// | ||
// ResumePending is never used because the security monitor stops the hart directly and only informs a hypervisor | ||
// about it for the bookkeeping pourposes. | ||
// ResumePending, | ||
} |
11 changes: 11 additions & 0 deletions
11
security-monitor/src/core/architecture/riscv/hart_lifecycle_state_transition.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2023 IBM Corporation | ||
// SPDX-FileContributor: Wojciech Ozga <woz@zurich.ibm.com>, IBM Research - Zurich | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use crate::core::transformations::{SbiHsmHartStart, SbiHsmHartSuspend}; | ||
|
||
pub enum HartLifecycleStateTransition { | ||
StoppedToStartPending(SbiHsmHartStart), | ||
StartedToSuspended(SbiHsmHartSuspend), | ||
SuspendedToStarted(), | ||
StartedToStopped(), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.