From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Yongjun Subject: [PATCHv2] KVM: x86 emulator: fix xchg instruction emulation Date: Thu, 15 Jul 2010 08:51:58 +0800 Message-ID: <4C3E5BAE.1010306@cn.fujitsu.com> References: <4C3D47DD.4010108@cn.fujitsu.com> <20100714163752.GA1100@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Avi Kivity , kvm@vger.kernel.org To: Marcelo Tosatti Return-path: Received: from cn.fujitsu.com ([222.73.24.84]:63481 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1757940Ab0GOAya (ORCPT ); Wed, 14 Jul 2010 20:54:30 -0400 In-Reply-To: <20100714163752.GA1100@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: 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. Signed-off-by: Wei Yongjun Acked-by: Gleb Natapov --- arch/x86/kvm/x86.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 86c8102..84bfb51 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -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); -- 1.7.0.4