Skip to content

Commit e3131f1

Browse files
dcuiliuw
authored andcommitted
x86/hyperv: Remove hv_isolation_type_en_snp
In ms_hyperv_init_platform(), do not distinguish between a SNP VM with the paravisor and a SNP VM without the paravisor. Replace hv_isolation_type_en_snp() with !ms_hyperv.paravisor_present && hv_isolation_type_snp(). The hv_isolation_type_en_snp() in drivers/hv/hv.c and drivers/hv/hv_common.c can be changed to hv_isolation_type_snp() since we know !ms_hyperv.paravisor_present is true there. Signed-off-by: Dexuan Cui <decui@microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Reviewed-by: Tianyu Lan <tiala@microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org> Link: https://lore.kernel.org/r/20230824080712.30327-10-decui@microsoft.com
1 parent b9b4fe3 commit e3131f1

File tree

7 files changed

+17
-39
lines changed

7 files changed

+17
-39
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int hyperv_init_ghcb(void)
5252
void *ghcb_va;
5353
void **ghcb_base;
5454

55-
if (!hv_isolation_type_snp())
55+
if (!ms_hyperv.paravisor_present || !hv_isolation_type_snp())
5656
return 0;
5757

5858
if (!hv_ghcb_pg)
@@ -117,7 +117,7 @@ static int hv_cpu_init(unsigned int cpu)
117117
* is blocked to run in Confidential VM. So only decrypt assist
118118
* page in non-root partition here.
119119
*/
120-
if (*hvp && hv_isolation_type_en_snp()) {
120+
if (*hvp && !ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
121121
WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1));
122122
memset(*hvp, 0, PAGE_SIZE);
123123
}
@@ -460,7 +460,7 @@ void __init hyperv_init(void)
460460
goto common_free;
461461
}
462462

