Re: [kvm-unit-tests PATCH v1 4/4] lib/vmalloc: allow vm_memalign with alignment > PAGE_SIZE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 3 Jul 2020 14:30:01 +0200
Andrew Jones <drjones@xxxxxxxxxx> wrote:

[...]

> > -void *alloc_vpages(ulong nr)
> > +/*
> > + * Allocate a certain number of pages from the virtual address
> > space (without
> > + * physical backing).
> > + *
> > + * nr is the number of pages to allocate
> > + * alignment_pages is the alignment of the allocation *in pages*
> > + */
> > +static void *alloc_vpages_intern(ulong nr, unsigned int
> > alignment_pages)  
> 
> This helper function isn't necessary. Just introduce
> alloc_vpages_aligned() and then call alloc_vpages_aligned(nr, 1) from
> alloc_vpages().

the helper will actually be useful in future patches.

maybe I should have written that in the patch description.

I can respin without helper if you prefer (and introduce it when
needed) or simply update the patch description.

> >  {
> >  	uintptr_t ptr;
> >  
> >  	spin_lock(&lock);
> >  	ptr = (uintptr_t)vfree_top;
> >  	ptr -= PAGE_SIZE * nr;
> > +	ptr &= GENMASK_ULL(63, PAGE_SHIFT +
> > get_order(alignment_pages)); vfree_top = (void *)ptr;
> >  	spin_unlock(&lock);
> >  
> > @@ -32,6 +41,16 @@ void *alloc_vpages(ulong nr)
> >  	return (void *)ptr;
> >  }
> >  
> > +void *alloc_vpages(ulong nr)
> > +{
> > +	return alloc_vpages_intern(nr, 1);
> > +}
> > +
> > +void *alloc_vpages_aligned(ulong nr, unsigned int alignment_pages)
> > +{
> > +	return alloc_vpages_intern(nr, alignment_pages);
> > +}
> > +
> >  void *alloc_vpage(void)
> >  {
> >  	return alloc_vpages(1);
> > @@ -55,17 +74,22 @@ void *vmap(phys_addr_t phys, size_t size)
> >  	return mem;
> >  }
> >  
> > +/*
> > + * Allocate virtual memory, with the specified minimum alignment.
> > + */
> >  static void *vm_memalign(size_t alignment, size_t size)
> >  {
> > +	phys_addr_t pa;
> >  	void *mem, *p;
> > -	size_t pages;
> >  
> > -	assert(alignment <= PAGE_SIZE);
> > -	size = PAGE_ALIGN(size);
> > -	pages = size / PAGE_SIZE;
> > -	mem = p = alloc_vpages(pages);
> > -	while (pages--) {
> > -		phys_addr_t pa = virt_to_phys(alloc_page());
> > +	assert(is_power_of_2(alignment));
> > +
> > +	size = PAGE_ALIGN(size) / PAGE_SIZE;
> > +	alignment = PAGE_ALIGN(alignment) / PAGE_SIZE;
> > +	mem = p = alloc_vpages_intern(size, alignment);
> > +	while (size--) {
> > +		pa = virt_to_phys(alloc_page());
> > +		assert(pa);
> >  		install_page(page_root, pa, p);
> >  		p += PAGE_SIZE;
> >  	}
> > -- 
> > 2.26.2
> >  
> 
> Otherwise
> 
> Reviewed-by: Andrew Jones <drjones@xxxxxxxxxx>
> 
> Thanks,
> drew 
> 




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux