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: 296cceed08 ("ANDROID: virt: gunyah: Add gup based demand paging support")
Change-Id: I6492b02d075d903ab68d6c89c4bb1cd78af25c28
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
This commit is contained in:
Elliot Berman 2024-09-10 13:27:13 -07:00 committed by Quentin Perret
parent 1d520bc926
commit 1fa94a1407

View File

@ -557,6 +557,7 @@ int gunyah_gup_share_parcel(struct gunyah_vm *ghvm, struct gunyah_rm_mem_parcel
} }
folio = page_folio(pages[0]); folio = page_folio(pages[0]);
*gfn -= folio_page_idx(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].size = cpu_to_le64(folio_size(folio));
parcel->mem_entries[0].phys_addr = cpu_to_le64(PFN_PHYS(folio_pfn(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)); cpu_to_le64(folio_size(folio));
parcel->mem_entries[entries].phys_addr = parcel->mem_entries[entries].phys_addr =
cpu_to_le64(PFN_PHYS(folio_pfn(folio))); cpu_to_le64(PFN_PHYS(folio_pfn(folio)));
*nr += folio_nr_pages(folio);
entries++; entries++;
} else { } else {
unpin_user_page(pages[i]); unpin_user_page(pages[i]);