Skip to content

Commit f6e87dc

Browse files
committed
rmp adjust the savic page
1 parent f98689e commit f6e87dc

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

arch/x86/include/asm/sev.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ struct rmp_state {
109109
u32 asid;
110110
} __packed;
111111

112-
#define RMPADJUST_VMSA_PAGE_BIT BIT(16)
112+
/* Target VMPL takes the first byte */
113+
#define RMPADJUST_ENABLE_READ BIT(8)
114+
#define RMPADJUST_ENABLE_WRITE BIT(9)
115+
#define RMPADJUST_USER_EXECUTE BIT(10)
116+
#define RMPADJUST_KERNEL_EXECUTE BIT(11)
117+
#define RMPADJUST_VMSA_PAGE_BIT BIT(16)
113118

114119
/* SNP Guest message request */
115120
struct snp_req_data {

drivers/hv/mshv_vtl_main.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,24 @@ static int mshv_vtl_alloc_context(unsigned int cpu)
653653
#endif
654654
} else if (hv_isolation_type_snp()) {
655655
#if defined(CONFIG_X86_64) && defined(CONFIG_SEV_GUEST)
656-
int ret;
657-
658-
struct page *secure_avic_page;
659-
660-
secure_avic_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
661-
if (!secure_avic_page)
662-
return -ENOMEM;
663-
per_cpu->secure_avic_page = secure_avic_page;
656+
if (cc_platform_has(CC_ATTR_SNP_SECURE_AVIC)) {
657+
struct page *secure_avic_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
658+
int ret = 0;
659+
660+
if (!secure_avic_page)
661+
return -ENOMEM;
662+
663+
/* VMPL 2 for the VTL0 */
664+
ret = rmpadjust((unsigned long)page_address(secure_avic_page),
665+
RMP_PG_SIZE_4K, 2 | RMPADJUST_ENABLE_READ | RMPADJUST_ENABLE_WRITE);
666+
if (ret) {
667+
pr_err("failed to adjust RMP for the secure AVIC page: %d\n", ret);
668+
free_page((u64)secure_avic_page);
669+
return -EINVAL;
670+
}
664671

665-
ret = mshv_configure_vmsa_page(0, &per_cpu->vmsa_page);
666-
if (ret < 0)
667-
return ret;
672+
per_cpu->secure_avic_page = secure_avic_page;
673+
}
668674
#endif
669675
} else if (mshv_vsm_capabilities.intercept_page_available)
670676
mshv_vtl_configure_reg_page(per_cpu);

0 commit comments

Comments
 (0)