From nobody Fri Jun 19 08:29:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23FD9C433F5 for ; Wed, 6 Apr 2022 00:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1587207AbiDFAIJ (ORCPT ); Tue, 5 Apr 2022 20:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573261AbiDEShI (ORCPT ); Tue, 5 Apr 2022 14:37:08 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE8B167E3 for ; Tue, 5 Apr 2022 11:35:09 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id p9-20020a63f449000000b0035ec8c16f0bso58519pgk.11 for ; Tue, 05 Apr 2022 11:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=K74uTYo0p50+68Eav5hPTlnLwyyYs0SvA0+aQKwvrcM=; b=KQEqtHlUIrCMPDEZNKiPS9MvgfELfDBKde+wsTIq1ryHFf4ypzTaT5ALjkqm0JVA/K 97yK54GjAMf/hbNvHEfcLoErQsv6rPoLKHy2OA9GpDLManJ08OL6cBliH1pE8PSbtm7x Egplaa+kzgODwKtSCsT31nZ0UmtGrh8hUA9msDIyH4k5N+aHpal+4rr8KrD7SYUpXE3m nBRZDzeYOKQosGLkqviomA/pOiSPf+ru1BtqjlgFBULpSQyd2phEdgIk9HV/Y5NxCLe8 iqooldC/WoJSZZ1Savcf5GCUvvf+FBFSipfwHPk+DR5bRvXG/cGwBk20mzlgOlgGncf3 D7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=K74uTYo0p50+68Eav5hPTlnLwyyYs0SvA0+aQKwvrcM=; b=eyHsI5p2G9koB164nx4oA1WN2qVz1gCJY3L6vPRx8n70/1SLrIjzxa+8a3HpjrgUzq 03p9sG9n1TWgo2qkwJhxlue3vezNzlA1pNBR6KGScV9DhFEn7AFg8ccI9YXl+vKIrZXL r6XzcPddhtMBnA3sZvxaALIb6HEQj0mOjv53gLeUdov325kbQTHElENV+tgbA/3XTEXm v0mevYBkJyrC+iyQWqoqJXLmVuh7+iojRZC/1mzwoACV3eRuQv9q0yrm1z/KUDYNoDdl mIaM++WSHZnsmVSwkVSU2A/Rv6WcyPl848J07iNF9/pDjE1ILfz1JHkR4O9SfNqE5fV9 /llQ== X-Gm-Message-State: AOAM530xuYj0Kvs9MkEAyhCBlDvrs1k1vfQVNM+TPNEcO4h3X7TYdEyo Grmj3KuhlLdmzecxB8ioBg5jlEsX7oQ= X-Google-Smtp-Source: ABdhPJwWLVGLr/vHL4lq1ATs4OZuBgElqxvfAYIpOrbOfXGyZoR0O+W+IABkWZEAFyqxM0aqFqnkdt8jf2k= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:9f5c:353e:771c:7686]) (user=pgonda job=sendgmr) by 2002:a17:902:e545:b0:154:4d5b:2006 with SMTP id n5-20020a170902e54500b001544d5b2006mr4889343plf.94.1649183709169; Tue, 05 Apr 2022 11:35:09 -0700 (PDT) Date: Tue, 5 Apr 2022 11:35:06 -0700 Message-Id: <20220405183506.2138403-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH V4] KVM, SEV: Add KVM_EXIT_SYSTEM_EVENT metadata for SEV-ES From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , Sean Christopherson , Vitaly Kuznetsov , Borislav Petkov , Tom Lendacky , Brijesh Singh , Joerg Roedel , Marc Orr , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SEV-ES guests can request termination using the GHCB's MSR protocol. See AMD's GHCB spec section '4.1.13 Termination Request'. Currently when a guest does this the userspace VMM sees an KVM_EXIT_UNKNOWN (-EVINAL) return code from KVM_RUN. By adding a KVM_EXIT_SYSTEM_EVENT to kvm_run struct the userspace VMM can clearly see the guest has requested a SEV-ES termination including the termination reason code set and reason code. Signed-off-by: Peter Gonda Suggested-by: Sean Christopherson Cc: Vitaly Kuznetsov Cc: Borislav Petkov Cc: Tom Lendacky Cc: Brijesh Singh Cc: Joerg Roedel Cc: Marc Orr Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- V4 * Switch to using KVM_SYSTEM_EVENT exit reason. V3 * Add Documentation/ update. * Updated other KVM_EXIT_SHUTDOWN exits to clear ndata and set reason to KVM_SHUTDOWN_REQ. V2 * Add KVM_CAP_EXIT_SHUTDOWN_REASON check for KVM_CHECK_EXTENSION. Tested by making an SEV-ES guest call sev_es_terminate() with hardcoded reason code set and reason code and then observing the codes from the userspace VMM in the kvm_run.system_event fields. --- arch/x86/kvm/svm/sev.c | 7 +++++-- include/uapi/linux/kvm.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 75fa6dd268f0..039b241a9fb5 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2735,8 +2735,11 @@ static int sev_handle_vmgexit_msr_protocol(struct vc= pu_svm *svm) pr_info("SEV-ES guest requested termination: %#llx:%#llx\n", reason_set, reason_code); =20 - ret =3D -EINVAL; - break; + vcpu->run->exit_reason =3D KVM_EXIT_SHUTDOWN; + vcpu->run->system_event.type =3D KVM_SYSTEM_EVENT_SEV_TERM; + vcpu->run->system_event.flags =3D control->ghcb_gpa; + + return 0; } default: /* Error, keep GHCB MSR value as-is */ diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 8616af85dc5d..d9d24db12930 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -444,6 +444,7 @@ struct kvm_run { #define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_CRASH 3 +#define KVM_SYSTEM_EVENT_SEV_TERM 4 __u32 type; __u64 flags; } system_event; --=20 2.35.1.1094.g7c7d902a7c-goog