6
6
7
7
use crate :: address:: { PhysAddr , VirtAddr } ;
8
8
use crate :: console:: init_console;
9
- use crate :: cpu:: cpuid:: cpuid_table;
10
- use crate :: cpu:: percpu:: { current_ghcb, PerCpu } ;
9
+ use crate :: cpu:: cpuid:: { cpuid_table, CpuidResult } ;
10
+ use crate :: cpu:: percpu:: { current_ghcb, this_cpu , PerCpu } ;
11
11
use crate :: error:: ApicError :: Registration ;
12
12
use crate :: error:: SvsmError ;
13
13
use crate :: io:: IOPort ;
@@ -29,6 +29,8 @@ use core::sync::atomic::{AtomicU32, Ordering};
29
29
static CONSOLE_IO : SVSMIOPort = SVSMIOPort :: new ( ) ;
30
30
static CONSOLE_SERIAL : ImmutAfterInitCell < SerialPort < ' _ > > = ImmutAfterInitCell :: uninit ( ) ;
31
31
32
+ static VTOM : ImmutAfterInitCell < usize > = ImmutAfterInitCell :: uninit ( ) ;
33
+
32
34
static APIC_EMULATION_REG_COUNT : AtomicU32 = AtomicU32 :: new ( 0 ) ;
33
35
34
36
#[ derive( Clone , Copy , Debug ) ]
@@ -47,8 +49,9 @@ impl Default for SnpPlatform {
47
49
}
48
50
49
51
impl SvsmPlatform for SnpPlatform {
50
- fn env_setup ( & mut self , _debug_serial_port : u16 ) -> Result < ( ) , SvsmError > {
52
+ fn env_setup ( & mut self , _debug_serial_port : u16 , vtom : usize ) -> Result < ( ) , SvsmError > {
51
53
sev_status_init ( ) ;
54
+ VTOM . init ( & vtom) . map_err ( |_| SvsmError :: PlatformInit ) ?;
52
55
Ok ( ( ) )
53
56
}
54
57
@@ -63,6 +66,10 @@ impl SvsmPlatform for SnpPlatform {
63
66
Ok ( ( ) )
64
67
}
65
68
69
+ fn env_setup_svsm ( & self ) -> Result < ( ) , SvsmError > {
70
+ this_cpu ( ) . configure_hv_doorbell ( )
71
+ }
72
+
66
73
fn setup_percpu ( & self , cpu : & PerCpu ) -> Result < ( ) , SvsmError > {
67
74
// Setup GHCB
68
75
cpu. setup_ghcb ( )
@@ -73,11 +80,12 @@ impl SvsmPlatform for SnpPlatform {
73
80
Ok ( ( ) )
74
81
}
75
82
76
- fn get_page_encryption_masks ( & self , vtom : usize ) -> PageEncryptionMasks {
83
+ fn get_page_encryption_masks ( & self ) -> PageEncryptionMasks {
77
84
// Find physical address size.
78
85
let processor_capacity =
79
86
cpuid_table ( 0x80000008 ) . expect ( "Can not get physical address size from CPUID table" ) ;
80
87
if vtom_enabled ( ) {
88
+ let vtom = * VTOM ;
81
89
PageEncryptionMasks {
82
90
private_pte_mask : 0 ,
83
91
shared_pte_mask : vtom,
@@ -98,6 +106,10 @@ impl SvsmPlatform for SnpPlatform {
98
106
}
99
107
}
100
108
109
+ fn cpuid ( & self , eax : u32 ) -> Option < CpuidResult > {
110
+ cpuid_table ( eax)
111
+ }
112
+
101
113
fn setup_guest_host_comm ( & mut self , cpu : & PerCpu , is_bsp : bool ) {
102
114
if is_bsp {
103
115
verify_ghcb_version ( ) ;
@@ -206,4 +218,11 @@ impl SvsmPlatform for SnpPlatform {
206
218
let _ = current_ghcb ( ) . wrmsr ( 0x80B , 0 ) ;
207
219
}
208
220
}
221
+
222
+ fn start_cpu ( & self , cpu : & PerCpu , start_rip : u64 ) -> Result < ( ) , SvsmError > {
223
+ cpu. setup ( self ) ?;
224
+ let ( vmsa_pa, sev_features) = cpu. alloc_svsm_vmsa ( * VTOM as u64 , start_rip) ?;
225
+
226
+ current_ghcb ( ) . ap_create ( vmsa_pa, cpu. get_apic_id ( ) . into ( ) , 0 , sev_features)
227
+ }
209
228
}
0 commit comments