Skip to content

Commit

Permalink
Added MaskID bitfield
Browse files Browse the repository at this point in the history
Signed-off-by: DGonzalezVillal <Diego.GonzalezVillalobos@amd.com>
  • Loading branch information
DGonzalezVillal committed Feb 8, 2024
1 parent c049cb8 commit 4502816
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
38 changes: 36 additions & 2 deletions src/firmware/host/types/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::{
fmt::Display,
};

use bitfield::bitfield;

use bitflags;

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -200,7 +202,7 @@ pub struct Config {

/// Indicates that the CHIP_ID field in the attestation report will always
/// be zero.
pub mask_id: u32,
pub mask_id: MaskId,

/// Reserved. Must be zero.
reserved: [u8; 52],
Expand All @@ -218,7 +220,7 @@ impl Default for Config {

impl Config {
/// Used to create a new Config
pub fn new(reported_tcb: TcbVersion, mask_id: u32) -> Self {
pub fn new(reported_tcb: TcbVersion, mask_id: MaskId) -> Self {
Self {
reported_tcb,
mask_id,
Expand Down Expand Up @@ -302,3 +304,35 @@ impl TcbVersion {
}
}
}

bitfield! {
/// Mask ID values that would go into an SNP CONFIG
///
/// | Bit(s) | Name | Description |
/// |--------|------|-------------|
/// |0|MASK_CHIP_ID|Indicates that the CHIP_ID field in the attestation report will alwaysbe zero.|
/// |1|MASK_CHIP_KEY|Indicates that the VCEK is not used in attestation and guest key derivation.|
#[repr(C)]
#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MaskId(u32);
impl Debug;
/// Indicates that the CHIP_ID field in the attestation report will alwaysbe zero.
pub mask_chip_id, _: 0, 0;
/// Indicates that the VCEK is not used in attestation and guest key derivation.
pub mask_chip_key, _: 1, 1;
}

impl Display for MaskId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
r#"
MaskID ({}):
Mask Chip ID: {}
ABI Chip Key: {}"#,
self.0,
self.mask_chip_id(),
self.mask_chip_key(),
)
}
}
6 changes: 4 additions & 2 deletions src/firmware/linux/host/types/snp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ impl CertTableEntry {
#[cfg(feature = "snp")]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[repr(C, packed)]
pub struct SnpCommit(u32);
pub struct SnpCommit {
pub buffer: u32,
}

/// Sets the system wide configuration values for SNP.
#[cfg(feature = "snp")]
Expand All @@ -229,7 +231,7 @@ pub struct SnpSetConfig {
/// mask_id [0] : whether chip id is present in attestation reports or not
/// mask_id [1]: whether attestation reports are signed or not
/// rsvd [2:31]: reserved
pub mask_id: u32,
pub mask_id: UAPI::MaskId,

/// Reserved. Must be zero.
reserved: [u8; 52],
Expand Down
4 changes: 2 additions & 2 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod sev {

#[cfg(feature = "snp")]
mod snp {
use sev::firmware::host::{Config, Firmware, SnpPlatformStatus, TcbVersion};
use sev::firmware::host::{Config, Firmware, MaskId, SnpPlatformStatus, TcbVersion};

use serial_test::serial;

Expand Down Expand Up @@ -182,7 +182,7 @@ mod snp {
#[serial]
fn set_config() {
let mut fw: Firmware = Firmware::open().unwrap();
let new_config = Config::new(TcbVersion::new(1, 0, 1, 1), 31);
let new_config = Config::new(TcbVersion::new(1, 0, 1, 1), MaskId(31));
fw.snp_set_config(new_config).unwrap();
}
}

0 comments on commit 4502816

Please sign in to comment.