From nobody Tue Oct 28 12:38:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522981318474357.71575287434086; Thu, 5 Apr 2018 19:21:58 -0700 (PDT) Received: from localhost ([::1]:44031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4H0g-0000tG-6T for importer@patchew.org; Thu, 05 Apr 2018 22:21:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4GsM-0002GY-IR for qemu-devel@nongnu.org; Thu, 05 Apr 2018 22:13:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f4GsK-0003WA-Ar for qemu-devel@nongnu.org; Thu, 05 Apr 2018 22:13:14 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:51093) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f4GsK-0003Vf-3h for qemu-devel@nongnu.org; Thu, 05 Apr 2018 22:13:12 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BDAB020AAB; Thu, 5 Apr 2018 22:13:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 05 Apr 2018 22:13:11 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 78616E47F2; Thu, 5 Apr 2018 22:13:11 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=uqRllghnUkBKksf2jlpdVeuO7e vjSaWxdutgQHV4V0c=; b=wGNAqjMoM1RZlbl+E5oIve0Bw64NIIOaS7K+5p0lde 3UKsYEDz/JGOq4CR4BWIrsC4290u3WMjmNHCba0DzfdbK+3JEhXNGikHL+YZ8Sc2 6Kh4DeSn5cQXeIcCSMyNCGhadDjjc5ht+g2mr9X8R+GmA05dnGQafDaVn5knl6ko 4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=uqRllg hnUkBKksf2jlpdVeuO7evjSaWxdutgQHV4V0c=; b=k+TiAx/Kerqx+v3zY3c9y7 qPV8/8h23j0KzLXkSyogpYKVvdmxLJiB1wWiZ+07sha2fO0D8e71NRyBkGGicrUM bJSMTnKBqbOr08RUnpT9X0eSxou+9lHW+bkQJRc8EQnbRFMYCAmzN9Jg43VUQFZc i/s2WTxC0HNe/aeMQ65NHGH2j4/qEXwpPCvvQjIlGnmOsyfk2yXRyt6oElfAHdsE muGCBv893/r5zle7rni9YzNsb3BADQ2V7EAKtEa1bb8XZdVqNVPBP50Lv9scKEzn nvRhYPi8vQEHGy1OrGauPwrPJ0/Ag0ExcODjpEePxjBR1buL5sMs2QPyZhGMmD6Q == X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 5 Apr 2018 22:13:03 -0400 Message-Id: <1522980788-1252-13-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522980788-1252-1-git-send-email-cota@braap.org> References: <1522980788-1252-1-git-send-email-cota@braap.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.29 Subject: [Qemu-devel] [PATCH v2 12/17] translate-all: add page_collection assertions 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: Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 The appended adds assertions to make sure we do not longjmp with page locks held. Some notes: - user-mode has nothing to check, since page_locks are !user-mode only. - The checks only apply to page collections, since these have relatively complex callers. - Some simple page_lock/unlock callers have been left unchecked -- namely page_lock_tb, tb_phys_invalidate and tb_link_page. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Emilio G. Cota --- include/exec/exec-all.h | 8 ++++++++ accel/tcg/cpu-exec.c | 1 + accel/tcg/translate-all.c | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index aeaa127..7911e69 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -431,6 +431,14 @@ void tb_lock(void); void tb_unlock(void); void tb_lock_reset(void); =20 +#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_DEBUG_TCG) +void assert_page_collection_locked(bool val); +#else +static inline void assert_page_collection_locked(bool val) +{ +} +#endif + #if !defined(CONFIG_USER_ONLY) =20 struct MemoryRegion *iotlb_to_region(CPUState *cpu, diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 778801a..6a3a21d 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -271,6 +271,7 @@ void cpu_exec_step_atomic(CPUState *cpu) tcg_debug_assert(!have_mmap_lock()); #endif tb_lock_reset(); + assert_page_collection_locked(false); } =20 if (in_exclusive_region) { diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 29bc1da..f8862f6 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -666,6 +666,18 @@ do_assert_page_locked(const PageDesc *pd, const char *= file, int line) =20 #define assert_page_locked(pd) do_assert_page_locked(pd, __FILE__, __LINE_= _) =20 +static __thread bool page_collection_locked; + +void assert_page_collection_locked(bool val) +{ + tcg_debug_assert(page_collection_locked =3D=3D val); +} + +static inline void set_page_collection_locked(bool val) +{ + page_collection_locked =3D val; +} + #else /* !CONFIG_DEBUG_TCG */ =20 #define assert_page_locked(pd) @@ -678,6 +690,10 @@ static inline void page_unlock__debug(const PageDesc *= pd) { } =20 +static inline void set_page_collection_locked(bool val) +{ +} + #endif /* CONFIG_DEBUG_TCG */ =20 static inline void page_lock(PageDesc *pd) @@ -754,6 +770,7 @@ static void do_page_entry_lock(struct page_entry *pe) page_lock(pe->pd); g_assert(!pe->locked); pe->locked =3D true; + set_page_collection_locked(true); } =20 static gboolean page_entry_lock(gpointer key, gpointer value, gpointer dat= a) @@ -846,6 +863,7 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr= _t end) set->tree =3D g_tree_new_full(tb_page_addr_cmp, NULL, NULL, page_entry_destroy); set->max =3D NULL; + assert_page_collection_locked(false); =20 retry: g_tree_foreach(set->tree, page_entry_lock, NULL); @@ -864,6 +882,7 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr= _t end) page_trylock_add(set, tb->page_addr[1]))) { /* drop all locks, and reacquire in order */ g_tree_foreach(set->tree, page_entry_unlock, NULL); + set_page_collection_locked(false); goto retry; } } @@ -876,6 +895,7 @@ void page_collection_unlock(struct page_collection *set) /* entries are unlocked and freed via page_entry_destroy */ g_tree_destroy(set->tree); g_free(set); + set_page_collection_locked(false); } =20 #endif /* !CONFIG_USER_ONLY */ --=20 2.7.4