Skip to content

Commit

Permalink
x86/hyperv: Remove hv_isolation_type_en_snp
Browse files Browse the repository at this point in the history
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
!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 !hyperv_paravisor_present is true there.

Signed-off-by: Dexuan Cui <decui@microsoft.com>
  • Loading branch information
dcui committed Aug 12, 2023
1 parent 81e938e commit 323de39
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 33 deletions.
8 changes: 4 additions & 4 deletions arch/x86/hyperv/hv_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static int hyperv_init_ghcb(void)
void *ghcb_va;
void **ghcb_base;

if (!hv_isolation_type_snp())
if (!hyperv_paravisor_present || !hv_isolation_type_snp())
return 0;

if (!hv_ghcb_pg)
Expand Down Expand Up @@ -117,7 +117,7 @@ static int hv_cpu_init(unsigned int cpu)
* is blocked to run in Confidential VM. So only decrypt assist
* page in non-root partition here.
*/
if (*hvp && hv_isolation_type_en_snp()) {
if (*hvp && !hyperv_paravisor_present && hv_isolation_type_snp()) {
WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1));
memset(*hvp, 0, PAGE_SIZE);
}
Expand Down Expand Up @@ -465,7 +465,7 @@ void __init hyperv_init(void)
goto common_free;
}

if (hv_isolation_type_snp()) {
if (hyperv_paravisor_present && hv_isolation_type_snp()) {
/* Negotiate GHCB Version. */
if (!hv_ghcb_negotiate_protocol())
hv_ghcb_terminate(SEV_TERM_SET_GEN,
Expand Down Expand Up @@ -588,7 +588,7 @@ void __init hyperv_init(void)
hv_query_ext_cap(0);

/* Find the VTL */
if (hv_isolation_type_en_snp())
if (!hyperv_paravisor_present && hv_isolation_type_snp())
ms_hyperv.vtl = get_vtl();

return;
Expand Down
12 changes: 1 addition & 11 deletions arch/x86/hyperv/ivm.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,24 +624,14 @@ bool hv_is_isolation_supported(void)
DEFINE_STATIC_KEY_FALSE(isolation_type_snp);

/*
* hv_isolation_type_snp - Check system runs in the AMD SEV-SNP based
* hv_isolation_type_snp - Check if the system runs in an AMD SEV-SNP based
* isolation VM.
*/
bool hv_isolation_type_snp(void)
{
return static_branch_unlikely(&isolation_type_snp);
}

DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp);
/*
* hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based
* isolation enlightened VM.
*/
bool hv_isolation_type_en_snp(void)
{
return static_branch_unlikely(&isolation_type_en_snp);
}

DEFINE_STATIC_KEY_FALSE(isolation_type_tdx);
/*
* hv_isolation_type_tdx - Check if the system runs in an Intel TDX based
Expand Down
4 changes: 1 addition & 3 deletions arch/x86/include/asm/mshyperv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
union hv_ghcb;

DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp);
DECLARE_STATIC_KEY_FALSE(isolation_type_tdx);

typedef int (*hyperv_fill_flush_list_func)(
Expand Down Expand Up @@ -269,8 +268,7 @@ static inline void hv_vtom_init(void) {}
static int hv_snp_boot_ap(int cpu, unsigned long start_ip) { return 0; }
#endif

extern bool hv_isolation_type_snp(void);
extern bool hv_isolation_type_en_snp(void);
bool hv_isolation_type_snp(void);

static inline bool hv_is_synic_reg(unsigned int reg)
{
Expand Down
6 changes: 2 additions & 4 deletions arch/x86/kernel/cpu/mshyperv.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus)
* Override wakeup_secondary_cpu_64 callback for SEV-SNP
* enlightened guest.
*/
if (hv_isolation_type_en_snp())
if (!hyperv_paravisor_present && hv_isolation_type_snp())
apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap;

if (!hv_root_partition)
Expand Down Expand Up @@ -442,9 +442,7 @@ static void __init ms_hyperv_init_platform(void)
ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b);


if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
static_branch_enable(&isolation_type_en_snp);
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) {
static_branch_enable(&isolation_type_snp);
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_TDX) {
static_branch_enable(&isolation_type_tdx);
Expand Down
4 changes: 2 additions & 2 deletions drivers/hv/hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int hv_synic_alloc(void)
}

if (!hyperv_paravisor_present &&
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
ret = set_memory_decrypted((unsigned long)
hv_cpu->synic_message_page, 1);
if (ret) {
Expand Down Expand Up @@ -227,7 +227,7 @@ void hv_synic_free(void)
}

if (!hyperv_paravisor_present &&
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
if (hv_cpu->synic_message_page) {
ret = set_memory_encrypted((unsigned long)
hv_cpu->synic_message_page, 1);
Expand Down
8 changes: 1 addition & 7 deletions drivers/hv/hv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ int hv_common_cpu_init(unsigned int cpu)
}

if (!hyperv_paravisor_present &&
(hv_isolation_type_en_snp() || hv_isolation_type_tdx())) {
(hv_isolation_type_snp() || hv_isolation_type_tdx())) {
ret = set_memory_decrypted((unsigned long)mem, pgcount);
if (ret) {
/* It may be unsafe to free 'mem' */
Expand Down Expand Up @@ -535,12 +535,6 @@ bool __weak hv_isolation_type_snp(void)
}
EXPORT_SYMBOL_GPL(hv_isolation_type_snp);

bool __weak hv_isolation_type_en_snp(void)
{
return false;
}
EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp);

bool __weak hv_isolation_type_tdx(void)
{
return false;
Expand Down
3 changes: 1 addition & 2 deletions include/asm-generic/mshyperv.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ extern void * __percpu *hyperv_pcpu_output_arg;

extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
extern bool hv_isolation_type_snp(void);
extern bool hv_isolation_type_en_snp(void);
bool hv_isolation_type_snp(void);
bool hv_isolation_type_tdx(void);

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

0 comments on commit 323de39

Please sign in to comment.