From patchwork Mon Jul 2 16:05:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 140822 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp126847ljj; Mon, 2 Jul 2018 09:08:50 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeeOfpiQ6+UYk1PB3eoKjJAOAbS8pVyDYZebXfwIBvOzd71RJlssPJ2NYQc6ObWyRvDF9cT X-Received: by 2002:ac8:855:: with SMTP id x21-v6mr23911626qth.42.1530547730884; Mon, 02 Jul 2018 09:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530547730; cv=none; d=google.com; s=arc-20160816; b=faNtJFU/IeP9rsgcrGP5hXG8RBp28yoXInMJoHXq5nLis+hedZRsMMrx4KsLehnkw8 qHm4cZer2ptvEfemPUTwIxMs+D/cF5NJq3z2H74Hpczl3laY8E+/czFmZ0Yf5V+bTAkI iqLtTgCJbEQ21WYVewwF9qe9qkM89BmNVO35/MjNMTfA3NZ31V9gDfUPT4BdlIuh+sU7 wZUCF1u3f2kjGvX/nCsMQdWwif30qsVFDyHpkmJ/kIxqvVUO95uwf9yQLis2pn/ghWv0 tkXoqELRmLUWXSVxfP7hupcDPWGqg6fyJ0KuphYwGCcTU/P7JxONvL/0SyRMXgUG86xR Y8aw== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=IGwmuLsh0l2gOpw4+GfJn6vetrwThkU6G7pxtiS16GI=; b=yL5zz4rQ2ml0aLGbF8RReepv8r/vLa+/NGC2xaoKLezmPj7oruXaIbvxzsxtEWy/5A 8QeZTQN+9wtt75OJGjg/1Z6Kb0Q7baQUmdQiIFU34wzzpJ1F/dXOKfWVOcVzuLcT2VHo dt8sX8BMdNiOt8yS/sxpM0e+QPtY/LPGWGY3/nv3EQkYTnR+cYWK2XTqT2IR/5itSZAh 7hwbdh9FoEssTV3YF82TWujta0+iszYbn8k6aIhBeFHMFzYM9KFH9uXZPL/RfILEb6qy EP0zD2YarXJkVuGxp6cfRU2Tmj3QzGOAq20Z9bGtbnxdSXgVXgh1anlP0T79e6pMxRdT HYfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C2Md0bNO; 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 f5-v6si1569917qve.92.2018.07.02.09.08.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 02 Jul 2018 09:08:50 -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=C2Md0bNO; 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]:33983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1Ni-0005oE-AJ for patch@linaro.org; Mon, 02 Jul 2018 12:08:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa1Ks-0004dz-Q1 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:05:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa1Kp-0005OF-A3 for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:05:54 -0400 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:43876) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fa1Kp-0005O1-2C for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:05:51 -0400 Received: by mail-pf0-x229.google.com with SMTP id y8-v6so7719193pfm.10 for ; Mon, 02 Jul 2018 09:05:50 -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 :mime-version:content-transfer-encoding; bh=IGwmuLsh0l2gOpw4+GfJn6vetrwThkU6G7pxtiS16GI=; b=C2Md0bNOg8HAVyFm49dK5PPHCcxs7mTOgcPZmIGUuagFiirOaGPQZ4sHEsTVkWqjFC Z9zD5Hh6eFppqogCGYbF05nK9RbMeCon0/4ahhI/6yOzoTP+rSLAIoEvalrBI/IRJiFY tZcnQWMoCdC5swHleyYK0AWAK7V5y9RxSItgo= 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:mime-version:content-transfer-encoding; bh=IGwmuLsh0l2gOpw4+GfJn6vetrwThkU6G7pxtiS16GI=; b=AyL2f1VNCbCw1dDYSaWoNl8Zw+itiLtxjbgnAVzsGHJoXe7aGQ8GPixg78rhUVgAQZ kTWgJDiwGHXxbj9go4HNPuIs+q9DYFvMsNk3S9AQ8DeOreKUppwJiXFiib6LpPfIbAqu BjlRmbw4C/v0+vWwvHWvtLqI5LUrf52dNy+XZsDYRu6vxDRDPZ6PlNXFJWSesi769bO2 qOCsUec5HMCGIRGFGJYgv4wlybNUU8JxFPb9YQdkapBwzrrcQnDeTTqXbp3pdcxF3hZp +kdb8tVSQnKFUemb/n3UNBisp+b8WOkqWqiZ4e9uS4rqFmddHK1Efb1R1vbTMAwT2VgC n4GA== X-Gm-Message-State: APt69E0gz+jlQO1BhB1/lIn0WcLtT4a7K1WF5K7DmL8/rhm1TJ86Aklp swui0427VXnQN9Y/TBeHqEx4eTAxFbc= X-Received: by 2002:a62:b20c:: with SMTP id x12-v6mr17059845pfe.64.1530547549826; Mon, 02 Jul 2018 09:05:49 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id e17-v6sm38107002pfd.15.2018.07.02.09.05.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jul 2018 09:05:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 09:05:41 -0700 Message-Id: <20180702160546.31969-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180702160546.31969-1-richard.henderson@linaro.org> References: <20180702160546.31969-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::229 Subject: [Qemu-devel] [PULL 1/6] translate-all: fix locking of TBs whose two pages share the same physical page 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" Commit 0b5c91f ("translate-all: use per-page locking in !user-mode", 2018-06-15) introduced per-page locking. It assumed that the physical pages corresponding to a TB (at most two pages) are always distinct, which is wrong. For instance, an xtensa test provided by Max Filippov is broken by the commit, since the test maps two virtual pages to the same physical page: virt1: 7fff, virt2: 8000 phys1 6000fff, phys2 6000000 Fix it by removing the assumption from page_lock_pair. If the two physical page addresses are equal, we only lock the PageDesc once. Note that the two callers of page_lock_pair, namely page_unlock_tb and tb_link_page, are also updated so that we do not try to unlock the same PageDesc twice. Fixes: 0b5c91f74f3c83a36f37740969df8c775c997e69 Reported-by: Max Filippov Tested-by: Max Filippov Tested-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Emilio G. Cota Message-Id: <1529944302-14186-1-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index e8228bf3e6..170b95793f 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -669,9 +669,15 @@ static inline void page_lock_tb(const TranslationBlock *tb) static inline void page_unlock_tb(const TranslationBlock *tb) { - page_unlock(page_find(tb->page_addr[0] >> TARGET_PAGE_BITS)); + PageDesc *p1 = page_find(tb->page_addr[0] >> TARGET_PAGE_BITS); + + page_unlock(p1); if (unlikely(tb->page_addr[1] != -1)) { - page_unlock(page_find(tb->page_addr[1] >> TARGET_PAGE_BITS)); + PageDesc *p2 = page_find(tb->page_addr[1] >> TARGET_PAGE_BITS); + + if (p2 != p1) { + page_unlock(p2); + } } } @@ -850,22 +856,34 @@ static void page_lock_pair(PageDesc **ret_p1, tb_page_addr_t phys1, PageDesc **ret_p2, tb_page_addr_t phys2, int alloc) { PageDesc *p1, *p2; + tb_page_addr_t page1; + tb_page_addr_t page2; assert_memory_lock(); - g_assert(phys1 != -1 && phys1 != phys2); - p1 = page_find_alloc(phys1 >> TARGET_PAGE_BITS, alloc); + g_assert(phys1 != -1); + + page1 = phys1 >> TARGET_PAGE_BITS; + page2 = phys2 >> TARGET_PAGE_BITS; + + p1 = page_find_alloc(page1, alloc); if (ret_p1) { *ret_p1 = p1; } if (likely(phys2 == -1)) { page_lock(p1); return; + } else if (page1 == page2) { + page_lock(p1); + if (ret_p2) { + *ret_p2 = p1; + } + return; } - p2 = page_find_alloc(phys2 >> TARGET_PAGE_BITS, alloc); + p2 = page_find_alloc(page2, alloc); if (ret_p2) { *ret_p2 = p2; } - if (phys1 < phys2) { + if (page1 < page2) { page_lock(p1); page_lock(p2); } else { @@ -1623,7 +1641,7 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, tb = existing_tb; } - if (p2) { + if (p2 && p2 != p) { page_unlock(p2); } page_unlock(p);