From nobody Tue Feb 10 04:12:42 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 10B7713AF9 for ; Fri, 23 Feb 2024 00:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649003; cv=none; b=dQQH0acqDRUpNOl1cc+gnEfkBWFPyooOwWhstbSBZPxna/UkwR6a8RHdSFDn6J8E+45cwcCUTNuncjvqr8esexOpj0CDAsKQ1eHfj7GsImP+TW5LxqEHzT1sNvA1Mce4HvvNVpoyOxbmFjMapwoQjnRCvR4pSJO/qu0gJVNDPzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708649003; c=relaxed/simple; bh=wYG3aBkI4214Z2xd6xHe4uZY8sEWm9j7oKweqpMTgCo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CXkJ6dS/AfplNsmwe+6jaapC4EWDj/N9FkBEPkLL74jp8jCRwPPsLqu42vu1r78HRj6bQbc0s6Gg9XDv4dHplCDNnk2Rg6HxOEyotYc3O7FrF9m89ud4ywZba7e05eKfUM2N9LtJDgkPRwxwOT8PbRaqfPpUmpw3TkFEulSvEMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Em36FEgh; arc=none smtp.client-ip=209.85.214.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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Em36FEgh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1dbc6ff68ffso2514085ad.1 for ; Thu, 22 Feb 2024 16:43:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708649001; x=1709253801; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ufdAB/OIgPR6sk1BH6tXU4Lb92iEyKpRUAsMWFh65lo=; b=Em36FEgh97nyp76bmotk8WR0avZyxpP/pj5q6LXuqFIyy13uo5sTPBOFJy8Yoivbgm XnVtw53YinNGs/V0PpKvxbhhQlfUvX5ndaOv8cYUraIkVJl8A8vUPRMzF7COJrRwKj0l yOzFbwH47axebAZzevu9Kudd01pSYCwLQgVVBHinKEcciW1d6PpV5V7tlHvd/uoz5Gyt G72ZWP82c7Bm9UMmMGnav+r059S113S7Bpf3fc9+2b6qkIk3nLVhOWQH9cMd5l5IdL2K VultK8yuvFMacqGcZRVLY2w/FEgwWCz7z8Chc2kvzxnBAQUGuJxeg0vOleA7uf/efhiB 3hsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708649001; x=1709253801; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ufdAB/OIgPR6sk1BH6tXU4Lb92iEyKpRUAsMWFh65lo=; b=ZjvHfhyWgQNeXkMSTwygL9jdUeElGjvb1BBKbr352NPwnUYk7lMZcixVkt1GQ2myXi aMOwJ76sHhN7gTK5KLMhHqVyEU2AAnfz2qI7O3qfeVQgHq2mMlBlAA7nqo/7HBwYGhtT BXRFnOfJvPaPxoVmWPtBZ8kQMci7H/87BLX903iaPIeVpPwzZn+eWjJToe25EjrbZfUR tDPaC7akICvwpiPUlIHBzZEIzObvwuY4vKdY8beMiHWEaTSkoKIoavohlWa0x1xxvNXo 0Qy5VNyYVsh913iTD9yWvoGnXRho7nAvSjBzWp0Yd0OKznAWyWtnf3ecpmpPLz05HcUw pJQA== X-Forwarded-Encrypted: i=1; AJvYcCUP8WoZNv8+v4+MxGgy6CttMZjDT5V6fggWg/iDgVHhH/nKjZk3CDj7Z5LtPFbE0aAFBjz16gwI+VAnKI4rDlVsHFiqvGZWVlviLtbA X-Gm-Message-State: AOJu0YxC9Vs0p8I8+dOgp4Z9lrkzEZB5LOYUI7LaMIh3EMZWUS5s+TKb MRJ1Ykr/y1LPrZ88+tmYz+M7468maefyhpyc39NjGOSlAN8B1+AsB25lySqcnoOcXUQj/qLn4+a 29Q== X-Google-Smtp-Source: AGHT+IG8+r/xpCHDcIabTu60pIgBwVS8FUp4lQYZJVuuCn7QXyTR4BHnC5QtDdnTL8fekJtdMeUpyEN6qt8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:234c:b0:1dc:1c81:1b2a with SMTP id c12-20020a170903234c00b001dc1c811b2amr1699plh.1.1708649001454; Thu, 22 Feb 2024 16:43:21 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 22 Feb 2024 16:42:57 -0800 In-Reply-To: <20240223004258.3104051-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240223004258.3104051-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240223004258.3104051-11-seanjc@google.com> Subject: [PATCH v9 10/11] KVM: selftests: Add a basic SEV smoke test From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Vishal Annapurve , Ackerley Tng , Andrew Jones , Tom Lendacky , Michael Roth , Carlos Bilbao , Peter Gonda , Itaru Kitayama Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Gonda Add a basic smoke test for SEV guests to verify that KVM can launch an SEV guest and run a few instructions without exploding. To verify that SEV is indeed enabled, assert that SEV is reported as enabled in MSR_AMD64_SEV, a.k.a. SEV_STATUS, which cannot be intercepted by KVM (architecturally enforced). Cc: Paolo Bonzini Cc: Sean Christopherson Cc: Vishal Annapurve Cc: Ackerly Tng cc: Andrew Jones Cc: Tom Lendacky Cc: Michael Roth Suggested-by: Michael Roth Tested-by: Carlos Bilbao Signed-off-by: Peter Gonda [sean: rename to "sev_smoke_test"] Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/sev_smoke_test.c | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/sev_smoke_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests= /kvm/Makefile index 169b6ee8f733..da20e6bb43ed 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -120,6 +120,7 @@ TEST_GEN_PROGS_x86_64 +=3D x86_64/vmx_pmu_caps_test TEST_GEN_PROGS_x86_64 +=3D x86_64/xen_shinfo_test TEST_GEN_PROGS_x86_64 +=3D x86_64/xen_vmcall_test TEST_GEN_PROGS_x86_64 +=3D x86_64/sev_migrate_tests +TEST_GEN_PROGS_x86_64 +=3D x86_64/sev_smoke_test TEST_GEN_PROGS_x86_64 +=3D x86_64/amx_test TEST_GEN_PROGS_x86_64 +=3D x86_64/max_vcpuid_cap_test TEST_GEN_PROGS_x86_64 +=3D x86_64/triple_fault_event_test diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/te= sting/selftests/kvm/x86_64/sev_smoke_test.c new file mode 100644 index 000000000000..54d72efd9b4d --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include +#include +#include + +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "svm_util.h" +#include "linux/psp-sev.h" +#include "sev.h" + +static void guest_sev_code(void) +{ + GUEST_ASSERT(this_cpu_has(X86_FEATURE_SEV)); + GUEST_ASSERT(rdmsr(MSR_AMD64_SEV) & MSR_AMD64_SEV_ENABLED); + + GUEST_DONE(); +} + +static void test_sev(void *guest_code, uint64_t policy) +{ + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + struct ucall uc; + + vm =3D vm_sev_create_with_one_vcpu(policy, guest_code, &vcpu); + + for (;;) { + vcpu_run(vcpu); + + switch (get_ucall(vcpu, &uc)) { + case UCALL_SYNC: + continue; + case UCALL_DONE: + return; + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + default: + TEST_FAIL("Unexpected exit: %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)); + + test_sev(guest_sev_code, SEV_POLICY_NO_DBG); + test_sev(guest_sev_code, 0); + + return 0; +} --=20 2.44.0.rc0.258.g7320e95886-goog