Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp18787lql; Fri, 12 Apr 2024 02:09:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVdDnxUlMk6Gi8D5F/11KIKR968BWCs1QnqLD/ARH6NekgeZItpEtFVIGr5G21v4Dg0TK3/oZpGNhF6J9FxTEEzBP74285sd7Oena4i/g== X-Google-Smtp-Source: AGHT+IGEqrmrPqhgjftc4HG8j1wAFGfGY0ry4Nor98L88bvV1Cx9LP+6koonpr57b54cyZZbPlh1 X-Received: by 2002:a05:6e02:1fc1:b0:36a:3f10:7ef4 with SMTP id dj1-20020a056e021fc100b0036a3f107ef4mr2327252ilb.29.1712912950953; Fri, 12 Apr 2024 02:09:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712912950; cv=pass; d=google.com; s=arc-20160816; b=IDIASXQUSJ3vOLGldNY79QCqz+eRh3n61yZi0LITdlVO90N3ks+5+a5Dk41i7nqye0 wEK7hd37USWk4vGi4OBQBtHQNy8qnxT4FiUvphj8K9pl/RIxkU2VkSZz1tlwpLm4rBD5 nAt+LmtAemCKQHxILuahE8SnTtT5zFJ+pcf0Zef3cYNI/8ZDOug8vC9FdN5XE7rSbMkW HDmOnbZRUGMEINs3Uno/ts2JPrOyOGSgvZk6DTWa1Ex6y5pTnCwTz3WYXq0ICUtgqQo7 S639zxm9Y1jApcks3vtCGdH6DO7U00jkTDqGIFNMO4kv2qqgPbnJswURUR1aC1Il9kA/ +h3A== 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=5/oYDfeOIgZjt9rUzTvs4u3ZimsS6MHFj2fqG46+V3A=; fh=9LvSfW0WHt2iGJzVq6ancEjPK6P/LWkxdE9eAG2qWdE=; b=CPwTepnUpNIMzbKV69OF1FTp2NRr4omG7jK2FGJUB0g62sUa+IalSlRZmL2TIowrlq ggKfCW6crdi1Yzr34HJLOLDBETLlbtSiSaXcJ+am3zkZ9kGqrgedlIccI/fkDDdne/bP SX0DOUXDhTHH9nukZl5jTlfCVS9wboj5Gt/FZaAsHWnEFvNZ9Xw0cnw35lkL8Ujq+cZq GPwn5rJN00655n94B7Z7RCl8FRPApqSmn1f3tefK1f5w4qiROzRy8xZ5bcP5aSHN6hWt XRQq8twgq8UJgZf1z8gRzDfiN/vOaLJZn1ozPIOjEZo3KBPv8rRp6L9JZOw+Jvs6c6+j phNg==; 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-142308-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142308-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 y129-20020a633287000000b005dc956c2c15si2723773pgy.70.2024.04.12.02.09.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 02:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142308-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-142308-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142308-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 9EB5028E69F for ; Fri, 12 Apr 2024 08:59:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54DEC130E44; Fri, 12 Apr 2024 08:44:43 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5C71F12F5B3; Fri, 12 Apr 2024 08:44:41 +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=1712911482; cv=none; b=ProvsTrY6FG3Taszz+cCLKjmhNXSkrqMCV5zDufEDma5etWP+Nn85QodqQJYkxDB9BDBjemQfVeosv0kBybibGK0zhkSGVaiAWdoEKxnHvhbrjMO1Jf4YlmzJy3LFja0v6PSeus42s64D+sdFQVJ+ZcYjI9V8Wii1xuya4inxLo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911482; c=relaxed/simple; bh=6RO1mE0SljN5zB2ChRtne2Phm80D1UoEgDPQQrnkBvI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L8irY7zmECb/rcCyUW+piUFoXGb8pZt8IA7o0VIBy0EXRmGxiHB570G9j/pxhviwWTLk4A8UgRZfje6s2s5aCyHs1ZFyJm6cLTZ62CarN7DQHyvDqZEHx5d9L0CuweKrXz2min7Tcvpf5Q0ukygK5H3SJSPsHj9re72ZCRBR8X8= 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 35CA214BF; Fri, 12 Apr 2024 01:45:10 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B34643F6C4; Fri, 12 Apr 2024 01:44:38 -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 v2 35/43] arm64: RME: Propagate number of breakpoints and watchpoints to userspace Date: Fri, 12 Apr 2024 09:43:01 +0100 Message-Id: <20240412084309.1733783-36-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084309.1733783-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-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 62d1fa82ac92..44aa95befc14 100644 --- a/arch/arm64/include/asm/kvm_rme.h +++ b/arch/arm64/include/asm/kvm_rme.h @@ -88,6 +88,7 @@ struct realm_rec { int 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 e60a1196a2fe..4edc8d98e1e6 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -271,6 +271,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 get_start_level(struct realm *realm) { return 4 - stage2_pgtable_levels(realm->ia_bits); diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 60452c6519a4..cb3dc640a4a5 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1708,7 +1708,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