From 1a2d547525a291e4068730dfdbf59fb2327b12a7 Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Tue, 10 Sep 2024 13:27:13 -0700 Subject: [PATCH] ANDROID: virt: gunyah: Correct the nr outval in gunyah_gup_share_parcel gunyah_gup_share_parcel() has an in/out parameter which indicates the number of pages requested to be shared in the mem parcel. We were not returning the number of pages actually shared in the mem parcel and this caused THPs to be undercounted. Later, when converting the parcel to demand paged (gunyah_vm_parcel_to_paged), we hit the BUG_ON on line 55 due to the undercount. Fix the BUG_ON by correctly counting the *nr return value. Fixes: due to the undercount. Fix the BUG_ON by correctly counting the *nr return value due to the undercount. Fix the BUG_ON by correctly counting the *nr return value. Fixes: 296cceed0844 ("ANDROID: virt: gunyah: Add gup based demand paging support") Change-Id: I6492b02d075d903ab68d6c89c4bb1cd78af25c28 Signed-off-by: Elliot Berman Signed-off-by: Elliot Berman --- drivers/virt/gunyah/vm_mgr_mem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/virt/gunyah/vm_mgr_mem.c b/drivers/virt/gunyah/vm_mgr_mem.c index a3d31385715e..8a5475635539 100644 --- a/drivers/virt/gunyah/vm_mgr_mem.c +++ b/drivers/virt/gunyah/vm_mgr_mem.c @@ -557,6 +557,7 @@ int gunyah_gup_share_parcel(struct gunyah_vm *ghvm, struct gunyah_rm_mem_parcel } folio = page_folio(pages[0]); *gfn -= folio_page_idx(folio, pages[0]); + *nr = folio_nr_pages(folio); parcel->mem_entries[0].size = cpu_to_le64(folio_size(folio)); parcel->mem_entries[0].phys_addr = cpu_to_le64(PFN_PHYS(folio_pfn(folio))); @@ -567,6 +568,7 @@ int gunyah_gup_share_parcel(struct gunyah_vm *ghvm, struct gunyah_rm_mem_parcel cpu_to_le64(folio_size(folio)); parcel->mem_entries[entries].phys_addr = cpu_to_le64(PFN_PHYS(folio_pfn(folio))); + *nr += folio_nr_pages(folio); entries++; } else { unpin_user_page(pages[i]);