From patchwork Tue Nov 19 06:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 844265 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp1005157wrx; Mon, 18 Nov 2024 22:07:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVvwnlaEK23pKQeax+p+9mZ4pPPIQUld9L+XgR2Qh1wQrKSl64R0pHQuF6dZIiGr6kl5W6VDg==@linaro.org X-Google-Smtp-Source: AGHT+IF4mbmm4em9iJ+KOOY9XY5s7l4WZnfao4amozYqukPY6aITnZkH9AEyBEqHHTw9Gbg2T4LM X-Received: by 2002:a05:6214:570a:b0:6cc:378f:f7fb with SMTP id 6a1803df08f44-6d3fb88beb2mr217171106d6.35.1731996449176; Mon, 18 Nov 2024 22:07:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731996449; cv=none; d=google.com; s=arc-20240605; b=fp3co8Pt0lxTx8kptiF5xP5KFSZx88XE4N4YqGbMkUogKTu95UNmEF8gML1bHd9K+C 6ktB0ZITkgg62lnM9dpYVb2L5Il6FjaRBXmpvxA3ael7XtTCfJDPl/N/3ag4SzE3+xt4 hiwgX15+uQuTxL/S6hV+Qc29aHH4AxTm/YbXreWDGjBIDeAgaaOQg482JJn8K0IW68t0 KJ7kE/yP4Huizq2lr3r8MlgnJIxYgTkTw5tgPNUbb16+zcGM2zVX0Yxd01ziG+d4uCBw S93TUl09hiBPly6i65ESwVHMW6Z4AUHF8FbV5ubx9Wx4LQv6JHMzesGfvcRGfRyX8EnX Gx/Q== 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=reKyoe4ucz2+yLsBvPtbuTHP7MTUMsECyCoSlfiBDmc=; fh=bJM08QyuQI9qNgdwAnWtM8YuXTWExZXcb9tnmXCkn/A=; b=b8vCNnFrhf+fkaIsc7s3TkSUOa2kGlJPiUswDNGvpYnnsnUU2Y0THzT1mgekFmYIPg kHR7e6ASTdis4tBr3tBBW3d0vUs6LiicofW2FQjs+uGv4dPMOgXE7UBjkYWq65B4InA9 2iVQ+71QvbDHrdT0eaSs5+Nal277AbjLdtFJ8NQOUPZqpbYdDmUZdngV5RZO1Uqa/xQd 4GM2jT25SLKIRTWIHGYP5wizptpzp+SdNZoY+r3JCGg7W7vIfEYZEWPAaxSMyL9IGNOm a8RQ/HEdVXqlEBuLmNrGmYBn9lQm5iAhloD+YoQoCR2aQRc7/kf+D2KOIBeNroGNrDGz xx6A==; 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-7b37a8a3a19si150108385a.626.2024.11.18.22.07.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 22:07:29 -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 1tDHM3-0001Aj-Py; Tue, 19 Nov 2024 01:04:52 -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 1tDHM0-00018y-QK; Tue, 19 Nov 2024 01:04:48 -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 1tDHLz-0004gE-0r; Tue, 19 Nov 2024 01:04:48 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 21C63A626A; Tue, 19 Nov 2024 09:04:15 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 49D461738DF; Tue, 19 Nov 2024 09:04:19 +0300 (MSK) Received: (nullmailer pid 2368954 invoked by uid 1000); Tue, 19 Nov 2024 06:04:18 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Pierrick Bouvier , Richard Henderson , Michael Tokarev Subject: [Stable-9.1.2 67/72] target/i386: fix hang when using slow path for ptw_setl Date: Tue, 19 Nov 2024 09:04:08 +0300 Message-Id: <20241119060418.2368866-10-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/3a41aa8226bdaa709121515faea6e0e5ad1efa39 in 9.1.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 9.1.x series) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index da732c2ca8..b812a9a97b 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -107,6 +107,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); @@ -114,6 +118,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; }