From nobody Tue Feb 10 03:40:14 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=1661174872; cv=none; d=zohomail.com; s=zohoarc; b=bZFXA2RC0xsJOZxl9RRAgIDqyEnqqK+lEs+mRcC2jGRYon7bwNoWU8nUtuNo1Sx/baJgEEi1k0WnbNb9jhJmfqPx2+WjzmXA7aX61bp4dSZjUDZO7lfu2oAH2BLGtGlov/us2j1K/asISILkBqCckNM/t54GdTXrHD80HI6rehM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661174872; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6yc2QQJRiauV/rnVG5qIFbv8E5zW00rmH8bNkLiSwRQ=; b=hC2/2/2taF0L2H5zer+Doo8Kpn87qmcpuB0XBEoG7nBMVx35fAYGLZJpvTgI+u+mD8JKC61BtdB7mr2Kx705c4tSxb7KK1JZjENCTPxgGknFNsthXLImckupJLA0vIyp2Zq146Ygait1p9m8PsMBQkDyrxl85Ay1ZKPZ5gG2MZA= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661174872732589.579713328604; Mon, 22 Aug 2022 06:27:52 -0700 (PDT) Received: from localhost ([::1]:38928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQ7T5-00039N-N1 for importer@patchew.org; Mon, 22 Aug 2022 09:27:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ7PV-000614-HP for qemu-devel@nongnu.org; Mon, 22 Aug 2022 09:24:09 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:36385) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ7PT-0001f3-Rc for qemu-devel@nongnu.org; Mon, 22 Aug 2022 09:24:09 -0400 Received: by mail-wr1-x431.google.com with SMTP id d16so7913202wrr.3 for ; Mon, 22 Aug 2022 06:24:06 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id f12-20020adff98c000000b0021f13097d6csm11527946wrr.16.2022.08.22.06.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 06:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=6yc2QQJRiauV/rnVG5qIFbv8E5zW00rmH8bNkLiSwRQ=; b=MxIIKoA/j+fJRx+GtFl6JLVbi7+dfJsozau6SY54wFuUAT7u5HeCEVv4A1TFwPtJ5R p+aLiodJyPvQxzOgtfK24idpeopiJVlUHlerP5M0tDkHEaXzXAYXHG/oRqKTk8wWvEhO 7RU6XCij5i6OFlg0WDxu6sdEvdau3OpdPozzsK1OnfgNj5az8V05shoKom5d70/At2f7 hX7l1+CVE1kKvj/QXSv3E7WiCVQcWiBrPbchTEagnNsIFfWBw+7+cYxq8M4Eqz+7NCyl B3KxviNsmC+ljhSFpIn7clmXVvhHeZTJVmx/wI4yxh/kBfIqcaxK8yblJYBCcrOcnCl7 fHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=6yc2QQJRiauV/rnVG5qIFbv8E5zW00rmH8bNkLiSwRQ=; b=Is1n3eAS3q5T+WqT0aitbJ5uTxquqoIj4l2QSJeV1NDkTtfnmiEeaWaPVTJKyJPYaP luJtiD8cNkW1maONGAvB3jvl0v7jqpEZlHYZVDnxaJUIsKRUYGf2ezy0NGYByJDnlZm+ SooIihSgStRZLo9xv59ObyIhdkziDyMEP8scSh1IDXjdajJgG8On3TNK05Pa+OVDsFd2 G39hYzfSm6OD2MGqiM6QQ68dbRO/aiBAH3K2bbE4YpY/4xKqHsNd8JNPcumWXash5vW3 kbQVxBg7a/Q76m1sMtF/TkIhcj8doM4bs1BUE1U9gUmPS0ebSrxj0wWwntb5sjewb0t1 VGQg== X-Gm-Message-State: ACgBeo2vUx4bgCO8BWiyNSHLn6VXyZv78SF4Qs9DJnXX4+o/JS6zdPXY vFDGFMxeQGCkRpCltYk1VHVp6Q== X-Google-Smtp-Source: AA6agR47VtGv1dSNacXxsyOw46Sr/giwX87+RC5YMwtSi/11pNwWfzw4UK8l5ONtM4NeALyZ0fJSNg== X-Received: by 2002:adf:fe04:0:b0:225:1c8e:9027 with SMTP id n4-20020adffe04000000b002251c8e9027mr10608630wrr.155.1661174645742; Mon, 22 Aug 2022 06:24:05 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH v2 05/10] target/arm: Honour MDCR_EL2.HPMD in Secure EL2 Date: Mon, 22 Aug 2022 14:23:53 +0100 Message-Id: <20220822132358.3524971-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822132358.3524971-1-peter.maydell@linaro.org> References: <20220822132358.3524971-1-peter.maydell@linaro.org> MIME-Version: 1.0 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=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1661174874782100001 Content-Type: text/plain; charset="utf-8" The logic in pmu_counter_enabled() for handling the 'prohibit event counting' bits MDCR_EL2.HPMD and MDCR_EL3.SPME is written in a way that assumes that EL2 is never Secure. This used to be true, but the architecture now permits Secure EL2, and QEMU can emulate this. Refactor the prohibit logic so that we effectively OR together the various prohibit bits when they apply, rather than trying to construct an if-else ladder where any particular state of the CPU ends up in exactly one branch of the ladder. This fixes the Secure EL2 case and also is a better structure for adding the PMUv8.5 bits MDCR_EL2.HCCD and MDCR_EL3.SCCD. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- I opted not to use bitwise |=3D for boolean operations. --- target/arm/helper.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index f2bf1c52eb2..7d4127a1573 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1094,7 +1094,7 @@ static bool pmu_counter_enabled(CPUARMState *env, uin= t8_t counter) { uint64_t filter; bool e, p, u, nsk, nsu, nsh, m; - bool enabled, prohibited, filtered; + bool enabled, prohibited =3D false, filtered; bool secure =3D arm_is_secure(env); int el =3D arm_current_el(env); uint64_t mdcr_el2 =3D arm_mdcr_el2_eff(env); @@ -1112,15 +1112,12 @@ static bool pmu_counter_enabled(CPUARMState *env, u= int8_t counter) } enabled =3D e && (env->cp15.c9_pmcnten & (1 << counter)); =20 - if (!secure) { - if (el =3D=3D 2 && (counter < hpmn || counter =3D=3D 31)) { - prohibited =3D mdcr_el2 & MDCR_HPMD; - } else { - prohibited =3D false; - } - } else { - prohibited =3D arm_feature(env, ARM_FEATURE_EL3) && - !(env->cp15.mdcr_el3 & MDCR_SPME); + /* Is event counting prohibited? */ + if (el =3D=3D 2 && (counter < hpmn || counter =3D=3D 31)) { + prohibited =3D mdcr_el2 & MDCR_HPMD; + } + if (secure) { + prohibited =3D prohibited || !(env->cp15.mdcr_el3 & MDCR_SPME); } =20 if (prohibited && counter =3D=3D 31) { --=20 2.25.1