From: "Pratik R. Sampat" <pratikrajesh.sampat@amd.com>
To: <kvm@vger.kernel.org>
Cc: <shuah@kernel.org>, <thomas.lendacky@amd.com>,
<michael.roth@amd.com>, <seanjc@google.com>,
<pbonzini@redhat.com>, <pgonda@google.com>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [RFC 4/5] selftests: KVM: SNP IOCTL test
Date: Wed, 10 Jul 2024 17:05:39 -0500 [thread overview]
Message-ID: <20240710220540.188239-5-pratikrajesh.sampat@amd.com> (raw)
In-Reply-To: <20240710220540.188239-1-pratikrajesh.sampat@amd.com>
Introduce testing of SNP ioctl calls. This patch includes both positive
and negative tests of various parameters such as flags, page types and
policies.
Signed-off-by: Pratik R. Sampat <pratikrajesh.sampat@amd.com>
---
.../selftests/kvm/x86_64/sev_smoke_test.c | 119 +++++++++++++++++-
1 file changed, 118 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
index 500c67b3793b..1d5c275c11b3 100644
--- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
+++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
@@ -186,13 +186,130 @@ static void test_sev_launch(void *guest_code, uint32_t type, uint64_t policy)
kvm_vm_free(vm);
}
+static int spawn_snp_launch_start(uint32_t type, uint64_t policy, uint8_t flags)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ int ret;
+
+ vm = vm_sev_create_with_one_vcpu(type, NULL, &vcpu);
+ ret = snp_vm_launch(vm, policy, flags);
+ kvm_vm_free(vm);
+
+ return ret;
+}
+
+static void test_snp_launch_start(uint32_t type, uint64_t policy)
+{
+ uint8_t i;
+ int ret;
+
+ ret = spawn_snp_launch_start(type, policy, 0);
+ TEST_ASSERT(!ret,
+ "KVM_SEV_SNP_LAUNCH_START should not fail, invalid flag.");
+
+ for (i = 1; i < 8; i++) {
+ ret = spawn_snp_launch_start(type, policy, BIT(i));
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_START should fail, invalid flag.");
+ }
+
+ ret = spawn_snp_launch_start(type, 0, 0);
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_START should fail, invalid policy.");
+
+ ret = spawn_snp_launch_start(type, SNP_POLICY_SMT, 0);
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_START should fail, invalid policy.");
+
+ ret = spawn_snp_launch_start(type, SNP_POLICY_RSVD_MBO, 0);
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_START should fail, invalid policy.");
+
+ ret = spawn_snp_launch_start(type, SNP_POLICY_SMT | SNP_POLICY_RSVD_MBO |
+ (255 * SNP_POLICY_ABI_MAJOR) |
+ (255 * SNP_POLICY_ABI_MINOR), 0);
+ TEST_ASSERT(ret && errno == EIO,
+ "KVM_SEV_SNP_LAUNCH_START should fail, invalid version.");
+}
+
+static void test_snp_launch_update(uint32_t type, uint64_t policy)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ int ret;
+
+ for (int pgtype = 0; pgtype <= KVM_SEV_SNP_PAGE_TYPE_CPUID; pgtype++) {
+ vm = vm_sev_create_with_one_vcpu(type, NULL, &vcpu);
+ snp_vm_launch(vm, policy, 0);
+ ret = snp_vm_launch_update(vm, pgtype);
+
+ switch (pgtype) {
+ case KVM_SEV_SNP_PAGE_TYPE_NORMAL:
+ case KVM_SEV_SNP_PAGE_TYPE_ZERO:
+ case KVM_SEV_SNP_PAGE_TYPE_UNMEASURED:
+ case KVM_SEV_SNP_PAGE_TYPE_SECRETS:
+ TEST_ASSERT(!ret,
+ "KVM_SEV_SNP_LAUNCH_UPDATE should not fail, invalid Page type.");
+ break;
+ case KVM_SEV_SNP_PAGE_TYPE_CPUID:
+ TEST_ASSERT(ret && errno == EIO,
+ "KVM_SEV_SNP_LAUNCH_UPDATE should fail, invalid Page type.");
+ break;
+ default:
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_UPDATE should fail, invalid Page type.");
+ }
+
+ kvm_vm_free(vm);
+ }
+}
+
+void test_snp_launch_finish(uint32_t type, uint64_t policy)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ int ret;
+
+ vm = vm_sev_create_with_one_vcpu(type, NULL, &vcpu);
+ snp_vm_launch(vm, policy, 0);
+ snp_vm_launch_update(vm, KVM_SEV_SNP_PAGE_TYPE_NORMAL);
+ ret = snp_vm_launch_finish(vm, 0);
+ TEST_ASSERT(!ret,
+ "KVM_SEV_SNP_LAUNCH_FINISH should not fail, invalid flag.");
+ kvm_vm_free(vm);
+
+ for (int i = 1; i < 16; i++) {
+ vm = vm_sev_create_with_one_vcpu(type, NULL, &vcpu);
+ snp_vm_launch(vm, policy, 0);
+ snp_vm_launch_update(vm, KVM_SEV_SNP_PAGE_TYPE_NORMAL);
+ ret = snp_vm_launch_finish(vm, BIT(i));
+ TEST_ASSERT(ret && errno == EINVAL,
+ "KVM_SEV_SNP_LAUNCH_FINISH should fail, invalid flag.");
+ kvm_vm_free(vm);
+ }
+}
+
+static void test_sev_ioctl(void *guest_code, uint32_t type, uint64_t policy)
+{
+ if (type == KVM_X86_SNP_VM) {
+ test_snp_launch_start(type, policy);
+ test_snp_launch_update(type, policy);
+ test_snp_launch_finish(type, policy);
+
+ return;
+ }
+
+ test_sev_launch(guest_code, type, policy);
+}
+
static void test_sev(void *guest_code, uint32_t type, uint64_t policy)
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
struct ucall uc;
- test_sev_launch(guest_code, type, policy);
+ test_sev_ioctl(guest_code, type, policy);
vm = vm_sev_create_with_one_vcpu(type, guest_code, &vcpu);
--
2.34.1
next prev parent reply other threads:[~2024-07-10 22:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 22:05 [RFC 0/5] SEV Kernel Selftests Pratik R. Sampat
2024-07-10 22:05 ` [RFC 1/5] selftests: KVM: Add a basic SNP smoke test Pratik R. Sampat
2024-07-11 15:16 ` Peter Gonda
2024-07-11 16:21 ` Sampat, Pratik Rajesh
2024-07-11 15:56 ` Tom Lendacky
2024-07-11 16:23 ` Sampat, Pratik Rajesh
2024-07-10 22:05 ` [RFC 2/5] selftests: KVM: Decouple SEV ioctls from asserts Pratik R. Sampat
2024-07-11 15:19 ` Peter Gonda
2024-07-11 16:11 ` Peter Gonda
2024-07-11 16:27 ` Sampat, Pratik Rajesh
2024-08-09 15:40 ` Sean Christopherson
2024-08-13 15:23 ` Pratik R. Sampat
2024-08-13 15:27 ` Sean Christopherson
2024-08-13 15:30 ` Pratik R. Sampat
2024-07-10 22:05 ` [RFC 3/5] selftests: KVM: SEV IOCTL test Pratik R. Sampat
2024-07-11 15:23 ` Peter Gonda
2024-07-11 16:23 ` Sampat, Pratik Rajesh
2024-07-11 18:34 ` Tom Lendacky
2024-07-11 20:02 ` Sampat, Pratik Rajesh
2024-08-09 15:45 ` Sean Christopherson
2024-08-13 15:23 ` Pratik R. Sampat
2024-07-10 22:05 ` Pratik R. Sampat [this message]
2024-07-11 15:57 ` [RFC 4/5] selftests: KVM: SNP " Peter Gonda
2024-07-11 16:27 ` Sampat, Pratik Rajesh
2024-08-09 15:48 ` Sean Christopherson
2024-08-13 15:23 ` Pratik R. Sampat
2024-07-10 22:05 ` [RFC 5/5] selftests: KVM: SEV-SNP test for KVM_SEV_INIT2 Pratik R. Sampat
2024-07-11 15:57 ` Peter Gonda
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=20240710220540.188239-5-pratikrajesh.sampat@amd.com \
--to=pratikrajesh.sampat@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=thomas.lendacky@amd.com \
/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
all inboxes | Powered by JetHome®