xen: re-define assign_pages and introduce a new function assign_page

In order to deal with the trouble of count-to-order conversion when page number
is not in a power-of-two, this commit re-define assign_pages for nr pages and
assign_page for original page with a single order.

Backporting confusion could be helped by altering the order of assign_pages
parameters, such that the compiler would point out that adjustments at call
sites are needed.

[stefano: switch to unsigned int for nr]
Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
Penny Zheng authored and Stefano Stabellini committed 2021-09-13 14:12:59 -07:00
1 parent 4a9e73e6e5
commit 5260e8fb93
5 files changed
+25 -14

No files matched your search

+1 -1
View File
@@ -568,7 +568,7 @@ int __init dom0_construct_pv(struct domain *d,
else else
{ {
while ( count-- ) while ( count-- )
if ( assign_pages(d, mfn_to_page(_mfn(mfn++)), 0, 0) ) if ( assign_pages(mfn_to_page(_mfn(mfn++)), 1, d, 0) )
BUG(); BUG();
} }
initrd->mod_end = 0; initrd->mod_end = 0;
+1 -1
View File
@@ -2358,7 +2358,7 @@ gnttab_transfer(
* is respected and speculative execution is blocked accordingly * is respected and speculative execution is blocked accordingly
*/ */
if ( unlikely(!evaluate_nospec(okay)) || if ( unlikely(!evaluate_nospec(okay)) ||
unlikely(assign_pages(e, page, 0, MEMF_no_refcount)) ) unlikely(assign_pages(page, 1, e, MEMF_no_refcount)) )
{ {
bool drop_dom_ref; bool drop_dom_ref;
+3 -3
View File
@@ -728,8 +728,8 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
/* Assign each output page to the domain. */ /* Assign each output page to the domain. */
for ( j = 0; (page = page_list_remove_head(&out_chunk_list)); ++j ) for ( j = 0; (page = page_list_remove_head(&out_chunk_list)); ++j )
{ {
if ( assign_pages(d, page, exch.out.extent_order, if ( assign_page(page, exch.out.extent_order, d,
MEMF_no_refcount) ) MEMF_no_refcount) )
{ {
unsigned long dec_count; unsigned long dec_count;
bool_t drop_dom_ref; bool_t drop_dom_ref;
@@ -797,7 +797,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
* cleared PGC_allocated. * cleared PGC_allocated.
*/ */
while ( (page = page_list_remove_head(&in_chunk_list)) ) while ( (page = page_list_remove_head(&in_chunk_list)) )
if ( assign_pages(d, page, 0, MEMF_no_refcount) ) if ( assign_pages(page, 1, d, MEMF_no_refcount) )
{ {
BUG_ON(!d->is_dying); BUG_ON(!d->is_dying);
free_domheap_page(page); free_domheap_page(page);
+14 -9
View File
@@ -2259,9 +2259,9 @@ void init_domheap_pages(paddr_t ps, paddr_t pe)
int assign_pages( int assign_pages(
struct domain *d,
struct page_info *pg, struct page_info *pg,
unsigned int order, unsigned int nr,
struct domain *d,
unsigned int memflags) unsigned int memflags)
{ {
int rc = 0; int rc = 0;
@@ -2281,7 +2281,7 @@ int assign_pages(
{ {
unsigned int extra_pages = 0; unsigned int extra_pages = 0;
for ( i = 0; i < (1ul << order); i++ ) for ( i = 0; i < nr; i++ )
{ {
ASSERT(!(pg[i].count_info & ~PGC_extra)); ASSERT(!(pg[i].count_info & ~PGC_extra));
if ( pg[i].count_info & PGC_extra ) if ( pg[i].count_info & PGC_extra )
@@ -2290,18 +2290,18 @@ int assign_pages(
ASSERT(!extra_pages || ASSERT(!extra_pages ||
((memflags & MEMF_no_refcount) && ((memflags & MEMF_no_refcount) &&
extra_pages == 1u << order)); extra_pages == nr));
} }
#endif #endif
if ( pg[0].count_info & PGC_extra ) if ( pg[0].count_info & PGC_extra )
{ {
d->extra_pages += 1u << order; d->extra_pages += nr;
memflags &= ~MEMF_no_refcount; memflags &= ~MEMF_no_refcount;
} }
else if ( !(memflags & MEMF_no_refcount) ) else if ( !(memflags & MEMF_no_refcount) )
{ {
unsigned int tot_pages = domain_tot_pages(d) + (1 << order); unsigned int tot_pages = domain_tot_pages(d) + nr;
if ( unlikely(tot_pages > d->max_pages) ) if ( unlikely(tot_pages > d->max_pages) )
{ {
@@ -2313,10 +2313,10 @@ int assign_pages(
} }
if ( !(memflags & MEMF_no_refcount) && if ( !(memflags & MEMF_no_refcount) &&
unlikely(domain_adjust_tot_pages(d, 1 << order) == (1 << order)) ) unlikely(domain_adjust_tot_pages(d, nr) == nr) )
get_knownalive_domain(d); get_knownalive_domain(d);
for ( i = 0; i < (1 << order); i++ ) for ( i = 0; i < nr; i++ )
{ {
ASSERT(page_get_owner(&pg[i]) == NULL); ASSERT(page_get_owner(&pg[i]) == NULL);
page_set_owner(&pg[i], d); page_set_owner(&pg[i], d);
@@ -2331,6 +2331,11 @@ int assign_pages(
return rc; return rc;
} }
int assign_page(struct page_info *pg, unsigned int order, struct domain *d,
unsigned int memflags)
{
return assign_pages(pg, 1UL << order, d, memflags);
}
struct page_info *alloc_domheap_pages( struct page_info *alloc_domheap_pages(
struct domain *d, unsigned int order, unsigned int memflags) struct domain *d, unsigned int order, unsigned int memflags)
@@ -2373,7 +2378,7 @@ struct page_info *alloc_domheap_pages(
pg[i].count_info = PGC_extra; pg[i].count_info = PGC_extra;
} }
} }
if ( assign_pages(d, pg, order, memflags) ) if ( assign_page(pg, order, d, memflags) )
{ {
free_heap_pages(pg, order, memflags & MEMF_no_scrub); free_heap_pages(pg, order, memflags & MEMF_no_scrub);
return NULL; return NULL;
+6
View File
@@ -132,9 +132,15 @@ int query_page_offline(mfn_t mfn, uint32_t *status);
void heap_init_late(void); void heap_init_late(void);
int assign_pages( int assign_pages(
struct page_info *pg,
unsigned int nr,
struct domain *d, struct domain *d,
unsigned int memflags);
int assign_page(
struct page_info *pg, struct page_info *pg,
unsigned int order, unsigned int order,
struct domain *d,
unsigned int memflags); unsigned int memflags);
/* Dump info to serial console */ /* Dump info to serial console */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.