From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: Andrew Jones <drjones@redhat.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, frankja@linux.ibm.com,
thuth@redhat.com, david@redhat.com
Subject: Re: [kvm-unit-tests PATCH v1 4/4] lib/vmalloc: allow vm_memalign with alignment > PAGE_SIZE
Date: Fri, 3 Jul 2020 15:49:42 +0200 [thread overview]
Message-ID: <20200703154942.6a6513bc@ibm-vm> (raw)
In-Reply-To: <20200703123001.o7kbtfaeq3rml6zo@kamzik.brq.redhat.com>
On Fri, 3 Jul 2020 14:30:01 +0200
Andrew Jones <drjones@redhat.com> 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@redhat.com>
>
> Thanks,
> drew
>
next prev parent reply other threads:[~2020-07-03 13:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-03 11:51 [kvm-unit-tests PATCH v1 0/4] More lib/alloc cleanup and a minor improvement Claudio Imbrenda
2020-07-03 11:51 ` [kvm-unit-tests PATCH v1 1/4] lib/vmalloc: fix pages count local variable to be size_t Claudio Imbrenda
2020-07-03 11:51 ` [kvm-unit-tests PATCH v1 2/4] lib/alloc_page: change some parameter types Claudio Imbrenda
2020-07-03 11:51 ` [kvm-unit-tests PATCH v1 3/4] lib/alloc_page: move get_order and is_power_of_2 to a bitops.h Claudio Imbrenda
2020-07-03 11:51 ` [kvm-unit-tests PATCH v1 4/4] lib/vmalloc: allow vm_memalign with alignment > PAGE_SIZE Claudio Imbrenda
2020-07-03 12:30 ` Andrew Jones
2020-07-03 13:49 ` Claudio Imbrenda [this message]
2020-07-03 16:20 ` Paolo Bonzini
2020-07-03 12:30 ` [kvm-unit-tests PATCH v1 0/4] More lib/alloc cleanup and a minor improvement Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200703154942.6a6513bc@ibm-vm \
--to=imbrenda@linux.ibm.com \
--cc=david@redhat.com \
--cc=drjones@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox