From patchwork Wed Oct 25 09:35:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 830220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="iZcYZag/"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yMQyk0zYNz9t16 for ; Wed, 25 Oct 2017 21:16:14 +1100 (AEDT) Received: from localhost ([::1]:47482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7IjM-0007vl-95 for incoming@patchwork.ozlabs.org; Wed, 25 Oct 2017 06:16:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7I79-0000TZ-FH for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7I78-0000Oz-E8 for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:43 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:43320) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e7I78-0000OZ-7Y for qemu-devel@nongnu.org; Wed, 25 Oct 2017 05:36:42 -0400 Received: by mail-wm0-x242.google.com with SMTP id m72so15236131wmc.0 for ; Wed, 25 Oct 2017 02:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fjx5ywsx7g6Eew44Ba6AvRlESsD6Q/tHYbpEi1syNBs=; b=iZcYZag/KI2S7dYJvSH4He89ZamJ8si4OJueK81xcZVi5zNmAf/bYCuhQVgBoo4qcG rtg8SCrgYiRfLLNFKUlFQcHjoiDQye/D1zCGfKzRHZyPN2JK4fnbRYJZqXWANFY2qBE9 EehThEaQKxbiKs2mkH7WIV70Xlzq225RiPKZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Fjx5ywsx7g6Eew44Ba6AvRlESsD6Q/tHYbpEi1syNBs=; b=YfgmhWNR0Gz1YvZFbF9at8fShToqRvbkgnt5JI9iEdv6OtgeUSola94KosL7jv0fhS 5RK0QRR4Il36ZP2nMkWxPe3doo2L2M42ktumDlyvmfUBW+ildqKr0PwUsaR8XESjdhZm aP+SRFgEKJEwH66NVmDRQb9B9fLJ4CR3ow7GqW7bsV286IJzZJZ9szjNYiwNBOupy9nB SLI5/L1GZD8n9R2Zpd5f2KWHwoibrupITP2tEVSrjND8IHNO/Lf4FwLKDdOiWa8Adej+ DP0sKXcY5zGiUnTBxuvqpLfoCpjPwsyImeWpZZ091mMfrF0V/qD/csAr1plpJoulESMr ZR9Q== X-Gm-Message-State: AMCzsaUn/FVMvbwOX+kkNwhftxmZT6LMo+NQZfcR+iro3mFOwKlgxCO/ UAwkR8xVPRFTe7dL3UZz7g5MzZV64dM= X-Google-Smtp-Source: ABhQp+QwpAK+ABvvrW3Bn1ecFDaQVx1diBjuw30lgTjTsnz2TGvw72Zvk3qocBZEu6wLqY/KYrAPJw== X-Received: by 10.28.181.2 with SMTP id e2mr1041329wmf.81.1508924201065; Wed, 25 Oct 2017 02:36:41 -0700 (PDT) Received: from cloudburst.twiddle.net ([62.168.35.107]) by smtp.gmail.com with ESMTPSA id v23sm2751025wmh.8.2017.10.25.02.36.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 02:36:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 25 Oct 2017 11:35:35 +0200 Message-Id: <20171025093535.10175-52-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171025093535.10175-1-richard.henderson@linaro.org> References: <20171025093535.10175-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 51/51] 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" 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. Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Message-Id: <1508445114-4717-1-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- 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 5724149289..34c5e28d07 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1079,7 +1079,9 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h = tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HASH_MASK, tb->trace_vcpu_dstate); - qht_remove(&tb_ctx.htable, tb, h); + if (!qht_remove(&tb_ctx.htable, tb, h)) { + return; + } /* remove the TB from the page list */ if (tb->page_addr[0] != page_addr) {