From patchwork Mon Nov 18 19:35:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 844112 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp802909wrx; Mon, 18 Nov 2024 11:38:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUyMAwHxmvzqXR+nOhmSxn8pHLTs8Y3zbqQ8UNQsvRXB6IWymo6La2RUpXeMUq94AcncVOzsw==@linaro.org X-Google-Smtp-Source: AGHT+IHcU53q3Fe8KMYtaqHZxUMH9WIWjMSKvsZW0yCdhT24Pkm1lES8wyLFTQClPrRz8uwDSo6o X-Received: by 2002:a05:620a:2410:b0:7b1:547d:9ba8 with SMTP id af79cd13be357-7b3622e7975mr2231424085a.21.1731958680688; Mon, 18 Nov 2024 11:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731958680; cv=none; d=google.com; s=arc-20240605; b=a5i8K+I5xV5KTZ4pRrXKYv96WW9FBUZiZrzrvPZlFDGN4w6CowN5RHLNokeakskQI9 apLuUGWl+7hijlxW5AAbYf+HeLDjeuVVaJX6WryeY6RbSy2T1AQ4pz8Z3lfSB+gF/gj0 TjG9SJIUkh+lFPvjtfya5P/Z4GRLnpnlm47uW7aFThyvFL6bxQD+1GFpomk6wf20nrk9 9oiRUSihsB0ShqGc/ImdFQUcI4mjytPdXtaQLJ2qPompjCwp08drHTpuwn5aP59kkF7p EQW21FrfY0y9RHQM6IUA7lH3HAb7c6e5kpAAf2heNEsU0Zr+KgDkdtrQztrk6RpI6HGO NF8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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:cc:to :from; bh=0k1fv1CCRxYpdRoxLTdajprJZKj15SpWvDdhqsnw6/o=; fh=bJM08QyuQI9qNgdwAnWtM8YuXTWExZXcb9tnmXCkn/A=; b=INYac52NEMX+xk/1y+5bT47lM/W7N5JRPqEacB8yS/aCU4qYxMK8TBH6GdOxvERDKt XObGoGbBQT4xRfU5CgaLOrB/oUTjAX/FkNMlWfbOlvO5kWpKz2xYO6MUMxjc8GWa5RWQ oNxyPYOjvGd1DNpVzbwvBBRbSx1Mq6JV+gBV992ybKYRW6sRrxcNlpmaCte5znBvLfNA spN5KLqtJOLRuj2uWxYZ2SEIWqYRcYfT7ZR+U+sS3cUTA0FWgE/Cs510Tp7N4dTBxuzL DWyUM9cnUxUHOQiV2klUES8PfHYx6u0kbbyosY5dNIS0t/JJX8aNf7PZ6BzNQFDsGSEi XkoQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b37a84afabsi39378085a.177.2024.11.18.11.38.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 11:38:00 -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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD7XQ-0006fi-7L; Mon, 18 Nov 2024 14:35:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tD7XM-0006fA-3v; Mon, 18 Nov 2024 14:35:53 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tD7XC-0002i3-KE; Mon, 18 Nov 2024 14:35:44 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id BF0D4A54E6; Mon, 18 Nov 2024 22:35:17 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3EBC91735A3; Mon, 18 Nov 2024 22:35:21 +0300 (MSK) Received: (nullmailer pid 2312695 invoked by uid 1000); Mon, 18 Nov 2024 19:35:20 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Pierrick Bouvier , Richard Henderson , Michael Tokarev Subject: [Stable-8.2.8 57/61] target/i386: fix hang when using slow path for ptw_setl Date: Mon, 18 Nov 2024 22:35:12 +0300 Message-Id: <20241118193520.2312620-9-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.5 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier When instrumenting memory accesses for plugin, we force memory accesses to use the slow path for mmu [1]. This create a situation where we end up calling ptw_setl_slow. This was fixed recently in [2] but the issue still could appear out of plugins use case. Since this function gets called during a cpu_exec, start_exclusive then hangs. This exclusive section was introduced initially for security reasons [3]. I suspect this code path was never triggered, because ptw_setl_slow would always be called transitively from cpu_exec, resulting in a hang. [1] https://gitlab.com/qemu-project/qemu/-/commit/6d03226b42247b68ab2f0b3663e0f624335a4055 [2] https://gitlab.com/qemu-project/qemu/-/commit/115ade42d50144c15b74368d32dc734ea277d853 [2] https://gitlab.com/qemu-project/qemu/-/commit/9a96406787afcc9960fbe8791892c78311d6971f in 8.2.x series [3] https://gitlab.com/qemu-project/qemu/-/issues/279 Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2566 Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Message-ID: <20241025175857.2554252-2-pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson (cherry picked from commit 7ba055b49b74c4d2f4a338c5198485bdff373fb1) Signed-off-by: Michael Tokarev (Mjt: mention [2] in 8.2.x series) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index bdf7b0df42..44b1b2ded6 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -106,6 +106,10 @@ static bool ptw_setl_slow(const PTETranslate *in, uint32_t old, uint32_t new) { uint32_t cmp; + CPUState *cpu = env_cpu(in->env); + /* We are in cpu_exec, and start_exclusive can't be called directly.*/ + g_assert(cpu->running); + cpu_exec_end(cpu); /* Does x86 really perform a rmw cycle on mmio for ptw? */ start_exclusive(); cmp = cpu_ldl_mmuidx_ra(in->env, in->gaddr, in->ptw_idx, 0); @@ -113,6 +117,7 @@ static bool ptw_setl_slow(const PTETranslate *in, uint32_t old, uint32_t new) cpu_stl_mmuidx_ra(in->env, in->gaddr, new, in->ptw_idx, 0); } end_exclusive(); + cpu_exec_start(cpu); return cmp == old; }