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: 117100 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp667425qgn; Wed, 25 Oct 2017 03:16:47 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TBTF4Hbc+IJSZlNET6d9Reeq+kC4n6ztvtKJJItZYMevTQ8BgrDJWtdXdBP8CkbHyRT1p0 X-Received: by 10.129.62.31 with SMTP id l31mr12543206ywa.345.1508926607756; Wed, 25 Oct 2017 03:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508926607; cv=none; d=google.com; s=arc-20160816; b=ZareRzuUwtfK6r/ldxwkfoTXM3lZCVCkOnZpBQ9pj24hvhO86QiCk1E95mAx7iEa+F YKtCYXPjjjidd+RghjNLmabyxSLXWsvDWwUAiD7UtngK4O0mY+kvqy4MfAw8wrMKSxAE qUKlpuKnIMqgIV6An9NpPt+uQT3PWUcejaT+/R72SkksTBqYbmF1115l5lreOJ7gTthm Z5uWeJCB/F+lqvyunSRPb1Q/lTEYWGiQFJLpCOoeqBIZh4g+LNY2EYvNoVm6j5ftPx+0 5P1yIlofYsbMrmt9Uod0HtInBBWyRCt+DzChCi9aNLrzagXWyoIQmRa7QWJ81kWgY6au HaSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Fjx5ywsx7g6Eew44Ba6AvRlESsD6Q/tHYbpEi1syNBs=; b=Crp+X8sjbDA8miC9shuDtQQx8h6/cUHWZ/+/vJges+iLtoi89/umyzbmLShSCZv0vn +YyJN4iZEDE5bha7gxyONUacVl92/WEEkDCskmsy76Uxw0mnNEGOA0WQGxAGa7szy+ES J5VMFTxZS+AWgbNcVRd10vNpCjTtHQpSY+sYrvydsk0VU0oFbtBYhaYhzPvRZxDuKGE0 dhU5kqVp/rb1hc1U7YI30cofhZXN8EjjKCDzVvR2+YG7oVQp3wmZBDrrN2tuMzud7ka6 D1h9v8QhjQptzXyD88AbdrOrTtkAX4N28Gl7xVXFi5Eo2qEfoxfI5doTaSoPoGqJoJbt +K4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iZcYZag/; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 124si373327ybt.311.2017.10.25.03.16.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 Oct 2017 03:16:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iZcYZag/; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7Ijv-0008EL-As for patch@linaro.org; Wed, 25 Oct 2017 06:16:47 -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-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+patch=linaro.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(-) -- 2.13.6 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) {