From patchwork Tue Mar 7 14:05:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13163872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D0C8C678D4 for ; Tue, 7 Mar 2023 14:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Gn5tAeJq/j1ekiKeMTWs063lGCv4BmJ46C4iTLpUilw=; b=Pyld2W4v75uPsJ xsaKiynYUo7cj1xYMCAC0ZKgnTF3MJWsal9RmZWn4CuSc0Qw0kcth0dYVwWWOxCgAz+2hppNQZL0S /JZJ94dMqXts3BcJx8KWEwxFXVvdSo1/x9SBBv35ObOdmopC0aYL1ZVOYJK1gexBz2yfSHl6nggS8 CbntZWhH8kb6uUbfENYq2cBKdG30z/u/csJQj5HGI74PRS0KOAa1qRdCwl6qevr10t7JMkToeiyhS GM3CbGlBABYmKYC3VbYrIpM5wlLaj+1OCXCTRDY4sr55HdwyfEQe2WuF/AbYG0p5K9Y4jiNnwUR0h utZcy5nLVKyn4FsAb4kA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZYhh-000zK9-5U; Tue, 07 Mar 2023 14:54:14 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXzn-000eyJ-PF for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 14:08:54 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E60256145F; Tue, 7 Mar 2023 14:08:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF498C433EF; Tue, 7 Mar 2023 14:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198130; bh=LnIMWXn/NUQhEHogfVRPC6N8nPTaYTu5SzPxylVFFFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dxt7vxDMrMeQJsTf2yCYbSQzPG4oUdjdzgCKdK8cy5uKjVjUBociHes0crp2TZ85Q 6ytey9H+NGpX2hcoXUItOOkym5riAqUnlaswFY16dhlC1EkretpkYelmEVj+MDsCMD L7P7JdIY7GR9Ep9zRDjiTybMUodqoRtw5XzVyBX23bHExKL/xkTcETbJwn7PCEHOvB OIcWAOB7MIsigEhku29GgdbFcg7dyBeKsHGwDNpr4Bg3K/q6CCH5QZfEHYYJdrR2ul zmUcsDKn3Nd33/ywDSxvs/Zf8X51lfhfiCD9Et5r5TwWMLX50BgOUHteDczk9uFe21 gIHG3unpgBDfQ== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: [PATCH v3 55/60] arm64: kvm: avoid CONFIG_PGTABLE_LEVELS for runtime levels Date: Tue, 7 Mar 2023 15:05:17 +0100 Message-Id: <20230307140522.2311461-56-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1031; i=ardb@kernel.org; h=from:subject; bh=LnIMWXn/NUQhEHogfVRPC6N8nPTaYTu5SzPxylVFFFA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdZbKb65Y0U7+zrwseKHzQe7TBcakxty1f+VSJoMU8E hURwaIdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCLJ+xkZTv7LehPcuoNHgeOb k2HvaRvudrOfKhv0Wju4Hl0R7H9Sz/C/dAHbM9H+BxqrE6eHLjn74nHoO73ctltzrEI3V5yYMfU bMwA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_060851_912252_613228BC X-CRM114-Status: GOOD ( 14.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org get_user_mapping_size() uses vabits_actual and CONFIG_PGTABLE_LEVELS to provide the starting point for a table walk. This is fine for LVA, as the number of translation levels is the same regardless of whether LVA is enabled. However, with LPA2, this will no longer be the case, so let's derive the number of levels from the number of VA bits directly. Signed-off-by: Ard Biesheuvel --- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d64be7b5f6692e8b..4e7c0f9a9c286c09 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -663,7 +663,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) .pgd = (kvm_pteref_t)kvm->mm->pgd, .ia_bits = vabits_actual, .start_level = (KVM_PGTABLE_MAX_LEVELS - - CONFIG_PGTABLE_LEVELS), + ARM64_HW_PGTABLE_LEVELS(pgt.ia_bits)), .mm_ops = &kvm_user_mm_ops, }; kvm_pte_t pte = 0; /* Keep GCC quiet... */