@@ -173,6 +173,23 @@ void __init snp_fixup_e820_tables(void)
173
173
__snp_fixup_e820_tables (probed_rmp_base + probed_rmp_size );
174
174
}
175
175
176
+ static bool __init clear_rmptable_bookkeeping (void )
177
+ {
178
+ void * bk ;
179
+
180
+ bk = memremap (probed_rmp_base , RMPTABLE_CPU_BOOKKEEPING_SZ , MEMREMAP_WB );
181
+ if (!bk ) {
182
+ pr_err ("Failed to map RMP bookkeeping area\n" );
183
+ return false;
184
+ }
185
+
186
+ memset (bk , 0 , RMPTABLE_CPU_BOOKKEEPING_SZ );
187
+
188
+ memunmap (bk );
189
+
190
+ return true;
191
+ }
192
+
176
193
/*
177
194
* Do the necessary preparations which are verified by the firmware as
178
195
* described in the SNP_INIT_EX firmware command description in the SNP
@@ -210,12 +227,17 @@ static int __init snp_rmptable_init(void)
210
227
goto nosnp ;
211
228
}
212
229
213
- rmptable_start = memremap (probed_rmp_base , probed_rmp_size , MEMREMAP_WB );
230
+ /* Map only the RMP entries */
231
+ rmptable_start = memremap (probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ ,
232
+ probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ ,
233
+ MEMREMAP_WB );
214
234
if (!rmptable_start ) {
215
235
pr_err ("Failed to map RMP table\n" );
216
236
goto nosnp ;
217
237
}
218
238
239
+ rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ ;
240
+
219
241
/*
220
242
* Check if SEV-SNP is already enabled, this can happen in case of
221
243
* kexec boot.
@@ -224,7 +246,14 @@ static int __init snp_rmptable_init(void)
224
246
if (val & MSR_AMD64_SYSCFG_SNP_EN )
225
247
goto skip_enable ;
226
248
227
- memset (rmptable_start , 0 , probed_rmp_size );
249
+ /* Zero out the RMP bookkeeping area */
250
+ if (!clear_rmptable_bookkeeping ()) {
251
+ memunmap (rmptable_start );
252
+ goto nosnp ;
253
+ }
254
+
255
+ /* Zero out the RMP entries */
256
+ memset (rmptable_start , 0 , rmptable_size );
228
257
229
258
/* Flush the caches to ensure that data is written before SNP is enabled. */
230
259
wbinvd_on_all_cpus ();
@@ -235,9 +264,6 @@ static int __init snp_rmptable_init(void)
235
264
on_each_cpu (snp_enable , NULL , 1 );
236
265
237
266
skip_enable :
238
- rmptable_start += RMPTABLE_CPU_BOOKKEEPING_SZ ;
239
- rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ ;
240
-
241
267
rmptable = (struct rmpentry_raw * )rmptable_start ;
242
268
rmptable_max_pfn = rmptable_size / sizeof (struct rmpentry_raw ) - 1 ;
243
269
0 commit comments