Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp399659lqp; Mon, 10 Jun 2024 07:30:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVVf70ETX4gsIClbTeDbGBN+PSev42fO/PM3W7PshQAX1MsNpWUccUVOUhn1RuBRqkWtcCkHx4CwZVkXjqMk+v270jNWGof62R2HbQOfg== X-Google-Smtp-Source: AGHT+IEaxAXQ+xCRZk2hmTDOLd9CTODOk9O4G/iY9Y4xIKvQ3YN1UaYKNLN4w8DlNtQaeP2KDui1 X-Received: by 2002:a17:903:40d2:b0:1f6:93a0:9a45 with SMTP id d9443c01a7336-1f6d02fcb4emr120637655ad.36.1718029853860; Mon, 10 Jun 2024 07:30:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718029853; cv=pass; d=google.com; s=arc-20160816; b=WEEFuGdGj0KeFovfD2v1vOtg+WYCrkqdGxQ5UTsdB6w5lOJfjk6QWjod4+qFBJY8eV 06AnmZlfSWBIZp6ffdJUJ1gPYmtLz/ecEQQZWYI34G9AKpqBvikcj0TMbS/53UyuOv58 qqa3OXK8sbojco7K4/JQoPVKsbFj2tT3IJY47IfzU7BeDRIsMScbm7pLEOpCdhfBYIG7 Y74uZ+lamej9RBmNdeSgBzGpTomTOujjXjGquqU5nPQ2JuoNb7taBrv+GSthpMXnE/E3 GGnF/lfCXZx6E7gUmKFjE9cL/uK2cI9/D6FfZFoaaQI/wZctwaXT+ucI8LdrU6dhkcWB srkA== 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=jLu5gxA0y38L2PE1BwGf/gMiuWSMaQRVixbhy225zd4=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=E73cBO5ABvyL88+rqL86uT5/+ScSeO/ow2UiSgao+HZU9220xQGopmZsKrC0YH8m2j P7tSCKXxRlEiisxmOh4CO+wab7eilGiZVEmvUOD7Lu7v/CLD3cU34iotkqxMh8vFQD5T O/cXdSQPDe6yDPc7MNr3t/Mr6BI1oC/jCbVMHpAC1fKFitjekIMZPod4+di3tId2QQQL yezLbBzM7BCy40gPJAfd9D+y1wHU2AXeJzsMyVgQ80OatvgAYuA5vB5EWrk7g7Fp8cZF TMxpOdnXxnUdyu8fsdMZfH9/UVtpu0Je4rM4VPnTb9awUyfCuEhU1yMhuthBy+EbPC76 5klg==; 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-208282-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208282-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f701a97057si30293995ad.304.2024.06.10.07.30.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208282-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-208282-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208282-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8B18F287789 for ; Mon, 10 Jun 2024 13:53:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A05A515749D; Mon, 10 Jun 2024 13:44:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE30615746E; Mon, 10 Jun 2024 13:44:11 +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=1718027053; cv=none; b=diKQq3xxtZzzW7rKqBaMq7rf7zVRmaxTiERLq4jMylbWozyL0yqwPctLbb+SpDHltEzHtqfBP5Xjmtt13lKytg5GZ1SDNN5E5GFtPYJ/+laUh2PGo4b8gIfAJ5aKVn8ZVCE+lIVjxQzc7oaiOmLDgcgUedU/0tlD+kcSA1/J89c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718027053; c=relaxed/simple; bh=P016wlSvBz1tNc5ePWC40PcWZ76iScNAiaoYZd5JHUk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e/NXhQTNNS6zaVJ/5g6nU/8Npw0WIJsUWFOZangYSdLCQ2dAjO07fHASSzvRvd9LuamHGcojNpxi8MTnBPJdzbjwRO7oo4PP31N9UUyTNbyq9xgj6m2xoWY17uXEDx4j30wXgT3LF1Hv72Bevek+77c5va6GwnYyxeTF95Nmjl4= 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 A995E1692; Mon, 10 Jun 2024 06:44:35 -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 B6DFF3F58B; Mon, 10 Jun 2024 06:44:08 -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 35/43] arm64: RME: Propagate number of breakpoints and watchpoints to userspace Date: Mon, 10 Jun 2024 14:41:54 +0100 Message-Id: <20240610134202.54893-36-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 The RMM describes the maximum number of BPs/WPs available to the guest in the Feature Register 0. Propagate those numbers into ID_AA64DFR0_EL1, which is visible to userspace. A VMM needs this information in order to set up realm parameters. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_rme.h | 1 + arch/arm64/kvm/rme.c | 22 ++++++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h index 80c7db964079..8aa02134c461 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); +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/rme.c b/arch/arm64/kvm/rme.c index 93757c550394..66e124b4d25a 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -286,6 +286,28 @@ u32 kvm_realm_ipa_limit(void) return u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_S2SZ); } +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); + u32 wps = u64_get_bits(rmm_feat_reg0, RMI_FEATURE_REGISTER_0_NUM_WPS); + u32 ctx_cmps; + + if (!kvm_is_realm(vcpu->kvm)) + return val; + + /* Ensure CTX_CMPs is still valid */ + ctx_cmps = FIELD_GET(ID_AA64DFR0_EL1_CTX_CMPs, val) + 1; + ctx_cmps = min(bps, ctx_cmps); + + val &= ~(ID_AA64DFR0_EL1_BRPs_MASK | ID_AA64DFR0_EL1_WRPs_MASK | + ID_AA64DFR0_EL1_CTX_CMPs); + val |= FIELD_PREP(ID_AA64DFR0_EL1_BRPs_MASK, bps - 1) | + FIELD_PREP(ID_AA64DFR0_EL1_WRPs_MASK, wps - 1) | + FIELD_PREP(ID_AA64DFR0_EL1_CTX_CMPs, ctx_cmps - 1); + + return val; +} + static int realm_create_rd(struct kvm *kvm) { struct realm *realm = &kvm->arch.realm; diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 435bcd02ddfd..96d73b1867ad 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1722,7 +1722,7 @@ static u64 read_sanitised_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, /* Hide SPE from guests */ val &= ~ID_AA64DFR0_EL1_PMSVer_MASK; - return val; + return kvm_realm_reset_id_aa64dfr0_el1(vcpu, val); } static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, -- 2.34.1