From: "Tycho Andersen (AMD)" <[email protected]>

If the hardware supports the RAPL_DIS policy bit and the ccp has been
loaded with the RAPL_DIS bit set, make sure a VM can
actually start using it.

Signed-off-by: Tycho Andersen (AMD) <[email protected]>
---
 tools/testing/selftests/kvm/include/x86/sev.h |  1 +
 .../selftests/kvm/x86/sev_smoke_test.c        | 24 ++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/include/x86/sev.h 
b/tools/testing/selftests/kvm/include/x86/sev.h
index 1af44c151d60..2bbac9cd192a 100644
--- a/tools/testing/selftests/kvm/include/x86/sev.h
+++ b/tools/testing/selftests/kvm/include/x86/sev.h
@@ -28,6 +28,7 @@ enum sev_guest_state {
 #define SNP_POLICY_SMT         (1ULL << 16)
 #define SNP_POLICY_RSVD_MBO    (1ULL << 17)
 #define SNP_POLICY_DBG         (1ULL << 19)
+#define SNP_POLICY_RAPL_DIS    (1ULL << 23)
 
 #define GHCB_MSR_TERM_REQ      0x100
 
diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c 
b/tools/testing/selftests/kvm/x86/sev_smoke_test.c
index 1a49ee391586..15c848749de6 100644
--- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c
+++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c
@@ -243,6 +243,18 @@ static void test_sev_smoke(void *guest, u32 type, u64 
policy)
        }
 }
 
+static u64 supported_policy_mask(void)
+{
+       int kvm_fd = open_kvm_dev_path_or_exit();
+       u64 policy_mask = 0;
+
+       kvm_device_attr_get(kvm_fd, KVM_X86_GRP_SEV,
+                           KVM_X86_SNP_POLICY_BITS,
+                           &policy_mask);
+       close(kvm_fd);
+       return policy_mask;
+}
+
 int main(int argc, char *argv[])
 {
        TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV));
@@ -252,8 +264,18 @@ int main(int argc, char *argv[])
        if (kvm_cpu_has(X86_FEATURE_SEV_ES))
                test_sev_smoke(guest_sev_es_code, KVM_X86_SEV_ES_VM, 
SEV_POLICY_ES);
 
-       if (kvm_cpu_has(X86_FEATURE_SEV_SNP))
+       if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) {
+               u64 supported_policy = supported_policy_mask();
+
                test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, 
snp_default_policy());
 
+               if (supported_policy & SNP_POLICY_RAPL_DIS &&
+                   kvm_get_module_param_bool("kvm_amd", "rapl_disable")) {
+                       u64 policy = snp_default_policy() | SNP_POLICY_RAPL_DIS;
+
+                       test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, policy);
+               }
+       }
+
        return 0;
 }
-- 
2.53.0


Reply via email to