From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043411; cv=none; d=zohomail.com; s=zohoarc; b=LnkDVNigLtZpFQ9HWwHTsdvNNORav9rUuHYGrrvDir/x+2l/oKIBNG34Y375frF+nwHLS1JNnKvViibc+pGa4D+2HS5dyVVXYuOwgFbwV8D6FvgubKrf60lop6iL1du3no78NL1vSXRKVNs38ZXXpPLVVyKAHNq4TRB1gcGhXY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043411; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+G/zHWkR0QCdbSyAQf68yG2AhF714TiDMy1VuhRq9nA=; b=mQ7S9Tz9XqVfdATJHchC7Sva5JAZREku5e83joP9L4FFhmZg8L5iEqHcnfOmTCjJrLIoJxfnHyGUQfFoDO4JPV5qIX5iWN8FFzmEwi0WTyt8T6qlKvaJ1DYRx1QePxQ+lAxrfnezTWiwrTgCruZ/WbhWoDR7/VYdkjUHJdH2dgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17800434118161000.7190341235815; Fri, 29 May 2026 01:30:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbL-0001Ok-8f; Fri, 29 May 2026 04:29:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbJ-0001Ny-89 for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:53 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbH-0005QD-LS for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:52 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-43d76dd4ee8so8568540f8f.2 for ; Fri, 29 May 2026 01:29:51 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34a0403sm1967087f8f.6.2026.05.29.01.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 386435FA5C; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043390; x=1780648190; 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=+G/zHWkR0QCdbSyAQf68yG2AhF714TiDMy1VuhRq9nA=; b=pSU0+LeD1KrtzdaI1GfPkbeeQMdTwV/897hnmjKybkQVzSCRsjC53WViVOb0yyLW04 FI/TWMlBxMO4/+CsSIJMZMi200vy0WkwQbIJRTUy5ZjO5f6dLay9dOnE6PxkSb6kYR5l g0QKBGyvpI4YTATVbvzCQ4t4xyhgIg+FXWTZkqIkZJzpyR45pmKK4yhCI08wM3R9mbrx Zy/C928KKt+pfXVtSggkkZqUlTWBeNdJFpqu9Wd/rwTDptCCrzZiqhAvx55faDl+hido 52n8XlYSuvxNOqE8CumhZCXXheNODmwnrhYFslN8Dx/AYTaMbdhWfeMMorrGdOHv7ww5 985Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043390; x=1780648190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+G/zHWkR0QCdbSyAQf68yG2AhF714TiDMy1VuhRq9nA=; b=oCNMtlQIxIrADVcmY1ztfqJbFJickXQGCEDBuZ+Cc/DxLST9IkAsdQIRpxiesx/zVu 0VT8Aqw/aDo7iS9iteRoONdWWAwwFlQb7wLlp0nhVRbm2IpVzFdZ9GPkSYd0x+h1zIVJ jA1SS2N7sHVWWNV1qk2iwGlghIKAwDW28Mw1L3vnZy6bv8BheuX3qEhSPyOfypY0/1e5 6oM74kR5UHwhmnOzZTGs/Xb0E6ZmzjYppfn6P96bGdTU8F9xr9Ds35FDgZ6ii4w9CEfa Af8a5ZTsvrYOz8hxEjQdbdtRAJDu4L7jBxALbTQQxxvZUFMzV0tLcpLj+XkjcG/yWEUp M98Q== X-Gm-Message-State: AOJu0YzUTQaWAAPINzYtSN9cHadJtTD1N8wCquSGUhv3WpznnKjG1j7/ TgvQKHEUi0nxwDooRLX4yc+pOT8DYPSvFxttyzgEpyUMt9sodjCyoZEKqzhMPX1IlNI= X-Gm-Gg: Acq92OFG8rCxQIFa2E8WaI4VA94J+qFVEpkl2iGhxzdR822U1UxY/gubrb/cnRr7hNQ Axjog3YZhHISzDqVliPAhMXvjZbObLeCXpINvK/AMmEVNF42t6hDitjsRkO8m4wfkQGe8JWo/yO l6QAr/Mv763YZuHLqRbxN7dbQPAJFiVvQiLiPOCyFx8pxp+gPV+Tv1kVfkGv3wUclvL1UNXWzNq LrS1XCyBL8ow0Xvjn2zzVnMOM36PmLO15D8G5SndLnWxOZg+q3f7Joj2hh4Q6RjcEhEaK46lf8l AuuSgaioTvIHpWp03uhsJvuhTudNOsO93Bcs256OvxO/36UqDHjVxEHcW3rEN5lmdM5cU5ixu6N 8Fw5BZlYb4wqgruXzCN+Fa2MT+YxqfbldIVGetz4Phs+WYXbBfvJ2Xzc2OszlgoCpq3jE1XrFi1 HGQUGPmncb0k8N2ImNHQ/5dXQu/sVKgOmnvQ3R9FSH12J9 X-Received: by 2002:adf:e612:0:b0:45e:edcc:f6dc with SMTP id ffacd0b85a97d-45ef14053e3mr2409052f8f.6.1780043389791; Fri, 29 May 2026 01:29:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 1/8] target/arm: fix WFET typo in syndrome Date: Fri, 29 May 2026 09:29:40 +0100 Message-ID: <20260529082948.363931-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043414913158500 A stray x slipped in and we didn't notice! Fortunately we haven't implemented WFET yet so nothing is affected. But we are about to so lets fix it. Fixes: 4575da5ecb7 (target/arm: report register in WFIT syndromes) Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v7 - mention how we got away with it --- target/arm/syndrome.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h index 4d1f1c529e2..0eb54c15ce7 100644 --- a/target/arm/syndrome.h +++ b/target/arm/syndrome.h @@ -674,7 +674,7 @@ typedef enum { WFI =3D 0b00, WFE =3D 0b01, WFIT =3D 0b10, - WFET =3D 0xb11 + WFET =3D 0b11 } wfx_ti; =20 static inline uint32_t syn_wfx(int cv, int cond, int rn, bool rv, wfx_ti t= i, bool is_16bit) --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043507; cv=none; d=zohomail.com; s=zohoarc; b=VNiCFTkvlPOvHj6fcv9ynBc/h1WK+RG4wmk0C6F/o5WImZ9u5EWOG7L2UJUh4kep9rGHlonPqHZUX3kcg7DCnVN2FRU+v1xCaD0T4ECocjESGpR/oKP5+A+Yi2V1h0R0EUyM89MCttbGA6JKIyzaq0PRDirpNc/tm+CcC8l+hIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043507; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TZKUB+wKUb0aYLSeMPcEAHuuX6sOf6z7ImGaMMZVjj8=; b=YjwNNAvX3InLWt3awCDTL4CC8nzzvYrFnZqXwMyWunTU6U/bztxhAgf/kv3itiQ+x4JuZ37hwhU2DYLAZPqoCsDdzX84D41ehvHTbYKjWpT8IOxUqceMZinWORPIekyUAXEatCYnrpE+hHnJ6rPOD7uUxCxcSQimu0TcyQF1UFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178004350744499.12704365389959; Fri, 29 May 2026 01:31:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbV-0001Sl-O9; Fri, 29 May 2026 04:30:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbL-0001Oe-1d for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:55 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbI-0005QS-12 for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:54 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4891e5b9c1fso118462565e9.2 for ; Fri, 29 May 2026 01:29:51 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d68a925sm37842375e9.2.2026.05.29.01.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 562B8602BD; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043390; x=1780648190; 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=TZKUB+wKUb0aYLSeMPcEAHuuX6sOf6z7ImGaMMZVjj8=; b=n/Rx7lXh45UI+0KJ/CmKUwg6XQ2uw3b+cZN73QloIYtA63fxgId6aIPjS99qjZtQhu DcJL7gbVthi5kfGPbResCR69tMfRh+zRmbWAnRp97dl4LpCJ/csFnFFlwaDKlUs4akqc AXm0wZPrBfrSLXWKzon9stXbVB1l7axXw1gA/nVttDFnryJifb56DTA/hwVIkyqZ/7z+ vwAL6SWAlt8iJ0m5wUPR4KVfi/UNxVr0yXeMB8x3HQCVSsqPSRRgNguYuT1n6WuhRHLg jc67DGP3vNkmn8lwr2sMlDRCXrxmwABwEUOqhVxb0Tyht9IhUwM95u2LynNQ6OT3zIdm 1fdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043390; x=1780648190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TZKUB+wKUb0aYLSeMPcEAHuuX6sOf6z7ImGaMMZVjj8=; b=ZsGOaEuhMjlvL8N7DKiwXbRcYoBznmx4UVqZ/Nc6nllY8vU1fbiNU1Nt3b4iD3aOg0 C2d1h651WV1rWCNq5NZIL82BpJ1dqrc+QAq0/RNadmgSGPXKvSLjdH+5JoTxEpmsFnCI SbQ6Bn5vWqEoBA2oToyT0oqw5jEtwILRk8q7CQhCu3KNQ/cvfSw8I9FEs04g7slNO8bB /qRkcnQFHYbwJ1TpNEE7I177LyfMfg4DMj7pxYYgJDKcQrdhUvPYf6+EkNEhrHE9IluA tT+GgDAL0SY4LY5Lkqxzh2fWJNGo5z0GQHiZ2A3oECRp0KfQ///cMQXSLbk2LFG3AXYM kF3g== X-Gm-Message-State: AOJu0YxiKYf/HitJ1sOUVmbmXMfVWItpX0WLX1vEKRtmJMI8vuqW/lGn uWsvb7BDARTIXL//9ZtaQe6Yt9gcfBoutomRpHzYMSkWQKQLaypy+4+4bgxxtIp8Hnc= X-Gm-Gg: Acq92OEaeaLK/aPlryBqXUjnX6Tw4HMvfAzqtsiVMwwLlWS4QLa5vlwY1a4PDlJcxPO dTpZuxPVyXfVaSzQPsJ7wXyGCMCal2Igh8yW/JP5TUX7PpbKX7+nxufApL2ogoepyHTDlmCkoQW k4vWHMb/1GeW5fSX0nlex29cUE4FDisFUkzXgbrH17G87nZEJs0JH1woY09h7skNNgUvsgKh2UC 6tfERv+x+5bjk78mnyc1WY7C42g9kgo/8YiLqMkvcOGmP7dmXxrvMal4uWmAujtWvQUmcgh+I9G iqWSSMiuUcXZ5QoqpV78DI68ySRWCabJwxHMfxrX35V9QqmGfHlhyRy3zlQLO8M5NZqv7+VUKBS BgaTu8QUHbVxlgIyymdRfKgngYaLxBSyARKe0vEeFij62P7YLkdwgRPNDZcsEFiQsCk9i0E3VIe xdrW1fFVI7ELcS5sVks2hneo+lDMxM0rkF9g== X-Received: by 2002:a05:600d:848a:b0:490:60cb:55f0 with SMTP id 5b1f17b1804b1-4909c0aa2c7mr22086495e9.21.1780043390221; Fri, 29 May 2026 01:29:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 2/8] target/arm: teach arm_cpu_has_work about halting reasons Date: Fri, 29 May 2026 09:29:41 +0100 Message-ID: <20260529082948.363931-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32f.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043511469154100 With the advent of WFE and WFI we need to pay closer attention to the reason why the vCPU may be sleeping to figure out if we should wake it up. Create env->halt_reason to track this and then re-order the tests so we: - ignore everything is the vCPU is powered off - wake up if the event_register is set and we were in a WFE - otherwise any IRQ event does wake the vCPU up. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v3 - move arm_set_cpu_power_state to internals.h - drop excess brackets v5 - more arm_set_cpu_power_state cases --- target/arm/cpu.h | 16 +++++++++++++++ target/arm/internals.h | 11 +++++++++++ target/arm/arm-powerctl.c | 6 +++--- target/arm/cpu.c | 40 +++++++++++++++++++++++++++----------- target/arm/kvm.c | 5 +++-- target/arm/machine.c | 2 +- target/arm/tcg/op_helper.c | 3 +++ 7 files changed, 66 insertions(+), 17 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 85552b573c4..dfc369b5844 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -224,6 +224,19 @@ typedef enum ARMFPStatusFlavour { /* Architecturally there are 128 PPIs in a GICv5 */ #define GICV5_NUM_PPIS 128 =20 +/** + * ARMHaltReason - the reason we have entered halt state + * + * To be able to correctly wake up via arm_cpu_has_work() we need to + * track the reason we went to sleep. + */ +typedef enum { + NOT_HALTED =3D 0, + HALT_PSCI, + HALT_WFI, + HALT_WFE +} ARMHaltReason; + typedef struct CPUArchState { /* Regs for current mode. */ uint32_t regs[16]; @@ -746,6 +759,9 @@ typedef struct CPUArchState { /* Optional fault info across tlb lookup. */ ARMMMUFaultInfo *tlb_fi; =20 + /* Reason the CPU is halted */ + ARMHaltReason halt_reason; + /* * The event register is shared by all ARM profiles (A/R/M), * so it is stored in the top-level CPU state. diff --git a/target/arm/internals.h b/target/arm/internals.h index ae5afc5362e..fb9df50da29 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -2027,4 +2027,15 @@ bool arm_cpu_match_cpreg_mig_tolerance(ARMCPU *cpu, = uint64_t kvmidx, ARMCPRegMigToleranceType type); =20 =20 +/** + * arm_set_cpu_power_state() - set power state synced with halt_reason + */ +static inline void arm_set_cpu_power_state(ARMCPU *cpu, ARMPSCIState state) +{ + CPUARMState *env =3D &cpu->env; + + cpu->power_state =3D state; + env->halt_reason =3D state =3D=3D PSCI_OFF ? HALT_PSCI : NOT_HALTED; +} + #endif diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c index a788376d1d3..a06be5cc997 100644 --- a/target/arm/arm-powerctl.c +++ b/target/arm/arm-powerctl.c @@ -78,7 +78,7 @@ static void arm_set_cpu_on_async_work(CPUState *target_cp= u_state, =20 /* Finally set the power status */ assert(bql_locked()); - target_cpu->power_state =3D PSCI_ON; + arm_set_cpu_power_state(target_cpu, PSCI_ON); } =20 int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id, @@ -186,7 +186,7 @@ static void arm_set_cpu_on_and_reset_async_work(CPUStat= e *target_cpu_state, =20 /* Finally set the power status */ assert(bql_locked()); - target_cpu->power_state =3D PSCI_ON; + arm_set_cpu_power_state(target_cpu, PSCI_ON); } =20 int arm_set_cpu_on_and_reset(uint64_t cpuid) @@ -239,7 +239,7 @@ static void arm_set_cpu_off_async_work(CPUState *target= _cpu_state, ARMCPU *target_cpu =3D ARM_CPU(target_cpu_state); =20 assert(bql_locked()); - target_cpu->power_state =3D PSCI_OFF; + arm_set_cpu_power_state(target_cpu, PSCI_OFF); target_cpu_state->halted =3D 1; target_cpu_state->exception_index =3D EXCP_HLT; } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index a13e6dae2a2..8771b695d9d 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -145,18 +145,36 @@ static bool arm_cpu_has_work(CPUState *cs) { ARMCPU *cpu =3D ARM_CPU(cs); =20 - if (arm_feature(&cpu->env, ARM_FEATURE_M)) { - if (cpu->env.event_register) { - return true; - } + /* + * Only another PSCI call can wake the CPU up in which case the + * power_state would be set by arm_set_cpu_on_and_reset_async_work() + */ + if (cpu->power_state =3D=3D PSCI_OFF) { + g_assert(cpu->env.halt_reason =3D=3D HALT_PSCI); + return false; + } + + /* + * A wake-up event should only wake us if we are halted on a WFE + */ + if (cpu->env.halt_reason =3D=3D HALT_WFE && cpu->env.event_register) { + cpu->env.halt_reason =3D NOT_HALTED; + return true; + } + + /* + * Otherwise pretty much any IRQ would wake us up + */ + if (cpu_test_interrupt(cs, + CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD + | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU= _INTERRUPT_VFNMI + | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU= _INTERRUPT_VSERR + | CPU_INTERRUPT_EXITTB)) { + cpu->env.halt_reason =3D NOT_HALTED; + return true; } =20 - return (cpu->power_state !=3D PSCI_OFF) - && cpu_test_interrupt(cs, - CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD - | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_V= FNMI - | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_V= SERR - | CPU_INTERRUPT_EXITTB); + return false; } #endif /* !CONFIG_USER_ONLY */ =20 @@ -327,7 +345,7 @@ static void arm_cpu_reset_hold(Object *obj, ResetType t= ype) env->vfp.xregs[ARM_VFP_MVFR1] =3D cpu->isar.mvfr1; env->vfp.xregs[ARM_VFP_MVFR2] =3D cpu->isar.mvfr2; =20 - cpu->power_state =3D cs->start_powered_off ? PSCI_OFF : PSCI_ON; + arm_set_cpu_power_state(cpu, cs->start_powered_off ? PSCI_OFF : PSCI_O= N); =20 if (arm_feature(env, ARM_FEATURE_AARCH64)) { /* 64 bit CPUs always start in 64 bit mode */ diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 7d194ea112b..a54ef51ec2a 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1149,11 +1149,12 @@ static int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu) if (cap_has_mp_state) { struct kvm_mp_state mp_state; int ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MP_STATE, &mp_state); + ARMPSCIState state; if (ret) { return ret; } - cpu->power_state =3D (mp_state.mp_state =3D=3D KVM_MP_STATE_STOPPE= D) ? - PSCI_OFF : PSCI_ON; + state =3D (mp_state.mp_state =3D=3D KVM_MP_STATE_STOPPED) ? PSCI_O= FF : PSCI_ON; + arm_set_cpu_power_state(cpu, state); } return 0; } diff --git a/target/arm/machine.c b/target/arm/machine.c index 58f8dfd53c8..fde3b3e8d75 100644 --- a/target/arm/machine.c +++ b/target/arm/machine.c @@ -916,7 +916,7 @@ static int get_power(QEMUFile *f, void *opaque, size_t = size, { ARMCPU *cpu =3D opaque; bool powered_off =3D qemu_get_byte(f); - cpu->power_state =3D powered_off ? PSCI_OFF : PSCI_ON; + arm_set_cpu_power_state(cpu, powered_off ? PSCI_OFF : PSCI_ON); return 0; } =20 diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index e8f0996ed39..504526153a6 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -402,6 +402,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len) target_el); } =20 + env->halt_reason =3D HALT_WFI; cs->exception_index =3D EXCP_HLT; cs->halted =3D 1; cpu_loop_exit(cs); @@ -463,6 +464,7 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd) } else { timer_mod(cpu->wfxt_timer, nexttick); } + env->halt_reason =3D HALT_WFI; cs->exception_index =3D EXCP_HLT; cs->halted =3D 1; cpu_loop_exit(cs); @@ -507,6 +509,7 @@ void HELPER(wfe)(CPUARMState *env) return; } =20 + env->halt_reason =3D HALT_WFE; cs->exception_index =3D EXCP_HLT; cs->halted =3D 1; cpu_loop_exit(cs); --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043527; cv=none; d=zohomail.com; s=zohoarc; b=I/uvWRW8BzeSAlkz+GJWfX99tsX2xNdYlEYOesheY9xuJBluwY58z92hKUqbK4t/5XAcSZDXNodfcyBtOk0y/55CEwq60syIQx82hulSq6t5fxfLca35H3gvfo7ofLbuy28EVozVUilodABiY58uD+M9g1dgWNFE8GlFRP68k9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043527; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=az9S1vGVboCrXLR85YpBzY90OGFAcAq/GvXnwLVzHvg=; b=Q3XP3WIv5+lKIdOFoML5JMZtzBEbL60mZzv08HBms0dxSPPIy/yVo3C8iJKn1Vr0mATKEHiF8l5o/y6I7MAFpW07seeBam9sWhBZGjTZCZohzw97g0ynJNtt1rOG68Km1Ee+OKWkn2YDE6PqPi/ArYB5CjXTCUiP92dCIhpRHig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043527244139.39342380078028; Fri, 29 May 2026 01:32:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbZ-0001Vy-Mj; Fri, 29 May 2026 04:30:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbM-0001PM-3r for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:57 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbJ-0005Qo-1u for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:55 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4905529b933so52910145e9.0 for ; Fri, 29 May 2026 01:29:52 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d6a0e42sm23561455e9.8.2026.05.29.01.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:49 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 71AFC602E1; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043391; x=1780648191; 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=az9S1vGVboCrXLR85YpBzY90OGFAcAq/GvXnwLVzHvg=; b=GJp2m1XrBNZ5Iv23uv1slfZRTsot06xHYSUraSIuaYUeNPwDw6HqmcyC00dLiVCWwq sDgwRZj3c1aWgjrKogwN2RCa5PRUb+URfr9FyaO0Rcqm68EPZtUHwSdwcpWcpJ3tRG1K n+mQ9M0IelEwTzduV/LjY1rp4KgtZ3F0MduXPCkz+9j/n1lSCF7aAcQHQFNutMcWQxZ6 mEXQPhdUf765hPglLAmmWU1OI30JJV1d8zKSEXbttFzHh0TlBgGLh8eaETZeUMeWURgM itvnnsco5xE/fQO+co6ppqhxIvqEzh3v0GybopZ5gsHYIWy7Y/5w64UpTnsOFt/F0Fwf CN6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043391; x=1780648191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=az9S1vGVboCrXLR85YpBzY90OGFAcAq/GvXnwLVzHvg=; b=smQyAlxWZ1V7/b4n2CVStL4DDn+uUpwzA8xcSGCZQ8Yri7GYrtm5rYwPPdqx0wCjpb pCBCYFH6LqwwYnx1Dr1+eFERxbdPeI9jzySgTdNfGPQSNxG5omblRCpQKiJVfewW0230 /KjctZ66N/UDqLZ5tvMP/tqdK6o9QP4E+aFANyo00uHTTw8YS4zcu+/UyY70J7/uC8Jo ejgf/ug3UO4iXq3CMOvIKSzA7oB3WV85xE0OmDsFTEGLJ81bvvG1Ex2K74wYU1c9ZZkk VQd8dqkADS99euAZ6x+MEDKWZuEyjMDasUbJW4wQcVUQJ2aKypAxWesVwG/8V85h9r61 xoKA== X-Gm-Message-State: AOJu0YyQ6MvyDCsUyhGCcA591pEMnhgeloDDBTEdiHq6Pq0wZ7QHGL+t OMyOTfGKKLHonFsCWHDLNzLhoTUhwwa8VMQIbWws7CAu4/bmeSTl+AdOKBEbeJ395qY= X-Gm-Gg: Acq92OGSZ6NxX+BjgwrwPtEofK6Y8t5mEfkcGt5FPszWwmRpTT7dLH+9T3HVyWyABuO SAEdHn81m1UO+4y0c8e3xEjJ396EqL+ICjrCokfmTws2V/OkjC5szIWUIEKR1mnt8a+WmaJYhkJ FT7wADRYgRhr+OcFF2DT3wXikc6n0Wdxkmpc2Y3jkOmqvUdHwfQdd5YPDoNwqTnyZATFejsXsPK fdv1j2q200+LuzoEI62XbIpZNByzJf61/1vhC+Sc4SgwdyBf8oBdE4phvx0IJFdOAvTDk3rapOK WdTmoN1zag3sGrKZyembjYZL250Vmp6JDmMz8+t0UBciEqAK5oFWUCG2yENQm0UVfLdxcZ70NBw IDrm7lyTYP3iIpgW427Zt22J2NzngVPKA19Q7WZ9bs9gXKQQIq3wxGNpgjf9cVaWvJdGgElUscD sHCWW6jotdmW6/NSk+v0D/PmfceQc3oaxbpg== X-Received: by 2002:a7b:cc1a:0:b0:490:845c:a1ea with SMTP id 5b1f17b1804b1-4909c0b0c32mr25010795e9.21.1780043391324; Fri, 29 May 2026 01:29:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 3/8] target/arm: redefine event stream fields Date: Fri, 29 May 2026 09:29:42 +0100 Message-ID: <20260529082948.363931-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043529574154100 The event stream control bits are the same for both CNTHCTL and CNTKCTL so rather than duplicating the definitions rename them to be useful in both cases. We will need these in a later commit when we start implementing event streams. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- target/arm/internals.h | 11 +++++++---- target/arm/helper.c | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index fb9df50da29..93f5bd0e830 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -272,14 +272,17 @@ FIELD(VSTCR, SA, 30, 1) * have different bit definitions, and EL1PCTEN might be * bit 0 or bit 10. We use _E2H1 and _E2H0 suffixes to * disambiguate if necessary. + * + * The event stream bits (EVN*) are in the same position for + * CNTKCTL_EL1/CTNKCTL. */ FIELD(CNTHCTL, EL0PCTEN_E2H1, 0, 1) FIELD(CNTHCTL, EL0VCTEN_E2H1, 1, 1) FIELD(CNTHCTL, EL1PCTEN_E2H0, 0, 1) FIELD(CNTHCTL, EL1PCEN_E2H0, 1, 1) -FIELD(CNTHCTL, EVNTEN, 2, 1) -FIELD(CNTHCTL, EVNTDIR, 3, 1) -FIELD(CNTHCTL, EVNTI, 4, 4) +FIELD(CNTxCTL, EVNTEN, 2, 1) +FIELD(CNTxCTL, EVNTDIR, 3, 1) +FIELD(CNTxCTL, EVNTI, 4, 4) FIELD(CNTHCTL, EL0VTEN, 8, 1) FIELD(CNTHCTL, EL0PTEN, 9, 1) FIELD(CNTHCTL, EL1PCTEN_E2H1, 10, 1) @@ -289,7 +292,7 @@ FIELD(CNTHCTL, EL1TVT, 13, 1) FIELD(CNTHCTL, EL1TVCT, 14, 1) FIELD(CNTHCTL, EL1NVPCT, 15, 1) FIELD(CNTHCTL, EL1NVVCT, 16, 1) -FIELD(CNTHCTL, EVNTIS, 17, 1) +FIELD(CNTxCTL, EVNTIS, 17, 1) FIELD(CNTHCTL, CNTVMASK, 18, 1) FIELD(CNTHCTL, CNTPMASK, 19, 1) =20 diff --git a/target/arm/helper.c b/target/arm/helper.c index 34487eeaa36..bed58e65b4d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1769,9 +1769,9 @@ static void gt_cnthctl_write(CPUARMState *env, const = ARMCPRegInfo *ri, uint32_t valid_mask =3D R_CNTHCTL_EL0PCTEN_E2H1_MASK | R_CNTHCTL_EL0VCTEN_E2H1_MASK | - R_CNTHCTL_EVNTEN_MASK | - R_CNTHCTL_EVNTDIR_MASK | - R_CNTHCTL_EVNTI_MASK | + R_CNTxCTL_EVNTEN_MASK | + R_CNTxCTL_EVNTDIR_MASK | + R_CNTxCTL_EVNTI_MASK | R_CNTHCTL_EL0VTEN_MASK | R_CNTHCTL_EL0PTEN_MASK | R_CNTHCTL_EL1PCTEN_E2H1_MASK | @@ -1786,7 +1786,7 @@ static void gt_cnthctl_write(CPUARMState *env, const = ARMCPRegInfo *ri, R_CNTHCTL_EL1TVCT_MASK | R_CNTHCTL_EL1NVPCT_MASK | R_CNTHCTL_EL1NVVCT_MASK | - R_CNTHCTL_EVNTIS_MASK; + R_CNTxCTL_EVNTIS_MASK; } if (cpu_isar_feature(aa64_ecv, cpu)) { valid_mask |=3D R_CNTHCTL_ECV_MASK; --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043527; cv=none; d=zohomail.com; s=zohoarc; b=kW8FYOgcEpzvDImk+NmuYuwpMS8IVaxxIFIJxaf4W5StBNaVdpbQPUmCW1QhuBsLzrCJT1gGMPMO10qCsNMQiMKH8Ddiz4YKwie5Z6G5YVwPseu2WNGc1jh8zMVIhQM2RFMkeFmuSZIjTbTTTF7yFCB3RAEklPqSGMWILgsOFIk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043527; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+hbeufYVzoMG/wzzAjSBDrNtpV9A32DdB20M94ZA85Y=; b=Oz/ETtNrYtGpLN3BMFapihuevHANOJU1OQ/Sdm6AloaNQRnuW6Mmqer0cMU0uRePWbVWKFE51CAKgthVwGVcVBIRSKJyBTYB6E0nqPKGGAYtBjKBnqVcB9qpsOQKCMKzkX1QA12s3uK1ME1fI8S9e+ao6RLHbxOsSFa+v+4jcp8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043527489188.93502931966384; Fri, 29 May 2026 01:32:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbX-0001TQ-SC; Fri, 29 May 2026 04:30:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbM-0001PQ-7V for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:57 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbJ-0005R2-N7 for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:55 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-49050ff7cbdso62077735e9.2 for ; Fri, 29 May 2026 01:29:53 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909c6319ddsm31623155e9.0.2026.05.29.01.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:50 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8A48060335; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043392; x=1780648192; 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=+hbeufYVzoMG/wzzAjSBDrNtpV9A32DdB20M94ZA85Y=; b=Ml7FFs7eoro+n6MWGRJhk8UjfOAa/iDIOr7A0ZJ9aifFJNBSUBKfnpKKuC9tC1LdPH mRU9QWl1VJU+846pmx9R3NbOz+ttApC8AKFSkSxpCuV27bsc0b/HlVGnkv+g/jmPHcJr QdGzmzXODpIDd5Prw3B1h/KkGTh6Yvtuocqhc8zqmuaXiq8ZvddO/NjBh8vKloNEe4EP alH6FAsGeFLJ5d5olvc54l4NLyqmr2ORkQoUVLzqJk8X0DAvkDcRQQ02iDey4MLkV0ll BKKPIPA1G9gU4GC6E1StVWBOqxggHdJtRrB96gJ5IqY98tPTcP6KIRRvBONtSonWkDZz QG8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043392; x=1780648192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+hbeufYVzoMG/wzzAjSBDrNtpV9A32DdB20M94ZA85Y=; b=bUW913sFC+SdKrtdjPN8d6X28oAIHcw5kWupnmlwgEjq1tHIvTfNRfGvNmr0AWE29J Pz34edGp3ftyIzbedvFXovk1OPNc71HrTODLYvt6BIdobiIsP3AHAcYJyenB+aZh22V0 szcqpFWHHLi7h4GBP2RYHuY/w9+qj38Uy1yrE4FeQuIvpghV7OrhKwiwtX16gHcHlC5V vOziNGR+5uiNLCLiFc9JmAI1iZX+UXKlmlvJGI9B7YmztyZd8i6sjVoTr1erhSlUUduO ObJugNEkkUbHMOJB8xzX+ZZX+inH7DYxLg2u6rM+ycfZsE4P/5zJH+8OQiufWfDO1gc3 GEEA== X-Gm-Message-State: AOJu0Yzice4yv9BhmzWkwgluImy/ZXMyClfR4b93Jf9H+Y1sAI2um0sr 0lQRSWQI8OpljeirFz+AR9dBIbQq/SushCiog8qzsfj/w3igVTgNOl/KLl8zAh1PLuo= X-Gm-Gg: Acq92OEhWbkYIs9DaHBjUUySTnQH0KyZRm/PpAa2FVObjvF5tap/h+Km7m6bLP+m2fw Bug0uPA64A8Qpp0uNKsxDdWdKaHs69gBb99kLpBl6vlR51hgBFDFC4qflq8CGanB+sPF0+Yu69n pfotVlk+9vIORq4RccDaSbADQCjhlD0IluQlqwLI06jP8j5avj1el0a6RWWVJDCF8jbFk43pufT dYtWKFng41tD5MBuW2Kx9eoz97Exdgh+NU99LpTJlEXcbnqVU2GsTHivlrimpOv4m9VDevxD3pO zFAcQOpbotszQsZNKlX7PFnEsE0DD/xn/372fx1JKqca437jPCG22eOcOVHD5sQ9zC1ZhgHlmkN +iWXY+vbOW/IKeh+djIx4TcnWm5VIIu/vZXqYGhufSaYrIKUsAwXfYoC+WvqtyQ4IoC6CCES+JU oF12qg8lSlrWExtn3M4d3oh7M1lxbOt/9yjA== X-Received: by 2002:a05:600d:864a:20b0:490:6869:7d8b with SMTP id 5b1f17b1804b1-4909c089d9dmr24637905e9.15.1780043392032; Fri, 29 May 2026 01:29:52 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 4/8] target/arm: ensure aarch64 DISAS_WFE will exit Date: Fri, 29 May 2026 09:29:43 +0100 Message-ID: <20260529082948.363931-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043529618154100 This mirrors the logic for DISAS_WFE in 32 bit world. As the WFE/WFI have similar behaviours shuffle the case statements around a little and update the commentary to cover both. Fixes: 252ec405768 (target-arm: implement WFE/YIELD as a yield for AArch64) Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v4 - shuffle case statements, unify the comments. --- target/arm/tcg/translate-a64.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 15b40090c0f..c20269b1501 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -10939,25 +10939,25 @@ static void aarch64_tr_tb_stop(DisasContextBase *= dcbase, CPUState *cpu) case DISAS_NORETURN: case DISAS_SWI: break; - case DISAS_WFE: - gen_a64_update_pc(dc, 4); - gen_helper_wfe(tcg_env); - break; case DISAS_YIELD: gen_a64_update_pc(dc, 4); gen_helper_yield(tcg_env); break; + /* + * Both WFE/WFI can cause exceptions or exit the loop to + * halt so we have to make sure we have rectified the PC. + * However they can also return directly if they don't + * enter a wait state so we must add an exit block so we exit + * the loop and check for interrupts. + */ + case DISAS_WFE: + gen_a64_update_pc(dc, 4); + gen_helper_wfe(tcg_env); + tcg_gen_exit_tb(NULL, 0); + break; case DISAS_WFI: - /* - * This is a special case because we don't want to just halt - * the CPU if trying to debug across a WFI. - */ gen_a64_update_pc(dc, 4); gen_helper_wfi(tcg_env, tcg_constant_i32(4)); - /* - * The helper doesn't necessarily throw an exception, but we - * must go back to the main loop to check for interrupts anywa= y. - */ tcg_gen_exit_tb(NULL, 0); break; } --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043504; cv=none; d=zohomail.com; s=zohoarc; b=LlAHJAf3jAgMrbE3LVh1l18kPh2gVgaD4POs0FaohNubwuO8JHL+ZM7lf3bekxnGoavbQ7+PZw4DtAWcHZkaDXCRiWFeLIEJIrZya/2EdQphN1mA//q59v21PplQIyGiG9JZvKH3mm5Rq3H1yAAPe4R2+JET/K/3r34Z7KMUWh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043504; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dt2pVSNtYi5awIMi0tBurROv0xQ5d0//K+fOntt40rM=; b=XY8CJQiAfjjPLhAQZPQzkSHrC+Eg7nOjwDn5wM9j1P/488DHr+hNTcmr1uT1w93596UzP1dv2ITaYGmqndnBsSGUBFBLsSCiy1uGsU1xK+BOiGr6sbZVKs4RJWqrFHGux1UoEknZ1DncViwNhllaXgkqe5XjbMktzB1vHOCjVVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043504459848.7290342731832; Fri, 29 May 2026 01:31:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsba-0001Zv-MB; Fri, 29 May 2026 04:30:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbN-0001Pl-SI for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:59 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbL-0005Re-2x for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:57 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-48e8132c6d0so86626815e9.1 for ; Fri, 29 May 2026 01:29:54 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef34a0374sm1669634f8f.2.2026.05.29.01.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A9E146036E; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043394; x=1780648194; 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=dt2pVSNtYi5awIMi0tBurROv0xQ5d0//K+fOntt40rM=; b=LRPZKuysFUSybP5HslVe4X/AoelSGUq/12oFGhH5L2a8RBq39FzsC8o62dSgDxYY2k 2MgSXT2n4QMkbuWNMzOsuHaKGakh0dUTCEB+XorOY2fGCM3a7Xhoveec0Qopr3NFUNzw 0/TT5FCjXPtvRtShlB/IGTF5MpDxCJlQlerejn6jKkwtAeCzpvZfMKgSQu+IyxFuPGQA ZsQS2hqXHeAj0H3OUEjJz7tdmT4g9nxUr6QKoAUtpmzUA+X9VlimikJ9u8yiMwMLsJjT E+KZ0+a6pPkvzgwCX/D0IdW6eL7yk5Eyj9kmTRAIDDRyFQq/d8KSXO6VVdU6WLSdNDM3 sVaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043394; x=1780648194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dt2pVSNtYi5awIMi0tBurROv0xQ5d0//K+fOntt40rM=; b=ojdpIE2HLN5d0pKHm4aFXwdA1uzZ2IlxmIqhe+71P49yOpe6XoDHUZikBy9JXhSJ1I LhlkcfHFe4EZhR1JeZ8IsGw4GZHirdEiJ54gk6AXUbest8yOl2pgQ+KFyH/GkmFmy5dt lPGiKKZJWQw5Iyy2d3QYN7q4C8WOn0xESkn8GB59juebSWGtCD8eJXnymymV7EYmMxtk jFAF6JSfOP2mcS4KHI8ERdHZNosb0VgBG67lJunmghbk7LFrprOLQzgtatQ35yaQz8aZ hT/gSTngce//Hc7+ai/mVUVPaypBcC/tzyx/FBBBb3ZVh5rFcOMGyzVGQHxTRIJE9pKa 5LLw== X-Gm-Message-State: AOJu0YzSWkK6U2ba8UIZE/89khBRMA2FdZTNBWgqF9j/V6vuBHG77vWz ZLZAZe7TnTuYkjivrCAuywWTwfAYMjMzaCPxSF5zrfTHCH6/nBe4Y8BRz+XnX6nAHUk= X-Gm-Gg: Acq92OG0gHsEuzR+NPbld95XdcgJqC81A43wloPSMxQAmppEWDuV2bPrdBumuvpqwff 4LEjFo0j+6AMZ5a2YYktr8dR8GoH/m5de7X4ewwvSSx9mQ2mlOB2dpRSWXsqG7brzUuYLXQpfnq 6m8uBNIl5uYeTRhQdKSlcPjMnirzizQO/VGi8ZKEGdpfk3P9Ig4IorUEtgD7meYZnESal7BIVXm gNr2xMk4Q+LCkeRi92T35G+UCrZ0dgl1R5sZmuNsLGLKuaPqILHAmwIqz1O26GeM0XKLrkQDv3s sWe42TItaC0wcEAiydH/qlLA/TzNQM3CVQAZxZRay3Wo1u6dZMQpyHMCkkdksROVZLHRQZtkLiE KSUaBDKRrjHjinJi8ggfSFZtPvGLdXJiUfai6lUrD9WtMH1KdEhgtjG2uMPB96VRaRmVGslVF3X tzgby7+0tg1QcZbKmm/j2E4skNfLkDqmeqrw== X-Received: by 2002:a05:600c:4504:b0:490:51e2:d992 with SMTP id 5b1f17b1804b1-4909c0b3349mr32182745e9.13.1780043393357; Fri, 29 May 2026 01:29:53 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 5/8] target/arm: implements SEV/SEVL for all modes Date: Fri, 29 May 2026 09:29:44 +0100 Message-ID: <20260529082948.363931-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043507342154100 Remove the restrictions that make this a M-profile only operation and enable the instructions for all Arm profiles. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v2 - fix alignment in a32.decode - set bool directly, defend with QEMU_BUILD_BUG_ON - s/instructions/profiles/ - share get_event_reg between translate/translate-a64 --- target/arm/tcg/translate.h | 18 ++++++++++++++++++ target/arm/tcg/a32.decode | 5 ++--- target/arm/tcg/a64.decode | 5 ++--- target/arm/tcg/t16.decode | 4 +--- target/arm/tcg/t32.decode | 4 +--- target/arm/tcg/op_helper.c | 4 +--- target/arm/tcg/translate-a64.c | 17 +++++++++++++++++ target/arm/tcg/translate.c | 13 ++++++++----- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h index d4bcc5bad4c..b71b1d5be66 100644 --- a/target/arm/tcg/translate.h +++ b/target/arm/tcg/translate.h @@ -856,6 +856,24 @@ static inline void gen_restore_rmode(TCGv_i32 old, TCG= v_ptr fpst) gen_helper_set_rmode(old, old, fpst); } =20 +/* + * Event Register signalling. + * + * A bunch of activities trigger events, we just need to latch on to + * true. The event eventually gets consumed by WFE/WFET. + * + * user-mode treats these as NOPs. + */ + +static inline void gen_event_reg(void) +{ +#ifndef CONFIG_USER_ONLY + TCGv_i32 set_event =3D tcg_constant_i32(1); + QEMU_BUILD_BUG_ON(sizeof_field(CPUARMState, event_register) !=3D 1); + tcg_gen_st8_i32(set_event, tcg_env, offsetof(CPUARMState, event_regist= er)); +#endif +} + /* * Helpers for implementing sets of trans_* functions. * Defer the implementation of NAME to FUNC, with optional extra arguments. diff --git a/target/arm/tcg/a32.decode b/target/arm/tcg/a32.decode index f2ca4809495..547aa2b1490 100644 --- a/target/arm/tcg/a32.decode +++ b/target/arm/tcg/a32.decode @@ -192,9 +192,8 @@ SMULTT .... 0001 0110 .... 0000 .... 1110 ...= . @rd0mn WFE ---- 0011 0010 0000 1111 ---- 0000 0010 WFI ---- 0011 0010 0000 1111 ---- 0000 0011 =20 - # TODO: Implement SEV, SEVL; may help SMP performance. - # SEV ---- 0011 0010 0000 1111 ---- 0000 0100 - # SEVL ---- 0011 0010 0000 1111 ---- 0000 0101 + SEV ---- 0011 0010 0000 1111 ---- 0000 0100 + SEVL ---- 0011 0010 0000 1111 ---- 0000 0101 =20 ESB ---- 0011 0010 0000 1111 ---- 0001 0000 ] diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode index 02c7264cb99..7ea52ac23b9 100644 --- a/target/arm/tcg/a64.decode +++ b/target/arm/tcg/a64.decode @@ -237,9 +237,8 @@ ERETA 1101011 0100 11111 00001 m:1 11111 1111= 1 &reta # ERETAA, ERETAB YIELD 1101 0101 0000 0011 0010 0000 001 11111 WFE 1101 0101 0000 0011 0010 0000 010 11111 WFI 1101 0101 0000 0011 0010 0000 011 11111 - # We implement WFE to never block, so our SEV/SEVL are NOPs - # SEV 1101 0101 0000 0011 0010 0000 100 11111 - # SEVL 1101 0101 0000 0011 0010 0000 101 11111 + SEV 1101 0101 0000 0011 0010 0000 100 11111 + SEVL 1101 0101 0000 0011 0010 0000 101 11111 # Our DGL is a NOP because we don't merge memory accesses anyway. # DGL 1101 0101 0000 0011 0010 0000 110 11111 XPACLRI 1101 0101 0000 0011 0010 0000 111 11111 diff --git a/target/arm/tcg/t16.decode b/target/arm/tcg/t16.decode index 778fbf16275..9a8f89538ac 100644 --- a/target/arm/tcg/t16.decode +++ b/target/arm/tcg/t16.decode @@ -228,10 +228,8 @@ REVSH 1011 1010 11 ... ... @rdm WFE 1011 1111 0010 0000 WFI 1011 1111 0011 0000 =20 - # M-profile SEV is implemented. - # TODO: Implement SEV for other profiles, and SEVL for all profiles; m= ay help SMP performance. SEV 1011 1111 0100 0000 - # SEVL 1011 1111 0101 0000 + SEVL 1011 1111 0101 0000 =20 # The canonical nop has the second nibble as 0000, but the whole of the # rest of the space is a reserved hint, behaves as nop. diff --git a/target/arm/tcg/t32.decode b/target/arm/tcg/t32.decode index 49b8d0037ec..8ae277fe112 100644 --- a/target/arm/tcg/t32.decode +++ b/target/arm/tcg/t32.decode @@ -369,10 +369,8 @@ CLZ 1111 1010 1011 ---- 1111 .... 1000 ..= .. @rdm WFE 1111 0011 1010 1111 1000 0000 0000 0010 WFI 1111 0011 1010 1111 1000 0000 0000 0011 =20 - # M-profile SEV is implemented. - # TODO: Implement SEV for other profiles, and SEVL for all profile= s; may help SMP performance. SEV 1111 0011 1010 1111 1000 0000 0000 0100 - # SEVL 1111 0011 1010 1111 1000 0000 0000 0101 + SEVL 1111 0011 1010 1111 1000 0000 0000 0101 =20 ESB 1111 0011 1010 1111 1000 0000 0001 0000 ] diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index 504526153a6..2b1fb1e059d 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -476,9 +476,7 @@ void HELPER(sev)(CPUARMState *env) CPUState *cs =3D env_cpu(env); CPU_FOREACH(cs) { ARMCPU *target_cpu =3D ARM_CPU(cs); - if (arm_feature(&target_cpu->env, ARM_FEATURE_M)) { - target_cpu->env.event_register =3D true; - } + target_cpu->env.event_register =3D true; if (!qemu_cpu_is_self(cs)) { qemu_cpu_kick(cs); } diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index c20269b1501..4b978c8b958 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -2033,6 +2033,23 @@ static bool trans_WFI(DisasContext *s, arg_WFI *a) return true; } =20 +static bool trans_SEV(DisasContext *s, arg_SEV *a) +{ + /* + * SEV is a NOP for user-mode emulation. + */ +#ifndef CONFIG_USER_ONLY + gen_helper_sev(tcg_env); +#endif + return true; +} + +static bool trans_SEVL(DisasContext *s, arg_SEV *a) +{ + gen_event_reg(); + return true; +} + static bool trans_WFE(DisasContext *s, arg_WFI *a) { /* diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index c744b163453..e1e5539f571 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -3246,17 +3246,20 @@ static bool trans_YIELD(DisasContext *s, arg_YIELD = *a) static bool trans_SEV(DisasContext *s, arg_SEV *a) { /* - * Currently SEV is a NOP for non-M-profile and in user-mode emulation. - * For system-mode M-profile, it sets the event register. + * SEV is a NOP for user-mode emulation. */ #ifndef CONFIG_USER_ONLY - if (arm_dc_feature(s, ARM_FEATURE_M)) { - gen_helper_sev(tcg_env); - } + gen_helper_sev(tcg_env); #endif return true; } =20 +static bool trans_SEVL(DisasContext *s, arg_SEV *a) +{ + gen_event_reg(); + return true; +} + static bool trans_WFE(DisasContext *s, arg_WFE *a) { /* --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043480; cv=none; d=zohomail.com; s=zohoarc; b=PBYSjhE2lqQM3R6lYmUActUxQ0F//B/RrEI+O4MYZsMZFX1K8PZQAk6ckLf11+lB/f9nf9yVyo8AVOULaTY6KViMj/fbiOHyqWZZPMOtrv+FYJN6vnTAUOUgrndK1vcLBjEo8ezhfK1anU0kD1f8QNfBCrHa4IVkSqJO5LqyAoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043480; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xM5kxa8UaLwO/IVN2pUPHL7tGeiJncGgEWLu3xGeqnI=; b=UBs21YrSWk1sFjOwBiCUlOVl9yae820d16H2XFXJCQotI1ij48r2HvJGmCM4hBqMTZ0gAxfV6p2x2c+UgVgLJnzZ+qWWbsTLxjfgnK8EMyJzpIPOy/zcpprJdfGC726KYCCmVXg4AbtcLbGwiR0B43aWn29wN8sM3+mhwAW7I8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043480781298.73930474192525; Fri, 29 May 2026 01:31:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbc-0001gN-6Y; Fri, 29 May 2026 04:30:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbO-0001Q6-1e for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:59 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbK-0005RK-7q for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:57 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-45eecb8bf67so991680f8f.2 for ; Fri, 29 May 2026 01:29:53 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d6f35f8sm20354765e9.13.2026.05.29.01.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:51 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C660F604BD; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043393; x=1780648193; 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=xM5kxa8UaLwO/IVN2pUPHL7tGeiJncGgEWLu3xGeqnI=; b=biA5RSk0Hd2rwFd+3YjFEFYUYOTZ6xV5zsfXqo25Pq0zpKQYlnADe0itYD37DMoJmP a+tdPjylbyZifzLDjf1N3d0H0YUshvER2ITVUvuNFUlTEcie+hBmNR+1f3CZwaJtdIA3 kfCndG/JWwWUuS2A2AfnzuWTvyul18grgppT+LSE85CwDdbpQfedHQrUTE32GbQkLcpj RorcPHqq9xdtMm7uWDy/70ZPieUJCGAFNG7eWINhlDkqQpkULUecPnqrnj1e22Faqg0O nR7grcLCm2i77Ef4dl2zJoS+2CoA4QKC1WUROM3eTrWkvDxdNdswjL1hJ6hYoYhOQldi VQnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043393; x=1780648193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xM5kxa8UaLwO/IVN2pUPHL7tGeiJncGgEWLu3xGeqnI=; b=Scf+e7/7a6c5LNzhd/VvDtPeJcpyXPeA9GQt38Nnh4ntdAM3eS5u0iADe3t9bOW2NF 0WiXcF1Ej+ZHv+82romP/EBkRZ7i++xHDuj3wA1gBYxcdvSnyavYlqsQ46CKEpQF5Nba t1+PsDPSTmLg5Gsj9obQADHk9J1lgkuBRXltH/C8jEgh+vQE2Xk75LhqB/qDfvcRcx9s rS0PtyJAo918QZePvls7q8PMUwdd08vAPCsV3idZzZ8GSe67TZTP877zGyvNvw04ub/e 9ssgDSyyy34VbbQh+psk1fEr1eX2zEyt1On5eQZJS30KwywMAmkg9J55qLNGLHTsLtOg pd+Q== X-Gm-Message-State: AOJu0YzDbFwyDShzBV3lRfRs2iy4GrthpfroMVi68KP094yBLmpBYIKW Fd8LwUclZr5AVPJFtOVrsTH8rqEMU4R6NQBV8ig5E/3VpA3LzLKOEfs/GZUG+4MkH08= X-Gm-Gg: Acq92OH6TNIYvcN+shjRGjUKltUWtYKdGx4YPMPRC987J2fmCBbVcpB5P/AoLArtUt+ 1khtXFIVyhqm15YBg5hCOAeHOAPiQtMlncahW8CsARcarqjcL/TbHMG59uxcHVV8LgsGI66/o7J tnie7nWfuiOLps7LWedz0NshLyhgNhasucdHqRoEjpHbj2h8W/yO/BgxlkwK6QIkqLTLIaOsYs1 qnPODljAWF6Cmtmn04mKwtOZM07Bex+6Pwk9psvVwLioe97lFGZXcHGHMC/v26pbYwzFLjpgTjE Bo4MiPQbdMQ+R5ybiT9DUchUkM26IpM6G5inQo+hweLDfP7fKklnPEGfW9uJnvUfCJ2OX6PksvW 8bAgNS7wGDU43yQMIpP9OazvCaM2mddOEjMHimcog4uPAXxXPcHepgz59CWO/pW3D5eZC3kOlNZ gHaz4MaGBLmyXVjUrH1R8+FdptpKMZXNLoQ0ZGW0tWQHmu X-Received: by 2002:a05:600c:c8f:b0:490:9d1b:f05c with SMTP id 5b1f17b1804b1-4909d1bf0demr29165975e9.33.1780043392462; Fri, 29 May 2026 01:29:52 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 6/8] target/arm: enable event stream on WFE instructions Date: Fri, 29 May 2026 09:29:45 +0100 Message-ID: <20260529082948.363931-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043483294154100 Two generic timers (K and H) are capable of generating timer event stream events. Provide a helper to calculate when the nearest one will happen. Now we can calculate when the next event stream event is we can re-use the wfxt_timer and configure it to fire as we enter a WFE that is going to sleep. Reverse the M-profile logic so we can enter a sleep state in both profiles. To avoid issues with QEMU's incomplete ldst exclusive handling causing potential deadlocks in common WFE enabled locking patterns we take advantage of the architectures flexibility and treat being in the exclusive region as a reason to exit. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v2 - merged target/arm: add gt_calc_next_event_stream - update to use halt_reason - made arm_wfxt_timer_cb atomically consume halt_reason v4 - skip sleep if in the exclusive region - update commit message - remove the CF_PARALLEL guards so we work in smp v5 - use env_archcpu for ARMCPU rather then expensive QOM cast - rely on cpu->wfxt_timer to guard event stream leg v6 - use atomic_xchg to consume event_register - remove extraneous target_el calculation --- target/arm/cpu.c | 13 +++ target/arm/tcg/op_helper.c | 142 ++++++++++++++++++++++++++++----- target/arm/tcg/translate-a64.c | 10 +-- target/arm/tcg/translate.c | 16 +--- 4 files changed, 139 insertions(+), 42 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 8771b695d9d..d01b4cee5f0 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -879,10 +879,23 @@ bool arm_cpu_exec_halt(CPUState *cs) } #endif =20 +/* + * Unlike almost everything else that messes with the halt_reason and + * event_register details the timer callbacks are not in the vCPU + * context. + * + * To prevent races we atomically consume a HALT_WFE and set the event + * register. Either way we trigger the an exit event. + */ static void arm_wfxt_timer_cb(void *opaque) { ARMCPU *cpu =3D opaque; CPUState *cs =3D CPU(cpu); + CPUARMState *env =3D &cpu->env; + + if (qatomic_cmpxchg(&env->halt_reason, HALT_WFE, NOT_HALTED)) { + qatomic_set(&env->event_register, true); + } =20 /* * We expect the CPU to be halted; this will cause arm_cpu_is_work() diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index 2b1fb1e059d..b803c9bf162 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -483,6 +483,97 @@ void HELPER(sev)(CPUARMState *env) } } =20 +#ifndef CONFIG_USER_ONLY +/* + * Event Stream events don't do anything apart from wake up sleeping + * cores. These helpers calculate the next event stream event time so + * the WFE helper can decide when its next wake up tick will be. + */ +static int64_t gt_recalc_one_evt(CPUARMState *env, uint32_t control, uint6= 4_t offset) +{ + ARMCPU *cpu =3D env_archcpu(env); + bool evnten =3D FIELD_EX32(control, CNTxCTL, EVNTEN); + + if (evnten) { + int evnti =3D FIELD_EX32(control, CNTxCTL, EVNTI); + bool evntis =3D FIELD_EX32(control, CNTxCTL, EVNTIS); + bool evntdir =3D FIELD_EX32(control, CNTxCTL, EVNTDIR); + /* + * To figure out when the next event timer should fire we need + * to calculate which bit of the counter we want to flip and + * which transition counts. + * + * So we calculate 1 << bit - current lower bits and then add + * 1 << bit if the bit needs to flip twice to meet evntdir + */ + int bit =3D evntis ? evnti + 8 : evnti; + uint64_t count =3D gt_get_countervalue(env) - offset; + uint64_t target_bit =3D BIT_ULL(bit); + uint64_t lower_bits =3D MAKE_64BIT_MASK(0, bit - 1); + uint64_t next_tick =3D target_bit - (count & lower_bits); + uint64_t abstick; + + /* do we need to bit flip twice? */ + if (((count & target_bit) !=3D 0) ^ evntdir) { + next_tick +=3D target_bit; + } + + /* + * Note that the desired next expiry time might be beyond the + * signed-64-bit range of a QEMUTimer -- in this case we just + * set the timer for as far in the future as possible. When the + * timer expires we will reset the timer for any remaining period. + */ + if (uadd64_overflow(next_tick, offset, &abstick)) { + abstick =3D UINT64_MAX; + } + if (abstick > INT64_MAX / gt_cntfrq_period_ns(cpu)) { + return INT64_MAX; + } else { + return abstick; + } + } + + return -1; +} + +/* + * Calculate the next event stream time and return it. Returns -1 if + * no event streams are enabled. It is up to the WFE helpers to decide + * on the next time. + */ +static int64_t gt_calc_next_event_stream(CPUARMState *env) +{ + ARMCPU *cpu =3D env_archcpu(env); + uint64_t hcr =3D arm_hcr_el2_eff(env); + int64_t next_time =3D -1; + uint64_t offset; + + /* Unless we are missing EL2 this can generate events */ + if (arm_feature(env, ARM_FEATURE_EL2)) { + offset =3D gt_direct_access_timer_offset(env, GTIMER_PHYS); + next_time =3D gt_recalc_one_evt(env, env->cp15.cnthctl_el2, offset= ); + } + + /* Event stream events from virtual counter enabled? */ + if (!cpu_isar_feature(aa64_vh, cpu) || + !((hcr & (HCR_E2H | HCR_TGE)) =3D=3D (HCR_E2H | HCR_TGE))) { + int64_t next_virt_time; + offset =3D gt_direct_access_timer_offset(env, GTIMER_VIRT); + next_virt_time =3D gt_recalc_one_evt(env, env->cp15.c14_cntkctl, o= ffset); + + /* is this earlier than the next physical event? */ + if (next_virt_time > 0) { + if (next_time < 0 || next_virt_time < next_time) { + next_time =3D next_virt_time; + } + } + } + + return next_time; +} +#endif + void HELPER(wfe)(CPUARMState *env) { #ifdef CONFIG_USER_ONLY @@ -495,32 +586,43 @@ void HELPER(wfe)(CPUARMState *env) #else /* * WFE (Wait For Event) is a hint instruction. - * For Cortex-M (M-profile), we implement the strict architectural beh= avior: + * * 1. Check the Event Register (set by SEV or SEVONPEND). * 2. If set, clear it and continue (consume the event). */ - if (arm_feature(env, ARM_FEATURE_M)) { - CPUState *cs =3D env_cpu(env); + CPUState *cs =3D env_cpu(env); + ARMCPU *cpu =3D env_archcpu(env); =20 - if (env->event_register) { - env->event_register =3D false; - return; - } + if (qatomic_xchg(&env->event_register, false)) { + return; + } =20 - env->halt_reason =3D HALT_WFE; - cs->exception_index =3D EXCP_HLT; - cs->halted =3D 1; - cpu_loop_exit(cs); - } else { - /* - * For A-profile and others, we rely on the existing "yield" behav= ior. - * Don't actually halt the CPU, just yield back to top - * level loop. This is not going into a "low power state" - * (ie halting until some event occurs), so we never take - * a configurable trap to a different exception level - */ - HELPER(yield)(env); + /* + * If the CPU has entered the exclusive region we could sleep + * until the global monitor moves from Exclusive to Open Access. + * However it would be expensive for QEMU to fully model the + * global monitor and not doing so would potentially trigger + * deadlocks in WFE enabled locking code. However as WFE is a hint + * instruction the architecture allows for the PE to leave + * low-power state for any reason. QEMU chooses to treat being in + * an exclusive region as such and return directly. + */ + if (env->exclusive_addr !=3D -1) { + return; + } + + /* For A-profile we also can be woken by the event stream */ + if (cpu->wfxt_timer) { + int64_t next_event =3D gt_calc_next_event_stream(env); + if (next_event > 0) { + timer_mod(cpu->wfxt_timer, next_event); + } } + + env->halt_reason =3D HALT_WFE; + cs->exception_index =3D EXCP_HLT; + cs->halted =3D 1; + cpu_loop_exit(cs); #endif } =20 diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 4b978c8b958..ec03eaa3bbd 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -2052,15 +2052,7 @@ static bool trans_SEVL(DisasContext *s, arg_SEV *a) =20 static bool trans_WFE(DisasContext *s, arg_WFI *a) { - /* - * When running in MTTCG we don't generate jumps to the yield and - * WFE helpers as it won't affect the scheduling of other vCPUs. - * If we wanted to more completely model WFE/SEV so we don't busy - * spin unnecessarily we would need to do something more involved. - */ - if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { - s->base.is_jmp =3D DISAS_WFE; - } + s->base.is_jmp =3D DISAS_WFE; return true; } =20 diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index e1e5539f571..c10cc382d15 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -3262,19 +3262,9 @@ static bool trans_SEVL(DisasContext *s, arg_SEV *a) =20 static bool trans_WFE(DisasContext *s, arg_WFE *a) { - /* - * When running single-threaded TCG code, use the helper to ensure that - * the next round-robin scheduled vCPU gets a crack. - * - * For Cortex-M, we implement the architectural WFE behavior (sleeping - * until an event occurs or the Event Register is set). - * For other profiles, we currently treat this as a NOP or yield, - * to preserve existing performance characteristics. - */ - if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { - gen_update_pc(s, curr_insn_len(s)); - s->base.is_jmp =3D DISAS_WFE; - } + /* For WFE, halt the vCPU until an event. */ + gen_update_pc(s, curr_insn_len(s)); + s->base.is_jmp =3D DISAS_WFE; return true; } =20 --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043450; cv=none; d=zohomail.com; s=zohoarc; b=fBiAu/gr4KkRcNjsSFsw/azgKfNf3kCoYhXExHtMPT/PHO30xHaKtnJVFJtztMvT0R6UedVQwh05Q8m3GdPt8A7hwU9EXW0EJZVshiQwlV37TPWXhd7bNYgBfla/8Ke4HznCuCTWRj9xvQcjA9z+lYUtJnmGEDeAJ/r8XZuU/Ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043450; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=icgEPrF2PyrBaUqEkggw3Y3TmAdUSPZeT980MGVssa8=; b=FHjEj73JAsR9yoyPUJ7fYgj5oxh4s200dhRAndwL+v7jkmA5ZC5QwVcFy0S5+lh70xRNgdjEjHlA/G1CpL3Hg62fZlBiI+IiedQCwYBaf6XCtYILc8QaiXpv+IlW0BL6XjilVee53sJ0PgVij4PZ5XkcYQTXvvFW7FM4DEU+J/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043450266416.638066834921; Fri, 29 May 2026 01:30:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbb-0001eG-8C; Fri, 29 May 2026 04:30:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbP-0001QE-1Y for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:59 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbM-0005SI-Ft for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:58 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-49048e043e5so58567195e9.1 for ; Fri, 29 May 2026 01:29:56 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909c0498e0sm12827755e9.0.2026.05.29.01.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:52 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E1C3160E17; Fri, 29 May 2026 09:29:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043395; x=1780648195; 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=icgEPrF2PyrBaUqEkggw3Y3TmAdUSPZeT980MGVssa8=; b=qftbTid84zn7a1WAe8r07b1eU5mS/dWGYqIphyb8PR0Jnmtwzr386QqGCXdevS1yuF mBQncINz7AP6L9pVeIYuzNz1tgQnNoyOcD5EuVkYXD6s4C1OwJl49iqPbRz+ZFTQW5n1 kgkDRAWxSqGdsI3KGDmcwk8ZUoIHWwHoUblmSb88iLc+N2HyBkj/HOhuWU/UHQUwGbIC fwuz3/bgRPxOvPEsdEQh6HsoMEnGn1AbvWAUEquSGiQUmCMFNbjswUN7QgtJIx/6EJAC P4KpdctgvVf4OQKvhgJvBqwyOFby9iWD04jfD8D2lSXlFcKls0vyLNyNNSsziupA6XA/ P/nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043395; x=1780648195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=icgEPrF2PyrBaUqEkggw3Y3TmAdUSPZeT980MGVssa8=; b=TOvOi8ReVNvglPkqsZD1ANq85Eez0se6Yy5d2u4/qP631KnOkeW08cVfpVKjfmgmbi FXhTQMx2nvXdHAHBOmodbr+mcvn/v05ZUKJPeRFRXEHyJFmbJNchv5aS92u7kPC2p7Mk 1wvsDngkHzRzmHM5t6BlDZ5lkEkLajNR2YKPszFdWz+wM1DD82Vjb40DACySELNR9Um/ ADZDsuFZc3n1FdheVfyjyV8Hjyy3OI0y2Z3kQd6P1DB+Jzlh+Nc1kK+g1yBuMZJH4D+Q BYIvnYv/zQ8cK90nY7SlwOLPMNF45mLnIo7tdPAz4o+dCGl+rXIATZg6Swi1Wd4crlMn V51A== X-Gm-Message-State: AOJu0YzPbSRrS1JgRGt7P8b3FzlXhlCYoYGxoojx9IR1bkbKo/cR5n2u E2pTXdVVoDQamvflFUZz+NclcdJ6YIYKt/SvdRCzE2/ONhM2eA/qmPX+RwXRfxRT4NbWaL121Vf mqE4g X-Gm-Gg: Acq92OHw0uVh6ytWsd/jlmDCM9cDM04FpJREyfIarkKvt9tDYEca4VgqoZAEbkZVIdd oxKvEiN68ft4ZohvE6vslBbTLjBbF4uj4UyFSTeVhUEavGM4sfpnTTNexNylnAys7oaXp4sr3oF KcG2acff+pqhd8eg2VEp3CD5gpGjlRW3XIQf7WojoELnigLIkSG+ajedRpGQGEy5X44rwb/0EHy 3+UM0Tm3hl40G2EEy45s+yTd4txuKijEMLDK4exi0Iu/pu3lvt9gxQVGpHS+0jRsaKExoTxzUmO 59IEDNK9XWjn2PEiexX/D7nwDNjewCNHnAHV8ULO2B0LvMaexGtKFkCZ7OHmdcKKx/+fkql3MpW rZ7i/zez6glAdGR22MTcwFmpcNePNmUh6RiVR8e/1pbra+v/c7Ll+s27t2xUGLoUu1jI3/p8DvE 3wcFxntY58gTMMJI28QRhiGmI/HIVB7EXjXA== X-Received: by 2002:a05:600c:644:b0:485:9a50:3370 with SMTP id 5b1f17b1804b1-4909c07b4c7mr20113755e9.8.1780043394760; Fri, 29 May 2026 01:29:54 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 7/8] target/arm: handle the WFE trap case Date: Fri, 29 May 2026 09:29:46 +0100 Message-ID: <20260529082948.363931-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043452592158500 Now WFE can actually suspend on A-profile we also need to handle when its trapped. To do this we need to pass the instruction size so we can deal with the is_16bit syndrome encoding. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v6 - defer calculating target_el until after the early return --- target/arm/tcg/helper-defs.h | 2 +- target/arm/tcg/op_helper.c | 16 +++++++++++++++- target/arm/tcg/translate-a64.c | 2 +- target/arm/tcg/translate.c | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/target/arm/tcg/helper-defs.h b/target/arm/tcg/helper-defs.h index a05f2258f29..ebdf09be38a 100644 --- a/target/arm/tcg/helper-defs.h +++ b/target/arm/tcg/helper-defs.h @@ -54,7 +54,7 @@ DEF_HELPER_2(exception_swstep, noreturn, env, i32) DEF_HELPER_2(exception_pc_alignment, noreturn, env, vaddr) DEF_HELPER_1(setend, void, env) DEF_HELPER_2(wfi, void, env, i32) -DEF_HELPER_1(wfe, void, env) +DEF_HELPER_2(wfe, void, env, i32) DEF_HELPER_2(wfit, void, env, i32) DEF_HELPER_1(yield, void, env) DEF_HELPER_1(pre_hvc, void, env) diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index b803c9bf162..060b155d559 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -574,7 +574,7 @@ static int64_t gt_calc_next_event_stream(CPUARMState *e= nv) } #endif =20 -void HELPER(wfe)(CPUARMState *env) +void HELPER(wfe)(CPUARMState *env, uint32_t insn_len) { #ifdef CONFIG_USER_ONLY /* @@ -592,11 +592,25 @@ void HELPER(wfe)(CPUARMState *env) */ CPUState *cs =3D env_cpu(env); ARMCPU *cpu =3D env_archcpu(env); + uint32_t excp; + int target_el; =20 if (qatomic_xchg(&env->event_register, false)) { return; } =20 + /* We might sleep, so now we check to see if we should trap */ + target_el =3D check_wfx_trap(env, true, &excp); + if (target_el) { + if (env->aarch64) { + env->pc -=3D insn_len; + } else { + env->regs[15] -=3D insn_len; + } + raise_exception(env, excp, syn_wfx(1, 0xe, 0, false, WFE, insn_len= =3D=3D 2), + target_el); + } + /* * If the CPU has entered the exclusive region we could sleep * until the global monitor moves from Exclusive to Open Access. diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index ec03eaa3bbd..a4603e1a5c7 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -10961,7 +10961,7 @@ static void aarch64_tr_tb_stop(DisasContextBase *dc= base, CPUState *cpu) */ case DISAS_WFE: gen_a64_update_pc(dc, 4); - gen_helper_wfe(tcg_env); + gen_helper_wfe(tcg_env, tcg_constant_i32(4)); tcg_gen_exit_tb(NULL, 0); break; case DISAS_WFI: diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index c10cc382d15..1f554f6c271 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -6836,7 +6836,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, = CPUState *cpu) tcg_gen_exit_tb(NULL, 0); break; case DISAS_WFE: - gen_helper_wfe(tcg_env); + gen_helper_wfe(tcg_env, tcg_constant_i32(curr_insn_len(dc))); /* * The helper can return if the event register is set, so we * must go back to the main loop to check for events. --=20 2.47.3 From nobody Sat May 30 15:31:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1780043516; cv=none; d=zohomail.com; s=zohoarc; b=en1Z08RPk6bxWMBvRuOhv/AwnhO/FEqNZU4jiZA+A2gfBFF+g8t0/NiXT8gJy1dNoaoicHl19fyNq0h7k9FUu76YHnaI1w34B8UvgSIJlGb6PR13yu3stKlVp4nnikW+KvvwUaWYHoraiNX8wCh4EBSzRZr6CjWZre+ZXour664= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780043516; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7tgFV7aLv3VEy/7Ybky9gI0Jx+ddlu649tCYp82H6wk=; b=IZRKKGgaZu8SAe5yS3p4O+pmx/9olrDiXHVepJ5RKa+3t5wGzlW1w0JcsapHUtQXp/LpgpLnE76AaTrUl34q+c6jdJQBc05ffIcLXvFBkH2v4if4TCNkT8iEzLeN7x9e6PkRlWdCJPAM+hUiDSAZOxh0wrfkdLK7UnB58mE9Rcs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780043516866478.9571225167201; Fri, 29 May 2026 01:31:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSsbX-0001Ti-Se; Fri, 29 May 2026 04:30:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSsbN-0001PY-Pi for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:59 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSsbL-0005Ri-BR for qemu-devel@nongnu.org; Fri, 29 May 2026 04:29:57 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4904c1ce4c1so77501225e9.3 for ; Fri, 29 May 2026 01:29:54 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909d68980csm31925225e9.1.2026.05.29.01.29.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 01:29:52 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 091C460E34; Fri, 29 May 2026 09:29:49 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780043394; x=1780648194; 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=7tgFV7aLv3VEy/7Ybky9gI0Jx+ddlu649tCYp82H6wk=; b=oSyqYz1+Ps+chmiS8h8qPL77IDY+lB00w+WLFvzzXhdhG4Xv1BLmebUgL30YhFZFA4 bXVSJxUstoIXUsg27c+a7V/xxEK7780kf4jozhRWTbwbfeFoJ4uJogNqLZUxR0uHqyxv pdMt80nO1reKTIBqz84MNCXwWdvbtVT4Rb0+sbzFdhKXEiIdU2X8gLeknDPyjowkiC1s y/A2bzcOElOoE6dTem594Xd0ikRVud9axle932H/r1Zzs0aGXBcaqYAJ7yIPdG4WvBKj /1+tT2y3Ttv50Y1FbKD7bpZrQZdrzEvhz3FvWFn9LYasWdcGIoHx3BsnnlvfbMaYDBMv EBkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780043394; x=1780648194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7tgFV7aLv3VEy/7Ybky9gI0Jx+ddlu649tCYp82H6wk=; b=R6Io/tAr3LIem2eMkLCQ0sDywYd7M/IpWJpAyD0geJ4KGJPNWqvRDvI0oHJ7UA2UPW kMvcJGo+fsZnggy8+Vir56PVlAS4kwRclxvyduTuVJPjVvp0KYvslAQum2LcOyLHQVl3 2DkzdU+PMbPxQPv7LPwu4ExSolF1fMDmRluUnyPYmZ3+c72J15+KTcPNMCJZ8o3cavo1 ALWga7XYX3OfCH1yMiDAVx/hRwMdpZrs7XCGn8M2Bn716iQSF4NHEhY5lsRz3wyUHPUl 9I+v/LNElPknxFYzx/4AGoFClgQiTxaxjtPeLd7UdT6GrZEeGSHmasyyBbiI3oKv/whP 2QFA== X-Gm-Message-State: AOJu0YxLZlYgAhAbVYFR34MCwj+OoCD5PSTXacZSLLtX59GkjTYFbozD xOh2xEZyAg4f/QkKfMKnXF03w2RpeFfeOUBtyMNNZ/5ZMua4HpfBLFtRwyyfJMCW3b8= X-Gm-Gg: Acq92OEk8Ll+LyLJzI31rZgyTf0xuE6QafVp2GvKlh67ZSN6E1H0eWlH8T4Z/SzszrP rjd1lryT6v5FkTDEDn0RAMNM98OjSHRMQH1vDFGTZCzIo1SRDK8m7jmHhYxldGFvVpO83ogjUs9 95WIZhTGku0GfFW+NfBbteXTgDnGILc/UKy9lb5J3woHnKO4gH4sQtp6cWeia5Xq3Ro2Cav3wtO FIqF1Wc+hvIWSEtqYbHXxjVLmT8ZDzd3oEi1XL7ZT0rrqbEeYLwo/dz8fFxIgN8/eiZaf2/Otj/ qpIEhBmVrNIQw02bc4uswBkoxy5iEwdP0ggyLtz6M1OlkbXW+UH79Cj8k5xps57kNR7KLK3JLV1 +B6rmWlmcqofDECDc9OLtBGlcx+de+CnGoTD/F4F67DTzB/+ifdSX/iXh2J7ALXaWQGRQ9OZIHQ CToj5MJdyu3GV01amlBz1jTXBfwk2isbAIPZjOExa0N6Ju X-Received: by 2002:a05:600c:48aa:b0:490:81cb:d7a with SMTP id 5b1f17b1804b1-4909c0c6b91mr19613565e9.29.1780043393788; Fri, 29 May 2026 01:29:53 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Alexander Graf , Mohamed Mediouni , Peter Maydell , Pedro Barbuda , qemu-arm@nongnu.org, kvm@vger.kernel.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v7 8/8] target/arm: implement WFET Date: Fri, 29 May 2026 09:29:47 +0100 Message-ID: <20260529082948.363931-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260529082948.363931-1-alex.bennee@linaro.org> References: <20260529082948.363931-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1780043518885158500 Now we have the event stream and SEV/SEVL implemented we can finally enable WFET for Aarch64. To avoid issues with QEMU's incomplete ldst exclusive handling causing potential deadlocks in common WFE enabled locking patterns we take advantage of the architectures flexibility and treat being in the exclusive region as a reason to exit. Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v2 - fix exception syndrome by using enum value - use env->halt_reason v3 - fix check_wfx_trap(s/false/true/) as it is a WFE v4 - defer expensive calculations until needed - treat cs->exclusive_addr as a IMPDEF WFE exit - update commit message v5 - use atomic_xchg to consume event_register --- target/arm/tcg/helper-defs.h | 1 + target/arm/tcg/op_helper.c | 94 ++++++++++++++++++++++++++++++++++ target/arm/tcg/translate-a64.c | 15 +++--- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/target/arm/tcg/helper-defs.h b/target/arm/tcg/helper-defs.h index ebdf09be38a..5e4d828dd55 100644 --- a/target/arm/tcg/helper-defs.h +++ b/target/arm/tcg/helper-defs.h @@ -56,6 +56,7 @@ DEF_HELPER_1(setend, void, env) DEF_HELPER_2(wfi, void, env, i32) DEF_HELPER_2(wfe, void, env, i32) DEF_HELPER_2(wfit, void, env, i32) +DEF_HELPER_2(wfet, void, env, i32) DEF_HELPER_1(yield, void, env) DEF_HELPER_1(pre_hvc, void, env) DEF_HELPER_2(pre_smc, void, env, i32) diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c index 060b155d559..b64b80fa653 100644 --- a/target/arm/tcg/op_helper.c +++ b/target/arm/tcg/op_helper.c @@ -640,6 +640,100 @@ void HELPER(wfe)(CPUARMState *env, uint32_t insn_len) #endif } =20 +void HELPER(wfet)(CPUARMState *env, uint32_t rd) +{ +#ifdef CONFIG_USER_ONLY + /* + * As for WFIT make it NOP here, because trying to raise EXCP_HLT + * would trigger an abort. + */ + return; +#else + CPUState *cs =3D env_cpu(env); + uint32_t excp; + int target_el; + ARMCPU *cpu; + uint64_t cntval, timeout, offset, cntvct, nexttick; + int64_t next_event; + + /* + * As for WFE if the event register is already set we can consume + * the event and return immediately. + */ + if (qatomic_xchg(&env->event_register, false)) { + return; + } + + /* + * Don't bother to go into our "low power state" if + * we would just wake up immediately. + * + * We want the value that we would get if we read CNTVCT_EL0 from + * the current exception level, so the direct_access offset, not + * the indirect_access one. Compare the pseudocode LocalTimeoutEvent(), + * which calls VirtualCounterTimer(). + */ + cntval =3D gt_get_countervalue(env); + offset =3D gt_direct_access_timer_offset(env, GTIMER_VIRT); + cntvct =3D cntval - offset; + timeout =3D env->xregs[rd]; + if (cpu_has_work(cs) || cntvct >=3D timeout) { + return; + } + + /* We might sleep, so now we check to see if we should trap */ + target_el =3D check_wfx_trap(env, true, &excp); + if (target_el) { + env->pc -=3D 4; + raise_exception(env, excp, syn_wfx(1, 0xe, rd, true, WFET, false),= target_el); + } + + /* + * If the CPU has entered the exclusive region we could sleep + * until the global monitor moves from Exclusive to Open Access. + * However it would be expensive for QEMU to fully model the + * global monitor and not doing so would potentially trigger + * deadlocks in WFE enabled locking code. However as WFE is a hint + * instruction the architecture allows for the PE to leave + * low-power state for any reason. QEMU chooses to treat being in + * an exclusive region as such and return directly. + */ + if (env->exclusive_addr !=3D -1) { + return; + } + + /* + * Finally work out if the timeout or event stream will kick in + * earlier. + * + * The WFET should time out when CNTVCT_EL0 >=3D the specified value. + */ + cpu =3D env_archcpu(env); + if (uadd64_overflow(timeout, offset, &nexttick)) { + nexttick =3D UINT64_MAX; + } + if (nexttick > INT64_MAX / gt_cntfrq_period_ns(cpu)) { + nexttick =3D INT64_MAX; + } + + next_event =3D gt_calc_next_event_stream(env); + if (next_event > 0 && next_event < nexttick) { + timer_mod(cpu->wfxt_timer, next_event); + } else { + if (nexttick =3D=3D INT64_MAX) { + timer_mod_ns(cpu->wfxt_timer, INT64_MAX); + } else { + timer_mod(cpu->wfxt_timer, nexttick); + } + } + + env->halt_reason =3D HALT_WFE; + cs->exception_index =3D EXCP_HLT; + cs->halted =3D 1; + cpu_loop_exit(cs); +#endif +} + void HELPER(yield)(CPUARMState *env) { CPUState *cs =3D env_cpu(env); diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index a4603e1a5c7..fb9a212df4b 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -2086,14 +2086,15 @@ static bool trans_WFET(DisasContext *s, arg_WFET *a) return false; } =20 - /* - * We rely here on our WFE implementation being a NOP, so we - * don't need to do anything different to handle the WFET timeout - * from what trans_WFE does. - */ - if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { - s->base.is_jmp =3D DISAS_WFE; + if (s->ss_active) { + /* Act like a NOP under architectural singlestep */ + return true; } + + gen_a64_update_pc(s, 4); + gen_helper_wfet(tcg_env, tcg_constant_i32(a->rd)); + /* Go back to the main loop to check for interrupts */ + s->base.is_jmp =3D DISAS_EXIT; return true; } =20 --=20 2.47.3