Skip to content

Commit 8c3799e

Browse files
Oleksandr AndrushchenkoBoris Ostrovsky
authored andcommitted
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: Oleksandr Andrushchenko <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Signed-off-by: Boris Ostrovsky <[email protected]>
1 parent d72e90f commit 8c3799e

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

drivers/xen/grant-table.c

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -769,44 +769,49 @@ void gnttab_free_auto_xlat_frames(void)
769769
}
770770
EXPORT_SYMBOL_GPL(gnttab_free_auto_xlat_frames);
771771

772-
/**
773-
* gnttab_alloc_pages - alloc pages suitable for grant mapping into
774-
* @nr_pages: number of pages to alloc
775-
* @pages: returns the pages
776-
*/
777-
int gnttab_alloc_pages(int nr_pages, struct page **pages)
772+
int gnttab_pages_set_private(int nr_pages, struct page **pages)
778773
{
779774
int i;
780-
int ret;
781-
782-
ret = alloc_xenballooned_pages(nr_pages, pages);
783-
if (ret < 0)
784-
return ret;
785775

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

790780
foreign = kzalloc(sizeof(*foreign), GFP_KERNEL);
791-
if (!foreign) {
792-
gnttab_free_pages(nr_pages, pages);
781+
if (!foreign)
793782
return -ENOMEM;
794-
}
783+
795784
set_page_private(pages[i], (unsigned long)foreign);
796785
#endif
797786
SetPagePrivate(pages[i]);
798787
}
799788

800789
return 0;
801790
}
802-
EXPORT_SYMBOL_GPL(gnttab_alloc_pages);
791+
EXPORT_SYMBOL_GPL(gnttab_pages_set_private);
803792

804793
/**
805-
* gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
806-
* @nr_pages; number of pages to free
807-
* @pages: the pages
794+
* gnttab_alloc_pages - alloc pages suitable for grant mapping into
795+
* @nr_pages: number of pages to alloc
796+
* @pages: returns the pages
808797
*/
809-
void gnttab_free_pages(int nr_pages, struct page **pages)
798+
int gnttab_alloc_pages(int nr_pages, struct page **pages)
799+
{
800+
int ret;
801+
802+
ret = alloc_xenballooned_pages(nr_pages, pages);
803+
if (ret < 0)
804+
return ret;
805+
806+
ret = gnttab_pages_set_private(nr_pages, pages);
807+
if (ret < 0)
808+
gnttab_free_pages(nr_pages, pages);
809+
810+
return ret;
811+
}
812+
EXPORT_SYMBOL_GPL(gnttab_alloc_pages);
813+
814+
void gnttab_pages_clear_private(int nr_pages, struct page **pages)
810815
{
811816
int i;
812817

@@ -818,6 +823,17 @@ void gnttab_free_pages(int nr_pages, struct page **pages)
818823
ClearPagePrivate(pages[i]);
819824
}
820825
}
826+
}
827+
EXPORT_SYMBOL_GPL(gnttab_pages_clear_private);
828+
829+
/**
830+
* gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
831+
* @nr_pages; number of pages to free
832+
* @pages: the pages
833+
*/
834+
void gnttab_free_pages(int nr_pages, struct page **pages)
835+
{
836+
gnttab_pages_clear_private(nr_pages, pages);
821837
free_xenballooned_pages(nr_pages, pages);
822838
}
823839
EXPORT_SYMBOL_GPL(gnttab_free_pages);

include/xen/grant_table.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ void gnttab_free_auto_xlat_frames(void);
198198
int gnttab_alloc_pages(int nr_pages, struct page **pages);
199199
void gnttab_free_pages(int nr_pages, struct page **pages);
200200

201+
int gnttab_pages_set_private(int nr_pages, struct page **pages);
202+
void gnttab_pages_clear_private(int nr_pages, struct page **pages);
203+
201204
int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
202205
struct gnttab_map_grant_ref *kmap_ops,
203206
struct page **pages, unsigned int count);

0 commit comments

Comments
 (0)