Skip to content

Commit

Permalink
xen/grant-table: Make set/clear page private code shared
Browse files Browse the repository at this point in the history
Make set/clear page private code shared and accessible to
other kernel modules which can re-use these instead of open-coding.

Signed-off-by: Oleksandr Andrushchenko <[email protected]>
Reviewed-by: Boris Ostrovsky <[email protected]>
Signed-off-by: Boris Ostrovsky <[email protected]>
  • Loading branch information
Oleksandr Andrushchenko authored and Boris Ostrovsky committed Jul 27, 2018
1 parent d72e90f commit 8c3799e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
54 changes: 35 additions & 19 deletions drivers/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,44 +769,49 @@ void gnttab_free_auto_xlat_frames(void)
}
EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames);

/**
* gnttab_alloc_pages - alloc pages suitable for grant mapping into
* @nr_pages: number of pages to alloc
* @pages: returns the pages
*/
int gnttab_alloc_pages(int nr_pages, struct page **pages)
int gnttab_pages_set_private(int nr_pages, struct page **pages)
{
int i;
int ret;

ret = alloc_xenballooned_pages(nr_pages, pages);
if (ret < 0)
return ret;

for (i = 0; i < nr_pages; i++) {
#if BITS_PER_LONG < 64
struct xen_page_foreign *foreign;

foreign = kzalloc(sizeof(*foreign), GFP_KERNEL);
if (!foreign) {
gnttab_free_pages(nr_pages, pages);
if (!foreign)
return -ENOMEM;
}

set_page_private(pages[i], (unsigned long)foreign);
#endif
SetPagePrivate(pages[i]);
}

return 0;
}
EXPORT_SYMBOL_GPL(gnttab_alloc_pages);
EXPORT_SYMBOL_GPL(gnttab_pages_set_private);

/**
* gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
* @nr_pages; number of pages to free
* @pages: the pages
* gnttab_alloc_pages - alloc pages suitable for grant mapping into
* @nr_pages: number of pages to alloc
* @pages: returns the pages
*/
void gnttab_free_pages(int nr_pages, struct page **pages)
int gnttab_alloc_pages(int nr_pages, struct page **pages)
{
int ret;

ret = alloc_xenballooned_pages(nr_pages, pages);
if (ret < 0)
return ret;

ret = gnttab_pages_set_private(nr_pages, pages);
if (ret < 0)
gnttab_free_pages(nr_pages, pages);

return ret;
}
EXPORT_SYMBOL_GPL(gnttab_alloc_pages);

void gnttab_pages_clear_private(int nr_pages, struct page **pages)
{
int i;

Expand All @@ -818,6 +823,17 @@ void gnttab_free_pages(int nr_pages, struct page **pages)
ClearPagePrivate(pages[i]);
}
}
}
EXPORT_SYMBOL_GPL(gnttab_pages_clear_private);

/**
* gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
* @nr_pages; number of pages to free
* @pages: the pages
*/
void gnttab_free_pages(int nr_pages, struct page **pages)
{
gnttab_pages_clear_private(nr_pages, pages);
free_xenballooned_pages(nr_pages, pages);
}
EXPORT_SYMBOL_GPL(gnttab_free_pages);
Expand Down
3 changes: 3 additions & 0 deletions include/xen/grant_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ void gnttab_free_auto_xlat_frames(void);
int gnttab_alloc_pages(int nr_pages, struct page **pages);
void gnttab_free_pages(int nr_pages, struct page **pages);

int gnttab_pages_set_private(int nr_pages, struct page **pages);
void gnttab_pages_clear_private(int nr_pages, struct page **pages);

int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
struct gnttab_map_grant_ref *kmap_ops,
struct page **pages, unsigned int count);
Expand Down

0 comments on commit 8c3799e

Please sign in to comment.