From: Sean Christopherson <seanjc@google.com>
To: Peter Gonda <pgonda@google.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4.1] KVM, SEV: Add KVM_EXIT_SHUTDOWN metadata for SEV-ES
Date: Fri, 8 Apr 2022 02:55:50 +0000 [thread overview]
Message-ID: <Yk+kNqJjzoJ9TWVH@google.com> (raw)
In-Reply-To: <20220407210233.782250-1-pgonda@google.com>
On Thu, Apr 07, 2022, Peter Gonda wrote:
> If an SEV-ES guest requests termination, exit to userspace with
> KVM_EXIT_SYSTEM_EVENT and a dedicated SEV_TERM type instead of -EINVAL
> so that userspace can take appropriate action.
>
> See AMD's GHCB spec section '4.1.13 Termination Request' for more details.
Maybe it'll be obvious by the lack of compilation errors, but the changelog should
call out the flags => ndata+data shenanigans, otherwise this looks like ABI breakage.
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Peter Gonda <pgonda@google.com>
>
> ---
> V4
> * Updated to Sean and Paolo's suggestion of reworking the
> kvm_run.system_event struct to ndata and data fields to fix the
> padding.
> * 4.1 Updated commit description
>
> 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.shutdown.data fields.
>
> ---
> arch/x86/kvm/svm/sev.c | 9 +++++++--
> include/uapi/linux/kvm.h | 5 ++++-
> 2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 75fa6dd268f0..1a080f3f09d8 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2735,8 +2735,13 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
> pr_info("SEV-ES guest requested termination: %#llx:%#llx\n",
> reason_set, reason_code);
>
> - ret = -EINVAL;
> - break;
> + vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
> + vcpu->run->system_event.type = KVM_SYSTEM_EVENT_SEV_TERM |
> + KVM_SYSTEM_EVENT_NDATA_VALID;
> + vcpu->run->system_event.ndata = 1;
> + vcpu->run->system_event.data[1] = control->ghcb_gpa;
> +
> + return 0;
Kinda silly, but
ret = 0;
break;
would be better so that this flows through the tracepoint. I wouldn't care much
if it didn't result in an unpaired "entry" tracepoint (and I still don't care that
much...).
> }
> default:
> /* Error, keep GHCB MSR value as-is */
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 8616af85dc5d..dd1d8167e71f 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -444,8 +444,11 @@ 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
> +#define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31)
> __u32 type;
> - __u64 flags;
> + __u32 ndata;
> + __u64 data[16];
> } system_event;
> /* KVM_EXIT_S390_STSI */
> struct {
> --
> 2.35.1.1178.g4f1659d476-goog
>
next prev parent reply other threads:[~2022-04-08 2:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-07 21:02 [PATCH v4.1] KVM, SEV: Add KVM_EXIT_SHUTDOWN metadata for SEV-ES Peter Gonda
2022-04-08 2:55 ` Sean Christopherson [this message]
2022-04-08 15:18 ` Peter Gonda
2022-04-08 17:01 ` Sean Christopherson
2022-04-11 9:12 ` Will Deacon
2022-04-11 14:00 ` Alexandru Elisei
2022-04-11 15:06 ` Sean Christopherson
2022-04-14 23:21 ` Sean Christopherson
2022-04-08 4:34 ` kernel test robot
2022-04-08 5:15 ` kernel test robot
2022-04-08 16:56 ` Paolo Bonzini
2022-04-11 9:45 ` Marc Zyngier
2022-04-11 14:25 ` Sean Christopherson
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=Yk+kNqJjzoJ9TWVH@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.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