Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c3799ee authored by Oleksandr Andrushchenko's avatar Oleksandr Andrushchenko Committed by Boris Ostrovsky
Browse files

xen/grant-table: Make set/clear page private code shared



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: default avatarOleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent d72e90f3
Loading
Loading
Loading
Loading
+35 −19
Original line number Original line Diff line number Diff line
@@ -769,29 +769,18 @@ void gnttab_free_auto_xlat_frames(void)
}
}
EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames);
EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames);


/**
int gnttab_pages_set_private(int nr_pages, struct page **pages)
 * 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 i;
	int i;
	int ret;

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


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


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

		set_page_private(pages[i], (unsigned long)foreign);
		set_page_private(pages[i], (unsigned long)foreign);
#endif
#endif
		SetPagePrivate(pages[i]);
		SetPagePrivate(pages[i]);
@@ -799,14 +788,30 @@ int gnttab_alloc_pages(int nr_pages, struct page **pages)


	return 0;
	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()
 * gnttab_alloc_pages - alloc pages suitable for grant mapping into
 * @nr_pages; number of pages to free
 * @nr_pages: number of pages to alloc
 * @pages: the pages
 * @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;
	int i;


@@ -818,6 +823,17 @@ void gnttab_free_pages(int nr_pages, struct page **pages)
			ClearPagePrivate(pages[i]);
			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);
	free_xenballooned_pages(nr_pages, pages);
}
}
EXPORT_SYMBOL_GPL(gnttab_free_pages);
EXPORT_SYMBOL_GPL(gnttab_free_pages);
+3 −0
Original line number Original line Diff line number Diff line
@@ -198,6 +198,9 @@ void gnttab_free_auto_xlat_frames(void);
int gnttab_alloc_pages(int nr_pages, struct page **pages);
int gnttab_alloc_pages(int nr_pages, struct page **pages);
void gnttab_free_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,
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
		    struct gnttab_map_grant_ref *kmap_ops,
		    struct gnttab_map_grant_ref *kmap_ops,
		    struct page **pages, unsigned int count);
		    struct page **pages, unsigned int count);