Skip to contentSkip to conversation

KVM: x86 emulator: fix xchg instruction emulation

PATCH Superseded Wei Yongjun 3 participants 5 messages Jul 14, 2010 – Jul 16, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86 emulator: fix xchg instruction emulation

If the destination is a memory operand and the memory cannot map to a valid page, the xchg instruction emulation will fail. If so, we should emulate exchange as write to fix it.

---
 arch/x86/kvm/x86.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +2 -0
index d94811e..ac63f6f 100644
@@ -3560,6 +3560,8 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 		goto emul_write;
 
 	page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
+	if (is_error_page(page))
+		goto emul_write;
 
 	kaddr = kmap_atomic(page, KM_USER0);
 	kaddr += offset_in_page(gpa);
Signature · 1 line
1.7.0.4
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Wei Yongjun

If the destination is a memory operand and the memory cannot map to a valid page, the xchg instruction emulation will fail. If so, we should emulate exchange as write to fix it.

Without this patch locked instruction does not work on io regions. They don't just fail, they stuck in endless loop.

Quoted 25 lines
---
 arch/x86/kvm/x86.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +2 -0
index d94811e..ac63f6f 100644
@@ -3560,6 +3560,8 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 		goto emul_write;
 
 	page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
+	if (is_error_page(page))
+		goto emul_write;
 
 	kaddr = kmap_atomic(page, KM_USER0);
 	kaddr += offset_in_page(gpa);
Signature · 7 lines
1.7.0.4


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
Gleb.

#2 lore raw
In reply to Wei Yongjun
Quoted 15 lines · Wei Yongjun

If the destination is a memory operand and the memory cannot map to a valid page, the xchg instruction emulation will fail. If so, we should emulate exchange as write to fix it.

---
 arch/x86/kvm/x86.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +0 -0
index d94811e..ac63f6f 100644

arch/x86/kvm/x86.c static int emulator_cmpxchg_emulated(unsigned long addr, · line 3564

Quoted 5 lines
arch/x86/kvm/x86.c +2 -0
@@ -3560,6 +3560,8 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 		goto emul_write;
 
 	page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
+	if (is_error_page(page))
+		goto emul_write;

Forgot to release page.

#3 lore raw

PATCH v2 1/1 KVM: x86 emulator: fix xchg instruction emulation

If the destination is a memory operand and the memory cannot map to a valid page, the xchg instruction emulation and locked instruction will not work on io regions and stuck in endless loop. We should emulate exchange as write to fix it.

---
 arch/x86/kvm/x86.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +4 -0
index 86c8102..84bfb51 100644
@@ -3562,6 +3562,10 @@ static int emulator_cmpxchg_emulated(unsigned long addr,
 		goto emul_write;
 
 	page = gfn_to_page(vcpu->kvm, gpa >> PAGE_SHIFT);
+	if (is_error_page(page)) {
+		kvm_release_page_clean(page);
+		goto emul_write;
+	}
 
 	kaddr = kmap_atomic(page, KM_USER0);
 	kaddr += offset_in_page(gpa);
Signature · 1 line
1.7.0.4