Skip to content

Commit 975fac3

Browse files
Shannon ZhaoDavid Vrabel
authored andcommitted
Xen: xlate: Use page_to_xen_pfn instead of page_to_pfn
Make xen_xlate_map_ballooned_pages work with 64K pages. In that case Kernel pages are 64K in size but Xen pages remain 4K in size. Xen pfns refer to 4K pages. Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Reviewed-by: Julien Grall <julien.grall@arm.com> Tested-by: Julien Grall <julien.grall@arm.com>
1 parent 243848f commit 975fac3

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

drivers/xen/xlate_mmu.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ int xen_xlate_unmap_gfn_range(struct vm_area_struct *vma,
189189
}
190190
EXPORT_SYMBOL_GPL(xen_xlate_unmap_gfn_range);
191191

192+
struct map_balloon_pages {
193+
xen_pfn_t *pfns;
194+
unsigned int idx;
195+
};
196+
197+
static void setup_balloon_gfn(unsigned long gfn, void *data)
198+
{
199+
struct map_balloon_pages *info = data;
200+
201+
info->pfns[info->idx++] = gfn;
202+
}
203+
192204
/**
193205
* xen_xlate_map_ballooned_pages - map a new set of ballooned pages
194206
* @gfns: returns the array of corresponding GFNs
@@ -205,11 +217,13 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,
205217
struct page **pages;
206218
xen_pfn_t *pfns;
207219
void *vaddr;
220+
struct map_balloon_pages data;
208221
int rc;
209-
unsigned int i;
222+
unsigned long nr_pages;
210223

211224
BUG_ON(nr_grant_frames == 0);
212-
pages = kcalloc(nr_grant_frames, sizeof(pages[0]), GFP_KERNEL);
225+
nr_pages = DIV_ROUND_UP(nr_grant_frames, XEN_PFN_PER_PAGE);
226+
pages = kcalloc(nr_pages, sizeof(pages[0]), GFP_KERNEL);
213227
if (!pages)
214228
return -ENOMEM;
215229

@@ -218,22 +232,24 @@ int __init xen_xlate_map_ballooned_pages(xen_pfn_t **gfns, void **virt,
218232
kfree(pages);
219233
return -ENOMEM;
220234
}
221-
rc = alloc_xenballooned_pages(nr_grant_frames, pages);
235+
rc = alloc_xenballooned_pages(nr_pages, pages);
222236
if (rc) {
223-
pr_warn("%s Couldn't balloon alloc %ld pfns rc:%d\n", __func__,
224-
nr_grant_frames, rc);
237+
pr_warn("%s Couldn't balloon alloc %ld pages rc:%d\n", __func__,
238+
nr_pages, rc);
225239
kfree(pages);
226240
kfree(pfns);
227241
return rc;
228242
}
229-
for (i = 0; i < nr_grant_frames; i++)
230-
pfns[i] = page_to_pfn(pages[i]);
231243

232-
vaddr = vmap(pages, nr_grant_frames, 0, PAGE_KERNEL);
244+
data.pfns = pfns;
245+
data.idx = 0;
246+
xen_for_each_gfn(pages, nr_grant_frames, setup_balloon_gfn, &data);
247+
248+
vaddr = vmap(pages, nr_pages, 0, PAGE_KERNEL);
233249
if (!vaddr) {
234-
pr_warn("%s Couldn't map %ld pfns rc:%d\n", __func__,
235-
nr_grant_frames, rc);
236-
free_xenballooned_pages(nr_grant_frames, pages);
250+
pr_warn("%s Couldn't map %ld pages rc:%d\n", __func__,
251+
nr_pages, rc);
252+
free_xenballooned_pages(nr_pages, pages);
237253
kfree(pages);
238254
kfree(pfns);
239255
return -ENOMEM;

0 commit comments

Comments
 (0)