All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: "Wei Gao via ltp" <ltp@lists.linux.it>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] mremap07.c: New case check mremap with MREMAP_DONTUNMAP
Date: Mon, 23 Mar 2026 07:03:08 +0000	[thread overview]
Message-ID: <69c0e5ae.050a0220.25bf93.a9a9@mx.google.com> (raw)
In-Reply-To: <20260225090525.19581-1-wegao@suse.com>

Hi Wei,

The overall structure looks good, but there are a few bugs that need
fixing before this can be merged.

> +static int uffd;

This is zero-initialized by the compiler, but fd 0 is a valid file
descriptor (stdin). cleanup() guards with `if (uffd != -1)`, so if
setup() fails before SAFE_USERFAULTFD assigns a real fd, cleanup() will
call SAFE_CLOSE(0) and close stdin. Initialize it to -1:

  static int uffd = -1;

> +static void fault_handler_thread(void)

pthread start routines must have the signature `void *(*)(void *)`.
Casting a `void (*)(void)` function to that type and calling it through
the incompatible pointer is undefined behavior. Please use the correct
signature:

  static void *fault_handler_thread(void *arg LTP_ATTRIBUTE_UNUSED)
  {
          ...
          return NULL;
  }

> +	if (new_remap_addr != NULL)
> +		SAFE_MUNMAP(new_remap_addr, page_size);
> +
> +	if (fault_addr != NULL)
> +		SAFE_MUNMAP(fault_addr, page_size);

Kernel coding style: drop the `!= NULL`, write `if (new_remap_addr)`
and `if (fault_addr)`. checkpatch also flags these.

> +	SAFE_PTHREAD_CREATE(&handler_thread, NULL,
> +		(void * (*)(void *))fault_handler_thread, NULL);
> +
> +	new_remap_addr = mremap(fault_addr, page_size, page_size,
> +		MREMAP_DONTUNMAP | MREMAP_MAYMOVE);
> +
> +	if (new_remap_addr == MAP_FAILED)
> +		tst_brk(TBROK | TTERRNO, "mremap failed");

Two issues here:

1. TTERRNO prints TST_ERR, which is the errno captured by the TEST()
   macro. mremap() is called directly, so TST_ERR is stale. Use TERRNO
   (system errno) instead.

2. new_remap_addr is a static variable that is set here but only freed
   in cleanup(). When the test is run with `-i N` for N > 1, each
   iteration overwrites new_remap_addr with a fresh mremap result, and
   the previous iteration's mapping is leaked. Add an explicit munmap at
   the end of run() and reset the pointer:

     SAFE_MUNMAP(new_remap_addr, page_size);
     new_remap_addr = NULL;

> +	.needs_root = 1,

This is not needed. SAFE_USERFAULTFD() is called with retry=true, which
automatically retries with UFFD_USER_MODE_ONLY when EPERM is returned.
Everything this test does (mmap/mremap, UFFDIO_REGISTER, UFFDIO_COPY on
user pages) works without root on kernels >= 5.11. On 5.7--5.10 the
retry will result in TCONF, which is the correct behavior. Please drop
.needs_root.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-03-23  7:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 23:02 [LTP] [PATCH v1] mremap07.c: New case check mremap with MREMAP_DONTUNMAP Wei Gao via ltp
2025-10-15  3:15 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-10-16 13:32   ` Petr Vorel
2025-10-17  7:51     ` Wei Gao via ltp
2025-10-30 19:39       ` Petr Vorel
2025-11-01  8:47         ` Wei Gao via ltp
2025-10-30  5:40   ` [LTP] [PATCH v3] " Wei Gao via ltp
2025-10-30 20:07     ` Petr Vorel
2026-02-25  9:05     ` [LTP] [PATCH v4] " Wei Gao via ltp
2026-03-23  7:03       ` Andrea Cervesato via ltp [this message]
2026-03-25  1:15       ` [LTP] [PATCH v5] " Wei Gao via ltp
2026-03-26 10:01         ` Andrea Cervesato via ltp
2026-04-10  2:31         ` [LTP] [PATCH v6] " Wei Gao via ltp
2026-04-17  6:53           ` [LTP] [PATCH v7] mremap07.c: New test for mremap() " Wei Gao via ltp
2026-04-17  7:55             ` [LTP] " linuxtestproject.agent
2026-04-17  8:00               ` Andrea Cervesato via ltp
2026-04-17 12:27             ` [LTP] [PATCH v8] " Wei Gao via ltp
2026-04-17 13:26               ` [LTP] " linuxtestproject.agent
2026-04-19  1:22                 ` Wei Gao via ltp
2026-04-20 10:12               ` [LTP] [PATCH v8] " Li Wang
2026-04-21  8:20                 ` Wei Gao via ltp
2026-04-21  9:11                   ` Li Wang
2026-04-22  2:30               ` [LTP] [PATCH v9] " Wei Gao via ltp

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=69c0e5ae.050a0220.25bf93.a9a9@mx.google.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.