From: Elliot Berman <quic_eberman@xxxxxxxxxxx> Gunyah Resource Manager sets up a virtual machine based on a device tree which lives in guest memory. Resource manager requires this memory to be provided as a memory parcel for it to read and manipulate. Construct a memory parcel, lend it to the virtual machine, and inform resource manager about the device tree location (the memory parcel ID and offset into the memory parcel). Signed-off-by: Elliot Berman <quic_eberman@xxxxxxxxxxx> Signed-off-by: Karim Manaouil <karim.manaouil@xxxxxxxxxx> --- arch/arm64/kvm/gunyah.c | 27 ++++++++++++++++++++++++--- include/linux/gunyah.h | 10 ++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/gunyah.c b/arch/arm64/kvm/gunyah.c index ef0971146b56..687f2beea4e7 100644 --- a/arch/arm64/kvm/gunyah.c +++ b/arch/arm64/kvm/gunyah.c @@ -699,8 +699,7 @@ static int gunyah_reclaim_memory_parcel(struct gunyah_vm *ghvm, if (parcel->mem_handle != GUNYAH_MEM_HANDLE_INVAL) { ret = gunyah_rm_mem_reclaim(ghvm->rm, parcel); if (ret) { - dev_err(ghvm->parent, "Failed to reclaim parcel: %d\n", - ret); + pr_err("Failed to reclaim parcel: %d\n", ret); /* We can't reclaim the pages -- hold onto the pages * forever because we don't know what state the memory * is in @@ -1574,6 +1573,7 @@ static void gunyah_vm_stop(struct gunyah_vm *ghvm) static int gunyah_vm_start(struct gunyah_vm *ghvm) { + struct kvm *kvm = &ghvm->kvm; struct gunyah_rm_hyp_resources *resources; struct gunyah_resource *ghrsc; int i, n, ret; @@ -1597,7 +1597,18 @@ static int gunyah_vm_start(struct gunyah_vm *ghvm) ghvm->vmid = ret; ghvm->vm_status = GUNYAH_RM_VM_STATUS_LOAD; - ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, 0, 0, 0, 0, 0); + ghvm->dtb.parcel_start = gpa_to_gfn(kvm->dtb.guest_phys_addr); + ghvm->dtb.parcel_pages = gpa_to_gfn(kvm->dtb.size); + ret = gunyah_share_memory_parcel(ghvm, &ghvm->dtb.parcel, + ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); + if (ret) { + pr_warn("Failed to allocate parcel for DTB: %d\n", ret); + goto err; + } + + ret = gunyah_rm_vm_configure(ghvm->rm, ghvm->vmid, ghvm->auth, + ghvm->dtb.parcel.mem_handle, 0, 0, 0, kvm->dtb.size); if (ret) { pr_warn("Failed to configure VM: %d\n", ret); goto err; @@ -1698,6 +1709,16 @@ static void gunyah_destroy_vm(struct gunyah_vm *ghvm) if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_RUNNING) gunyah_vm_stop(ghvm); + if (ghvm->vm_status == GUNYAH_RM_VM_STATUS_LOAD || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_READY || + ghvm->vm_status == GUNYAH_RM_VM_STATUS_INIT_FAILED) { + ret = gunyah_reclaim_memory_parcel(ghvm, &ghvm->dtb.parcel, + ghvm->dtb.parcel_start, + ghvm->dtb.parcel_pages); + if (ret) + pr_err("Failed to reclaim DTB parcel: %d\n", ret); + } + gunyah_vm_remove_resource_ticket(ghvm, &ghvm->addrspace_ticket); gunyah_vm_remove_resource_ticket(ghvm, &ghvm->host_shared_extent_ticket); gunyah_vm_remove_resource_ticket(ghvm, &ghvm->host_private_extent_ticket); diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h index 1d363ab8967a..72aafc813664 100644 --- a/include/linux/gunyah.h +++ b/include/linux/gunyah.h @@ -94,6 +94,12 @@ struct gunyah_vm_resource_ticket { * @resource_tickets: List of &struct gunyah_vm_resource_ticket * @auth: Authentication mechanism to be used by resource manager when * launching the VM + * @dtb: For tracking dtb configuration when launching the VM + * @dtb.parcel_start: Guest frame number where the memory parcel that we lent to + * VM (DTB could start in middle of folio; we lend entire + * folio; parcel_start is start of the folio) + * @dtb.parcel_pages: Number of pages lent for the memory parcel + * @dtb.parcel: Data for resource manager to lend the parcel */ struct gunyah_vm { u16 vmid; @@ -113,6 +119,10 @@ struct gunyah_vm { struct gunyah_vm_resource_ticket host_shared_extent_ticket; struct gunyah_vm_resource_ticket guest_private_extent_ticket; struct gunyah_vm_resource_ticket guest_shared_extent_ticket; + struct { + gfn_t parcel_start, parcel_pages; + struct gunyah_rm_mem_parcel parcel; + } dtb; }; /** -- 2.39.5