Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp383184lqp; Mon, 10 Jun 2024 07:05:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUH/MfFazBxwBziCT41C4221s5Ub8RjWq1zA2nUDETIwAFF56tISQC7eYFU5WGPcP8mxdGymXLNq2q2pka+yXMDftDKxbLT6jZcsYrrPg== X-Google-Smtp-Source: AGHT+IGrTj9akg6Vpro9U4OTP9b62Om/XC2sGA4LGb/IiPbtNpVfzWs3kcr4kK3lTCHn5zLxcIK8 X-Received: by 2002:a17:906:a16:b0:a6f:2ea0:b013 with SMTP id a640c23a62f3a-a6f2ea0b0b8mr57757866b.43.1718028359773; Mon, 10 Jun 2024 07:05:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718028359; cv=pass; d=google.com; s=arc-20160816; b=XdN+FFEGZHEPFtUU1yzlAh3pQFvZ2fCBZUrcFG+4mM5jxRzxhmo1TPEIJQRChHx4dc f3j35QcGg4b0tVKQeE8TYmnWImD/YK8Drv04vDu3RJeksVUqHQbbvamle7tbsgGUfUiP 9ih8vnmwt8AQHpV/fuTp9+ukOgX+WQGZr4SNVaxneRhtr/Zeid7Tbv3WYJecva98dA/y l4kvcxsxSKjOAMjDoqkjTmFGu9dm/bG9/AwDs6NlJbjJ5n9Ii9CtUaq6rL78QLQMhPPt SCbHJmKyie1rUP4xPlaHMqRE3pWm2gPvMuaPq1B/DyVr69wRF0s1LhUS3LOntoEzNMbR 7qEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=a2X8rashidcRbaHLQlgjd0Lh+8zHt6kfUcJN6CbGIm8=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=Hzj7SU5zJMiXb1CYkmmz9ddnKn1xyYHVoqsDZWWiAkP4jZK8451T5cBu6tI28wHgoS e54THKOJuCf2ZUOsz50AI0uPCrpniqQMmo/djHkY0need4Mzo+aApvV/PLuGHg5F2hbI B78JcUhSQAGXCVtvg3tfLNV/5FNjkcJ0HPCBVVfibvUVo5YIyVJMPivgplNn7ft+8jr+ uju4OhN/EP7oKDx0ju7QbTtC7pJqsI0fzDk9ar91orjMXFklVZ4eDChq7FW04YqHE8Ir bLbr7/hzLi/z5dC9bIClwx/oy/Ux0D42J8yfGv7/NhFYQ89MhJ29bUQCM/Pybr4U/mTR NoqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208286-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6ef60fef25si308896066b.714.2024.06.10.07.05.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208286-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208286-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1F2001F25841 for ; Mon, 10 Jun 2024 13:54:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D3751586F4; Mon, 10 Jun 2024 13:44:19 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4466C1581FA; Mon, 10 Jun 2024 13:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027058; cv=none; b=nVCm49mWVaZa+lmPuP4/zUheZfaXTf7bDHhjhK/Zemmc9f5I/4VMsnfKHwuoefPYhai5RFZ77VQyfSff23UiSfjr8UdJZm/sS5/IBt2/jpXyq6y1M6AhPZ2YGzIkLhNb5nL324F593AO3HRROybXAca7xYfpROjxqk1uIDALuiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027058; c=relaxed/simple; bh=iBExssQg7cBlqDJX/5mMOc6Kk4mYW3rSU9q6BA/aEKs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Er6MQ0+r5+lgtGykNSTvyIXY5Tgundq+/Va4NY+Gm94hwfWbEU5fzxPLNYcU7qgt2KzhNwhtB09NVlDuVz4TwluHLxrh/cle5WY9fiGb0rMg+jxCbVhMlBvMsvDfjnRGYRmuyeKTB3wW5W7DicnAk7iuaGj9FdnSN5Ug36X61uw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2851816A3; Mon, 10 Jun 2024 06:44:41 -0700 (PDT) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.35.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1D0763F58B; Mon, 10 Jun 2024 06:44:13 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Jean-Philippe Brucker , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Steven Price Subject: [PATCH v3 37/43] arm64: RME: Initialize PMCR.N with number counter supported by RMM Date: Mon, 10 Jun 2024 14:41:56 +0100 Message-Id: <20240610134202.54893-38-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610134202.54893-1-steven.price@arm.com> References: <20240610134202.54893-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jean-Philippe Brucker Provide an accurate number of available PMU counters to userspace when setting up a Realm. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_rme.h | 1 + arch/arm64/kvm/pmu-emul.c | 3 +++ arch/arm64/kvm/rme.c | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h index 8aa02134c461..c30d7899f58b 100644 --- a/arch/arm64/include/asm/kvm_rme.h +++ b/arch/arm64/include/asm/kvm_rme.h @@ -88,6 +88,7 @@ struct realm_rec { void kvm_init_rme(void); u32 kvm_realm_ipa_limit(void); +u8 kvm_realm_max_pmu_counters(void); u64 kvm_realm_reset_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, u64 val); bool kvm_rme_supports_sve(void); diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index ce7c8e55d904..39790736f1e2 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -912,6 +912,9 @@ u8 kvm_arm_pmu_get_max_counters(struct kvm *kvm) { struct arm_pmu *arm_pmu = kvm->arch.arm_pmu; + if (kvm_is_realm(kvm)) + return kvm_realm_max_pmu_counters(); + /* * The arm_pmu->num_events considers the cycle counter as well. * Ignore that and return only the general-purpose counters. diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index 31e00c52551d..1d355f0bb0eb 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -286,6 +286,11 @@ u32 kvm_realm_ipa_limit(void) return u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_S2SZ); } +u8 kvm_realm_max_pmu_counters(void) +{ + return u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_PMU_NUM_CTRS); +} + u64 kvm_realm_reset_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, u64 val) { u32 bps = u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_NUM_BPS); -- 2.34.1