From nobody Sun Apr 5 18:17:28 2026 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 79D923161A1; Mon, 23 Feb 2026 16:31:21 +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=1771864281; cv=none; b=rxLy011U7zPikDZShIPuIDf52mw/nCtI2CY7evthYqbt1MpbVEwepwxRpdSphnWF6OiyswqosliWCxamyROPXTK5CQFHz1AJp1N1dZsdgr7IfdC2d5DLy/yHVpzZVWqI6QbpaYoubcTgZwtpphyHIffhY2J/NLg1a7oP4zZroJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864281; c=relaxed/simple; bh=iSojNmc5jEvKxXWTFvXiIJ5x0/SbjJU1adUGx+WYgvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O8/HUQPK2Ia7R8Kb6SUaJf2gmESnT+0MdwZ9tB5jRaquSr1ZoUXGUYqFeBkDhQSTbNxTj7mwPBrlC6eH+B2VS1o/YTFp+Qn/jXwCZGhzcfKhSjuvUF7J8pzGuDMnhVcDnqMTBLuXX0joU8KxzFOhZup4t5mWJ04BHKUIhcX+/UE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eXKZ9pkn; 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="eXKZ9pkn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4A11C19423; Mon, 23 Feb 2026 16:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771864281; bh=iSojNmc5jEvKxXWTFvXiIJ5x0/SbjJU1adUGx+WYgvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eXKZ9pknkND5W6PK+VuZ7+C6Gp81gaDe4qQzufdeE4yApsTYtYT60SCS21fp3DjH8 Cqg2wzEgLkr9hFHkVnd00xCYr3iEkRW3fsdptt3y/RnP5L3Ov31tb7a9ARUjv3kDV4 JSk3blo9T2dvPsK68C1wEAVgtJdpxV+hpWLbCJNbUT5RRa2gFskX8E0Kcb/FmCqzz4 ZRGuiiOJpRhSHoNxlFFX5NlwmuBlRJE0pKKEHV+8/e8k0uSVb3sHVT3DeTLJVYbhOS sypCD/KlVbouhi0/xrqWA4CemAVXtYlCSplIlCJnkxgbihmGwp66mHujFOmdRJxu5i HeDHY2NbHgfZQ== 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 1/4] selftests/kvm: allow retrieving underlying SEV firmware error Date: Mon, 23 Feb 2026 09:28:57 -0700 Message-ID: <20260223162900.772669-2-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" In addition to the errno, sometimes it is useful to know the underlying SEV firmware error. Update the raw vm ioctl macro to allow for optionally retrieving this. Signed-off-by: Tycho Andersen (AMD) --- tools/testing/selftests/kvm/include/x86/sev.h | 6 ++++-- tools/testing/selftests/kvm/x86/sev_migrate_tests.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86/sev.h b/tools/testing/= selftests/kvm/include/x86/sev.h index 008b4169f5e2..fd11f4222ec2 100644 --- a/tools/testing/selftests/kvm/include/x86/sev.h +++ b/tools/testing/selftests/kvm/include/x86/sev.h @@ -76,7 +76,7 @@ static inline u64 snp_default_policy(void) * creating an overlay to pass in an "unsigned long" without a cast (casti= ng * will make the compiler unhappy due to dereferencing an aliased pointer). */ -#define __vm_sev_ioctl(vm, cmd, arg) \ +#define __vm_sev_ioctl(vm, cmd, arg, errorp) \ ({ \ int r; \ \ @@ -90,12 +90,14 @@ static inline u64 snp_default_policy(void) } }; \ \ r =3D __vm_ioctl(vm, KVM_MEMORY_ENCRYPT_OP, &sev_cmd.raw); \ + if (errorp !=3D NULL) \ + *((__u32 *)errorp) =3D sev_cmd.c.error; \ r ?: sev_cmd.c.error; \ }) =20 #define vm_sev_ioctl(vm, cmd, arg) \ ({ \ - int ret =3D __vm_sev_ioctl(vm, cmd, arg); \ + int ret =3D __vm_sev_ioctl(vm, cmd, arg, NULL); \ \ __TEST_ASSERT_VM_VCPU_IOCTL(!ret, #cmd, ret, vm); \ }) diff --git a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c b/tools/te= sting/selftests/kvm/x86/sev_migrate_tests.c index 0a6dfba3905b..18f3091e0bd8 100644 --- a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c +++ b/tools/testing/selftests/kvm/x86/sev_migrate_tests.c @@ -232,7 +232,7 @@ static void verify_mirror_allowed_cmds(struct kvm_vm *v= m) * These commands should be disallowed before the data * parameter is examined so NULL is OK here. */ - ret =3D __vm_sev_ioctl(vm, cmd_id, NULL); + ret =3D __vm_sev_ioctl(vm, cmd_id, NULL, NULL); TEST_ASSERT( ret =3D=3D -1 && errno =3D=3D EINVAL, "Should not be able call command: %d. ret: %d, errno: %d", --=20 2.53.0 From nobody Sun Apr 5 18:17:28 2026 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 E799D318EE4; Mon, 23 Feb 2026 16:31:22 +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=1771864283; cv=none; b=dZLSfD0EDgcOUsgfx1lUeXOV1PExVgKY80qJCC7zIwiPCuOr6pDP/yLzWYUDzOXoUROPk0SSae19RGhuJmWKcLfoM+XdXQvSncqoEVHnokXE5hsEURD+j7vPMRnesIDyXOmLc4QzKpXWDDBX06Vy4mqYioPD98L1wB//xJGpjeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864283; c=relaxed/simple; bh=j1r3jSLPXenJHWtPXhz5B7SgywI7mhO4sMwe7uArPqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u4qn6yFgwdDKf9JegTefXylKobqtuNC/MVpf6UY0MdpnhxJbbJFCcfaRL8Q9avDlG7lcDoRdcx9aeRtfzezfO/kWuLg9r5o103qKP6/bLTmVW+ecTyPz8HTz3Pn6rEu5ebqtEpK5MIhsqf2sUo8noX4YaUjCXJ8+bJV8NPKGWUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=otBREyNn; 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="otBREyNn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 586E3C116C6; Mon, 23 Feb 2026 16:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771864282; bh=j1r3jSLPXenJHWtPXhz5B7SgywI7mhO4sMwe7uArPqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otBREyNnNk8AW78n036fGfwS99ZdT9JlzE5JAsSaMyKPog0DePiD6RiRSFHPoV/pk YJKt9fsRWqzJZMDXCj3ughu8qlPw9TFsw61ZxyxF0CO5b1LDQTNiR8VcwS2M3FSl8L zbPbauzaTHhOG1mJRfI0mW1eXZbHHcuo+MYccSqbKMplakC1Ehmk/lawsRyL+dLSAX kK2dNGjKQhuMNDT8B0h0C3n76yIDegAIKG9gDcKXW78TQiGrIz+NhkzamqDnjkVz1K 0hesc+vGPtelDsV+UTFmAW/ymbBHMXNuoSUlOoEWkB6t2H+VXX/HbIa/VIL6HwRlln NXgjBCsvKstHw== 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 2/4] selftests/kvm: check that SEV-ES VMs are allowed in SEV-SNP mode Date: Mon, 23 Feb 2026 09:28:58 -0700 Message-ID: <20260223162900.772669-3-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" As in the comment, check to make sure that SEV-ES VMs are allowed before running the test. Otherwise, there is a generic: =3D=3D=3D=3D Test Assertion Failure =3D=3D=3D=3D lib/x86/sev.c:91: !ret pid=3D3678 tid=3D3678 errno=3D5 - Input/output error 1 0x0000000000417000: sev_vm_launch at sev.c:91 (discriminator 4) 2 0x0000000000417d49: vm_sev_launch at sev.c:191 3 0x0000000000402a7d: test_sev at sev_smoke_test.c:132 4 0x000000000040328f: test_sev_smoke at sev_smoke_test.c:198 5 0x00000000004026c8: main at sev_smoke_test.c:223 6 0x00007fdde5c2a1c9: ?? ??:0 7 0x00007fdde5c2a28a: ?? ??:0 8 0x00000000004027f4: _start at ??:? KVM_SEV_LAUNCH_START failed, rc: -1 errno: 5 (Input/output error) Signed-off-by: Tycho Andersen (AMD) --- .../selftests/kvm/x86/sev_smoke_test.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c b/tools/testi= ng/selftests/kvm/x86/sev_smoke_test.c index 86ad1c7d068f..c7fda9fc324b 100644 --- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c @@ -213,13 +213,48 @@ static void test_sev_smoke(void *guest, uint32_t type= , uint64_t policy) } } =20 +static bool sev_es_allowed(void) +{ + struct kvm_sev_launch_start launch_start =3D { + .policy =3D SEV_POLICY_ES, + }; + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + int firmware_error, ret; + bool supported =3D true; + + if (!kvm_cpu_has(X86_FEATURE_SEV_ES)) + return false; + + if (!kvm_cpu_has(X86_FEATURE_SEV_SNP)) + return true; + + /* + * In some cases when SEV-SNP is enabled, firmware disallows starting + * an SEV-ES VM. When SEV-SNP is enabled try to launch an SEV-ES, and + * check the underlying firmware error for this case. + */ + vm =3D vm_sev_create_with_one_vcpu(KVM_X86_SEV_ES_VM, guest_sev_es_code, + &vcpu); + + ret =3D __vm_sev_ioctl(vm, KVM_SEV_LAUNCH_START, &launch_start, + &firmware_error); + if (ret =3D=3D -1 && firmware_error =3D=3D SEV_RET_UNSUPPORTED) { + pr_info("SEV-ES not supported with SNP\n"); + supported =3D false; + } + + kvm_vm_free(vm); + return supported; +} + int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); =20 test_sev_smoke(guest_sev_code, KVM_X86_SEV_VM, 0); =20 - if (kvm_cpu_has(X86_FEATURE_SEV_ES)) + if (sev_es_allowed()) test_sev_smoke(guest_sev_es_code, KVM_X86_SEV_ES_VM, SEV_POLICY_ES); =20 if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) --=20 2.53.0 From nobody Sun Apr 5 18:17:28 2026 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 49EC23161A1; Mon, 23 Feb 2026 16:31:24 +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=1771864284; cv=none; b=VatSqgZfUmeaJJgpqNBdWODaCWA5TcbOYfrxXqqGV7dKDQZZaEXbv1vB/cF/gtJmk7Nb8zGMX7IRXanQmB54kcmYZraFo6KSSMljaa1pAlgdIwfNbB9McxbD61vGoaSTq9PwnOuFJ+f5Cx9A65rmgUb+cgr9WP0//RIqmmywjfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864284; c=relaxed/simple; bh=z0+k2/vsL3nwF+DeqeI8DQy/GT6X1KPt1rxrFs1rkXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pTq33sn84SviThgTw3AweaLIkt3utFpt9yaSaxzp2daIeWiNUOZkzNDVr8MITwyvb088fpf/NLd2OiYaBTEcGtIQ07ahy9/mtTqEFZiUunEgLNtYsc+6fPyQSjND13cUbpfJGQRv2BPOW9wMEYfUu0rnvLI1lCGWS5QYdvyn+CM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RjlhTPfr; 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="RjlhTPfr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DECB6C2BCAF; Mon, 23 Feb 2026 16:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771864284; bh=z0+k2/vsL3nwF+DeqeI8DQy/GT6X1KPt1rxrFs1rkXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RjlhTPfrVN5DVJWrNv5hq1GjuhRYaxOeL4pgKhzQF5uQJQ6HbJKQwd2tygXyj5sCe 8oG7puqb15MJ/F99OPVxRywJ+LzvOZ4xkRUMzMjkfDMKpNhqUdpKhnNom+5Hmp6aOq Ri83bj7rD9rwKxYUirpItvQIoTUB8I8d5DM63kE5gSr9sjkFLW8VUu69Ps6g5oXnqI N7TAzQkAAWlPh6NQ7l2ytCwjBlsyLg5cEQaKgkqOk6Is29jSiZvfUJlaTbIczWbWEP 3eLLDCD5WgeHj34oR7iLUl/L9BQaYstG1BGmFQb08MrmQi4Cd6Qan7kqib4MlBRqlc ipLwxzhmZrL2A== 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 3/4] crypto/ccp: support setting RAPL_DIS in SNP_INIT_EX Date: Mon, 23 Feb 2026 09:28:59 -0700 Message-ID: <20260223162900.772669-4-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Tycho Andersen (AMD)" The kernel allows setting the RAPL_DIS policy bit, but had no way to set the RAPL_DIS bit during SNP_INIT_EX. Setting the policy bit would always result in: [ 898.840286] ccp 0000:a9:00.5: sev command 0xa0 failed (0x00000007) Allow setting the RAPL_DIS bit during SNP_INIT_EX via a module parameter. If the hardware does not support RAPL_DIS, log and disable the module parameter. Signed-off-by: Tycho Andersen (AMD) --- drivers/crypto/ccp/sev-dev.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 096f993974d1..362126453ef0 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -75,6 +75,10 @@ static bool psp_init_on_probe =3D true; module_param(psp_init_on_probe, bool, 0444); MODULE_PARM_DESC(psp_init_on_probe, " if true, the PSP will be initialize= d on module init. Else the PSP will be initialized on the first command req= uiring it"); =20 +static bool rapl_disable; +module_param(rapl_disable, bool, 0444); +MODULE_PARM_DESC(rapl_disable, " if true, the RAPL_DIS bit will be set du= ring INIT_EX if supported"); + #if IS_ENABLED(CONFIG_PCI_TSM) static bool sev_tio_enabled =3D true; module_param_named(tio, sev_tio_enabled, bool, 0444); @@ -1428,6 +1432,16 @@ static int __sev_snp_init_locked(int *error, unsigne= d int max_snp_asid) data.max_snp_asid =3D max_snp_asid; } =20 + if (rapl_disable) { + if (sev->snp_feat_info_0.ecx & SNP_RAPL_DISABLE_SUPPORTED) { + data.rapl_dis =3D 1; + } else { + dev_info(sev->dev, + "SEV: RAPL_DIS requested, but not supported"); + rapl_disable =3D false; + } + } + data.init_rmp =3D 1; data.list_paddr_en =3D 1; data.list_paddr =3D __psp_pa(snp_range_list); --=20 2.53.0 From nobody Sun Apr 5 18:17:28 2026 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =20 #define GHCB_MSR_TERM_REQ 0x100 =20 diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c b/tools/testi= ng/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; } =20 +static u64 supported_policy_mask(void) +{ + int kvm_fd =3D open_kvm_dev_path_or_exit(); + u64 policy_mask =3D 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); =20 - if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) + if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) { + int supported_policy =3D supported_policy_mask(); + test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, snp_default_policy()); =20 + if (supported_policy & SNP_POLICY_RAPL_DIS && + kvm_get_module_param_bool("ccp", "rapl_disable")) { + uint32_t policy =3D snp_default_policy() | SNP_POLICY_RAPL_DIS; + + test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, policy); + } + } + return 0; } --=20 2.53.0