From patchwork Fri Oct 4 15:27:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Price X-Patchwork-Id: 13822566 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81FAD1C75F5; Fri, 4 Oct 2024 15:29:13 +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=1728055755; cv=none; b=uxWqUczOqfNApPBnczqRGFdfTSVpSIebrJMDJdkQeaVNizFs6JGDJZ2YCoNo2XLlySEChYgCFGrIICmq2us75DONTRlzDpY3HFOyKbMHjJEcnm8RwAQRqbRIBD0oQFLful373t85D13LFBSQDow0V48MSpKHUV1wuIb8XevZ7Ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728055755; c=relaxed/simple; bh=DIxNh9RLAx6GBL/bkIFqPK7BjBh9R5CNPUM/GF7UT0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cnFrl9m4Eq73CThjl4i9ZPDM1gyCr6Sta2MdTMTzFOQPYm/AU+m3mYpTiLcTSqpn64HAn7RLSMtLYEnNf5MBmCwEsk9fcNDSaO63vdkLZFsTFdrjxmLDDgz8g4eSX2/YOCtANv1g7ZSyH3FztDL+KeTfNFl7YRXoAc7yEQNfuCo= 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 9785C339; Fri, 4 Oct 2024 08:29:42 -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 B0D1C3F640; Fri, 4 Oct 2024 08:29:08 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , 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" Subject: [PATCH v5 12/43] arm64: RME: Keep a spare page delegated to the RMM Date: Fri, 4 Oct 2024 16:27:33 +0100 Message-Id: <20241004152804.72508-13-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: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Pages can only be populated/destroyed on the RMM at the 4KB granule, this requires creating the full depth of RTTs. However if the pages are going to be combined into a 2MB huge page the last RTT is only temporarily needed. Similarly when freeing memory the huge page must be temporarily split requiring temporary usage of the full depth oF RTTs. To avoid needing to perform a temporary allocation and delegation of a page for this purpose we keep a spare delegated page around. In particular this avoids the need for memory allocation while destroying the realm guest. Reviewed-by: Suzuki K Poulose Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_rme.h | 5 +++++ arch/arm64/kvm/rme.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h index 209cd99f03dd..bd306bd7b64b 100644 --- a/arch/arm64/include/asm/kvm_rme.h +++ b/arch/arm64/include/asm/kvm_rme.h @@ -50,6 +50,9 @@ enum realm_state { * @state: The lifetime state machine for the realm * @rd: Kernel mapping of the Realm Descriptor (RD) * @params: Parameters for the RMI_REALM_CREATE command + * @spare_page: A physical page that has been delegated to the Realm world but + * is otherwise free. Used to avoid temporary allocation during + * RTT operations. * @num_aux: The number of auxiliary pages required by the RMM * @vmid: VMID to be used by the RMM for the realm * @ia_bits: Number of valid Input Address bits in the IPA @@ -60,6 +63,8 @@ struct realm { void *rd; struct realm_params *params; + phys_addr_t spare_page; + unsigned long num_aux; unsigned int vmid; unsigned int ia_bits; diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c index 4d21ec5f2910..f6430d460519 100644 --- a/arch/arm64/kvm/rme.c +++ b/arch/arm64/kvm/rme.c @@ -104,6 +104,7 @@ static int realm_create_rd(struct kvm *kvm) } realm->rd = rd; + realm->spare_page = PHYS_ADDR_MAX; if (WARN_ON(rmi_rec_aux_count(rd_phys, &realm->num_aux))) { WARN_ON(rmi_realm_destroy(rd_phys)); @@ -286,6 +287,13 @@ void kvm_destroy_realm(struct kvm *kvm) rme_vmid_release(realm->vmid); + if (realm->spare_page != PHYS_ADDR_MAX) { + /* Leak the page if the undelegate fails */ + if (!WARN_ON(rmi_granule_undelegate(realm->spare_page))) + free_page((unsigned long)phys_to_virt(realm->spare_page)); + realm->spare_page = PHYS_ADDR_MAX; + } + for (i = 0; i < pgt->pgd_pages; i++) { phys_addr_t pgd_phys = kvm->arch.mmu.pgd_phys + i * PAGE_SIZE;