From patchwork Thu Aug 11 15:24:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 73777 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp172491qga; Thu, 11 Aug 2016 08:40:38 -0700 (PDT) X-Received: by 10.237.54.34 with SMTP id e31mr11353510qtb.132.1470930038058; Thu, 11 Aug 2016 08:40:38 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b127si575721qkf.4.2016.08.11.08.40.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 11 Aug 2016 08:40:38 -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; 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 dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXs61-0000qH-GE for patch@linaro.org; Thu, 11 Aug 2016 11:40:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrqg-0003qD-7c for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:24:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXrqf-0006em-5i for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:24:46 -0400 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:37896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXrqe-0006eZ-Um for qemu-devel@nongnu.org; Thu, 11 Aug 2016 11:24:45 -0400 Received: by mail-wm0-x229.google.com with SMTP id o80so3128079wme.1 for ; Thu, 11 Aug 2016 08:24:44 -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=nTMnM7CfCN4/KFKkuC1gSp6nviT8yxldu66wt/BKJrs=; b=AsAVheKOYZEEkIfJnjwcW3quHuIY3aXzMAovobZnPNH2yKY5Z4x4r+SjudMLq4k/D4 RFNtc8kmJ3U0qHjHoGYCm9vZXGR1/LFXdlKBfoyIJ6BBMUorDUxo3ya+L47tL0AA/ZYR CT854OwJMC9/Wzm4jUFvJkJqtgJ0FFW1Xr7Zc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nTMnM7CfCN4/KFKkuC1gSp6nviT8yxldu66wt/BKJrs=; b=NiB5+fntYF9qxWikZQc74Y9Q5jTlbL+cUNFaCIrvOL5yWuSmp3tVFdjQ6F/IsURAOr Keqg9P3CI8yuA0MhXADXMq72coD58s+W3GD7loNLdlTqkny2Olsi4EykchK+RRIATr20 pSxScfT9OsCNApaykd+fZR00FKbfEIEwrq3b15yVKCqwe2nqrfFLukBcHcWGEy/f3UDh MXqqOjgOU8dQZeV8+BtlZ5IT2zNo7MFXS+SmhaLrRPLz5WBhHbWjUGwvP93A01Og5Fqt 6r0CCowqTDaFTTi13l7XyRo0len+zFDjZl0RqSLjhDw/EX2GqEbfWgZp6fyhax4PxmTN wkSA== X-Gm-Message-State: AEkoouvr2uUTChw4l8qMPN6JCz0eRM9t4TXlFo754+pJrC3YNAiQUyxQqcPoPjtXNFdcbdZA X-Received: by 10.28.226.85 with SMTP id z82mr10624838wmg.101.1470929084278; Thu, 11 Aug 2016 08:24:44 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n131sm609082wmd.3.2016.08.11.08.24.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 08:24:41 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 70B853E033F; Thu, 11 Aug 2016 16:24:31 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com Date: Thu, 11 Aug 2016 16:24:17 +0100 Message-Id: <1470929064-4092-22-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org> References: <1470929064-4092-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::229 Subject: [Qemu-devel] [RFC v4 21/28] tcg: enable tb_lock() for SoftMMU 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, claudio.fontana@huawei.com, Peter Crosthwaite , jan.kiszka@siemens.com, mark.burton@greensocs.com, serge.fdrv@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , rth@twiddle.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" tb_lock() has long been used for linux-user mode to protect code generation. By enabling it now we prepare for MTTCG and ensure all code generation is serialised by this lock. The other major structure that needs protecting is the l1_map and its PageDesc structures. For the SoftMMU case we also use tb_lock() to protect these structures instead of linux-user mmap_lock() which as the name suggests serialises updates to the structure as a result of guest mmap operations. Signed-off-by: Alex Bennée --- v4 - split from main tcg: enable thread-per-vCPU patch --- translate-all.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/translate-all.c b/translate-all.c index c53ae8c..cfb009a 100644 --- a/translate-all.c +++ b/translate-all.c @@ -82,7 +82,11 @@ #endif #ifdef CONFIG_SOFTMMU -#define assert_memory_lock() do { /* nothing */ } while (0) +#define assert_memory_lock() do { \ + if (DEBUG_MEM_LOCKS) { \ + g_assert(have_tb_lock); \ + } \ + } while (0) #else #define assert_memory_lock() do { \ if (DEBUG_MEM_LOCKS) { \ @@ -146,36 +150,28 @@ static void *l1_map[V_L1_SIZE]; TCGContext tcg_ctx; /* translation block context */ -#ifdef CONFIG_USER_ONLY __thread int have_tb_lock; -#endif void tb_lock(void) { -#ifdef CONFIG_USER_ONLY assert(!have_tb_lock); qemu_mutex_lock(&tcg_ctx.tb_ctx.tb_lock); have_tb_lock++; -#endif } void tb_unlock(void) { -#ifdef CONFIG_USER_ONLY assert(have_tb_lock); have_tb_lock--; qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); -#endif } void tb_lock_reset(void) { -#ifdef CONFIG_USER_ONLY if (have_tb_lock) { qemu_mutex_unlock(&tcg_ctx.tb_ctx.tb_lock); have_tb_lock = 0; } -#endif } #ifdef DEBUG_LOCKING @@ -184,15 +180,11 @@ void tb_lock_reset(void) #define DEBUG_TB_LOCKS 0 #endif -#ifdef CONFIG_SOFTMMU -#define assert_tb_lock() do { /* nothing */ } while (0) -#else #define assert_tb_lock() do { \ if (DEBUG_TB_LOCKS) { \ g_assert(have_tb_lock); \ } \ } while (0) -#endif static TranslationBlock *tb_find_pc(uintptr_t tc_ptr);