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: 13728415 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 D58CD17B04F for ; Tue, 9 Jul 2024 18:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720549791; cv=none; b=YoxARNH+8LnenaXBr/Z1ZH7s05UoXm1jUpcia2VWGzDCNufJZRkM4M65CKzStbpEfoM8MEYtVegOs+Hi45u95pDiiPJfTgnh8i457y0IZUU/6oYPF0pG4+Y+YwkdTVStnw7KT12XV2ltx7hIwFXtKmV0TPeAf7NWpq39W8Pb7RA= 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.202 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-f202.google.com with SMTP id d2e1a72fcca58-70afd833ba9so3163175b3a.1 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=qVnke+Hs4pHoQY/OiKES4qacGcAG2gr3H4oK5fc/LwF+ySNzqq4UnQRDD0nYD3Rzyv J8d8qI8F3gg3Z+jJdTGQyAx4ZV6hEzVeqBqJwmuG1EdgslF0L5z40pPi0TyaM/RKencm KnYv6Mx4tzTSZRINkrMyFZsFn8/1Ye83sqrKdnOG0eVGFt7AGd6K7gJ9mBUi6TGRSeAr Cm56QjY4j3AIFQjyQbco93JWgAV5fSrUlWl0bbhERwzMejLj3Jpfj/toUz1e5KOs59r2 F8YCOXAfA1i/jtsfGCvwbaoYTY0kua9zvEENU1FTn4JCN6y2WTJ/TgFLyJ+EqI/S7O9D tdVQ== X-Forwarded-Encrypted: i=1; AJvYcCXpdc3obSeLw6SzfxWSU/hDx05d0BnSW/OJHuLhtJTMqBs8UTjkxU/N6/aIJ9dDgo09c4s3zFJcehjYBHtl1YczCw3du/mIsOnJrZblgl0j X-Gm-Message-State: AOJu0Yz4H7YSzQrq5HNqAoy3JfhOsNGPlinn2FfadnLa5/BL8hawea9M sAqD5O6WDrw2xuQTI+ZEc0f7O91QR5Lk9lww4Ga/Yg3ZCmM9XlgVqe51cffbRQEc2lavYQ2QkSh rgw== 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: linux-kselftest@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);