KVM: SEV: Add GHCB handling for Hypervisor Feature Support requests
authorBrijesh Singh <brijesh.singh@amd.com>
Wed, 1 May 2024 07:10:46 +0000 (02:10 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 May 2024 17:28:04 +0000 (13:28 -0400)
Version 2 of the GHCB specification introduced advertisement of features
that are supported by the Hypervisor.

Now that KVM supports version 2 of the GHCB specification, bump the
maximum supported protocol version.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Message-ID: <20240501071048.2208265-3-michael.roth@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/sev-common.h
arch/x86/kvm/svm/sev.c

index 01261f7054ad7b1d35afa4e919c67c6ac5471037..5a8246dd532f8dc8c5969cdf0cb7d30909799fce 100644 (file)
@@ -101,6 +101,8 @@ enum psc_op {
 /* GHCB Hypervisor Feature Request/Response */
 #define GHCB_MSR_HV_FT_REQ             0x080
 #define GHCB_MSR_HV_FT_RESP            0x081
+#define GHCB_MSR_HV_FT_POS             12
+#define GHCB_MSR_HV_FT_MASK            GENMASK_ULL(51, 0)
 #define GHCB_MSR_HV_FT_RESP_VAL(v)                     \
        /* GHCBData[63:12] */                           \
        (((u64)(v) & GENMASK_ULL(63, 12)) >> 12)
index 6e31cb408dd8790de813f4b69acb6f7c4a8d2b8f..37d396636b717d9351dfb10970510d8c328ae972 100644 (file)
@@ -36,6 +36,8 @@
 #define GHCB_VERSION_MAX       1ULL
 #define GHCB_VERSION_MIN       1ULL
 
+#define GHCB_HV_FT_SUPPORTED   GHCB_HV_FT_SNP
+
 /* enable/disable SEV support */
 static bool sev_enabled = true;
 module_param_named(sev, sev_enabled, bool, 0444);
@@ -2701,6 +2703,7 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
        case SVM_VMGEXIT_AP_HLT_LOOP:
        case SVM_VMGEXIT_AP_JUMP_TABLE:
        case SVM_VMGEXIT_UNSUPPORTED_EVENT:
+       case SVM_VMGEXIT_HV_FEATURES:
                break;
        default:
                reason = GHCB_ERR_INVALID_EVENT;
@@ -2961,6 +2964,12 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
                                  GHCB_MSR_INFO_MASK,
                                  GHCB_MSR_INFO_POS);
                break;
+       case GHCB_MSR_HV_FT_REQ:
+               set_ghcb_msr_bits(svm, GHCB_HV_FT_SUPPORTED,
+                                 GHCB_MSR_HV_FT_MASK, GHCB_MSR_HV_FT_POS);
+               set_ghcb_msr_bits(svm, GHCB_MSR_HV_FT_RESP,
+                                 GHCB_MSR_INFO_MASK, GHCB_MSR_INFO_POS);
+               break;
        case GHCB_MSR_TERM_REQ: {
                u64 reason_set, reason_code;
 
@@ -3085,6 +3094,11 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
                ret = 1;
                break;
        }
+       case SVM_VMGEXIT_HV_FEATURES:
+               ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_HV_FT_SUPPORTED);
+
+               ret = 1;
+               break;
        case SVM_VMGEXIT_UNSUPPORTED_EVENT:
                vcpu_unimpl(vcpu,
                            "vmgexit: unsupported event - exit_info_1=%#llx, exit_info_2=%#llx\n",