[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH V4 08/10] xen/arm: introduce acquire_staticmem_pages and acquire_domstatic_pages
On 28.07.2021 12:27, Penny Zheng wrote: > @@ -1065,6 +1069,73 @@ static struct page_info *alloc_heap_pages( > return pg; > } > > +#ifdef CONFIG_STATIC_MEMORY > +/* > + * Acquire nr_mfns contiguous reserved pages, starting at #smfn, of > + * static memory. > + */ > +static struct page_info * __init acquire_staticmem_pages(unsigned long > nr_mfns, > + mfn_t smfn, > + unsigned int > memflags) > +{ > + bool need_tlbflush = false; > + uint32_t tlbflush_timestamp = 0; > + unsigned long i; > + struct page_info *pg; > + > + /* For now, it only supports pre-configured static memory. */ > + if ( !mfn_valid(smfn) || !nr_mfns ) > + return NULL; > + > + spin_lock(&heap_lock); > + > + pg = mfn_to_page(smfn); Nit: This can easily be done prior to acquiring the lock. And since PDX compression causes this to be a non-trivial calculation, it is probably better that way despite the compiler then being forced to use a non- call-clobbered register to hold the variable (it might do so anyway, but as it looks there currently is nothing actually requiring this). > + for ( i = 0; i < nr_mfns; i++ ) > + { > + /* > + * Reference count must continuously be zero for free pages > + * of static memory(PGC_reserved). > + */ > + if ( pg[i].count_info != (PGC_state_free | PGC_reserved) ) > + { > + printk(XENLOG_ERR > + "pg[%lu] Static MFN %"PRI_mfn" c=%#lx t=%#x\n", > + i, mfn_x(page_to_mfn(pg + i)), "mfn_x(smfn) + i" would cause less code to be generated, again due to PDX compression making the transformation a non-trivial operation. > + pg[i].count_info, pg[i].tlbflush_timestamp); > + BUG(); > + } > + > + if ( !(memflags & MEMF_no_tlbflush) ) > + accumulate_tlbflush(&need_tlbflush, &pg[i], > + &tlbflush_timestamp); > + > + /* > + * Preserve flag PGC_reserved and change page state > + * to PGC_state_inuse. > + */ > + pg[i].count_info = (PGC_reserved | PGC_state_inuse); Nit: Parentheses aren't really needed here. > @@ -2411,6 +2483,38 @@ struct page_info *alloc_domheap_pages( > return pg; > } > > +#ifdef CONFIG_STATIC_MEMORY > +/* > + * Acquire nr_mfns contiguous pages, starting at #smfn, of static memory, > + * then assign them to one specific domain #d. > + */ > +struct page_info * __init acquire_domstatic_pages(struct domain *d, > + unsigned long nr_mfns, > + mfn_t smfn, unsigned int > memflags) > +{ > + struct page_info *pg = NULL; Unnecessary initializer. > + ASSERT(!in_irq()); > + > + pg = acquire_staticmem_pages(nr_mfns, smfn, memflags); > + if ( !pg ) > + return NULL; > + > + /* > + * MEMF_no_owner/MEMF_no_refcount cases are missing here because > + * right now, acquired static memory is only for guest RAM. > + */ I think you want to ASSERT() or otherwise check that the two flags are clear. Whether you then still deem the comment appropriate in this form is up to you, I guess. Otoh ... > + ASSERT(d); ... I'm less convinced that this ASSERT() is very useful. At the very least if you use other than or more than ASSERT() for the checking above, this one should follow suit. Perhaps altogether if ( !d || (memflags & (MEMF_no_owner | MEMF_no_refcount)) ) { /* * Respective handling omitted here because right now * acquired static memory is only for guest RAM. */ ASSERT_UNREACHABLE(); return NULL; } ? Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |