pub struct CpuidPolicy {Show 15 fields
pub max_basic_leaf: u32,
pub max_extended_leaf: u32,
pub family: u32,
pub model: u32,
pub stepping: u32,
pub cores: u32,
pub threads: u32,
pub leaf1_ecx: u32,
pub leaf1_edx: u32,
pub extended1_ecx: u32,
pub extended1_edx: u32,
pub tsc_ratio_denominator: u32,
pub tsc_ratio_numerator: u32,
pub crystal_hz: u32,
pub base_mhz: u32,
}Expand description
Guest-visible CPU description.
The policy is a small Copy value: the exit loop keeps one per world in
its crate::s9vm::machine::Machine and replays every CPUID exit against
it. CpuidPolicy::default is a safe, boot-capable 64-bit profile:
family 6, one core, one thread, no nested virtualization, no XSAVE.
The fields are public so the syscall layer can assemble a policy from the ABI structure; the accessors and feature helpers enforce the invariants documented at module level.
Fields§
§max_basic_leaf: u32Highest basic leaf, reported by CPUID.0:EAX.
max_extended_leaf: u32Highest extended leaf, reported by CPUID.0x8000_0000:EAX.
family: u32Guest-visible family (CPUID.1:EAX[11:8]).
model: u32Guest-visible model, extended-model bits included.
stepping: u32Guest-visible stepping.
cores: u32Number of physical cores per package (at least one).
threads: u32Number of hardware threads per core (at least one).
leaf1_ecx: u32Raw CPUID.1:ECX mask; forbidden bits are filtered when read.
leaf1_edx: u32Raw CPUID.1:EDX mask.
extended1_ecx: u32Raw CPUID.0x8000_0001:ECX mask; forbidden bits are filtered when
read.
extended1_edx: u32Raw CPUID.0x8000_0001:EDX mask.
tsc_ratio_denominator: u32CPUID.0x15:EAX : TSC/core-crystal ratio denominator.
Zero publishes the host value from the crate::s9vm::tsc cache, or
nothing when the host frequency is unknown.
tsc_ratio_numerator: u32CPUID.0x15:EBX : TSC/core-crystal ratio numerator.
crystal_hz: u32CPUID.0x15:ECX : core-crystal frequency, in hertz.
base_mhz: u32CPUID.0x16:EAX : nominal base frequency, in megahertz.
Implementations§
Source§impl CpuidPolicy
impl CpuidPolicy
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Builds the safe default profile.
This is a const fn so a policy can back a static without runtime
initialization.
Sourcepub fn set_tsc_frequency(&mut self, frequency: TscFrequency)
pub fn set_tsc_frequency(&mut self, frequency: TscFrequency)
Publishes frequency in CPUID leaves 0x15 and 0x16.
The four fields are filled from
TscFrequency::cpuid_leaves.
A caller that leaves them at zero keeps the host-derived fallback, which
is the right default for a world that should see the real host TSC.
Sourcepub fn logical_processors(&self) -> u32
pub fn logical_processors(&self) -> u32
Number of logical processors per package, clamped to the 8-bit
CPUID.1:EBX[23:16] field. Never zero: an empty policy still describes
one processor.
Sourcepub fn effective_leaf1_ecx(&self) -> u32
pub fn effective_leaf1_ecx(&self) -> u32
Effective CPUID.1:ECX, with the forbidden bits cleared.
Sourcepub fn effective_extended1_ecx(&self) -> u32
pub fn effective_extended1_ecx(&self) -> u32
Effective CPUID.0x8000_0001:ECX, with the forbidden bits cleared.
Sourcepub fn signature(&self) -> u32
pub fn signature(&self) -> u32
CPUID.1:EAX: stepping, model and family encoding.
The extended model field is used when model > 0x0F; the extended
family field is only used for families at or above 0x0F, which the
default never is. Bits outside the architectural fields are zero.
Sourcepub fn set_feature(&mut self, feature: Feature)
pub fn set_feature(&mut self, feature: Feature)
Sets one feature bit.
Forbidden bits (LEAF1_ECX_FORBIDDEN, EXTENDED1_ECX_FORBIDDEN)
are silently ignored: a caller can never enable nested virtualization
through this helper.
Sourcepub fn clear_feature(&mut self, feature: Feature)
pub fn clear_feature(&mut self, feature: Feature)
Clears one feature bit.
Sourcepub fn has_feature(&self, feature: Feature) -> bool
pub fn has_feature(&self, feature: Feature) -> bool
Reports whether one feature bit is in effect, forbidden bits included.
Sourcepub fn leaf(&self, leaf: u32, subleaf: u32) -> [u32; 4]
pub fn leaf(&self, leaf: u32, subleaf: u32) -> [u32; 4]
Replays one CPUID instruction: returns [EAX, EBX, ECX, EDX].
The function is total and deterministic. leaf == 0 always answers
with the advertised basic range; a basic leaf above
CpuidPolicy::max_basic_leaf and an extended leaf above
CpuidPolicy::max_extended_leaf return zeros, as does every leaf
this model does not implement (notably the 0x4000_0000 hypervisor
range, because the hypervisor-present bit is never set).
Sourcefn vendor_leaf(&self) -> [u32; 4]
fn vendor_leaf(&self) -> [u32; 4]
CPUID.0: max basic leaf and vendor string.
Sourcefn feature_leaf(&self) -> [u32; 4]
fn feature_leaf(&self) -> [u32; 4]
CPUID.1: signature, topology count and feature masks.
Sourcefn extended_features_leaf(&self) -> [u32; 4]
fn extended_features_leaf(&self) -> [u32; 4]
CPUID.0x8000_0001: extended feature masks.
Sourcefn tsc_ratio_leaf(&self) -> [u32; 4]
fn tsc_ratio_leaf(&self) -> [u32; 4]
CPUID.0x15: TSC/core-crystal ratio and crystal frequency.
The policy fields win when they form a usable ratio (non-zero
denominator, numerator and crystal). Otherwise the host frequency cache
is consulted, so a guest sees the real host TSC frequency even when the
policy was not explicitly tuned; when neither source is available the
leaf reads as zero and the guest falls back to leaf 0x16 or to
calibration.
Sourcefn base_frequency_leaf(&self) -> [u32; 4]
fn base_frequency_leaf(&self) -> [u32; 4]
CPUID.0x16: nominal base frequency in EAX (megahertz).
The policy field wins; otherwise the host frequency cache is truncated to megahertz. Zero means “not published”.
Sourcefn extended_frequency_leaf(&self) -> [u32; 4]
fn extended_frequency_leaf(&self) -> [u32; 4]
CPUID.0x8000_0007: invariant TSC bit in EDX.
Only bit 8 is set: the guest TSC is the host TSC, s9vm never offsets or scales it, so the invariant-TSC guarantee is published unconditionally. Advanced power-management bits are not advertised.
Sourcefn brand_leaf(&self, leaf: u32) -> [u32; 4]
fn brand_leaf(&self, leaf: u32) -> [u32; 4]
CPUID.0x8000_0002..=0x8000_0004: one quarter of the brand string.
Sourcefn address_sizes_leaf(&self) -> [u32; 4]
fn address_sizes_leaf(&self) -> [u32; 4]
CPUID.0x8000_0008: physical and virtual address sizes.
Sourcefn topology_leaf(&self, subleaf: u32) -> [u32; 4]
fn topology_leaf(&self, subleaf: u32) -> [u32; 4]
Topology enumeration, shared by CPUID.0x0B and CPUID.0x1F.
Both leaves use the same ECX[15:8] level-type encoding (1 = SMT,
2 = core) and terminate with an invalid type. 0x1F additionally
carries the x2APIC identifier in EDX[31:16]; with a single package
identifier 0 both variants return the same words.
Trait Implementations§
Source§impl Clone for CpuidPolicy
impl Clone for CpuidPolicy
impl Copy for CpuidPolicy
Source§impl Debug for CpuidPolicy
impl Debug for CpuidPolicy
Source§impl Default for CpuidPolicy
impl Default for CpuidPolicy
impl Eq for CpuidPolicy
Source§impl PartialEq for CpuidPolicy
impl PartialEq for CpuidPolicy
impl StructuralPartialEq for CpuidPolicy
Auto Trait Implementations§
impl Forget for CpuidPolicy
impl Freeze for CpuidPolicy
impl Move for CpuidPolicy
impl RefUnwindSafe for CpuidPolicy
impl Send for CpuidPolicy
impl Sync for CpuidPolicy
impl Unpin for CpuidPolicy
impl UnsafeUnpin for CpuidPolicy
impl UnwindSafe for CpuidPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more