From patchwork Sat Dec 25 21:16:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Smith X-Patchwork-Id: 76702 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 80978B70CF for ; Sun, 26 Dec 2010 08:17:19 +1100 (EST) Received: from localhost ([127.0.0.1]:46752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWbUK-000872-HN for incoming@patchwork.ozlabs.org; Sat, 25 Dec 2010 16:17:16 -0500 Received: from [140.186.70.92] (port=60244 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PWbTo-000853-UA for qemu-devel@nongnu.org; Sat, 25 Dec 2010 16:16:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PWbTn-0005Xq-Nk for qemu-devel@nongnu.org; Sat, 25 Dec 2010 16:16:44 -0500 Received: from speedy.comstyle.com ([206.51.28.2]:2757 helo=mail.comstyle.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PWbTn-0005Xk-LU for qemu-devel@nongnu.org; Sat, 25 Dec 2010 16:16:43 -0500 Received: from rox.home.comstyle.com (unknown [IPv6:2607:f2c0:f00e:3000:ca0a:a9ff:fe93:42c9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: brad) by mail.comstyle.com (Postfix) with ESMTPSA id 9E219984A7 for ; Sat, 25 Dec 2010 16:16:40 -0500 (EST) Date: Sat, 25 Dec 2010 16:16:39 -0500 From: Brad To: qemu-devel@nongnu.org Message-ID: <20101225211637.GA13596@rox.home.comstyle.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-comstyle-MailScanner-Information: Please contact the ISP for more information X-comstyle-MailScanner-ID: 9E219984A7.A4D7D X-comstyle-MailScanner: Found to be clean X-comstyle-MailScanner-From: brad@comstyle.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] i386 target bug with cmpxchg instruction handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The following diff fixes a bug with the i386 targets cmpxhg instruction handling. I'm making an attempt to submit this upstream since OpenBSD currently has this in our port but it was originally from NetBSD's pkgsrc tree with QEMU. http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=42158 https://bugs.launchpad.net/qemu/+bug/569760 diff --git a/target-i386/translate.c b/target-i386/translate.c index 7b6e3c2..b5d6c97 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -4879,20 +4879,24 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start) tcg_gen_sub_tl(t2, cpu_regs[R_EAX], t0); gen_extu(ot, t2); tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1); + label2 = gen_new_label(); if (mod == 3) { - label2 = gen_new_label(); gen_op_mov_reg_v(ot, R_EAX, t0); tcg_gen_br(label2); gen_set_label(label1); gen_op_mov_reg_v(ot, rm, t1); - gen_set_label(label2); } else { - tcg_gen_mov_tl(t1, t0); + /* perform no-op store cycle like physical cpu; must be + before changing accumulator to ensure idempotency if + the store faults and the instruction is restarted + */ + gen_op_st_v(ot + s->mem_index, t0, a0); gen_op_mov_reg_v(ot, R_EAX, t0); + tcg_gen_br(label2); gen_set_label(label1); - /* always store */ gen_op_st_v(ot + s->mem_index, t1, a0); } + gen_set_label(label2); tcg_gen_mov_tl(cpu_cc_src, t0); tcg_gen_mov_tl(cpu_cc_dst, t2); s->cc_op = CC_OP_SUBB + ot;