[PATCH v3 3/3] Add mremap tests

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Jul 24 15:20:21 GMT 2024



On 23/07/24 19:11, H.J. Lu wrote:
> 
> On Wed, Jul 24, 2024, 12:35 AM Adhemerval Zanella Netto <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>> wrote:
> 
> 
> 
>     On 22/07/24 18:13, H.J. Lu wrote:
>     > On Tue, Jul 23, 2024, 2:50 AM Adhemerval Zanella Netto <adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org> <mailto:adhemerval.zanella@linaro.org <mailto:adhemerval.zanella@linaro.org>>> wrote:
>     >
>     >
>     >
>     >     On 17/07/24 04:59, H.J. Lu wrote:
> 
>     >     > +static int
>     >     > +mremap_failure_exit (int err, int flags)
>     >     > +{
>     >     > +  if (err != EINVAL)
>     >     > +    return EXIT_FAILURE;
>     >     > +
>     >     > +  unsigned int kernel = get_linux_kernel_version ();
>     >     > +  TEST_VERIFY_EXIT (kernel != 0);
>     >     > +
>     >     > +  /* Since MREMAP_FIXED was added to Linux kernel 2.3.31, return
>     >     > +     EXIT_FAILURE if the kernel is 2.3.31 or newer.  */
>     >     > +  if (flags == MREMAP_FIXED
>     >     > +      && kernel >= make_linux_kernel_version (2, 3, 31))
>     >     > +    return EXIT_FAILURE;
>     >     > +
>     >     > +  /* Since MREMAP_DONTUNMAP was added to Linux kernel 5.7, return
>     >     > +     EXIT_FAILURE if the kernel is 5.7 or newer.  */
>     >     > +  if (flags == MREMAP_DONTUNMAP
>     >     > +      && kernel >= make_linux_kernel_version (5, 7, 0))
>     >     > +    return EXIT_FAILURE;
>     >     > +
>     >     > +  return EXIT_UNSUPPORTED;
>     >     > +}
>     >
>     >     I still think we should test for functionality and not tie the tests
>     >     for an specific Linux version.  So just set unsupported if mremap
>     >     MREMAP_DONTUNMAP fails with EINVAL.
>     >
>     >
>     > Do you have suggestions to make the test
>     > to fail on supported kernel without the
>     > mremap fix?
> 
>     I don't think we should for this specific case, we are testing that the libc
>     is passing the correct arguments to the kernel; so either EINVAL (meaning
>     invalid/unsupported flags) or a successful call is expected (assuming that
>     the mremap usage is valid).
> 
> 
> ?  If a test case doesn't fail when glibc is wrong, it is useless.

Maybe something like the below then:

#include <errno.h>
#include <stdio.h>
#include <sys/mman.h>

#ifndef MREMAP_DONTUNMAP
#define MREMAP_DONTUNMAP 4
#endif

int main (int argc, char *argv[])
{
  void * r = mremap (0, 4096, 4096, MREMAP_MAYMOVE | MREMAP_DONTUNMAP, 0);
  printf ("r=%p (errno=%d)\n", r, errno);
}

And check for EFAULT to assume MREMAP_DONTUNMAP support.

On a 5.4 kernel:

$ ./t
r=0xffffffffffffffff (errno=22)

While on a 6.5 kernel:

$ ./t
r=0xffffffffffffffff (errno=14)


More information about the Libc-alpha mailing list