Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp368712lqp; Mon, 10 Jun 2024 06:44:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXCSimA7ZKqh21M8SHrTzobM58Y5BJlAamqkfAeR0txC3qclulBWWz96GZCfeiDNARFQjuAV16XZvpPXc3u2CEzqSp2Kv+vEbLLYJix8A== X-Google-Smtp-Source: AGHT+IGpwtBMnadrycGSIItwMNkDveO+fDFEpSrDfvcAz5Dxj1kJlJ/0qtyXzk1TaCWaVNWZYtYw X-Received: by 2002:a17:903:2b0e:b0:1f4:5dc0:5fe8 with SMTP id d9443c01a7336-1f6d02e22efmr110452225ad.15.1718027072899; Mon, 10 Jun 2024 06:44:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718027072; cv=pass; d=google.com; s=arc-20160816; b=0Gc10FCaHQXexVj6kyE2aTVhquyksIOUxHmrG6CJo6QWoIxeZJshL8nbblNiMsZQO7 MrkCCL2A5HDysgk9apcuWqHDHes4dEuv+xbs19p8TCK6if1gP0Q4/vgPZ3XK2Ug1FlHQ cuttz0kOA2WOlnOyTsFXMzfjv7KFq1AsErcNmc5UiSqWR7IDLgj9BJIQJ/HqhO0HC0GJ ABu9UkpqIo/m+BmAYYs/r5v97lkADiLE3dH9YcmyE79xZmOmCymCm8zjwKHEL20DzBpT IxmBnFvDR7mFCAihupnji69yA9K6V0A8ZeC/q1ovgNxf+p2WqDHzbiYfj7V+ndazfjQF NXMg== 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=HnG/8ERmsBZXkonIpo6gGJ2IdS4ikXhV3rffCzYwQTY=; fh=mU6xl5FN63PgqIKyLHx/u5uRervM0V89cYoVjXl22Bs=; b=gLX86eYwg3Y7QFPEJV/DVjv8SCbA2/jmWdEdIU1IbXFLOipaepFtX/c3yaakFFbZ+B CLBwiOUWin+yzfc46t5Ms0G8LRXXPvj2/hQWCMh7Yl1+vvP+Qg6wBt++1yT3KGXufN8h 4HlwmU+3sbP+vZL02G2aw2IS5LQ2pbpgTz1oSh067KnrCY3JrgtnzRtIUUAAzp/sPKCD 6DLv3q6xX/NwUpZPcA1rr7rhjcQwtkHYVoRe0c6z0lI5m3aQUgprZhI8ZYyDcm6/60Fh 2N9g4ECyI9DlqZjdvNaGdcyYa43iQiUejSjQLPhxHpVlwZVGan8PuzWZJEOFJjoKtPIn ae/w==; 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-208249-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208249-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-1f719b4ccd8si12554775ad.513.2024.06.10.06.44.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 06:44:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208249-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-208249-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208249-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 362332866E5 for ; Mon, 10 Jun 2024 13:43:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2EA2813212C; Mon, 10 Jun 2024 13:42:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32B2F7CF18; Mon, 10 Jun 2024 13:42:25 +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=1718026947; cv=none; b=m+xrowCnatsmQg8jezitRyY6NjkIZpMIhONQRpO570uG3tsyQTuV99dwfU8QbiRKO3f7iIfeGGE0x41GnSc6jvd79RdvkldLkHcnO5uUjcsAF9CmNSVGLPA7yyffBdRYQ+DSub1QXDFYC2USU1ksWsQz+p39njA7BZwtHuMse28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718026947; c=relaxed/simple; bh=54Ptsmbp6ObfHrpA040MuGlN8qVZzJgfKXDO3oDMwHg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h6fHe5v1k7rMTGdE0qVd/y9JUkSIn6DMx88S67ZLebIqe98hUYc9y9vogSuaqd7zIzFvjcj2sTIxYg0ILTwiXWEq4HNJrqkBbbDLfkaMqXlPeDHO6+tW794BXHKSaM7tfKygLEhVivnCH/m8Ch1gnOM0Shxjk6gFVtJODx0dB3E= 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 293EC1688; Mon, 10 Jun 2024 06:42:50 -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 484AA3F58B; Mon, 10 Jun 2024 06:42:22 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Suzuki K Poulose , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , 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 02/43] kvm: arm64: pgtable: Track the number of pages in the entry level Date: Mon, 10 Jun 2024 14:41:21 +0100 Message-Id: <20240610134202.54893-3-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: Suzuki K Poulose Keep track of the number of pages allocated for the top level PGD, rather than computing it everytime (though we need it only twice now). This will be used later by Arm CCA KVM changes. Signed-off-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_pgtable.h | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 19278dfe7978..0350c08ada7a 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -362,6 +362,7 @@ static inline bool kvm_pgtable_walk_lock_held(void) * struct kvm_pgtable - KVM page-table. * @ia_bits: Maximum input address size, in bits. * @start_level: Level at which the page-table walk starts. + * @pgd_pages: Number of pages in the entry level of the page-table. * @pgd: Pointer to the first top-level entry of the page-table. * @mm_ops: Memory management callbacks. * @mmu: Stage-2 KVM MMU struct. Unused for stage-1 page-tables. @@ -372,6 +373,7 @@ static inline bool kvm_pgtable_walk_lock_held(void) struct kvm_pgtable { u32 ia_bits; s8 start_level; + u8 pgd_pages; kvm_pteref_t pgd; struct kvm_pgtable_mm_ops *mm_ops; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 9e2bbee77491..fb6675838b65 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1574,7 +1574,8 @@ int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu, u32 sl0 = FIELD_GET(VTCR_EL2_SL0_MASK, vtcr); s8 start_level = VTCR_EL2_TGRAN_SL0_BASE - sl0; - pgd_sz = kvm_pgd_pages(ia_bits, start_level) * PAGE_SIZE; + pgt->pgd_pages = kvm_pgd_pages(ia_bits, start_level); + pgd_sz = pgt->pgd_pages * PAGE_SIZE; pgt->pgd = (kvm_pteref_t)mm_ops->zalloc_pages_exact(pgd_sz); if (!pgt->pgd) return -ENOMEM; @@ -1626,7 +1627,7 @@ void kvm_pgtable_stage2_destroy(struct kvm_pgtable *pgt) }; WARN_ON(kvm_pgtable_walk(pgt, 0, BIT(pgt->ia_bits), &walker)); - pgd_sz = kvm_pgd_pages(pgt->ia_bits, pgt->start_level) * PAGE_SIZE; + pgd_sz = pgt->pgd_pages * PAGE_SIZE; pgt->mm_ops->free_pages_exact(kvm_dereference_pteref(&walker, pgt->pgd), pgd_sz); pgt->pgd = NULL; } -- 2.34.1