From patchwork Fri Oct 20 23:20:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 116577 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2238217qgn; Fri, 20 Oct 2017 16:49:17 -0700 (PDT) X-Received: by 10.55.190.195 with SMTP id o186mr9576987qkf.7.1508543357874; Fri, 20 Oct 2017 16:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508543357; cv=none; d=google.com; s=arc-20160816; b=JJI4iZSLeNdwXngczZetZXLN8WEDOEssM2nDZqqZU07x+WTgii8PMJ806Kp/1eL73S Ivd8vjepmrkE2PVKH/V7osnY7dcFcGNrG/pU147tKp69j/6xYF+MJ1IgVRNCCnhGeujC Z4IEbZAwb3JTuDKKnaW8hcgocjCafsVRtqYJUfTwA9coiQm1iH3gb/LHKC9VKi3kMScl IQMdHjW30n6wuRbtKO5sUGvCTnq11nxhk+K9izxI/TmJlnBBwpNP88uvE1ZWhi+Chutw etQ9CKKL/H5kL+lIxX22UX+NFjdkSRyoWAlfcMBVKbZZkxFLs8p/jz5WcYLOqzFmhvw9 Dywg== 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=SqJiOhNCq22EZRoeEyCe64JrTCeZS0bltKmhtfOge7OU9JFvjByt665KsHB5iIgkcC rQK5W7aUfiU0oSQeeiHW+pN6LYM2btyA/27T/egR7m6ny/7zdfNLNk0tgzA0EvWV092p 5ziRLIiaFroYfDYXqetO2AXUSYLEpa3a9GzOmRuojmVDEzMvagaj6Ijzw65g0yBKLKrO 7bb3Gnzv6INxaFe8WR+PIFZswTV5haj7k18KdppeW/mHDV65mYWRKK5qGkzV0Ole1L06 pbTfte5uC8eiAYTNadIeuM8sI76p1YGp+D6pQqFsSJQ6q88vZr1OjTqRShDhscguXP9r UKhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ABqtt4Sa; 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 w2si125269qte.123.2017.10.20.16.49.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 20 Oct 2017 16:49:17 -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=ABqtt4Sa; 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]:56094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5h2R-0005rE-NZ for patch@linaro.org; Fri, 20 Oct 2017 19:49:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5gbo-0006pV-Tt for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5gbn-000874-HV for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:44 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:43675) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5gbn-00086k-Av for qemu-devel@nongnu.org; Fri, 20 Oct 2017 19:21:43 -0400 Received: by mail-pf0-x244.google.com with SMTP id a8so13075748pfc.0 for ; Fri, 20 Oct 2017 16:21:43 -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=ABqtt4Sas3qnTZDvERVKYxAzohSvFdgXHXcUAtJkXvEPdJa9tBAXtqwmockPxlggUF hCc72VmWdOxM8x/DlLMABl86Bk13ZRNOvfsJwfZYets/EHm7rzZtMPgPW7jmNmtrxslM ElwoEuMI4l71C0yKt8D4RdcK+E/dZFJgjU/k8= 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=PSpImjpgcAJk9xgb+9Md/Ce+032tw5Pws/+YDqKhKaEuLqTW2L78FbLI6ahHYN1wci XVjkRnyCB4OqtS1WTkIHN8dcoFTkI30+ADAL18dEpqdhizXwAjeP1dB4XwJmzlAEcaqj a+LZcNT0+hUupwXUP+9duKvsxfrudUEanJKPnCv+P+4XVLLLaiHD1R1DwrVzerp2PDbr IS8oeECyjqZFKveqcysjIJ/W+/WCCeHB8oxcGpwUCwMICXxDWBY6FizFIcV1+ZxvudzI 4O6q72HDgBGRUgQjtKPOLpbnP1pNuEulOFeHE3wqaAMEZFos8xaonGfnsrLbrdaJ2DDS WAUg== X-Gm-Message-State: AMCzsaW8lh49NTP2iYucktr1mNO9hTpdRdfSEE7pzDFinu8GCDG0db3U IWyFBclLTX56ougNYqqQVxkOfOPz3IY= X-Google-Smtp-Source: ABhQp+R/OV4uxnwiOe4I+Nk4VcDolYfz4ij3r4gFJlmJ8WdqoNiTyZVrY8IJq1YDF9duWrvwn8KxMA== X-Received: by 10.98.74.23 with SMTP id x23mr6379849pfa.205.1508541702002; Fri, 20 Oct 2017 16:21:42 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-165-104.tukw.qwest.net. [97.113.165.104]) by smtp.gmail.com with ESMTPSA id a17sm3532594pfk.173.2017.10.20.16.21.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 16:21:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 20 Oct 2017 16:20:23 -0700 Message-Id: <20171020232023.15010-53-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020232023.15010-1-richard.henderson@linaro.org> References: <20171020232023.15010-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v7 52/52] 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: pbonzini@redhat.com, cota@braap.org, f4bug@amsat.org 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) {