From nobody Sat May 30 17:33:08 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=1779882299; cv=none; d=zohomail.com; s=zohoarc; b=kgELNn5dobgWYveAkkH+MECZjgxyghbS2aHbS34n5mj6GYvn/rTO72ceXSIKDkCPWA7rPOfG+tQraFylam6LzWFJGHlH4QqnUte0E+EaqEQBnZ17nZ7S9yXE5b4eHz5qElB0QwAZVVWMeQ2tpq8JzhlKax6Dr5x0yWonDbyLLhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882299; 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=+7GYxN2UVnGng7v1vHA64tX2rIv4kqC27OcexOk0+YM=; b=CX0Cps0PVgKhjO6DrKTRg7nrtFUe8TjLIvPb+dLPr3ZjGLsBo1ooSKhn1GoscJLwYgDWRzCS89DvpiMvdgh6B8CByQE/uYLAcHIX4BH1gJ6EWoDIK98M0O+mge697XDrsRFSnB/jZsAaMZ142zZVf6gI5MDzYU8NVXKpix0CGi8= 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 1779882299219289.93080769803896; Wed, 27 May 2026 04:44:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfY-0005KG-I9; Wed, 27 May 2026 07:43:28 -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 1wSCfX-0005I4-Gf for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:27 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfU-0008UW-Nz for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:27 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-44a5174670eso6482351f8f.1 for ; Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45edb5c47a2sm5341167f8f.37.2026.05.27.04.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:21 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E2E5F5F92B; Wed, 27 May 2026 12:43:20 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882203; x=1780487003; 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=+7GYxN2UVnGng7v1vHA64tX2rIv4kqC27OcexOk0+YM=; b=U5B9t06H7u9az+5T4GeRnxIWGoRLwNCaoQBQnTGd4fHVrC1oHILBAtYkPLfrDLMDM0 Q7sELKEpsSfPBdYWx8DpbWeFKmShc6oBXTsZBfBJNHyzrv9wr0IRwu0ynk1FC9ijjj6P O2bLGunOXaG+5xofdoeQuJr6WPQ1eKFZAjvP/WdqKjn+tmbJnqxaoH9PdqLj8blI7LOV qPKjcJHRWUjFx7aEbViiiYN+UA+gmYei3iWclNLPgYRsuCWS2ROKGy8EuL/FkDKNtAgK IovycJ8UjEbugdcwFa5p4dBWbY4Mbzpnc3IzawYHSczQZl6fNqloKYBaFOzBqAa7gJaq +wUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882203; x=1780487003; 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=+7GYxN2UVnGng7v1vHA64tX2rIv4kqC27OcexOk0+YM=; b=eMHa5/UoJfJ3JHktRn5bmq3pJFdA0f8i2HcxbMDTem6wlk6jdK5Sd4+BphXz7mjWsc vkSkYroOo0zXTZLBBj18ByykL5i0KqAw5esqYHeEEDJByESpijDMO83xRUrX+iuuUOmr tINYUUiPvDupdbockB2fE2UGzY2XakRjE5WHglHPVjDwUZ9LI1tFidHbZGDrzm8/bYzc COZgpUEG9Dy0jVOqoksF7GFDvcTohUKUIg3+mVnggQSwnhd3X2YIRe+wrroKfzPKLjC+ rcMeJT4LCMCnbmw9zFr7I8M2eJKMAN8VbHmXMm7qDk9IFaOnZvWObmxlb7rykQSTTfq7 a1uA== X-Gm-Message-State: AOJu0Ywk3vUua1l8ulLJs3oqBKR2q9sDqb1YSUUjqEBlFRIB8d/7P4Tu oJBLu6Xv3ctrGMFqzKQXoeBgcKlnpCndCwgK2EUfZeXdoQ6N4JkOcOeOppHhopEOd08= X-Gm-Gg: Acq92OHKZSaVbV5fEq+xtjPMTBz/QPWZo0RLIuyPQADPPxd8959fCYKlbkdC2AEMYTM os6GaBgnHjvU3TMv3Oo2FGII5CjhEnKZf+Ar76oUPO2m3cxtX1+5VLBmx9KKHN1PjJi/UtS+2fe FvLGBPuXHgv82dOQGDO8qpm/4ZynX4gOdWFQwWnHiCU/UVDt5OG6ZWOkd3CfRJsVrGYBHIAlFHQ XZXBvKYm4mjg1qmSTmYTE/z/l6AuloIoNT9RjxmFPlUKDKpIf2OZ4v49yjkevZCztIzHUo0YltK LN8otSh97UF8k04E8qPPE50dcNANfJcBjVQ/me5APTh8dPhZt/tyDbPLNhmkoEAmvGMka5rjNsf JMb/WvDearCs7Q1EkONr/WLuoRvbd1ckAL51UmuUNsAsEqiaVYp5eklHMODpzYJOs/Kd1oVMzuC m1HHjYkHXAEtfc6qEa5wtwgfaptc7LI6Oi4Q== X-Received: by 2002:a05:6000:26c1:b0:44f:d9f8:c0e7 with SMTP id ffacd0b85a97d-45eb36731f6mr39921252f8f.5.1779882202929; Wed, 27 May 2026 04:43:22 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v6 1/8] target/arm: fix WFET typo in syndrome Date: Wed, 27 May 2026 12:43:13 +0100 Message-ID: <20260527114320.1581552-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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: 1779882301270158500 A stray x slipped in and we didn't notice! Fixes: 4575da5ecb7 (target/arm: report register in WFIT syndromes) Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- 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 17:33:08 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=1779882326; cv=none; d=zohomail.com; s=zohoarc; b=Z0kn8Shs6Vbq0Q/eP2DXwFvK8wdlLpp5cIc3aa5tGaPnOrPbcWwPHu1tsrE+LFNbTD8Pe2eP5NaFKkWSftpJQdNo4McAHqWdbk5bFGjVnvBgQXQa2kj9vIGILI/e34UVzEdIFEMC6o2d7Tk0YuW0EEl4lccg+g4p5H+sNawFiHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882326; 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=usmkTmoNt7MujhX2fIpEqD99hA9+jgSr5Arc9FH3Q5g=; b=PVmY6VB/r+tVVvx2GE3aaXmzu12d0iRKQ7sjROE/o5NPUZCqcZVWmCxYlKYKULUOMCuHhDupJwL2H8dRe/p8tI6MBtQ+QZMhD7aPP5KIWlKppK/9h3t9efa+vak6pXEkK13GZ9h1cl+5eEcQNYl7A9DuAeoKrGshuMP3Y+Pe6/Q= 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 1779882326528872.754134085565; Wed, 27 May 2026 04:45:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfb-0005MO-Ik; Wed, 27 May 2026 07:43:31 -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 1wSCfZ-0005L0-Mz for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:29 -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 1wSCfW-0008WG-TZ for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:29 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4903d730b1fso51023235e9.2 for ; Wed, 27 May 2026 04:43:26 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4908098f8c8sm15238135e9.15.2026.05.27.04.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 0CF8A5FB8B; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882205; x=1780487005; 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=usmkTmoNt7MujhX2fIpEqD99hA9+jgSr5Arc9FH3Q5g=; b=DeVcJ0GZEZz+U23kssjkNHKH3AztkJ5eEa41S706Kntkf3S5da9ltR7ltDGUnCDfpJ VA0hsHmkPeImQZ1DpbqjdUqxWc5eVTqmIK5y4XN5FGF/fIIIsAjUYwz3CS2/SG7Xy74x 8cGJAojcTvz4sD+iZztDtIBtNrOh32nHfWgUf5JgRPIEN+LTwS+gcj5y+tNmjIkg2/3x IfiBZmPdbkctpLjeepHnt3fANkCIrtAmyXwXs3Pv2TRwVivuHZuPFVXfRftm1RCbAvHU 6Hfd4LnDfUknK3nQX3I0MbYYVmJQthAf0HkbA5xPxjnczLyEuskvUzfhTxomsKyx7Olp WqPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882205; x=1780487005; 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=usmkTmoNt7MujhX2fIpEqD99hA9+jgSr5Arc9FH3Q5g=; b=LzpMlx++Bp9ynCy0DEPZeiBbPKMjrBntV+8ChnwS1eVxzoRr+/lqgrwloj6lPUmY/l vaHtBLlDIgVfz6Ff8TwfHw+Y2g2TW9d7sN1/2Zh35IS2HXcnNEpHqEbYe+kktR8b0dH5 1mGfslFIExO1v9VFRH5wX3LRMk37vGuk+hAoj2FMG0VaIyujZ2jPvgg61i7FLyryM8ch Qo9KTcr13eRiuT6EIX+K2lsHLGzjbbMXqFwJgXQ9JubykUhmjuZNc5yB3paA2fSjbiZ4 znoZcheFrL8ztAA9qEXBhAuPgR+NF+GGyC4s36Stn69uyGsnlKNowwguLdiI0Iwue31b JthQ== X-Gm-Message-State: AOJu0Yw8Yc15NP07eQNdEDJ/7o7gPhCNcQqEiAPMmdQkWXDcsuBqDwll nBPCkhy8MxcR4KlIEq55RVu+fPXI369qyaWWFBPf46hFs79H+yWTGlShOQBVtmSM9L98ql19U8q ojsxD X-Gm-Gg: Acq92OHpsITJKiZWxHrJ8kzjs5Nn2hPcD7oLCgQXYuV1FQgDcrWboH0fff5eQW0JAuq wR4eH6Iyov1tEXfXW+FzKKN2g2uWfNMnsY5/BSTjWoOUUpZsnP0YsPqkjsK14mISvt0KvY5o+Q2 iCMfAjYa3In+6r2JkPRFk7Jc7d9Ue8Rzwyb8NSz5a9S/9DTneBnjg4PdPki0hepMFigTYU/amix GkJqSxUzBS1fX+ZEAWoOH0TdyIto8o24loQ4hg6ZiUAvROdGwiZG8K7E4l0wX66G+1mRUarFO3z xhMMesmZFWZ+fIa0wU5c6ytoQxi/l7euDpHeczGuqfmL/HVFQyan61DmC0XvGF2dXfWG5hFsWFd 0buLWQ2DE8gA1N0dTEBKQ5Xit3l6Slu6AvFPR18tzm+Hzf04UHKhqQc6eLVJrBjVMQVqgQ9WJfr YlTrZmlgphKiQ4DYLBHuM1hrwrmzgO24U/XQ== X-Received: by 2002:a05:600c:5298:b0:48f:e230:2a26 with SMTP id 5b1f17b1804b1-490428e16bamr379652715e9.33.1779882205137; Wed, 27 May 2026 04:43:25 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 2/8] target/arm: teach arm_cpu_has_work about halting reasons Date: Wed, 27 May 2026 12:43:14 +0100 Message-ID: <20260527114320.1581552-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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: 1779882327424158500 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 15a13b92927..85f2c25f476 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -260,6 +260,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]; @@ -781,6 +794,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 00830b17248..7deaf1ab6de 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -2010,4 +2010,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 c47b70ac694..8bed5214eed 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 8dc766d3225..dbd39e7ba76 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 17:33:08 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=1779882318; cv=none; d=zohomail.com; s=zohoarc; b=ALHz1QqzQqCS3Mou7pi+6Jw830R6aYKZcKwdIpilYPteqA/2RklUA2Tvfu9U4i6L85AsZl9qSJo4h8I/95s3Krtbz+XAYkDxP+FUDdEi3pgqAYUPq0tk/XMouiJN5KF0nkefKwQfie8M/S8m2+rwbNOjH8WisnLY1GyHCrpfR2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882318; 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=Vr/dCWZqkxecamIVH5FjFCNfp5PazmhoCWjfR1OvVNg=; b=BIpohjV/TYTiHKZM2EiOzEnH8eow5oy7UYyy1G5HYpKIXWRA4Xs4UuPfj5MQmCVTjKvLUdRy3NmfyD5ufuLYmnGFm6ok1/mQ6/qg0O4hTVqf7gNk0tFGmBzayAciavwUKt5xPTe137vSHm+u7gie4qy7GPl9xxEWEMTRmgTiCJ8= 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 1779882318435214.92575645831334; Wed, 27 May 2026 04:45:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfZ-0005L3-Q8; Wed, 27 May 2026 07:43:29 -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 1wSCfY-0005JI-1C for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:28 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfU-0008Uc-TI for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:27 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-48fde648a71so77041875e9.0 for ; Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490454c600esm383473175e9.3.2026.05.27.04.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:21 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 24CF75FB96; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882203; x=1780487003; 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=Vr/dCWZqkxecamIVH5FjFCNfp5PazmhoCWjfR1OvVNg=; b=SogYB00knIA9Uql+I2ujVkTkelh37FDKuyP++dNS4ZzoUX5jpuiarx8fODIbVQwMgG lDQGWRSIftyE05pG7oPtq3nEEHo46tWLhI8CnPsLZY8u0l8U3K5Pm0N/YZ4C+5GqJs/U Sa5nvGurWY6AXw/c1FDNZgp0a7/NAwVresaq07GnxzHrCobaID2VbojXVtZ9PC2lz9pU Nkl6AP2Ie5TQEHI9vViZh8Qe+4quUuD6j2LBJ0KOaF8tOjg8p7hMYSaz/CbuNBfw3vFG 6ULP/zdE5aiiy8dv0gmEHHOPelBswZ0jn/vpzfrgYDXzVTEKZs/OjNaagECuYqa2Ys3w hxnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882203; x=1780487003; 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=Vr/dCWZqkxecamIVH5FjFCNfp5PazmhoCWjfR1OvVNg=; b=n19ArKbmcE7isUQC7JInefszrH8Gc9IIsDl3UWUcYnifbc4KgQckcLx0QkK9c41Ltk DwPoV2jewUSW785zlLSBsNr9PdTmIyGHAvNrT0tkMvyDvj7x37WIPkfuQ3JwI3lpFmFy SIFc5PKhMz1AQNc10QRk9OyqrAujXrGSzR1qmxahNb81YD5DjCtaaBwelmBc8bbwoxtn tFAH5qDJXi7YsjjmMlN4oZsqSLwZ4Gmt1voZYBXFcNC2K07VARzN6bW5N1Q4fuEH3Bhg 9079Whes4WzuOM3wW6a/zm2mYnuaicBwpFuPldzGgnKn7Aj6IBSYX5RJQqUFD45auGCM viyw== X-Gm-Message-State: AOJu0YzG9N5Pb/IjcVbL/ncjHjbBVmDQ4Q3Y8ufW3wZEBJ2uJ2LYXXch fOikj0cL4BQ+bfOu0jLQkzoOtdA7uZfx+Q87hXS9ahstcPJQnNnK2ExfLX4gM0uFksw= X-Gm-Gg: Acq92OGv8K+7Pjs69i8Fgq1VJRwizK640uoGrW5FP0kRJBXvWn9K6j3J04cSXBBYE9J 8qC8H69VOZInk8H6IzeRwmjWR6tuwR+FxhHDMcz75PXgRqZtEkTE+Tvva39O82MWM0ol/KkfiIl iVhtiZUcdbhh1jfDHYGGfBCU7Fbsn0dSwKb6V2dIbgTRscfv4qAsnn8eLA0G9+hX3ILNzlEhpTn klp2SKPZhBzrJ11+yhE0Oq1dCzWcFsSsVeXungVzEjVskXhu9xToKz2AqLx/Q7CjmtwGnuTPXq2 RUsR2k4L2uhv3O40L0fHBV/owGiXtPVnYZ7Tkp080R6xERMII376ShXa303xrEG0YSVSGIMMrAf WMAmJynRMFw0burVI/3SEZS4+fD3JkF+SZVmlfh52cIZrFCUD7JSh1fpsv5wiOZZ943t1iojHw/ V36c7tV1MwHXAtzIORsA4H0Qs+k/p6XGy0Yw== X-Received: by 2002:a05:600c:6992:b0:490:5000:917 with SMTP id 5b1f17b1804b1-49050000ae6mr310718185e9.1.1779882203368; Wed, 27 May 2026 04:43:23 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 3/8] target/arm: redefine event stream fields Date: Wed, 27 May 2026 12:43:15 +0100 Message-ID: <20260527114320.1581552-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.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: 1779882321111154100 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 7deaf1ab6de..0c22781919b 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -269,14 +269,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) @@ -286,7 +289,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 8240f1b3848..3b06bd80a01 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1766,9 +1766,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 | @@ -1783,7 +1783,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 17:33:08 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=1779882326; cv=none; d=zohomail.com; s=zohoarc; b=KYImONhYDTdn37WtZxEoCFQ0E2J4vlnJTrIV3VIdnMmMHHSvvyxbnYs/pHby8zG3+3/bgEl414vDAlXQrCZMvu5MBzxzh5Efml42hzaTLfryEP9i1jUI4leZpW85lnO+na035j1nFfP74LhpNtTbszd3OCAwCUQiJ6LrHWaEcGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882326; 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=AJonqsC661AicUoZ3WXf5dOPD/EyukyFdYhNbfWENfY=; b=jAKqu5nW86bc9YTCURl/7LN8oiriCYKdDxBjCvFn/fl9Hk8a7b7hinykRyuJgGR3v05I0jBAHWRlF7H6Wm5seYiiqjoK5nZgyBbulZPokm7TSjW4QcR6Y4tHyxuS4nYrVNax9gmBHoRU0UOIXg1Nm415stu8TaRJueizS7d8BEs= 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 1779882326408480.50495294533687; Wed, 27 May 2026 04:45:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfb-0005M8-2M; Wed, 27 May 2026 07:43:31 -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 1wSCfY-0005Jr-5T for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:28 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfW-0008Vd-74 for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:27 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4904c1ce4c1so53438185e9.3 for ; Wed, 27 May 2026 04:43:25 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45edb557679sm9410757f8f.10.2026.05.27.04.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 396A95FBBF; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882204; x=1780487004; 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=AJonqsC661AicUoZ3WXf5dOPD/EyukyFdYhNbfWENfY=; b=Bdwi5i8YkT07kA5l7QiSdckCarbeG9BMmi0JFpaGiRxrOabKEVA9+A60WTQeCVL0F/ dI4r/txCPitjy/vFM7Pd8SiibC7Nerc3V7ZCxVYsH4dU7CHLtxaNCuPD2YBIGMjaBB+E lIEGyzI5LXI/Be78moHR5HzlgqHNUDtP0ZiTUXL08dL1Rpjna8byUa2aCkZofq/7+1Mw HgOJbAHO6I1CL8WT4+eNL3AIc77fGvx+CkSB1B3xpr6fBbNPOw5FImZCenZZAioPIBub ryI1J45bHv3nb0uZkv/n1hPhFHCfcb3Ve8C8AbOORZGFFzI54jAPQgFWdiKMLmhwlOWX ikCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882204; x=1780487004; 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=AJonqsC661AicUoZ3WXf5dOPD/EyukyFdYhNbfWENfY=; b=EGyk9Pf6o780bLLy/XbfNsIJQaAeYjm5KSuOWpZjwEWnw5CB8n9hjJvjiT2ft3Bb2n I5mTTnZqSf0sUjMfCaYesqwryN99/B2ShfO+1g2iecwocOhaPRRtBqE8iJUhu3Ffi5Z+ 2+G6+1cF31yamMFIS9HHxauzLWVIo0wagTaAehwvhHjvwWrlmUYV4KEeOIeuscKV6iEA Ug/qEo83f5yeNuxfp60Aa2wQRLhz4cmTghMJpn98+d1X65GrgTv18QKRxgNBqJcQTNpf CeyXXI21mNyypAZDQMWDIKhSV5xeSeZmCCiHdgjecO2MibNsb6ife9QVML1yDoC48xBw 9JOw== X-Gm-Message-State: AOJu0Yw5VWyCfKod+s/RhoUew8Tt2+z15aRQqLnHKk59HIhb2dAvwaPz 9kedCWoUY7RNHwGVSPvLXzAW3rKZKb+LbxJ7U9EJ7bzVwn9tv1pou/tf1aSwIbPGtsM= X-Gm-Gg: Acq92OE4C98oZkIkUU5wYsi1sohWhGmsg6VKWXPVJ/g6AYrY178MAFlCD00h3nyjWJY uxPhzx+ZWarGC4nMaHtzs60e5UNSWcGT/6+E9nm6oA10jb3CkvrgT8spqQBH8VOK88AVqJOwm4q MbHoPrzg1GUfDVJpXtE8JRY+kOHHx1IVS7xrn9oZcOQOHAfSLYVOy+yntUPHO5FjKnk9ekNgvUL 9x0cnrreXTmFZT5LNttfTED035vLNGo4mtpXcBM0AyDuWHOARgct7cDiQebQ/Ax3h//fl7BnWdb 0+FjrDjAq0thSXx2SOuFmrQiRgRRo/5dUzmqGakgVDLbinhPxShq++tLeSnEFiRGPI2MeB6vElR gMrCvi8Tw01NXFC9qxC0WNNc1Yk2ZjFodsca6U61/HHC0O7p7Hdzz2dPoDmhEa0JDgz+qahGPVK K2Vo03eMlakjhC6GbML6uGSX4= X-Received: by 2002:a05:600c:45ce:b0:490:59cc:998e with SMTP id 5b1f17b1804b1-49059cc99famr238489835e9.3.1779882204321; Wed, 27 May 2026 04:43:24 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 4/8] target/arm: ensure aarch64 DISAS_WFE will exit Date: Wed, 27 May 2026 12:43:16 +0100 Message-ID: <20260527114320.1581552-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.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: 1779882327297158500 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 3e3971db3fb..d057241e9df 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -10913,25 +10913,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 17:33:08 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=1779882299; cv=none; d=zohomail.com; s=zohoarc; b=i1GBcKEm+OQIBCArBnsoLDmufUilTPEIqxFiLWg3uZV5nLuIeFRHQii2sLJ+u7Ln4CjPPvcj/MrXdjJu1YEcwCXaer7csHiw/U3+enfF16HcZ45znciiFZW8Ea9TU5j2tQAt1IPSaepUcyQtcWuokrj6Woqps6aV4zSiip5DI6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882299; 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=FBl31Y76dj9Fn6xR53TQmxaU3MhNp2vGodHlX1p76nM=; b=joQw4+bcIGMFrOvvpS+3wA2NCzG6u4ExmKYUKcj8RjRIDEAUpclXoCj+KwoV2vyEo6pz1wE5DRdX5YNkmvj4jFBel9EuiSw1g9FgeOrxnATRQrDPmSHXWOc3fFqvoa6VJKsGtdLBEz66+lZRk11AkCB4hi85AdFP9yLL0d7WNaA= 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 1779882299676269.34942966205665; Wed, 27 May 2026 04:44:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfd-0005OH-5A; Wed, 27 May 2026 07:43:33 -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 1wSCfb-0005MJ-Bq for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:31 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfY-00006R-5J for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:31 -0400 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-44a74032ff8so8628233f8f.1 for ; Wed, 27 May 2026 04:43:27 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45edb557679sm9411055f8f.10.2026.05.27.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 572CF5FD5B; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882206; x=1780487006; 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=FBl31Y76dj9Fn6xR53TQmxaU3MhNp2vGodHlX1p76nM=; b=JN8pheJNsmJeT+dftAkIYC6RpeQ5T0K8V8VtNnPjMTEfXH8mH9eUQ1h51ggSE+lfTN k0UHuRRy9wqDKliTbEdSif1HrnTN5/JZ0pecBekYBuCaFXjA/K2TKdFvNFbJ8wuTXjEU kCpBqh0GFPKgGo+gVj9mG2Qx6Vpk5wCoI2Jzfy1gpeF873wD2SS1l7Gpvb2ba8wFKFU9 YdPq1T+mrtRhXSWyPKUUQ7Y3hJVLkZ3exnOhMKadtOGpjA5gBE8JtrScVo9eeJzcJIrG jB/w+pKWCkrmjekyz6gTQOJuY0rPHdn5LBUuLMK9T9J08hfvh6I0vAHq7/XEGDuCvRSO p4eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882206; x=1780487006; 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=FBl31Y76dj9Fn6xR53TQmxaU3MhNp2vGodHlX1p76nM=; b=Wxwhrsf+cYEs8JW1fhgTGV+PvJJma1MiVKWLGjt1hS5PaTWUrL0kSkklzATPl3nU7w P6MIsSlgMol+eaIufehcIqIVuRTQKT0b/HM/TOQ3KCxlA0Xhv/yiOFSFHYT8lrYNlPI6 go2OdIIRw6eH1PflJf1CYeqATEpApxW7jWptecnW88uQl642V4JOZA9nJOhYl71xBvJ9 tkDq/izbRcXiSwNi5UMhVWUpfVomsgwNvg8c0tkBxxlQUQakNl9dWSBmLlldL3UxV+Nd sqzY5/b5KMEVTzViRLCHrA2k2LnGmVKdrtLcWPbl/fXyxLVMo5ghRFF4vN0EY4fWRuo+ TQ4A== X-Gm-Message-State: AOJu0Yw/LPJ6n9/R1cEvgVhZk19kOsrALaR+ACGkoRJf5wfp3fHI1qtC uPZqIXZ/whZhSdhN0lKJ/i+5kmADEsXjNQFZDWfBRXcJQACHZsYO21OfGgie0+Fmni0= X-Gm-Gg: Acq92OH1qEvzIOHcWW2il0NqmHiXRAvvwLzJMBqULyCFunyCO8VlxNJGZhb9+8VAR8A B8ueRu2ARm6xfesrqX60PJpRe6tMVJt6Ud2XLFyyjXJW1gNUVwuu7zU+d7q7NsX/vEzntqr/z1A B3brMyl3avrewZqEA45onqrDqqmMIRZjyiFvw+8JjE7Kj8Y3iD7oXjDH8J1voeSCbL0C7R82bkF 5/CGTgP37GLQL3+Fk8yPGhNOL2kB5RjRJqntJUSyVrceSE4NKyuC1kJnJ977P1pBPJpLHeBc/M6 UZ1ehiNlwTn9S4Ovhk94w91Fc37rfPvOuMlY/EWM7hxSCx9V5xzktllpR6ArRXK7Pr74l65tO4W icx5Of59AFHQBrVCzQlNKKghkCRiHAj9ZG8aJvoUjgImsjq7yYbW73LNnFSCZenT1YMu9gpXmQS y8K5ZT243zXgyxBiWBgg5zZ5+ZWn15HA4E2g== X-Received: by 2002:a05:600c:8b08:b0:490:601f:d785 with SMTP id 5b1f17b1804b1-490601fd90amr251387705e9.2.1779882206437; Wed, 27 May 2026 04:43:26 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 5/8] target/arm: implements SEV/SEVL for all modes Date: Wed, 27 May 2026 12:43:17 +0100 Message-ID: <20260527114320.1581552-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.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: 1779882301532154100 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 77fdc5f3a17..340848793d4 100644 --- a/target/arm/tcg/translate.h +++ b/target/arm/tcg/translate.h @@ -854,6 +854,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 01b1b3e38be..dcb3099dd5c 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 d057241e9df..88c5832fcbe 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 17:33:08 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=1779882288; cv=none; d=zohomail.com; s=zohoarc; b=OAGwHVNpUSIVNt6lGKn3wFsm1A4b/X1F208kcgLirvePySn7J+A/P12DXYBAeKfN5U9VmqbwXNMl8h+HxYZVCcbzpFtDswHe3EYujCPv4BCAP0y0GS95t4Jb9GaInfucylX+1fXIrpSXNxaq98/P2jVT3vbimE/UlgRTzoxbLys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882288; 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=b83Ewop06ud+aRvyIeWlXePLR1iRPsH+uS2u5AxXgk0=; b=azp/qUIKCLI+XhM40hydvxDdcpWi6sAL3FT926ZM6l1lgmHIVuXLyeZkpexT54bZKV/LDN3fnW6VpT7lujBwWrhitzsfZDIPkDex2uP5e+NTp5p0K5wtjTjt5FTPdd1kvoe31VSe0g8n7toU9RVj1Se9bPjUPr7AlTWcWMiKDc8= 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 1779882288721548.3089740794453; Wed, 27 May 2026 04:44:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfd-0005Q0-TW; Wed, 27 May 2026 07:43:33 -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 1wSCfb-0005Mf-IV for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:31 -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 1wSCfY-00006d-CT for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:31 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-48fde648a71so77042105e9.0 for ; Wed, 27 May 2026 04:43:27 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490809a0e7csm14743915e9.22.2026.05.27.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 721015FF90; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882206; x=1780487006; 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=b83Ewop06ud+aRvyIeWlXePLR1iRPsH+uS2u5AxXgk0=; b=axm5eLDv3K3ZjV9/s7pBm/YWRcM3TOofLlQUHGyU5MAyqtDzRCDqxDh7rzNLQaU6pW LBFyLCm612ET0OtBDuRYjvbm4b7wybhtTcycUpplXuwmPlQQNj9B3vlVPtXobUQdwWAO azODIWM6v3h9ThjYcTADLBjVQm2Dh/LP27rFHizvfGXePiW81kfQvclQwTWpbVO12qnH 9koF/x22ZZgIX+EfvKx0dkmce2onYjocs9cuHg6BJzbK9vOSGYuxD7ZLV37wxNOusmbe I2q5WosYYH6Pcg1qTraXxlSs+ZhRRGx/XCh/3iXVx6+02XjH/raGhfrnfXNdtlPagh3b K47w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882206; x=1780487006; 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=b83Ewop06ud+aRvyIeWlXePLR1iRPsH+uS2u5AxXgk0=; b=RN8nqwEaZjOPPgTbbgK9EuqflAFLxp/TK7JQaiOR+GYgubEixbY9WRxjxaSYdiABSx Kga35QnG9+ghphkDg9EuSl+3ixJEaMzqSqJ66k/dpX5r4ECFEAymkZiKvVjgcI+hHg52 3ltMgDpCRamK1gatdURgWJ1YzhyK//VgHLFyTaQX+L6DYeLGT9KwyVQ3ngjJLQfk6rX9 hkmatxPHWYLiyVczSwN9DyTg8Idmvw4tzF49Ig17MrCp8maa8LWL/8HmX/8pjqexVxhP KbI7rK7BlVAoaY9jU/k6FKoOAgHHp7BqmzIT9PZfwWjcMb/yZOSV7Lolzo+VXfhY8nl5 fNMA== X-Gm-Message-State: AOJu0Yxnd8Ff9EgogdMEka/g30rJ5dn+gVyJB4FK7uavQYoJETU8hjtO 64crzAjTeyhVHo0LWoyShXj3/Ezc0ezwif+rDHQaKLB0k03X17d0rbnKeXNbc0rihxo= X-Gm-Gg: Acq92OFs3pTuj86ffn7W5sIccTy/59ymFNb7hLqEfOY1n7Ql3FTpH2HzEqZbkywZ+Ll v8urNN3+di60UIKSbUt1aM4FY9iWqDdHd01KMLbmsIGsvS3d9tqapBV0rUO4GMhA+X5YnZIBcqQ OeiaCEVdaDD7X91J+gjCdMsTR7CCKosRu3pLoA7hsWIl0n05vioimTqtGdfQNjgw7XeBpwvRbrk n5mE9G/tiipYiFNycWM0560bwwPYEE2OawfiUqN5bxVV0oAhWxOWRjUmSogy1yddLi9TGALPI8O OUIydMTC20dxO7/p8QWyUIudhu04anSUgYnKO33BLGABYT1DMc+HUUIPzrzZ8Nhb4/HpYJb+acz H4x+S1lZ9N7kC0yXZ0xI96ejWbSbOncnyOR7wUI+bPhz03VUFoidCAFjumTwI6aWGBnOao2JD9Z yevXwb28rbLPGXUtcDkNmDBeo= X-Received: by 2002:a05:600c:2a8b:b0:489:1abb:5559 with SMTP id 5b1f17b1804b1-4904226d9camr205536055e9.5.1779882205519; Wed, 27 May 2026 04:43:25 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v6 6/8] target/arm: enable event stream on WFE instructions Date: Wed, 27 May 2026 12:43:18 +0100 Message-ID: <20260527114320.1581552-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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=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: 1779882290934158500 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. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- 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 8bed5214eed..39fe9ee0701 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -876,10 +876,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 88c5832fcbe..ee584e9a793 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 17:33:08 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=1779882335; cv=none; d=zohomail.com; s=zohoarc; b=FRpK5UJf5bkX0YtoSFKyxLvPAYH/eqVTZpARjJzU/p5wR8hr2vB4/x3JICGKWWUFCX7jBRX5R5AZyR6x11QHsr4/AxaZksr8sVlJkMKZp/Q3N8JIWfR546hYXqGqkexfC080G5kHKnmOXrDlzMx7WzbrTvf4wPzjmXipCmb4hnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882335; 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=0nGT9Jp4pthasA5g2F4sYzBBA0JTzuDlDIySeJkpXWw=; b=g1JRxvEbBKAeiyWl9N+Ni1ffCoyEkWfPvzTAEFPRrMSCJWWL/TuvSfsHEKA+/DvvSb6cWOdJReURDDoro2oAciZ18IObAJzaQeoWe1MDZxtLDSXkLFY0OMkwNVm/y3gquVvz0OQRHz96DZdJ4Ba76HtuxrY9t3DDoOS7oT13Bf4= 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 1779882335516870.3360902282105; Wed, 27 May 2026 04:45:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCfb-0005MP-Ix; Wed, 27 May 2026 07:43:31 -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 1wSCfZ-0005Kw-Iv for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:29 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfX-00005a-H0 for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:29 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4905e190c71so38276905e9.3 for ; Wed, 27 May 2026 04:43:26 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49045620c05sm389935035e9.14.2026.05.27.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8D7045FFEF; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882206; x=1780487006; 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=0nGT9Jp4pthasA5g2F4sYzBBA0JTzuDlDIySeJkpXWw=; b=eO8gg54NhNvbwpkBDkn7wVdsSS2Ju85gT6XI1w7ZM+7IBJW0rWbl61mEnmPbyCplHe EkkjZaYn1yTdEUcKIXzcoc0iPmwUuRoo5QstIRl3iZfjEs7WiNN/5IanySyrkqW4om/O 3guSJfCBmNyDIwyYuZRpF5cJamUvqXwEweP1soO8JM/AMjMHY2Am+LE1jzOeFv1U8epj MxLEmTdepWzGs0YiMxNGU8qfGBb+xYWbLNs2T93YquJaGeUEj/zyPQzaOHA7ZvTxjHlm Jewd3tNGY51HHevsBGFASDDKRX1sczUfj393MKrKEEzc3GhIqMyYaWFHumsAysbQe8rg 52Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882206; x=1780487006; 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=0nGT9Jp4pthasA5g2F4sYzBBA0JTzuDlDIySeJkpXWw=; b=APxXtx2f0h8znoNEPUVer0bR8WX6QLIn0S7H20uR/WRIWdeq4VIniHgvxgGEsK8PWH EXi3EWlRusebAB/qkJLUZUsewEgqTvJ2tjMPTn418KidZYUsERqI5Pzhq2eQZiSQwjLf oq4hUAOpg5hbxkoVcitPcWQO5naANKrwEFvCDiHZt4QafUQIW3kvnAem0CKjq+yPBvzS Tva4jJC/mHjG+nAAWORgpK2LSKCBl8FRlbDHWwvvMCdhthp5wnrjxeH9X6FbcL00wmcr Yznr6O2IsEbxZGhEZG8+eHgiavIPjzlKvOjcOBXxqUbommOGlBZSpGd/G62+VuJ9KhVB 4WdQ== X-Gm-Message-State: AOJu0YwCK5ypR60s0h0l1bS16O1MlEWQ/Qj1h6YRCmwVhoVqtqPbQZiz hsKPMP4ESeQ0oDdVoJab3Z8EwPNYQQbi7lXUa+qW2qXK0DxTmC9DTjf+ETRWXP3KCfw= X-Gm-Gg: Acq92OGw8WSKv9frELlXyGLzo1edjaZJv1/JJGfpEo6J3FKbW2KJDmNNPJiZSku5fCn 2Z4mHH2e8pGijwJgaWX/2Ec0M+HzUcjKRaRFjSHqWITXZUrThk9qhYN2R8aSziYT7kzCS49TE59 xjjWk/WOPXbOX4wHsgW/PK0mlu0FAQROkBUFMafDnAK6ZIUAGwxA6KC3YINy3AW+jGvcPpYf6PO vOQNAV7ArDODd7SZ3UVDHSsfGWjbWV5KuQS37C7d9bdITNtL0DcWuwTrKJFCoDMHet0h1i1gOh6 KpHKEEwQutpBtnPDYpoZVY2In2NURJMcNScazEv82Gy5V/Vp1juSveGnRSz+/Hp36qZNYPZV2be TJ+qty8QuIIDTPeZwlf3XA6clk81TJJPvDUVPyYcXGAcTizmMcOmIJWMFJCeLFi92MX5c0Ku32K AAUFQjLR5RH/BtK7gsL8ihCFY= X-Received: by 2002:a05:600c:45d2:b0:490:6237:521d with SMTP id 5b1f17b1804b1-490623753admr219397755e9.13.1779882205893; Wed, 27 May 2026 04:43:25 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 7/8] target/arm: handle the WFE trap case Date: Wed, 27 May 2026 12:43:19 +0100 Message-ID: <20260527114320.1581552-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::333; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x333.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: 1779882337072158500 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 ee584e9a793..92db4e69b64 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -10935,7 +10935,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 17:33:08 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=1779882257; cv=none; d=zohomail.com; s=zohoarc; b=CM8QVORHUSxkMRhkex5e7r7lcuzIkpioafhzyg4tWm/OGMNtZgI47eXisQAdx7IN3Kr9NVEkyiQ/Vh/SWQM7uYHW72Htozk+mS3x2llfqBUDkXHHsIDVtYniEnHJQmGqOm6BC4zOmoouMeqUxm9JTKyqcxEPqgJA/m+J4s8Wwn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779882257; 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=35klr9KydrIrWjxQJ+LzEO3Q866fe5zrRjk/XLnaeTY=; b=SxepN+skNljwUJGPgIK055Wt4x0nH7f7RQEVGJz+QfWjyBkaUea+VJReBbHdssborW89WZpr6DqGX476pQ9ihB25nxy+xYSmeIxBzQxqRTTxPfuyzCg48zjk6Sw7Zcwmm91xyX849ln6Bpb+OLCm7ZiOYlDqcjF9Jk9+chtye3s= 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 1779882257842131.21874657171827; Wed, 27 May 2026 04:44:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSCff-0005QZ-7W; Wed, 27 May 2026 07:43:35 -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 1wSCfb-0005NE-W0 for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:32 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wSCfY-00006h-Dj for qemu-devel@nongnu.org; Wed, 27 May 2026 07:43:31 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4903d730b1fso51023485e9.2 for ; Wed, 27 May 2026 04:43:27 -0700 (PDT) Received: from draig.lan ([185.124.0.195]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45edb54a432sm7752119f8f.3.2026.05.27.04.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 04:43:24 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A68436000E; Wed, 27 May 2026 12:43:21 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779882207; x=1780487007; 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=35klr9KydrIrWjxQJ+LzEO3Q866fe5zrRjk/XLnaeTY=; b=ZgPTpqcgUBNN7QQqMZ6tJsRquZgi+16nhgLS9LtOqaUpFHsyahcG5MP2b6X7i3xzAI ZmTjxG136m3hhKiuMB8wMPQeRpM7MkJ4ivFXAN3Nx0EH5tmCEQyP7u6VUZxozTAdhjBM 6FUu3dDX6hU/TywLRXN0gFtczahX+sb5BrGa9c7mPVvYqHlcky6oCDP1zWdscVHbKwBF ScjwOMWZlpOxmdaWu8kJcGhMOw/oo9gXb0zWX+rL7jP/xaN9RPBRvzgW1VMpMD2mjL/U yJc37SNQicickINhMaWM8Nh416536oTpBXMguT8PBl2PFwlwFVV02C5jREK/98x47V0E ghfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779882207; x=1780487007; 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=35klr9KydrIrWjxQJ+LzEO3Q866fe5zrRjk/XLnaeTY=; b=GL8kjZXywMPhis0nKrxg1qnJMdymqndPCslAl2MPXII51LdM8GYrTJjKDohp36oaaR RkCdaSzGyOJg2esd0ztOHQkTJkpBdlY9PhWkomFkzkUTP/saD2bdygbMnQoqHgrvrgQT n5Se6x7wFLHoeArfYZGtAq3naVAoy90nuoAmhzjJ5hWz14cZG3JVhMlENx8gZ53AAMWc Y/BQwqA5sC49gxKl/pp96XIl8E/NT4UKKzDOC2emaQgv0qVi+k2RDEjMEppltgHvUDLI bPHRKblIxESeKHNcZUUDJaz5wUXcTFVshWAd4Vh2a1rsJTwnuJ/wtJ3C0DO9b7pm0KHu TQjg== X-Gm-Message-State: AOJu0YwbnHT98Jq4g/zJMGVR7+JQSqm2DlSi2L5eyMdkNm70vUyk/Zvm qKTHDAg7Gjg9l0b4cQb4nNRAEHTZFBGNb4h+hfc+t30jpSDVZ7pcPNNMJ9pCAkTmgZU= X-Gm-Gg: Acq92OGOh49OKGu2I+hC4mPlY1VhluSSCVoQR5I08HJf0npcq5t39OpiGNQCaPnQNT/ zADOXtlvL+y9Jv9uKz/7OXua6dhJwHKqQ/dTYDQPgszwE0s98lbRtEWCpUxBK4ujmGNu6DUBBjE 9RfMppJ3B6UMtHho/vukJ+INkHesfLeZxfHcjkVzEihdb+ktjBydghiK1HnuMWqQ5vnBkAJhwik RR8Ny8t6m+iP+R8GWgnMADkRhOd0XREDg4cog1Ze/vu6Nr7W4SMGh4ekcoxOyi+asZOgBZVhYLi QdViq+VpWbRradVj9EDl+EzwuAD3a88LzQ4WnRtYBYizuhkSTKH6fXJBH/Uv5ZgDtqmzE0FK18l qU1Q1GI+Fvn1y77C9B5ZT8x8f89trRnjSONbBGHxfiAx8df9XFEpA5wURygMpb5AKK/8GIFNWhX zGx3lyIyZw41wN0c1nRUap/Q0oXytzsk44Dw== X-Received: by 2002:a05:600c:83c8:b0:490:601f:d783 with SMTP id 5b1f17b1804b1-490601fd8f3mr242474495e9.4.1779882206843; Wed, 27 May 2026 04:43:26 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , kvm@vger.kernel.org, Mohamed Mediouni , Pedro Barbuda , Alexander Graf , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [PATCH v6 8/8] target/arm: implement WFET Date: Wed, 27 May 2026 12:43:20 +0100 Message-ID: <20260527114320.1581552-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260527114320.1581552-1-alex.bennee@linaro.org> References: <20260527114320.1581552-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::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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: 1779882258928158500 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 92db4e69b64..d170cf22b0b 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