From patchwork Tue Jul 9 18:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Gonda X-Patchwork-Id: 13728416 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1D9A17B045 for ; Tue, 9 Jul 2024 18:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720549791; cv=none; b=TrTW3lzuLZ292x5XWJhZldKRNbwvU1ryv2cypmICaPL8bsxSFEhVffIzvDNpLE8lwQii2Ql3e1VegNpV8cdi6bwNHXEPMBCK9tG4LIjWIWbUG/wWxATwGlqszyMm4edsJojgs8TVcr4VHZK0KokEROrsbE9zd8MpNpPEk9pXf2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720549791; c=relaxed/simple; bh=g7uGEN+YddoxxZ0oSW8KlTk+Tg8ldl5shSEbz8kvz1Y=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=pNGby66a6LYxOtomsLsgTJIN+V1CWL2RujBhUVoslAnN87/K5LLJTUdeVr3/EbIvgS7frPL+oLWFA8zi+Hn3qah7GR7J+iA2Aj8ETLbhZoLTOQtlO7Ox6de0o7ej7rMbDV83v+rZ/G0z8/UuwWkMoNw1wb9XcD0xvqdb4q+iw+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--pgonda.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wNo3ZXym; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--pgonda.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wNo3ZXym" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-70af58f79d1so3841495b3a.0 for ; Tue, 09 Jul 2024 11:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720549789; x=1721154589; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ZqTDIUJuejWJVRRv7rSZlF+QjRVhuEo942Ds62pbMYg=; b=wNo3ZXym2YhcyFEAGuZWHuSUQIH0zAEHmdnoghfFwnONbNwqJpCUjQEod2TDwvknYx 3AguYJfOSq2oD9utbnFEft3RoBeePCJF+Kf2bkyqooiLOIOvrdAmX8647zqyUWHnSWyt nTf8LDPv++HGbyYq2faHM9lMgIv7XhJ409shH7fdSHIDqlvUfHuT+sEcikMgiyOdlUY9 xcc99Lr4le1sy1UmJZk7k2j3rwUt1hw01yX8wiKjXb+nPQ4Y4Jgh1UQEu4kHhkPxb9YQ JEONsMPoXc48OTNcLZliQdzZZ+JIGzSr0FuZoJYwqA8XkI2sDh5PAEtgNs/TG+a1s5BU eNzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720549789; x=1721154589; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZqTDIUJuejWJVRRv7rSZlF+QjRVhuEo942Ds62pbMYg=; b=qzrCpz6EACMvJKcWKlDcFtg7nGL2kzVTOgA+aEjAfQP3s+QI1QA12L8IimeZJA4SoJ 1K+HwKgYDVW94oTtVMEZAfHRhoRuFDYiowJ3+lr3Ur5Fnr+3+gRvIpcKpI/uI1ZyCxF5 htrOxef8rCXtSOQfPNpy7skR7YCoONOOCGavFVfPl/FHc+6XQZkiSuEOfSDpMr19hham r4NSo0dIg8hDsRDiU2TX1/0I0/YySIh7x/oTHTLqPTTu58pO0CITFWBiLrAPHDBQCb75 UHeACW/LuMRGmJs1h5G2uP8TzqJXIVAFFrvg4CUfWITs13MiGl6n3HBQMii0HnT9InZq 5hHw== X-Gm-Message-State: AOJu0Yy8tcfZUYspYpr3oyxf0Pxcmwtte/LYbVT8/BsCcgLwdh4g16mV 1UF+m6cFeR1xWGzySd2Nk0H1lveaHxAfKYHRUUOPYK0aPf9nBA54OmhxU5xTC2jmDTchJ4Mrt/G rKHyV7LHJVF2W0cqANgkVuxam8l+AZ0BvYcFpRwD8nKmiz7fkT9n0V2tN810oIIgdfHZA7SK4sx kTc8o1hZl65xhuABYXOQv27m79Ass0 X-Google-Smtp-Source: AGHT+IHpJFxP41Dhe/Y2rfoBfzikDk7c/bwo4bZq+HFvVhN55O8dbsQtilruMtC5PfdsbeyNGFXuQte4hhI= X-Received: from pgonda1.kir.corp.google.com ([2620:0:1008:15:f7d0:8e04:1846:cd97]) (user=pgonda job=sendgmr) by 2002:aa7:98de:0:b0:70a:f547:382 with SMTP id d2e1a72fcca58-70b4369d510mr75072b3a.5.1720549788460; Tue, 09 Jul 2024 11:29:48 -0700 (PDT) Date: Tue, 9 Jul 2024 11:29:36 -0700 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240709182936.146487-1-pgonda@google.com> Subject: [PATCH] KVM: selftests: Add SEV-ES shutdown test From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Paolo Bonzini , Sean Christopherson , Alper Gun , Tom Lendacky , Michael Roth , linux-kselftest@vger.kernel.org Regression test for ae20eef5 ("KVM: SVM: Update SEV-ES shutdown intercepts with more metadata"). Test confirms userspace is correctly indicated of a guest shutdown not previous behavior of an EINVAL from KVM_RUN. Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Alper Gun Cc: Tom Lendacky Cc: Michael Roth Cc: kvm@vger.kernel.org Cc: linux-kselftest@vger.kernel.org Signed-off-by: Peter Gonda Tested-by: Pratik R. Sampat --- .../selftests/kvm/x86_64/sev_smoke_test.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 7c70c0da4fb74..04f24d5f09877 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -160,6 +160,30 @@ static void test_sev(void *guest_code, uint64_t policy) kvm_vm_free(vm); } +static void guest_shutdown_code(void) +{ + __asm__ __volatile__("ud2"); +} + +static void test_sev_es_shutdown(void) +{ + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + + uint32_t type = KVM_X86_SEV_ES_VM; + + vm = vm_sev_create_with_one_vcpu(type, guest_shutdown_code, &vcpu); + + vm_sev_launch(vm, SEV_POLICY_ES, NULL); + + vcpu_run(vcpu); + TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_SHUTDOWN, + "Wanted SHUTDOWN, got %s", + exit_reason_str(vcpu->run->exit_reason)); + + kvm_vm_free(vm); +} + int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); @@ -171,6 +195,8 @@ int main(int argc, char *argv[]) test_sev(guest_sev_es_code, SEV_POLICY_ES | SEV_POLICY_NO_DBG); test_sev(guest_sev_es_code, SEV_POLICY_ES); + test_sev_es_shutdown(); + if (kvm_has_cap(KVM_CAP_XCRS) && (xgetbv(0) & XFEATURE_MASK_X87_AVX) == XFEATURE_MASK_X87_AVX) { test_sync_vmsa(0);