From patchwork Sat Mar 6 21:35:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 394557 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp549934jai; Sat, 6 Mar 2021 13:39:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFM1KAZT6Tx/G10F4HotYw2wzDWnbQ4enpUgrHzYQ7msiAG+P3OL4XaS9O5d94A7rcLDWk X-Received: by 2002:a25:d14d:: with SMTP id i74mr22604662ybg.38.1615066746500; Sat, 06 Mar 2021 13:39:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615066746; cv=none; d=google.com; s=arc-20160816; b=ON7yf9ugvmyZGuVenHl9HaWIINKE1ZD+koiaKkABUzlzWH2eVHu4PXKCQaqD/HbqQ4 oiBSdkC467aQbMKNKgk75eJmlc897/0XDoqtkoJJs/qOTPiXQA6nolTQnKvY3i70XxDX 6HOJdttYfe56kRvQihP1z9ama28BYG3V+NhT77iCuOSJIt1JIL4rx/vJfnEL+HsN44Zh JeI5apb/J6zwZY+Yf+SZU60EFxc/RMVtn5Xahdzij7ZxRTsB2noL/IvDLLPsPYSZzbah L17uRT5Vg0DSaJhZzlf7ZyZlDDKTZASH/onQn2589uVwUWzWL+WOPv7+E1gXDP9Y2fm1 mUyw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=vXWtOAbqO0IiL4x1PJ+ry/MmusWHvhWYDh4bY00za1s=; b=Mj3aScAiRUKaD/hWnWvFlxoJnLRgUaYoqGf/VAP7OjdROmHZRcIj7aaqzxKfY5j/6W YKOOcOz3BJ/iJe7F3a0ykhtuPap+FfKDNv3u5duKnzovfMSKhEBT7yHnsBYDhERXP2pc h2nVkPf6dFZZ/MRJr4XgUX7lX06Y7FeLw2vJBgRyUOsfvlI0d9OnvM05rNLt6JoeOY3h VovF2h/VBoTgcF6kLjnBSY1+cDKXmjJ7wg04dGm8UAC5JCBkQhqkSjlH2YelH9J1Q5tI TxhnwXNivbJWiwS2I+d3g8R5+D47prh4kesanaYN+vqBfI5Ys5W7J50IfltLQHi4/cdz 4odA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kpd50Ibp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 130si6483646ybu.189.2021.03.06.13.39.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 06 Mar 2021 13:39:06 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kpd50Ibp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIedd-00023E-UK for patch@linaro.org; Sat, 06 Mar 2021 16:39:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIeb9-0006y7-AP for qemu-devel@nongnu.org; Sat, 06 Mar 2021 16:36:32 -0500 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:36968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lIeb1-0002x1-0l for qemu-devel@nongnu.org; Sat, 06 Mar 2021 16:36:31 -0500 Received: by mail-pg1-x533.google.com with SMTP id o10so3810024pgg.4 for ; Sat, 06 Mar 2021 13:36:22 -0800 (PST) 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=vXWtOAbqO0IiL4x1PJ+ry/MmusWHvhWYDh4bY00za1s=; b=kpd50IbpVc4XoNRRhBIyqS/ZxPYamEXvdvmIBrR7iaiaguawXE8gkB9DbAyDD452Pe SkZeMyfrUG/WsMrjrbqIXkP4X++oG+YpBDQQwSU4WZeztZ3TN3c/EcX0ADCulcRXVoBJ fpYL7yzbnUhzjunklXCNcTkaJCESSZNvqH7OayK8EQ/4kkWvS9NV/1EANyAdtHbqNck5 Jtf6xfouVN4flotOUlGj89sCpTDpeaHs1HMSs9mypgLelSGU7od9AIMa8fFr3jAxohke jm7Z0zsvMbLCm+4GRZGJSf7azKQm/UMY6Xz44Fhea4QLNn/xW+KvjnFmnf9lbDvcu6jC K5OQ== 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=vXWtOAbqO0IiL4x1PJ+ry/MmusWHvhWYDh4bY00za1s=; b=nnvCb0eL3SyZ3LcChGu9hK+yjoqPDQu5Ylt05tN9vPgcNZtFAv0d6RQRL56UCrWWu/ cQb+Ll1OjjhgSPohSU7pSzN47y49RHHjOjE8KMf8aYgga6HeHB5r9Qkf8UdMxMNTMH2f 8LmtkiNKv7r0BtuBdCia1s4ebB+TYU6+75Umjx1T6gpyS2Hnv4AWbjCZxD8Xgj9MjVGD WVfUGZo2S3CnVogcWSS7c73nY53BlVDD8lfCeJ4OnDjZaAfVKE0sS6d9mC12fx9325X9 wN8kdmb5CKe/WfOidQGfdPEOI7nqqgLdMxNKHPAlbXi68yP9HFe7DEc6WBjnkVtt5/fW vxMw== X-Gm-Message-State: AOAM5335jP97+a51cT+tUr040IRvH0uCE6ak6k3TC86xIDlXAn+YxwwK nmhRgLS0bAyTulM0Htp4ffhQxvaiAAyLdA== X-Received: by 2002:a63:4e26:: with SMTP id c38mr14266789pgb.81.1615066581606; Sat, 06 Mar 2021 13:36:21 -0800 (PST) Received: from localhost.localdomain ([71.212.131.83]) by smtp.gmail.com with ESMTPSA id r30sm6365616pgu.86.2021.03.06.13.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 13:36:21 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 06/27] tcg: Manage splitwx in tc_ptr_to_region_tree by hand Date: Sat, 6 Mar 2021 13:35:52 -0800 Message-Id: <20210306213613.85168-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210306213613.85168-1-richard.henderson@linaro.org> References: <20210306213613.85168-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The use in tcg_tb_lookup is given a random pc that comes from the pc of a signal handler. Do not assert that the pointer is already within the code gen buffer at all, much less the writable mirror of it. Fixes: db0c51a3803 Signed-off-by: Richard Henderson --- tcg/tcg.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/tcg/tcg.c b/tcg/tcg.c index bbe3dcee03..2991112829 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -513,11 +513,21 @@ static void tcg_region_trees_init(void) } } -static struct tcg_region_tree *tc_ptr_to_region_tree(const void *cp) +static struct tcg_region_tree *tc_ptr_to_region_tree(const void *p) { - void *p = tcg_splitwx_to_rw(cp); size_t region_idx; + /* + * Like tcg_splitwx_to_rw, with no assert. The pc may come from + * a signal handler over which the caller has no control. + */ + if (!in_code_gen_buffer(p)) { + p -= tcg_splitwx_diff; + if (!in_code_gen_buffer(p)) { + return NULL; + } + } + if (p < region.start_aligned) { region_idx = 0; } else { @@ -536,6 +546,7 @@ void tcg_tb_insert(TranslationBlock *tb) { struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); + g_assert(rt != NULL); qemu_mutex_lock(&rt->lock); g_tree_insert(rt->tree, &tb->tc, tb); qemu_mutex_unlock(&rt->lock); @@ -545,6 +556,7 @@ void tcg_tb_remove(TranslationBlock *tb) { struct tcg_region_tree *rt = tc_ptr_to_region_tree(tb->tc.ptr); + g_assert(rt != NULL); qemu_mutex_lock(&rt->lock); g_tree_remove(rt->tree, &tb->tc); qemu_mutex_unlock(&rt->lock); @@ -561,6 +573,10 @@ TranslationBlock *tcg_tb_lookup(uintptr_t tc_ptr) TranslationBlock *tb; struct tb_tc s = { .ptr = (void *)tc_ptr }; + if (rt == NULL) { + return NULL; + } + qemu_mutex_lock(&rt->lock); tb = g_tree_lookup(rt->tree, &s); qemu_mutex_unlock(&rt->lock);