From nobody Thu Nov 28 05:32:57 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C76011DEC04; Fri, 4 Oct 2024 15:31:02 +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=1728055864; cv=none; b=Pa+FsdKCmBZpK1hdYw4UFO491hcSTKiHfCxly20QpPoki6BYpeGhD+niIlCO+Jg13M8BMjBCTPAG88ING87fdmZOqZ4inSKMMW2DOMPgh3rDE/GMKaDmCejSOHs+u777NTfukpkwP0K+WMoFWdDOxehmhCAumVWYMWgH9i1e4Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728055864; c=relaxed/simple; bh=D13xXmIV47uyEQ12nb++CPf0y87w9xhHXZpWHF4kjeA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rgthHea0iiVdfA5wfSIAqlKr71dKlPTNZgua+kYCaOqf8VYqTtYWQyAyxyjqG3y9xvK4xFzghLebQLlNK4tABqj//3l1vi7c8f+BIHr3zwLmdviIzgPEFAg/+lIaOn6dvtB/74YJm9/vMPnYoUk9Mh3EzgGd0pqIkb3KAxtjCXs= 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 C7F021063; Fri, 4 Oct 2024 08:31:31 -0700 (PDT) Received: from e122027.cambridge.arm.com (unknown [10.1.25.25]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 204D73F640; Fri, 4 Oct 2024 08:30:57 -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 , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Steven Price Subject: [PATCH v5 36/43] arm64: RME: Set breakpoint parameters through SET_ONE_REG Date: Fri, 4 Oct 2024 16:27:57 +0100 Message-Id: <20241004152804.72508-37-steven.price@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241004152804.72508-1-steven.price@arm.com> References: <20241004152804.72508-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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jean-Philippe Brucker Allow userspace to configure the number of breakpoints and watchpoints of a Realm VM through KVM_SET_ONE_REG ID_AA64DFR0_EL1. The KVM sys_reg handler checks the user value against the maximum value given by RMM (arm64_check_features() gets it from the read_sanitised_id_aa64dfr0_el1() reset handler). Userspace discovers that it can write these fields by issuing a KVM_ARM_GET_REG_WRITABLE_MASKS ioctl. Signed-off-by: Jean-Philippe Brucker Signed-off-by: Steven Price --- arch/arm64/kvm/guest.c | 2 ++ arch/arm64/kvm/rme.c | 3 +++ arch/arm64/kvm/sys_regs.c | 21 ++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 1833dec36cd2..91472d478d50 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -784,6 +784,7 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct= kvm_one_reg *reg) } =20 #define KVM_REG_ARM_PMCR_EL0 ARM64_SYS_REG(3, 3, 9, 12, 0) +#define KVM_REG_ARM_ID_AA64DFR0_EL1 ARM64_SYS_REG(3, 0, 0, 5, 0) =20 /* * The RMI ABI only enables setting the lower GPRs (x0-x7) and PC. @@ -806,6 +807,7 @@ static bool validate_realm_set_reg(struct kvm_vcpu *vcp= u, } else { switch (reg->id) { case KVM_REG_ARM_PMCR_EL0: + case KVM_REG_ARM_ID_AA64DFR0_EL1: return true; } } diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index 87f466e5b548..5f3abee45bc2 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -315,6 +315,7 @@ static int realm_create_rd(struct kvm *kvm) void *rd =3D NULL; phys_addr_t rd_phys, params_phys; struct kvm_pgtable *pgt =3D kvm->arch.mmu.pgt; + u64 dfr0 =3D kvm_read_vm_id_reg(kvm, SYS_ID_AA64DFR0_EL1); int i, r; =20 if (WARN_ON(realm->rd) || WARN_ON(!realm->params)) @@ -346,6 +347,8 @@ static int realm_create_rd(struct kvm *kvm) params->rtt_num_start =3D pgt->pgd_pages; params->rtt_base =3D kvm->arch.mmu.pgd_phys; params->vmid =3D realm->vmid; + params->num_bps =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, BRPs, dfr0); + params->num_wps =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, WRPs, dfr0); =20 if (kvm->arch.arm_pmu) { params->pmu_num_ctrs =3D kvm->arch.pmcr_n; diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index a73e0eb5dd85..5ebc71d90356 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1755,6 +1755,9 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcpu, { u8 debugver =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, DebugVer, val); u8 pmuver =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, PMUVer, val); + u8 bps =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, BRPs, val); + u8 wps =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, WRPs, val); + u8 ctx_cmps =3D SYS_FIELD_GET(ID_AA64DFR0_EL1, CTX_CMPs, val); =20 /* * Prior to commit 3d0dba5764b9 ("KVM: arm64: PMU: Move the @@ -1774,10 +1777,11 @@ static int set_id_aa64dfr0_el1(struct kvm_vcpu *vcp= u, val &=3D ~ID_AA64DFR0_EL1_PMUVer_MASK; =20 /* - * ID_AA64DFR0_EL1.DebugVer is one of those awkward fields with a - * nonzero minimum safe value. + * ID_AA64DFR0_EL1.DebugVer, BRPs and WRPs all have to be greater than + * zero. CTX_CMPs is never greater than BRPs. */ - if (debugver < ID_AA64DFR0_EL1_DebugVer_IMP) + if (debugver < ID_AA64DFR0_EL1_DebugVer_IMP || !bps || !wps || + ctx_cmps > bps) return -EINVAL; =20 return set_id_reg(vcpu, rd, val); @@ -1860,10 +1864,11 @@ static int set_id_reg(struct kvm_vcpu *vcpu, const = struct sys_reg_desc *rd, mutex_lock(&vcpu->kvm->arch.config_lock); =20 /* - * Once the VM has started the ID registers are immutable. Reject any - * write that does not match the final register value. + * Once the VM has started or the Realm descriptor is created, the ID + * registers are immutable. Reject any write that does not match the + * final register value. */ - if (kvm_vm_has_ran_once(vcpu->kvm)) { + if (kvm_vm_has_ran_once(vcpu->kvm) || kvm_realm_is_created(vcpu->kvm)) { if (val !=3D read_id_reg(vcpu, rd)) ret =3D -EBUSY; else @@ -2391,7 +2396,9 @@ static const struct sys_reg_desc sys_reg_descs[] =3D { .set_user =3D set_id_aa64dfr0_el1, .reset =3D read_sanitised_id_aa64dfr0_el1, .val =3D ID_AA64DFR0_EL1_PMUVer_MASK | - ID_AA64DFR0_EL1_DebugVer_MASK, }, + ID_AA64DFR0_EL1_DebugVer_MASK | + ID_AA64DFR0_EL1_BRPs_MASK | + ID_AA64DFR0_EL1_WRPs_MASK, }, ID_SANITISED(ID_AA64DFR1_EL1), ID_UNALLOCATED(5,2), ID_UNALLOCATED(5,3), --=20 2.34.1