463-
if (hv_isolation_type_snp()) {
463+
if (ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
464464
/* Negotiate GHCB Version. */
465465
if (!hv_ghcb_negotiate_protocol())
466466
hv_ghcb_terminate(SEV_TERM_SET_GEN,
@@ -583,7 +583,7 @@ void __init hyperv_init(void)
583583
hv_query_ext_cap(0);
584584

585585
/* Find the VTL */
586-
if (hv_isolation_type_en_snp())
586+
if (!ms_hyperv.paravisor_present && hv_isolation_type_snp())
587587
ms_hyperv.vtl = get_vtl();
588588

589589
return;

arch/x86/hyperv/ivm.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -637,24 +637,14 @@ bool hv_is_isolation_supported(void)
637637
DEFINE_STATIC_KEY_FALSE(isolation_type_snp);
638638

639639
/*
640-
* hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based
640+
* hv_isolation_type_snp - Check if the system runs in an AMD SEV-SNP based
641641
* isolation VM.
642642
*/
643643
bool hv_isolation_type_snp(void)
644644
{
645645
return static_branch_unlikely(&isolation_type_snp);
646646
}
647647

648-
DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp);
649-
/*
650-
* hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based
651-
* isolation enlightened VM.
652-
*/
653-
bool hv_isolation_type_en_snp(void)
654-
{
655-
return static_branch_unlikely(&isolation_type_en_snp);
656-
}
657-
658648
DEFINE_STATIC_KEY_FALSE(isolation_type_tdx);
659649
/*
660650
* hv_isolation_type_tdx - Check if the system runs in an Intel TDX based

arch/x86/include/asm/mshyperv.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
union hv_ghcb;
2727

2828
DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
29-
DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp);
3029
DECLARE_STATIC_KEY_FALSE(isolation_type_tdx);
3130

3231
typedef int (*hyperv_fill_flush_list_func)(
@@ -50,7 +49,7 @@ extern u64 hv_current_partition_id;
5049

5150
extern union hv_ghcb * __percpu *hv_ghcb_pg;
5251

53-
extern bool hv_isolation_type_en_snp(void);
52+
bool hv_isolation_type_snp(void);
5453
bool hv_isolation_type_tdx(void);
5554
u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2);
5655

@@ -79,7 +78,7 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
7978
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
8079
return hv_tdx_hypercall(control, input_address, output_address);
8180

82-
if (hv_isolation_type_en_snp()) {
81+
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
8382
__asm__ __volatile__("mov %4, %%r8\n"
8483
"vmmcall"
8584
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
@@ -135,7 +134,7 @@ static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)
135134
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
136135
return hv_tdx_hypercall(control, input1, 0);
137136

138-
if (hv_isolation_type_en_snp()) {
137+
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
139138
__asm__ __volatile__(
140139
"vmmcall"
141140
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
@@ -189,7 +188,7 @@ static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
189188
if (hv_isolation_type_tdx() && !hyperv_paravisor_present)
190189
return hv_tdx_hypercall(control, input1, input2);
191190

192-
if (hv_isolation_type_en_snp()) {
191+
if (hv_isolation_type_snp() && !hyperv_paravisor_present) {
193192
__asm__ __volatile__("mov %4, %%r8\n"
194193
"vmmcall"
195194
: "=a" (hv_status), ASM_CALL_CONSTRAINT,
@@ -284,8 +283,6 @@ static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {}
284283
static inline int hv_snp_boot_ap(int cpu, unsigned long start_ip) { return 0; }
285284
#endif
286285

287-
extern bool hv_isolation_type_snp(void);
288-
289286
#if defined(CONFIG_AMD_MEM_ENCRYPT) || defined(CONFIG_INTEL_TDX_GUEST)
290287
void hv_vtom_init(void);
291288
void hv_ivm_msr_write(u64 msr, u64 value);

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus)
304304
* Override wakeup_secondary_cpu_64 callback for SEV-SNP
305305
* enlightened guest.
306306
*/
307-
if (hv_isolation_type_en_snp()) {
307+
if (!ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
308308
apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap;
309309
return;
310310
}
@@ -440,10 +440,7 @@ static void __init ms_hyperv_init_platform(void)
440440

441441

442442
if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
443-
if (ms_hyperv.paravisor_present)
444-
static_branch_enable(&isolation_type_snp);
445-
else
446-
static_branch_enable(&isolation_type_en_snp);
443+
static_branch_enable(&isolation_type_snp);
447444
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_TDX) {
448445
static_branch_enable(&isolation_type_tdx);
449446

@@ -556,7 +553,8 @@ static void __init ms_hyperv_init_platform(void)
556553

557554
# ifdef CONFIG_SMP
558555
smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu;
559-
if (hv_root_partition || hv_isolation_type_en_snp())
556+
if (hv_root_partition ||
557+
(!ms_hyperv.paravisor_present && hv_isolation_type_snp()))
560558
smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus;
561559
# endif
562560

drivers/hv/hv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int hv_synic_alloc(void)
164164
}
165165

166166
if (!ms_hyperv.paravisor_present &&
167-
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
167+
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
168168
ret = set_memory_decrypted((unsigned long)
169169
hv_cpu->synic_message_page, 1);
170170
if (ret) {
@@ -225,7 +225,7 @@ void hv_synic_free(void)
225225
}
226226

227227
if (!ms_hyperv.paravisor_present &&
228-
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
228+
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
229229
if (hv_cpu->synic_message_page) {
230230
ret = set_memory_encrypted((unsigned long)
231231
hv_cpu->synic_message_page, 1);

drivers/hv/hv_common.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ int hv_common_cpu_init(unsigned int cpu)
383383
}
384384

385385
if (!ms_hyperv.paravisor_present &&
386-
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
386+
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
387387
ret = set_memory_decrypted((unsigned long)mem, pgcount);
388388
if (ret) {
389389
/* It may be unsafe to free 'mem' */
@@ -532,12 +532,6 @@ bool __weak hv_isolation_type_snp(void)
532532
}
533533
EXPORT_SYMBOL_GPL(hv_isolation_type_snp);
534534

535-
bool __weak hv_isolation_type_en_snp(void)
536-
{
537-
return false;
538-
}
539-
EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp);
540-
541535
bool __weak hv_isolation_type_tdx(void)
542536
{
543537
return false;

include/asm-generic/mshyperv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ extern void * __percpu *hyperv_pcpu_output_arg;
6464

6565
extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
6666
extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
67-
extern bool hv_isolation_type_snp(void);
68-
extern bool hv_isolation_type_en_snp(void);
67+
bool hv_isolation_type_snp(void);
6968
bool hv_isolation_type_tdx(void);
7069

7170
/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */

0 commit comments

Comments
 (0)