Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDDFF10796 for ; Tue, 28 Nov 2023 13:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oJNoNAyp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56459C433C8; Tue, 28 Nov 2023 13:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701178906; bh=4FdcDR4BJp+cPecgiaRseF4eJ+HqOqTtKDZxiaPAnkk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=oJNoNAypn+LATivniCe0tj0GbHGwMMNp1CclSu88T2EiNvBOvv6YLd0jdWKaJRBjl exWioEaDx67vYY513EJ4vfT2u3L6OO0pRLRfFl191en2LZtw18ljLTlgv043Li4iUc a+K60qhBnWz8HRodGcQYjFBS0nmi79qwJ34HUOgnVoNV7a1fYaC3dRxZrlyVi9uEkN 7U1QKoQkzPFsOwNQsBy7U/9Z6YOi06cw8zNUDA4gqKVNE+np2UoCd+KnXD7V70R9/E BbMTeR1Wg5j5b2Fxja1HJMhM/gvDvuapq9QL51YbQHt+IBLZRwVCZKh5xz38oh5zld fQqje97fzvR7Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r7yLP-00H9Xv-SO; Tue, 28 Nov 2023 13:41:44 +0000 Date: Tue, 28 Nov 2023 13:41:43 +0000 Message-ID: <86a5qyc7vs.wl-maz@kernel.org> From: Marc Zyngier To: Ard Biesheuvel , Ryan Roberts Cc: Catalin Marinas , Will Deacon , Oliver Upton , Suzuki K Poulose , James Morse , Zenghui Yu , Anshuman Khandual , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v6 08/12] KVM: arm64: Convert translation level parameter to s8 In-Reply-To: References: <20231127111737.1897081-1-ryan.roberts@arm.com> <20231127111737.1897081-9-ryan.roberts@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ardb@kernel.org, ryan.roberts@arm.com, catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, suzuki.poulose@arm.com, james.morse@arm.com, yuzenghui@huawei.com, anshuman.khandual@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Tue, 28 Nov 2023 12:23:38 +0000, Ryan Roberts wrote: > > On 28/11/2023 10:49, Ard Biesheuvel wrote: > > On Mon, 27 Nov 2023 at 12:18, Ryan Roberts wrote: > >> > >> With the introduction of FEAT_LPA2, the Arm ARM adds a new lel of > >> translation, level -1, so levels can now be in the range [-1;3]. 3 is > >> always the last level and the first level is determined based on the > >> number of VA bits in use. > >> > >> Convert level variables to use a signed type in preparation for > >> supporting this new level -1. > >> > >> Since the last level is always anchored at 3, and the first level varies > >> to suit the number of VA/IPA bits, take the opportunity to replace > >> KVM_PGTABLE_MAX_LEVELS with the 2 macros KVM_PGTABLE_FIRST_LEVEL and > >> KVM_PGTABLE_LAST_LEVEL. This removes the assumption from the code that > >> levels run from 0 to KVM_PGTABLE_MAX_LEVELS - 1, which will soon no > >> longer be true. > >> > >> Reviewed-by: Oliver Upton > >> Signed-off-by: Ryan Roberts > >> --- > >> arch/arm64/include/asm/kvm_emulate.h | 2 +- > >> arch/arm64/include/asm/kvm_pgtable.h | 31 +++++++------ > >> arch/arm64/include/asm/kvm_pkvm.h | 5 +- > >> arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 +-- > >> arch/arm64/kvm/hyp/nvhe/mm.c | 4 +- > >> arch/arm64/kvm/hyp/nvhe/setup.c | 2 +- > >> arch/arm64/kvm/hyp/pgtable.c | 66 +++++++++++++++------------ > >> arch/arm64/kvm/mmu.c | 16 ++++--- > >> 8 files changed, 71 insertions(+), 61 deletions(-) > >> > >> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > >> index 78a550537b67..13fd9dbf2d1d 100644 > >> --- a/arch/arm64/include/asm/kvm_emulate.h > >> +++ b/arch/arm64/include/asm/kvm_emulate.h > >> @@ -409,7 +409,7 @@ static __always_inline u8 kvm_vcpu_trap_get_fault_type(const struct kvm_vcpu *vc > >> return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_TYPE; > >> } > >> > >> -static __always_inline u8 kvm_vcpu_trap_get_fault_level(const struct kvm_vcpu *vcpu) > >> +static __always_inline s8 kvm_vcpu_trap_get_fault_level(const struct kvm_vcpu *vcpu) > >> { > >> return kvm_vcpu_get_esr(vcpu) & ESR_ELx_FSC_LEVEL; > >> } > > > > This helper is currently only used for permission faults, which don't > > exist at level -1. Also, there is only a single caller of this helper, > > which uses the result only to infer the size covered by the block > > entry that describes the mapping. > > > > So in my LPA2 series, I intend to remove this helper altogether, and > > just replace it with something along the lines of > > > > static inline > > u64 kvm_vcpu_trap_get_perm_fault_granule(const struct kvm_vcpu *vcpu) > > { > > unsigned long esr = kvm_vcpu_get_esr(vcpu); > > > > BUG_ON(!esr_is_permission_fault(esr)); > > return BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(esr & ESR_ELx_FSC_LEVEL)); > > } > > > > to avoid having to reason about whether masking with ESR_ELx_FSC_LEVEL > > is appropriate for the fault type in question. > > > > https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/commit/?h=arm64-lpa2-v6-combined&id=26c3425ec73ca751c45848f6f3f2d96e02cb4327 > > https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/commit/?h=arm64-lpa2-v6-combined&id=d6a849d6b318e70bf2f80f9b18a933136520019a > > > > This would take me an afternoon to get educated enough to even be able to offer > an opinon. So I'll leave this to the bigger boys to discuss. :) Dunno who the big boys are (I'm rather small, myself). Looking at the first patch, I rather like that cleanup. It makes it clear (cue the fault_granule handling for permission fault) that we should consider splitting user_mem_abort() into two functions: one that deals with translation faults, and one that is solely concerned with permissions faults. Ard, if you want to split the KVM stuff from the core arch code in that patch and post the result, I'd be happy to take it for a ride in -next. Thanks, M. -- Without deviation from the norm, progress is not possible.