ANDROID: virt: gunyah: Allow host to reclaim memory provided to the guest

Introduce an ioctl, GH_VM_RECLAIM_REGION which attempts to reclaim guest
memory. If the guest hasn't relinquished the memory, an error is
returned.

Bug: 395833312
Change-Id: I005c947435f0256f6200c0d7d86eea145e1daa0a
Signed-off-by: Elliot Berman <elliot.berman@oss.qualcomm.com>
This commit is contained in:
Elliot Berman
2025-02-10 13:49:26 -08:00
committed by Todd Kjos
parent c5f87aea6b
commit 216adf28ee
2 changed files with 25 additions and 0 deletions
+16
View File
@@ -923,6 +923,22 @@ static long gunyah_vm_ioctl(struct file *filp, unsigned int cmd,
r = gunyah_vm_binding_alloc(ghvm, &region, lend);
break;
}
case GH_VM_RECLAIM_REGION: {
struct gunyah_address_range range;
/* only allow owner task to remove memory */
if (ghvm->mm_s != current->mm)
return -EPERM;
if (copy_from_user(&range, argp, sizeof(range)))
return -EFAULT;
if (!PAGE_ALIGNED(range.size) || !PAGE_ALIGNED(range.guest_phys_addr))
return -EINVAL;
r = gunyah_vm_reclaim_range(ghvm,
gunyah_gpa_to_gfn(range.guest_phys_addr),
gunyah_gpa_to_gfn(range.size) - 1);
break;
}
case GUNYAH_VM_SET_BOOT_CONTEXT: {
struct gunyah_vm_boot_context boot_ctx;
+9
View File
@@ -387,4 +387,13 @@ struct gunyah_vm_firmware_config {
#define GH_VM_ANDROID_SET_FW_CONFIG _IOW(GH_ANDROID_IOCTL_TYPE, 0x12, \
struct gunyah_vm_firmware_config)
struct gunyah_address_range {
__u64 guest_phys_addr;
__u64 size;
};
#define GH_VM_RECLAIM_REGION _IOW(GH_ANDROID_IOCTL_TYPE, 0x13, \
struct gunyah_address_range)
#endif