Cc: Paolo Bonzini <[email protected]>
Cc: Radim Krčmář <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: KarimAllah Ahmed <[email protected]>
---
 arch/x86/kvm/x86.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index ac38143..db0fd24 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4843,9 +4843,9 @@ static int emulator_cmpxchg_emulated(struct 
x86_emulate_ctxt *ctxt,
                                     unsigned int bytes,
                                     struct x86_exception *exception)
 {
+       struct kvm_host_mapping mapping;
        struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
        gpa_t gpa;
-       struct page *page;
        char *kaddr;
        bool exchanged;
 
@@ -4862,12 +4862,10 @@ static int emulator_cmpxchg_emulated(struct 
x86_emulate_ctxt *ctxt,
        if (((gpa + bytes - 1) & PAGE_MASK) != (gpa & PAGE_MASK))
                goto emul_write;
 
-       page = kvm_vcpu_gfn_to_page(vcpu, gpa >> PAGE_SHIFT);
-       if (is_error_page(page))
+       if (!kvm_vcpu_gpa_to_host_mapping(vcpu, gpa, &mapping, true))
                goto emul_write;
 
-       kaddr = kmap_atomic(page);
-       kaddr += offset_in_page(gpa);
+       kaddr = mapping.kaddr + offset_in_page(gpa);
        switch (bytes) {
        case 1:
                exchanged = CMPXCHG_TYPE(u8, kaddr, old, new);
@@ -4884,8 +4882,8 @@ static int emulator_cmpxchg_emulated(struct 
x86_emulate_ctxt *ctxt,
        default:
                BUG();
        }
-       kunmap_atomic(kaddr);
-       kvm_release_page_dirty(page);
+
+       kvm_release_host_mapping(&mapping, true);
 
        if (!exchanged)
                return X86EMUL_CMPXCHG_FAILED;
-- 
2.7.4

Reply via email to