From patchwork Fri Jun 3 20:40:16 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: 69277 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp447608qgf; Fri, 3 Jun 2016 13:43:06 -0700 (PDT) X-Received: by 10.55.201.154 with SMTP id m26mr5425335qkl.18.1464986586815; Fri, 03 Jun 2016 13:43:06 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d71si3463288qkj.177.2016.06.03.13.43.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 03 Jun 2016 13:43:06 -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]:57631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vvu-0001N2-BD for patch@linaro.org; Fri, 03 Jun 2016 16:43:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtX-0008RL-M8 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8vtW-0000UQ-Ei for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:39 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8vtV-0000SV-D0 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 16:40:38 -0400 Received: by mail-wm0-x22e.google.com with SMTP id m124so4111954wme.1 for ; Fri, 03 Jun 2016 13:40:37 -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=NFXIQzvIF3irwhoCrn/0sQrS58YJEi3y/qITkO3AGBs=; b=F+FMQnxq6KJLXFk46NSA+5MtU1d7T+wMfznWg3PG9bBn4AEg3nRjEF8bs7mlZsJUWl R7j0PsjWxpC6tqyBard9Q9DnY70BFHg/xluB9UBVJhjEw/9cHPKZOqJOAecouuKWWz3c IW9e3zNeBOhNruhtxiM+DgBVl2u3XozsbS9Lg= 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=NFXIQzvIF3irwhoCrn/0sQrS58YJEi3y/qITkO3AGBs=; b=IZ8BeKTRgQHtYcY7Y2icikj9uF6sH1GmYaCwrPPx4LpZKF6XTgfcE1o9p2cPaQZEkj GQdb6cpg8tdW/M0nO3RFgyhl9J4Fhf61bqHQr4krmp8ZChPtjScVGsiPucxGVK9XiTJL cOsFQ1uLgqUw+833/FlzcAakcz5fnZfZY50/SzWnvjEkKeEe6y9v87MACGaf0qiCXktu dDbzo0N0MvELBbTNsC3DhrdFEQnIsfyqNtjFALEVcX6ycwg2GgfthYDmjSc4cfV1rV3u Pt4x7IFq+/AclaWW77ebZ6U0cbHAa/j1A6Cdh1HhJEs9qMo/znZhmofjBsLb0lMY5BD8 yMYA== X-Gm-Message-State: ALyK8tJ6o0AdXDO5fUAZPrDkIuyzxBnRaxCAJQuG4dQR4MJrOs9m1zgDfH1mVNt393k6S0KO X-Received: by 10.28.61.137 with SMTP id k131mr1068412wma.37.1464986436713; Fri, 03 Jun 2016 13:40:36 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id ug8sm7368795wjc.42.2016.06.03.13.40.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 13:40:33 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C40C13E2DB2; Fri, 3 Jun 2016 21:40:39 +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, serge.fdrv@gmail.com, cota@braap.org, bobby.prani@gmail.com Date: Fri, 3 Jun 2016 21:40:16 +0100 Message-Id: <1464986428-6739-8-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1464986428-6739-1-git-send-email-alex.bennee@linaro.org> References: <1464986428-6739-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::22e Subject: [Qemu-devel] [RFC v3 07/19] translate-all: Add assert_memory_lock annotations 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, Peter Crosthwaite , claudio.fontana@huawei.com, Riku Voipio , mark.burton@greensocs.com, jan.kiszka@siemens.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" This adds calls to the assert_memory_lock for all public APIs which are documented as holding the mmap_lock for user-mode. Signed-off-by: Alex Bennée --- linux-user/elfload.c | 4 ++++ translate-all.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) -- 2.7.4 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index bb2558f..f72c275 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1839,6 +1839,8 @@ static void load_elf_image(const char *image_name, int image_fd, info->pt_dynamic_addr = 0; #endif + mmap_lock(); + /* Find the maximum size of the image and allocate an appropriate amount of memory to handle that. */ loaddr = -1, hiaddr = 0; @@ -1999,6 +2001,8 @@ static void load_elf_image(const char *image_name, int image_fd, load_symbols(ehdr, image_fd, load_bias); } + mmap_unlock(); + close(image_fd); return; diff --git a/translate-all.c b/translate-all.c index 8b162ff..aba6cb6 100644 --- a/translate-all.c +++ b/translate-all.c @@ -453,6 +453,10 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc) void **lp; int i; + if (alloc) { + assert_memory_lock(); + } + /* Level 1. Always allocated. */ lp = l1_map + ((index >> V_L1_SHIFT) & (V_L1_SIZE - 1)); @@ -819,6 +823,8 @@ static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; + assert_tb_lock(); + if (tcg_ctx.tb_ctx.nb_tbs >= tcg_ctx.code_gen_max_blocks) { return NULL; } @@ -831,6 +837,8 @@ static TranslationBlock *tb_alloc(target_ulong pc) /* Called with tb_lock held. */ void tb_free(TranslationBlock *tb) { + assert_tb_lock(); + /* In practice this is mostly used for single use temporary TB Ignore the hard cases and just back up if this TB happens to be the last one generated. */ @@ -1047,6 +1055,8 @@ void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr) uint32_t h; tb_page_addr_t phys_pc; + assert_tb_lock(); + /* remove the TB from the hash list */ phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); h = tb_hash_func(phys_pc, tb->pc, tb->flags); @@ -1125,6 +1135,8 @@ static inline void tb_alloc_page(TranslationBlock *tb, bool page_already_protected; #endif + assert_memory_lock(); + tb->page_addr[n] = page_addr; p = page_find_alloc(page_addr >> TARGET_PAGE_BITS, 1); tb->page_next[n] = p->first_tb; @@ -1181,6 +1193,8 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, { uint32_t h; + assert_memory_lock(); + /* add in the hash table */ h = tb_hash_func(phys_pc, tb->pc, tb->flags); qht_insert(&tcg_ctx.tb_ctx.htable, tb, h); @@ -1212,6 +1226,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef CONFIG_PROFILER int64_t ti; #endif + assert_memory_lock(); phys_pc = get_page_addr_code(env, pc); if (use_icount && !(cflags & CF_IGNORE_ICOUNT)) { @@ -1339,6 +1354,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, */ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) { + assert_memory_lock(); + while (start < end) { tb_invalidate_phys_page_range(start, end, 0); start &= TARGET_PAGE_MASK; @@ -1375,6 +1392,8 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, uint32_t current_flags = 0; #endif /* TARGET_HAS_PRECISE_SMC */ + assert_memory_lock(); + p = page_find(start >> TARGET_PAGE_BITS); if (!p) { return; @@ -1972,6 +1991,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) assert(end < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)); #endif assert(start < end); + assert_memory_lock(); start = start & TARGET_PAGE_MASK; end = TARGET_PAGE_ALIGN(end);