<commit_before>//
// Copyright 2022 The Project Oak Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

use log::trace;
use oak_sev_guest::vmsa::{calculate_rdx_from_fms, Vmsa, VmsaPage};
use x86_64::{
    structures::paging::{PageSize, Size4KiB},
    PhysAddr,
};

/// The CPU family of the vCPU we expect to be running on.
const CPU_FAMILY: u8 = 6;

/// The CPU model of the vCPU we expect to be running on.
const CPU_MODEL: u8 = 0;

/// The stepping of the vCPU we expect to be running on.
const CPU_STEPPING: u8 = 0;

/// The guest-physical address of the VMSA page.
///
/// The current implementation uses the same fixed address for all VMSA pages. It is calculated as
/// the start-address of the last 4KiB page that can be addressed within the allowed physical bits.
///
/// For AMD "Milan" CPUs the maximum supported physical memory bit-width is 48 when SEV-SNP is
/// enabled.
#[allow(unused)]
pub const VMSA_ADDRESS: PhysAddr = PhysAddr::new((1 << 48) - Size4KiB::SIZE);

/// Gets the initial VMSA for the vCPU that is used to boot the VM.
pub fn get_boot_vmsa() -> VmsaPage {
    let result = VmsaPage::new(Vmsa::new_vcpu_boot(calculate_rdx_from_fms(
        CPU_FAMILY,
        CPU_MODEL,
        CPU_STEPPING,
    )));
    trace!("Boot VMSA: {:?}", result);
    result
}
<commit_msg>Update the initial VMSA state for measurements (#3495)<commit_after>//
// Copyright 2022 The Project Oak Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

use log::trace;
use oak_sev_guest::vmsa::{calculate_rdx_from_fms, Vmsa, VmsaPage};
use x86_64::{
    structures::paging::{PageSize, Size4KiB},
    PhysAddr,
};

/// The CPU family of the vCPU we expect to be running on.
const CPU_FAMILY: u8 = 6;

/// The CPU model of the vCPU we expect to be running on.
const CPU_MODEL: u8 = 0;

/// The stepping of the vCPU we expect to be running on.
const CPU_STEPPING: u8 = 0;

/// The guest-physical address of the VMSA page.
///
/// The current implementation uses the same fixed address for all VMSA pages. It is calculated as
/// the start-address of the last 4KiB page that can be addressed within the allowed physical bits.
///
/// For AMD "Milan" CPUs the maximum supported physical memory bit-width is 48 when SEV-SNP is
/// enabled.
#[allow(unused)]
pub const VMSA_ADDRESS: PhysAddr = PhysAddr::new((1 << 48) - Size4KiB::SIZE);

/// Gets the initial VMSA for the vCPU that is used to boot the VM.
pub fn get_boot_vmsa() -> VmsaPage {
    let mut result = VmsaPage::new(Vmsa::new_vcpu_boot(calculate_rdx_from_fms(
        CPU_FAMILY,
        CPU_MODEL,
        CPU_STEPPING,
    )));
    // We expect a slightly different initial state to use for the measurement.
    result.vmsa.g_pat = 0x00070106;
    result.vmsa.sev_features = 0x00000001;

    trace!("Boot VMSA: {:?}", result);
    result
}

{'fraction_non_alphanumeric': 0.1033672670321065, 'fraction_numerical': 0.01931610545549465, 'mean_word_length': 3.325056433408578, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '787005', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1182, 'n_words': 492}