@@ -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;
@@ -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;