From: Tycho Andersen <tycho@kernel.org>
To: Ashish Kalra <ashish.kalra@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
John Allen <john.allen@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Shuah Khan <shuah@kernel.org>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
Kim Phillips <kim.phillips@amd.com>,
Alexey Kardashevskiy <aik@amd.com>,
"Tycho Andersen (AMD)" <tycho@kernel.org>,
Nikunj A Dadhania <nikunj@amd.com>,
Andrew Morton <akpm@linux-foundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Dapeng Mi <dapeng1.mi@linux.intel.com>,
Kees Cook <kees@kernel.org>, Marco Elver <elver@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Li RongQing <lirongqing@baidu.com>,
Eric Biggers <ebiggers@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
linux-doc@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH v2 4/4] KVM: selftests: Add a smoke test support for RAPL_DIS
Date: Mon, 27 Apr 2026 14:48:47 -0600 [thread overview]
Message-ID: <20260427204847.112899-5-tycho@kernel.org> (raw)
In-Reply-To: <20260427204847.112899-1-tycho@kernel.org>
From: "Tycho Andersen (AMD)" <tycho@kernel.org>
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) <tycho@kernel.org>
---
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
prev parent reply other threads:[~2026-04-27 20:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 20:48 [PATCH v2 0/4] Allow disabling RAPL during SNP initialization Tycho Andersen
2026-04-27 20:48 ` [PATCH v2 1/4] crypto/ccp: Pass init_args to __sev_snp_init_locked() Tycho Andersen
2026-04-27 20:48 ` [PATCH v2 2/4] crypto/ccp: Support setting RAPL_DIS in SNP_INIT_EX Tycho Andersen
2026-04-27 20:48 ` [PATCH v2 3/4] KVM: SEV: Add the kvm-amd.rapl_disable module parameter Tycho Andersen
2026-04-27 21:20 ` Sean Christopherson
2026-04-27 20:48 ` Tycho Andersen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260427204847.112899-5-tycho@kernel.org \
--to=tycho@kernel.org \
--cc=aik@amd.com \
--cc=akpm@linux-foundation.org \
--cc=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=elver@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=hpa@zytor.com \
--cc=john.allen@amd.com \
--cc=kees@kernel.org \
--cc=kim.phillips@amd.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rdunlap@infradead.org \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox