Commit c24a950e authored by Peter Gonda's avatar Peter Gonda Committed by Paolo Bonzini

KVM, SEV: Add KVM_EXIT_SHUTDOWN metadata for SEV-ES

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.
Suggested-by: default avatarSean Christopherson <seanjc@google.com>
Suggested-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarPeter Gonda <pgonda@google.com>
Reported-by: default avatarkernel test robot <lkp@intel.com>
Message-Id: <20220407210233.782250-1-pgonda@google.com>
[Add documentatino. - Paolo]
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 9bd1f0ef
...@@ -6088,8 +6088,12 @@ should put the acknowledged interrupt vector into the 'epr' field. ...@@ -6088,8 +6088,12 @@ should put the acknowledged interrupt vector into the 'epr' field.
#define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
#define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_RESET 2
#define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_CRASH 3
#define KVM_SYSTEM_EVENT_SEV_TERM 4
#define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31)
__u32 type; __u32 type;
__u32 ndata;
__u64 flags; __u64 flags;
__u64 data[16];
} system_event; } system_event;
If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
...@@ -6099,7 +6103,7 @@ HVC instruction based PSCI call from the vcpu. The 'type' field describes ...@@ -6099,7 +6103,7 @@ HVC instruction based PSCI call from the vcpu. The 'type' field describes
the system-level event type. The 'flags' field describes architecture the system-level event type. The 'flags' field describes architecture
specific flags for the system-level event. specific flags for the system-level event.
Valid values for 'type' are: Valid values for bits 30:0 of 'type' are:
- KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
VM. Userspace is not obliged to honour this, and if it does honour VM. Userspace is not obliged to honour this, and if it does honour
...@@ -6112,12 +6116,18 @@ Valid values for 'type' are: ...@@ -6112,12 +6116,18 @@ Valid values for 'type' are:
has requested a crash condition maintenance. Userspace can choose has requested a crash condition maintenance. Userspace can choose
to ignore the request, or to gather VM memory core dump and/or to ignore the request, or to gather VM memory core dump and/or
reset/shutdown of the VM. reset/shutdown of the VM.
- KVM_SYSTEM_EVENT_SEV_TERM -- an AMD SEV guest requested termination.
The guest physical address of the guest's GHCB is stored in `data[0]`.
Valid flags are: Valid flags are:
- KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (arm64 only) -- the guest issued - KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (arm64 only) -- the guest issued
a SYSTEM_RESET2 call according to v1.1 of the PSCI specification. a SYSTEM_RESET2 call according to v1.1 of the PSCI specification.
Extra data for this event is stored in the `data[]` array, up to index
`ndata-1` included, if bit 31 is set in `type`. The data depends on the
`type` field. There is no extra data if bit 31 is clear or `ndata` is zero.
:: ::
/* KVM_EXIT_IOAPIC_EOI */ /* KVM_EXIT_IOAPIC_EOI */
......
...@@ -2738,8 +2738,13 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) ...@@ -2738,8 +2738,13 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
pr_info("SEV-ES guest requested termination: %#llx:%#llx\n", pr_info("SEV-ES guest requested termination: %#llx:%#llx\n",
reason_set, reason_code); reason_set, reason_code);
ret = -EINVAL; vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
break; 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;
} }
default: default:
/* Error, keep GHCB MSR value as-is */ /* Error, keep GHCB MSR value as-is */
......
...@@ -444,8 +444,11 @@ struct kvm_run { ...@@ -444,8 +444,11 @@ struct kvm_run {
#define KVM_SYSTEM_EVENT_SHUTDOWN 1 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
#define KVM_SYSTEM_EVENT_RESET 2 #define KVM_SYSTEM_EVENT_RESET 2
#define KVM_SYSTEM_EVENT_CRASH 3 #define KVM_SYSTEM_EVENT_CRASH 3
#define KVM_SYSTEM_EVENT_SEV_TERM 4
#define KVM_SYSTEM_EVENT_NDATA_VALID (1u << 31)
__u32 type; __u32 type;
__u64 flags; __u32 ndata;
__u64 data[16];
} system_event; } system_event;
/* KVM_EXIT_S390_STSI */ /* KVM_EXIT_S390_STSI */
struct { struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment