From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09C4B31B81C; Mon, 23 Feb 2026 16:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864286; cv=none; b=n0g7a6rr44XLcsliriCZaokw8eUfBNLZfMLTdZDD3BwNXBcbDmC15/lqTm/1eNhU7t8y1o/fF5/KjXV6dYNILfUiPYw4YfQ6e1MLKt+orYutB0WHrSgQQlqM4KehGu0iJz+TLqMKbUuNpP3hwTyy38skx5Rq49Bzz5hhMKoltLQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864286; c=relaxed/simple; bh=juj+8vO04jk/GoYa7dMPuG3nxfJTzUwEpk16BlfnOXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S3c8W9IMmch6RozVIzRrU3JFY5FLvYqcJEuZz+CV/Gsn9meA/ppUjnEDFhyXK4eik2hCRXs42oR8O2QeaBIgBgoQQNzD39yPECr3ij05EX6fQVimtzLHamdBeety5Ti1i7EE+5xrs3I4/pcqQaCxBT4waGUQRdiTJ8HSiCg5eGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uc0hknJa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uc0hknJa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 721A8C2BCB0; Mon, 23 Feb 2026 16:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771864285; bh=juj+8vO04jk/GoYa7dMPuG3nxfJTzUwEpk16BlfnOXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uc0hknJa/1TEhARErGWn/5YMJoqNsrFXQXWyshL8P1YFOeOh3NS/tlQeZQ6isR0Th FedOCce3Znexb52j2gXDaiqFB7wzLYJ4pRCNdg11JYHFoTkeXveNSB+k0dKyv3/gKC /fLs3R2ljsha1kChKQO9iTTr+1+uueH8k0DAgZkcmJSGZYfQJDQactbuT5zmhX2Q9k PZhT6k5yWcRGu+upK8iJIcM9oFncuG1W4eBXy8fWr+UGrxDpNCHgnCWjATLqwzOebl eE773GNC1491TZS0676tdS2lkmr5BY6VhmD7i78ZYk8ScQ16ROmmKNXZPrvehcBUiZ cRy2rnJhdVFbg== From: Tycho Andersen To: Ashish Kalra , Tom Lendacky , John Allen , Herbert Xu , Sean Christopherson , Paolo Bonzini , Shuah Khan , "David S. Miller" Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH 4/4] selftests/kvm: smoke test support for RAPL_DIS Date: Mon, 23 Feb 2026 09:29:00 -0700 Message-ID: <20260223162900.772669-5-tycho@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260223162900.772669-1-tycho@kernel.org> References: <20260223162900.772669-1-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Tycho Andersen (AMD)" 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) --- 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 fd11f4222ec2..e9a566ff6df1 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 c7fda9fc324b..e4cf5b99b19a 100644 --- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c @@ -248,6 +248,18 @@ static bool sev_es_allowed(void) return supported; } +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)); @@ -257,8 +269,18 @@ int main(int argc, char *argv[]) if (sev_es_allowed()) 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)) { + int 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("ccp", "rapl_disable")) { + uint32_t policy = snp_default_policy() | SNP_POLICY_RAPL_DIS; + + test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, policy); + } + } + return 0; } -- 2.53.0