From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: will@kernel.org, maz@kernel.org, apatel@ventanamicro.com,
atishp@rivosinc.com, seanjc@google.com, pgonda@google.com
Subject: [PATCH 1/4] KVM: x86: always initialize system_event.ndata
Date: Thu, 21 Apr 2022 14:04:40 -0400 [thread overview]
Message-ID: <20220421180443.1465634-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20220421180443.1465634-1-pbonzini@redhat.com>
The KVM_SYSTEM_EVENT_NDATA_VALID mechanism that was introduced
contextually with KVM_SYSTEM_EVENT_SEV_TERM is not a good match
for ARM and RISC-V, which want to communicate information even
for existing KVM_SYSTEM_EVENT_* constants. Userspace is not ready
to filter out bit 31 of type, and fails to process the
KVM_EXIT_SYSTEM_EVENT exit.
Therefore, tie the availability of ndata to a system capability
(which will be added once all architectures are on board).
Userspace written for released versions of Linux has no reason to
check flags, since it was never written, so it is okay to replace
it with ndata and data[0] (on 32-bit kernels) or with data[0]
(on 64-bit kernels).
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/svm/sev.c | 3 +--
arch/x86/kvm/x86.c | 2 ++
include/uapi/linux/kvm.h | 1 -
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index a93f0d01bb90..51b963ec122b 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2739,8 +2739,7 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
reason_set, reason_code);
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.type = KVM_SYSTEM_EVENT_SEV_TERM;
vcpu->run->system_event.ndata = 1;
vcpu->run->system_event.data[1] = control->ghcb_gpa;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4e7f3a8da16a..517c0228881c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10056,12 +10056,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) {
vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH;
+ vcpu->run->system_event.ndata = 0;
r = 0;
goto out;
}
if (kvm_check_request(KVM_REQ_HV_RESET, vcpu)) {
vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
vcpu->run->system_event.type = KVM_SYSTEM_EVENT_RESET;
+ vcpu->run->system_event.ndata = 0;
r = 0;
goto out;
}
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index dd1d8167e71f..5a57f74b4903 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -445,7 +445,6 @@ struct kvm_run {
#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;
__u32 ndata;
__u64 data[16];
--
2.31.1
next prev parent reply other threads:[~2022-04-21 18:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 18:04 [PATCH 0/4] KVM: fix KVM_EXIT_SYSTEM_EVENT mess Paolo Bonzini
2022-04-21 18:04 ` Paolo Bonzini [this message]
2022-04-22 9:48 ` [PATCH 1/4] KVM: x86: always initialize system_event.ndata Marc Zyngier
2022-04-22 10:11 ` Paolo Bonzini
2022-04-21 18:04 ` [PATCH 2/4] KVM: ARM: replace system_event.flags with ndata and data[0] Paolo Bonzini
2022-04-21 18:04 ` [PATCH 3/4] KVM: RISC-V: " Paolo Bonzini
2022-04-21 18:04 ` [PATCH 4/4] KVM: tell userspace that system_event.ndata is valid Paolo Bonzini
2022-04-22 7:58 ` [PATCH 0/4] KVM: fix KVM_EXIT_SYSTEM_EVENT mess Oliver Upton
2022-04-22 9:41 ` Paolo Bonzini
2022-04-22 10:01 ` Marc Zyngier
2022-04-22 10:19 ` Paolo Bonzini
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=20220421180443.1465634-2-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=apatel@ventanamicro.com \
--cc=atishp@rivosinc.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=pgonda@google.com \
--cc=seanjc@google.com \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®