[PATCH 15/45] KVM: VMX: return error from kvm_set_cr*
From: Paolo Bonzini
Date: Mon Nov 02 2026 - 13:06:17 EST
This is already done by svm.c, copy it over to vmx.c so
that kvm_complete_insn_gp() can return -EFAULT on PDPTR
loads.
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kvm/vmx/vmx.c | 12 ++++++++----
arch/x86/kvm/x86.c | 2 ++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index b341af4c6057..fe43718b751b 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -5630,6 +5630,7 @@ static int handle_set_cr0(struct kvm_vcpu *vcpu, unsigned long val)
if (is_guest_mode(vcpu)) {
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
unsigned long orig_val = val;
+ int r;
/*
* We get here when L2 changed cr0 in a way that did not change
@@ -5642,8 +5643,9 @@ static int handle_set_cr0(struct kvm_vcpu *vcpu, unsigned long val)
val = (val & ~vmcs12->cr0_guest_host_mask) |
(vmcs12->guest_cr0 & vmcs12->cr0_guest_host_mask);
- if (kvm_set_cr0(vcpu, val))
- return 1;
+ r = kvm_set_cr0(vcpu, val);
+ if (r)
+ return r;
vmcs_writel(CR0_READ_SHADOW, orig_val);
return 0;
} else {
@@ -5656,12 +5658,14 @@ static int handle_set_cr4(struct kvm_vcpu *vcpu, unsigned long val)
if (is_guest_mode(vcpu)) {
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
unsigned long orig_val = val;
+ int r;
/* analogously to handle_set_cr0 */
val = (val & ~vmcs12->cr4_guest_host_mask) |
(vmcs12->guest_cr4 & vmcs12->cr4_guest_host_mask);
- if (kvm_set_cr4(vcpu, val))
- return 1;
+ r = kvm_set_cr4(vcpu, val);
+ if (r)
+ return r;
vmcs_writel(CR4_READ_SHADOW, orig_val);
return 0;
} else
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1fcef4a8ac22..c7970bcfdc24 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -580,6 +580,8 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_requeue_exception);
int kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int err)
{
+ if (err < 0)
+ return err;
if (err)
kvm_inject_gp(vcpu, 0);
else
--
2.52.0