]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
KVM: x86: report negative values from wrmsr emulation to userspace
authorMaxim Levitsky <mlevitsk@redhat.com>
Thu, 1 Oct 2020 11:29:52 +0000 (14:29 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 21 Oct 2020 21:36:34 +0000 (17:36 -0400)
This will allow the KVM to report such errors (e.g -ENOMEM)
to the userspace.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20201001112954.6258-3-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index 0cc0db500f718f554e7f111aea36f0e1db32da8a..0d917eb70319498965590068afa61e4e85d3841a 100644 (file)
@@ -3712,10 +3712,10 @@ static int em_wrmsr(struct x86_emulate_ctxt *ctxt)
        if (r == X86EMUL_IO_NEEDED)
                return r;
 
-       if (r)
+       if (r > 0)
                return emulate_gp(ctxt, 0);
 
-       return X86EMUL_CONTINUE;
+       return r < 0 ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE;
 }
 
 static int em_rdmsr(struct x86_emulate_ctxt *ctxt)
index 3f5d08f7a637020fde1ad2b2021b8e280ccca8e4..ecdeab8fa0b16d94b3dfe7d947bc2421e26134e7 100644 (file)
@@ -1737,13 +1737,16 @@ int kvm_emulate_wrmsr(struct kvm_vcpu *vcpu)
        r = kvm_set_msr(vcpu, ecx, data);
 
        /* MSR write failed? See if we should ask user space */
-       if (r && kvm_set_msr_user_space(vcpu, ecx, data, r)) {
+       if (r && kvm_set_msr_user_space(vcpu, ecx, data, r))
                /* Bounce to user space */
                return 0;
-       }
+
+       /* Signal all other negative errors to userspace */
+       if (r < 0)
+               return r;
 
        /* MSR write failed? Inject a #GP */
-       if (r) {
+       if (r > 0) {
                trace_kvm_msr_write_ex(ecx, data);
                kvm_inject_gp(vcpu, 0);
                return 1;