From nobody Fri May 3 20:29:12 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1508445199618155.25004932547154; Thu, 19 Oct 2017 13:33:19 -0700 (PDT) Received: from localhost ([::1]:51159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5HUq-0002VV-2T for importer@patchew.org; Thu, 19 Oct 2017 16:32:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5HU2-0002BA-7q for qemu-devel@nongnu.org; Thu, 19 Oct 2017 16:32:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5HTx-0007gK-HP for qemu-devel@nongnu.org; Thu, 19 Oct 2017 16:32:02 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:48085) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e5HTx-0007fw-AJ for qemu-devel@nongnu.org; Thu, 19 Oct 2017 16:31:57 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6959F20BD7; Thu, 19 Oct 2017 16:31:55 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 16:31:55 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 1E8F52484B; Thu, 19 Oct 2017 16:31:55 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=mesmtp; bh=0AJhd2MtTvnRTaYAzQiscUAmGrjUtAmb+u6h/c RmSTE=; b=Mm0HErDRDX2TwPnJf5Nj7DWezxRolkGTNJbxcJ/8AItDtbCb+mrPY3 NlagmNsZvpP+o+LU2Iwz3lOguuFAKdTZ9fBoIkN091DY9M+QR/OH3K6x0WQyIDBL 72nLiLSP2IR7uie7IMapvNTyzR+2Ko8KT9Yo/Bleokgld+0q/sAeI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=0AJhd2MtTvnRTaYAz QiscUAmGrjUtAmb+u6h/cRmSTE=; b=kcvUbCnPJnbIO04I6RBZdgCoEk3Sbvcv3 UpV+ogqfiFigudG0EgtklUSSstWRDgfzW873A3wr4s/TI7OfL3tGyc5NU6+Cbkkx +d3kJVMztOEgPfM5scpHIYweHt75r0g+YtI72jgtgyHM08/EJfomJZ3SS5zmsFHI Y4jk6NYMMzsXLuE/wi0YPxmRaudDeoEyoZ5XiF1qOAlAGsmrHAp097pr7UBdpPWY Ogq0tT0qqC0cmsYceU4iUIQo6KX+Q/1nEYtJfB/hpSZHAarMbQpOuYWdj6YBcS2z 0DIRE439lW/AaI38+I/8IFzbZ1gfPtNG3mN28wxOLTZ6HkaWMwa1Q== X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 19 Oct 2017 16:31:54 -0400 Message-Id: <1508445114-4717-1-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.28 Subject: [Qemu-devel] [PATCH] translate-all: exit from tb_phys_invalidate if qht_remove fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Two or more threads might race while invalidating the same TB. We currently do not check for this at all despite taking tb_lock, which means we would wrongly invalidate the same TB more than once. This bug has actually been hit by users: I recently saw a report on IRC, although I have yet to see the corresponding test case. Fix this by using qht_remove as the synchronization point; if it fails, that means the TB has already been invalidated, and therefore there is nothing left to do in tb_phys_invalidate. Note that this solution works now that we still have tb_lock, and will continue working once we remove tb_lock. Signed-off-by: Emilio G. Cota --- This patch applies on top of the "[PATCH v6 00/50] tcg tb_lock removal" ser= ies: https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg03612.html --- accel/tcg/translate-all.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index ac8dfe6..2fe8b14 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1081,7 +1081,9 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page= _addr_t page_addr) phys_pc =3D tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h =3D tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HASH_MA= SK, tb->trace_vcpu_dstate); - qht_remove(&tb_ctx.htable, tb, h); + if (!qht_remove(&tb_ctx.htable, tb, h)) { + return; + } =20 /* remove the TB from the page list */ if (tb->page_addr[0] !=3D page_addr) { --=20 2.7.4