From patchwork Wed Oct 23 22:20:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 837830 Delivered-To: patch@linaro.org Received: by 2002:adf:a399:0:b0:37d:45d0:187 with SMTP id l25csp61696wrb; Wed, 23 Oct 2024 15:21:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUBRxpTva7C6Dcgse6sy7DT3soxIDYCIsNiDURTfjcQbjYHyD+cszpaYx0rhIr95Pb+xsq41A==@linaro.org X-Google-Smtp-Source: AGHT+IGgFUCZvzxiRIabO3WVFnWIBuAybCvdNURAdqPW7jxQUObqYTcQ7hHT21MQlBtD4CqB7KSY X-Received: by 2002:a05:620a:4544:b0:7b1:4aa3:d3c9 with SMTP id af79cd13be357-7b17e5bd72cmr579376385a.61.1729722091169; Wed, 23 Oct 2024 15:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729722091; cv=none; d=google.com; s=arc-20240605; b=h57WhPAU0982GsGuKChrSyFderEUXqvla/6xRxV40PIw61WGSdawDXH22+1DHLenlA LKkIEgT45tLsFB0gFooqJZmwsDKqFcDISgWWcT71g0yR47cXgXtyV/0rNv/i8hoHJ/Q9 iSJedei1d9LlfDgcpvoSEtw5i30ZPEUdHcraLTEBFW5t77WM55Sz1J9idm8unn/OKMck B4Z6GhZoVpSnm6U7uNiI+68w4ev+JFTbNPZKmFBYm+0nHZEqrzsECweAyT+cHESdZFL4 4BIk+TW9yQHOy3YKwKKe0xMOhPMq+MiCEprW07E+ifYsoGgZE6Ya0DSQzTDE7sNpx3XS cPFA== 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:dkim-signature; bh=r5913GPkL4WEYCP3Y6kC6MHAYq2/hchSUBRFU1ZK8b4=; fh=BRvItN/qD5wknT+tulENMlwWp7K26sWk2V65AM8JNtw=; b=I1Y45nat7akQml4QLmPshVaUAS8qBHbmhvWYHu6MFwVLNQFh/gmWZWP58vX5+Nbfix AnTRBUXP406Pv489HCZSCDrDd8GjjQnkF92RXvUCMTL728XN3RNeKib4BJcg6B03CkGc td1pbRStO9aJNAlMzJN0FlAFrjmeVCyK7Za49m9x4y0uRavotn3rs0fVn6HsHWYATiHM W0hjbmF03mQUAObEEv6arZgGW0NtaIzm7Et4A30DX21dVlHmaFTgRCyinEp3Wkyj7dUc j0pSsZ0bEzpBOxwosX4s9bD/xcxIbwRuk9ZF1ZnE/sgKQcQLjjINEPMUnl0rma9dzdN2 0rxQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZbSMBF89; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b165a8930fsi1003019985a.486.2024.10.23.15.21.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Oct 2024 15:21:31 -0700 (PDT) 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=ZbSMBF89; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3jig-0004uH-IP; Wed, 23 Oct 2024 18:20:46 -0400 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 1t3jia-0004tL-8e for qemu-devel@nongnu.org; Wed, 23 Oct 2024 18:20:40 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3jiY-00060z-9S for qemu-devel@nongnu.org; Wed, 23 Oct 2024 18:20:39 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-20c7ee8fe6bso1686065ad.2 for ; Wed, 23 Oct 2024 15:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729722036; x=1730326836; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r5913GPkL4WEYCP3Y6kC6MHAYq2/hchSUBRFU1ZK8b4=; b=ZbSMBF892lB0U16ItLKEJA0lgZnezkp6C2ZlH2mCg/EkMLXvjBqWALPhMqNJcvB3P4 PvVi9Da86Kl3xUMqJErpQsf0zmhGKbHfe6XwKgfHN1UMa0S79ckl2xPPNiM+dU/2WhO5 PnVaTdQBSq4Ab8+J6ddaic7S34+qz6EzMHjjRRwrCsgBaqejUrTbaBS01bmnpIAXSxEk ouczT6gzQ2TDjU3Fzz4IwCas6Q5I4jD14Lo3swluviuqaRJxHmEBV7Cj4IT7u/yBcaxj hyFT4R3CHxwcfz+AN7XXAOv0dQaCoVUI5m+S/H4QBKLqrSnP3Mkdo4X+WUTq8e14ecUR qsqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729722036; x=1730326836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r5913GPkL4WEYCP3Y6kC6MHAYq2/hchSUBRFU1ZK8b4=; b=cFMQootD3aXuXhCY6Y0Mdr6k4a1cWN1a1PDJ2mON3rmzszD5bGfOggQLKKRSMiQ/0i W3bpGOVrOcdZqOILuCyAF++UEpXfP+2LNwPmnWIvQPFtmx/mE+9Jy0f1hJIvXFrsnBTG 7SmbwTLwEiLWqVU2hbfuOc1VJqJq0U+lbZ0VqQ5jGDz9ObaBcXeYdzup95OxSJg3miUp XpRMX8zz3caDezax4wn9n0EX4CfHy9OSChjxvzxwYpI1MPuHogXU3qY7BhQ8ypJeKoBL 02cEhE65oNg8g6zJ1L28FQLCw8HoLXmqYVfIupqks+ubGqNjgbu1VUCa5jiKkTFQFVl5 EdTA== X-Gm-Message-State: AOJu0YxOGIxEjslhjbo61N8aEbRmVg5sD+ZsEWAq4W7n4eRFzaNIyaU4 rvmAt7wnn9jlA0iD/rSZ12B+bHNFh6HzFrOK6g+eUt4zOoh+egaABirBIPsEUNOF1bwpy/f4Ggq Z0YGopg== X-Received: by 2002:a17:903:2287:b0:20c:bcd8:5ccb with SMTP id d9443c01a7336-20fa9e61d41mr55996825ad.30.1729722036389; Wed, 23 Oct 2024 15:20:36 -0700 (PDT) Received: from linaro.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0dba36sm61897395ad.215.2024.10.23.15.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 15:20:36 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Eduardo Habkost , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH 1/2] target/i386: fix hang when using slow path for ptw_setl Date: Wed, 23 Oct 2024 15:20:25 -0700 Message-Id: <20241023222026.1430014-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241023222026.1430014-1-pierrick.bouvier@linaro.org> References: <20241023222026.1430014-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62e.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.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 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. Since this function gets called during a cpu_exec, start_exclusive then hangs. This exclusive section was introduced initially for security reasons [2]. 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/-/issues/279 Fixes: https://gitlab.com/qemu-project/qemu/-/issues/2566 Signed-off-by: Pierrick Bouvier --- target/i386/tcg/sysemu/excp_helper.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index 8fb05b1f531..f30102b5362 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -108,6 +108,9 @@ static bool ptw_setl_slow(const PTETranslate *in, uint32_t old, uint32_t new) { uint32_t cmp; + /* We are in cpu_exec, and start_exclusive can't be called directly.*/ + g_assert(current_cpu && current_cpu->running); + cpu_exec_end(current_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); @@ -115,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(current_cpu); return cmp == old; }