KVM: VMX: Formally define KVM's "0xdead" exit reason used for failed VM-Enter
Sean Christopherson
maintainerPATCH 1/1 KVM: VMX: Formally define KVM's "0xdead" exit reason used for failed VM-Enter
Add EXIT_REASON_UNDEFINED to track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).
Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
No functional change intended.
--- arch/x86/include/asm/vmx.h | 8 ++++++++ arch/x86/kvm/vmx/vmx.c | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-)
arch/x86/include/asm/vmx.h +8 -0
@@ -20,6 +20,14 @@#include <asm/trapnr.h> #include <asm/vmxfeatures.h> +/* +* UNDEFINED is a KVM-defined value used to indicate that the basic exit reason +* is undefined/invalid, e.g. on VM-Fail or if TDX never attempted VM-Enter. +* The value itself is arbitrary, it just needs to not collide with a real exit +* reason. +*/ +#define EXIT_REASON_UNDEFINED 0xdead +struct vmcs_hdr {u32 revision_id:31 ;u32 shadow_vmcs:1 ;
arch/x86/kvm/vmx/vmx.c +3 -1
@@ -6388,6 +6388,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +static_assert (EXIT_REASON_UNDEFINED >=ARRAY_SIZE (kvm_vmx_exit_handlers)); +void vmx_get_exit_info (struct kvm_vcpu *vcpu,u32 *reason,u64 *info1,u64 *info2,u32 *intr_info,u32 *error_code) {
@@ -7474,7 +7476,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,vmx_enable_fb_clear (vmx);if (unlikely (vmx->fail)) { - vmx->vt.exit_reason.full =0xdead ; + vmx->vt.exit_reason.full =EXIT_REASON_UNDEFINED ; goto out; }
base-commit: d4b7fb647204f0c81dfeae2d1a708e4d858e0c94
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Quoted 8 lines · Sean Christopherson
Add
EXIT_REASON_UNDEFINEDto track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
Quoted 8 lines
No functional change intended.
Cc Xiaoyao Li <[email protected]>Cc Yan Zhao <[email protected]>Cc Binbin Wu <[email protected]>Cc Rick Edgecombe <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 48 lines
--- arch/x86/include/asm/vmx.h | 8 ++++++++ arch/x86/kvm/vmx/vmx.c | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-)arch/x86/include/asm/vmx.h +8
-0@@ -20,6 +20,14 @@#include <asm/trapnr.h> #include <asm/vmxfeatures.h> +/* +* UNDEFINED is a KVM-defined value used to indicate that the basic exit reason +* is undefined/invalid, e.g. on VM-Fail or if TDX never attempted VM-Enter. +* The value itself is arbitrary, it just needs to not collide with a real exit +* reason. +*/ +#define EXIT_REASON_UNDEFINED 0xdead +struct vmcs_hdr {u32 revision_id:31 ;u32 shadow_vmcs:1 ;arch/x86/kvm/vmx/vmx.c +3
-1@@ -6388,6 +6388,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +static_assert (EXIT_REASON_UNDEFINED >=ARRAY_SIZE (kvm_vmx_exit_handlers)); +void vmx_get_exit_info (struct kvm_vcpu *vcpu,u32 *reason,u64 *info1,u64 *info2,u32 *intr_info,u32 *error_code) {@@ -7474,7 +7476,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,vmx_enable_fb_clear (vmx);if (unlikely (vmx->fail)) { - vmx->vt.exit_reason.full =0xdead ; + vmx->vt.exit_reason.full =EXIT_REASON_UNDEFINED ; goto out; }base-commit:
d4b7fb647204f0c81dfeae2d1a708e4d858e0c94
Quoted 8 lines · Sean Christopherson
Add
EXIT_REASON_UNDEFINEDto track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
Quoted 8 lines
No functional change intended.
Cc Xiaoyao Li <[email protected]>Cc Yan Zhao <[email protected]>Cc Binbin Wu <[email protected]>Cc Rick Edgecombe <[email protected]>Signed-off-by Sean Christopherson <[email protected]>
Quoted 8 lines · Sean Christopherson
Add
EXIT_REASON_UNDEFINEDto track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
Quoted 8 lines
No functional change intended.
Cc Xiaoyao Li <[email protected]>Cc Yan Zhao <[email protected]>Cc Binbin Wu <[email protected]>Cc Rick Edgecombe <[email protected]>
?? To help the backport of the DOS stuff? Seems strange: "no functional change intended, CC stable"
Otherwise,
Quoted 47 lines
Signed-off-by Sean Christopherson <[email protected]>---
arch/x86/include/asm/vmx.h | 8 ++++++++
arch/x86/kvm/vmx/vmx.c | 4 +++-2 files changed, 11 insertions(+), 1 deletion(-)arch/x86/include/asm/vmx.h +0
-0@@ -20,6 +20,14 @@ #include <asm/trapnr.h> #include <asm/vmxfeatures.h>arch/x86/include/asm/vmx.h +8
-0+/* +* UNDEFINED is a KVM-defined value used to indicate that the basic exit reason +* is undefined/invalid, e.g. on VM-Fail or if TDX never attempted VM-Enter. +* The value itself is arbitrary, it just needs to not collide with a real exit +* reason. +*/ +#define EXIT_REASON_UNDEFINED 0xdead +struct
vmcs_hdr{
u32 revision_id:31;
u32 shadow_vmcs:1;arch/x86/kvm/vmx/vmx.c +0
-0@@ -6388,6 +6388,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int
kvm_vmx_max_exit_handlers=
ARRAY_SIZE(kvm_vmx_exit_handlers);arch/x86/kvm/vmx/vmx.c +2
-0+static_assert (EXIT_REASON_UNDEFINED >=ARRAY_SIZE (kvm_vmx_exit_handlers)); +void vmx_get_exit_info(struct
kvm_vcpu*vcpu, u32 *reason,
u64 *info1, u64 *info2, u32*intr_info, u32*error_code) {arch/x86/kvm/vmx/vmx.c +0
-0@@ -7474,7 +7476,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, vmx_enable_fb_clear(vmx);
if (unlikely(vmx->fail)) {arch/x86/kvm/vmx/vmx.c +1
-1- vmx->vt.exit_reason.full =0xdead ; + vmx->vt.exit_reason.full =EXIT_REASON_UNDEFINED ;goto out;
}
Sean Christopherson
maintainerQuoted 16 lines · Rick P Edgecombe
Quoted 14 lines · Sean Christopherson
Add
EXIT_REASON_UNDEFINEDto track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
No functional change intended.
Cc Xiaoyao Li <[email protected]>Cc Yan Zhao <[email protected]>Cc Binbin Wu <[email protected]>Cc Rick Edgecombe <[email protected]>
Quoted 4 lines
Quoted 1 line
?? To help the backport of the DOS stuff? Seems strange: "no functional change intended, CC stable"
Yep, I massaged two of those patches ("thanks" incoming soon) to yield:
KVM: TDX: Stuff exit_reason with UNDEFINED on wait_for_sept_zap return
KVM: TDX: Set bits 31:16 to 0 and use UNDEFINED when synthesizing exit reason
Quoted 9 lines · Sean Christopherson
Add
EXIT_REASON_UNDEFINEDto track KVM's magic "0xdead" value that's used to stuff the exit reason on a failed VM-Enter so that the magic can be reused by TDX, and to make it more obvious that it's an arbitrary, KVM- defined value (though the whole "dead" thing makes it pretty darn obvious).Opportunistically add a compile-time assert to ensure the KVM-defined exit reason never collides with a "real" exit reason.
[...]
Applied to kvm-x86 vmx, thanks!
[1/1] KVM: VMX: Formally define KVM's "0xdead" exit reason used for failed VM-Enter
https://github.com/kvm-x86/linux/commit/d85f7dc8cf3c