Re: [PATCH 5.13 191/223] selftest: use mmap instead of posix_memalign to allocate memory

From: Greg Kroah-Hartman
Date: Wed Aug 04 2021 - 06:05:06 EST


On Mon, Aug 02, 2021 at 01:10:47PM -0700, Peter Collingbourne wrote:
> On Thu, Jul 29, 2021 at 9:38 PM Greg Kroah-Hartman
> <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > On Thu, Jul 29, 2021 at 10:58:11AM -0700, Peter Collingbourne wrote:
> > > On Mon, Jul 26, 2021 at 9:16 AM Greg Kroah-Hartman
> > > <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> > > >
> > > > From: Peter Collingbourne <pcc@xxxxxxxxxx>
> > > >
> > > > commit 0db282ba2c12c1515d490d14a1ff696643ab0f1b upstream.
> > > >
> > > > This test passes pointers obtained from anon_allocate_area to the
> > > > userfaultfd and mremap APIs. This causes a problem if the system
> > > > allocator returns tagged pointers because with the tagged address ABI
> > > > the kernel rejects tagged addresses passed to these APIs, which would
> > > > end up causing the test to fail. To make this test compatible with such
> > > > system allocators, stop using the system allocator to allocate memory in
> > > > anon_allocate_area, and instead just use mmap.
> > > >
> > > > Link: https://lkml.kernel.org/r/20210714195437.118982-3-pcc@xxxxxxxxxx
> > > > Link: https://linux-review.googlesource.com/id/Icac91064fcd923f77a83e8e133f8631c5b8fc241
> > > > Fixes: c47174fc362a ("userfaultfd: selftest")
> > > > Co-developed-by: Lokesh Gidra <lokeshgidra@xxxxxxxxxx>
> > > > Signed-off-by: Lokesh Gidra <lokeshgidra@xxxxxxxxxx>
> > > > Signed-off-by: Peter Collingbourne <pcc@xxxxxxxxxx>
> > > > Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>
> > > > Cc: Vincenzo Frascino <vincenzo.frascino@xxxxxxx>
> > > > Cc: Dave Martin <Dave.Martin@xxxxxxx>
> > > > Cc: Will Deacon <will@xxxxxxxxxx>
> > > > Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
> > > > Cc: Alistair Delva <adelva@xxxxxxxxxx>
> > > > Cc: William McVicker <willmcvicker@xxxxxxxxxx>
> > > > Cc: Evgenii Stepanov <eugenis@xxxxxxxxxx>
> > > > Cc: Mitch Phillips <mitchp@xxxxxxxxxx>
> > > > Cc: Andrey Konovalov <andreyknvl@xxxxxxxxx>
> > > > Cc: <stable@xxxxxxxxxxxxxxx> [5.4]
> > > > Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > > > Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> > > > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> > > > ---
> > > > tools/testing/selftests/vm/userfaultfd.c | 6 ++++--
> > > > 1 file changed, 4 insertions(+), 2 deletions(-)
> > > >
> > > > --- a/tools/testing/selftests/vm/userfaultfd.c
> > > > +++ b/tools/testing/selftests/vm/userfaultfd.c
> > > > @@ -197,8 +197,10 @@ static int anon_release_pages(char *rel_
> > > >
> > > > static void anon_allocate_area(void **alloc_area)
> > > > {
> > > > - if (posix_memalign(alloc_area, page_size, nr_pages * page_size)) {
> > > > - fprintf(stderr, "out of memory\n");
> > > > + *alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
> > > > + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> > > > + if (*alloc_area == MAP_FAILED)
> > >
> > > Hi Greg,
> > >
> > > It looks like your backport of this patch (and the backports to stable
> > > kernels) are missing a left brace here.
> >
> > Already fixed up in the latest -rc releases, right?
>
> It looks like you fixed it on linux-4.19.y and linux-5.4.y, but not
> linux-4.14.y, linux-5.10.y or linux-5.13.y.

4.14 had not had a release with this in it yet (it is in the queue), I
missed that I also broke this on 5.10 and 5.13 so will go add it there
as well.

thanks!

greg k-h