From patchwork Mon Nov 18 21:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 844129 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp839071wrx; Mon, 18 Nov 2024 13:11:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVkTms1o06ghQQ8lYXw/XDt9pXpqlZXcXy+7TQP0TybdtcXAEYx6HZVzHK3J62maf6BcQ2mtw==@linaro.org X-Google-Smtp-Source: AGHT+IHtuP6x9KfQ+4gv0QOd5bqgtE0bs6jZ3AR6DTRDxSr9uTFP9ANL5VZNrZi+60oDmkY9mOCw X-Received: by 2002:a05:622a:22a3:b0:463:59f2:1835 with SMTP id d75a77b69052e-46363ec8b91mr198533581cf.54.1731964295001; Mon, 18 Nov 2024 13:11:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731964294; cv=none; d=google.com; s=arc-20240605; b=HKj16SaC3E74MxVzzKttsagK93uXGXF7vBi2vAtSo56jiYpAQ2ZskbOWaobHm+N0E/ Ocjn2UaYGZZhI6nxP6hMZ0FqXEm23Hu8Z7rbXiPScOMVLH9gqO9VNCPS9cOTYRs9ny5b LnRWrZ7ViZJii0RhQVsttZwCnryr8h9VQ6GRcHxXtgJApAsd3MMW7oOMDo9udzagwHzz PszXZ93VFCTCXKDG2ssioSjPBW0QATsElzf7ayrpY9bHK4E4HTbja5iA3N6Gx/6sULNu y4OA3ozFvCWmfNMiC9S0JX2gfXY5XVDF5t7z9HRgbliI+gNvd4HlY8D4MDdXXQwzQR6K ejmQ== 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=PuBVO93AEuyE7XllskxYUzp40s5BcEb0mMM2BFe9d1E=; fh=bJM08QyuQI9qNgdwAnWtM8YuXTWExZXcb9tnmXCkn/A=; b=ah8A8hxuUVIozlQoh1HlpvP89YHQYQu0dvVWTxZ8LcuuejDoN4ja33x5JBl0WDKjnX feoObtgHdT+WbwCxGMN9HUknePkVT4LzJ5IgWi2jjPBcTy7K2XVnMMav3rk9ZsSFsBKE gM7LCYW4/qhKzAxDPKWs4nNPkEKBQOS9fojPqOtsqvp5JfD+thvSFe16qVtiCxtdo5G5 T8P8UORmRY9+d7sQcreYMM+rH6UWCoqJwImZbOW0vzYhwYluI3MlnXcGfHnmBBFvMTLF mUhTM4kptEg6H7mV3VbWjadXd/w2rJBljnZlp9PQE6bFYm1ZBcUs2CrnVVMKMIVep49r YIpg==; 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 d75a77b69052e-46392c429e5si5212141cf.421.2024.11.18.13.11.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 13:11:34 -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 1tD90E-00033y-97; Mon, 18 Nov 2024 16:09:46 -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 1tD8zT-0001w0-Ao; Mon, 18 Nov 2024 16:08:59 -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 1tD8zR-0005PS-Cz; Mon, 18 Nov 2024 16:08:58 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id C44B7A5610; Tue, 19 Nov 2024 00:08:31 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 5D939173629; Tue, 19 Nov 2024 00:08:35 +0300 (MSK) Received: (nullmailer pid 2366125 invoked by uid 1000); Mon, 18 Nov 2024 21:08:34 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Pierrick Bouvier , Richard Henderson , Michael Tokarev Subject: [Stable-9.0.4 67/71] target/i386: fix hang when using slow path for ptw_setl Date: Tue, 19 Nov 2024 00:08:24 +0300 Message-Id: <20241118210834.2366046-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/88442869cf709f885a9c09fad00b96f802d58ffe in 9.0.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.0.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; }