From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: Pavithra <pavrampu@linux.ibm.com>
Cc: pavrampu@linux.ibm.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] [PATCH] [V2] Migrating the libhugetlbfs/testcases/ptrace-write-hugepage.c
Date: Thu, 26 Mar 2026 10:25:46 +0000 [thread overview]
Message-ID: <69c509aa.050a0220.1a7546.aec9@mx.google.com> (raw)
In-Reply-To: <20260311092723.254153-1-pavrampu@linux.ibm.com>
Hi Pavithra,
Thanks for the migration. A few things to address below.
First, the commit subject should follow the LTP convention, e.g.:
hugemmap41: Migrate ptrace-write-hugepage from libhugetlbfs
The body "Changed testcase to use new API" is too brief. Please explain
what the original test does and why it is being migrated (preserving
regression coverage for the ptrace hugepage fix, etc.).
> +/*\
> + * [Description]
> + *
The [Description] tag is deprecated and must not be used. Just remove
the line and keep the description text directly after the /*\ opener.
> +static volatile int ready_to_trace;
[...]
> + ready_to_trace = 1;
[...]
> + while (!ready_to_trace)
> + ;
This busy-wait spin loop combined with a SIGCHLD handler is fragile and
wastes CPU. The whole signal handler + spin loop can be replaced with
TST_PROCESS_STATE_WAIT() after PTRACE_ATTACH:
err = ptrace(PTRACE_ATTACH, cpid, NULL, NULL);
if (err)
tst_brk(TFAIL | TERRNO, "ptrace(ATTACH) failed");
TST_PROCESS_STATE_WAIT(cpid, 't');
This waits for the child to enter tracing stop, which is exactly what
the original code was trying to achieve. It also eliminates the need for
sigchld_handler() and the ready_to_trace variable entirely.
> +static void run_test(void)
> +{
[...]
> + hpage_size = tst_get_hugepage_size();
> + fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
Both hpage_size and fd are static variables set inside run_test(). When
run with -i N, fd is overwritten each iteration without closing the
previous one, leaking file descriptors. Move these to a setup() callback
so they are initialized once, or close fd at the end of each iteration.
Also, ready_to_trace is never reset to 0 at the top of run_test(), so
on -i N runs the spin loop is skipped on iteration 2+, causing a race.
(This goes away if you adopt TST_PROCESS_STATE_WAIT() as suggested
above.)
> + SAFE_PIPE(pipefd);
[...]
> + SAFE_READ(1, pipefd[0], &p, sizeof(p));
The pipe file descriptors are never closed. Close pipefd[1] in the
parent after fork, and close pipefd[0] after the read. In the child,
close pipefd[0] before use and close pipefd[1] after the write.
> +static void child(int hugefd, int pipefd)
> +{
> + void *p;
> +
> + p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
> + hugefd, 0);
[...]
> + pause();
> +}
The child maps a hugepage but never calls SAFE_MUNMAP(). Add a munmap
before pause(), or restructure so the mapping is cleaned up.
> + int signal;
[...]
> + SAFE_WAITPID(cpid, &signal, 0);
Minor: the variable name "signal" shadows the signal() function. Rename
it to "status" for clarity.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-03-26 10:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 9:27 [LTP] [PATCH] [PATCH] [V2] Migrating the libhugetlbfs/testcases/ptrace-write-hugepage.c Pavithra
2026-03-26 10:25 ` Andrea Cervesato via ltp [this message]
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=69c509aa.050a0220.1a7546.aec9@mx.google.com \
--to=ltp@lists.linux.it \
--cc=andrea.cervesato@suse.com \
--cc=pavrampu@linux.ibm.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