With hardware-assisted PMC filtering, a write that enables an event missing from the hypervisor's allow list raises a #VC in an SEV-ES or SNP guest. The hypervisor can't read the guest's event-selects from the encrypted VMSA, so it can't vet the write on its own. Add a NAE event for the guest to forward the write: RCX holds the MSR, EDX:EAX the value, and the scratch buffer every event-select. The hypervisor returns the value to program in EDX:EAX, and the value of each event-select in the buffer. Signed-off-by: Manali Shukla --- arch/x86/include/asm/sev-common.h | 12 ++++++++++++ arch/x86/include/uapi/asm/svm.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index 01a6e4dbe4235..bab705f6ddfd7 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -176,6 +176,18 @@ struct snp_psc_desc { struct psc_entry entries[VMGEXIT_PSC_MAX_ENTRY]; } __packed; +/* SVM_VMGEXIT_PMC_FILTER buffer, one entry per event-select. */ +struct perf_ctl_entry { + u64 perf_ctl_idx; + u64 perf_ctl_val; +} __packed; + +struct perf_ctls { + u8 num_counters; + u8 reserved[7]; + struct perf_ctl_entry counters[]; +} __packed; + #define GHCB_MSR_TERM_REQ 0x100 #define GHCB_MSR_TERM_REASON_SET_POS 12 #define GHCB_MSR_TERM_REASON_SET_MASK 0xf diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index 010a45c9f6147..fb917d0384fb5 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -122,6 +122,7 @@ #define SVM_VMGEXIT_SAVIC_REGISTER_GPA 0 #define SVM_VMGEXIT_SAVIC_UNREGISTER_GPA 1 #define SVM_VMGEXIT_SAVIC_SELF_GPA ~0ULL +#define SVM_VMGEXIT_PMC_FILTER 0x8000001eull #define SVM_VMGEXIT_HV_FEATURES 0x8000fffdull #define SVM_VMGEXIT_TERM_REQUEST 0x8000fffeull #define SVM_VMGEXIT_TERM_REASON(reason_set, reason_code) \ @@ -245,6 +246,7 @@ { SVM_VMGEXIT_GUEST_REQUEST, "vmgexit_guest_request" }, \ { SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, \ { SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \ + { SVM_VMGEXIT_PMC_FILTER, "vmgexit_pmc_filter" }, \ { SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \ { SVM_EXIT_ERR, "invalid_guest_state" } -- 2.43.0