Re: [LTP] hugemmap: Migrate alloc-instantiate-race test from libhugetlbfs

[email protected]
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Hi Samir,

On Aug 21, 2026, Samir Mulani wrote:
> hugemmap: Migrate alloc-instantiate-race test from libhugetlbfs

> +		SAFE_PTHREAD_CREATE(&thread1, NULL, thread_racer, &ri1);
> +		SAFE_PTHREAD_CREATE(&thread2, NULL, thread_racer, &ri2);
> +
> +		/* Wake both threads to start the race simultaneously */
> +		TST_CHECKPOINT_WAKE2(0, 2);

Medium: Could the MAP_PRIVATE pthread race run in a child process so that
the parent can translate SIGBUS into TFAIL?

The allocation failure under test makes hugetlb_no_page() return
VM_FAULT_SIGBUS. An unhandled SIGBUS in either thread terminates the whole
thread group, after which LTP's check_child_status() reports TBROK instead
of identifying the kernel regression as TFAIL. The MAP_SHARED variant
already translates signal deaths in its child racers.

> +	cpu_set_t cpuset;
> +	int total_cpus, cpu_idx;
> +
> +	CPU_ZERO(&cpuset);
> +
> +	total_cpus = get_nprocs_conf();
> +
> +	if (sched_getaffinity(0, sizeof(cpu_set_t), &cpuset) == -1)
> +		tst_brk(TBROK | TERRNO, "sched_getaffinity() failed");

Medium: Could this use a dynamic mask sized with tst_ncpus_max(),
CPU_ALLOC(), and CPU_ALLOC_SIZE()?

sched_getaffinity() returns EINVAL when the supplied buffer is smaller
than the kernel affinity mask. A kernel supporting more than CPU_SETSIZE
CPUs therefore produces TBROK even when the test has two usable CPUs.

> +#include <pthread.h>
> +#include "tst_test.h"
> +#include "tst_safe_pthread.h"

Medium: Could hugemmap42 be added to the Makefile's existing
CFLAGS += -pthread rule?

The test links on modern glibc because libpthread was merged into libc,
but older supported libc versions need -pthread to resolve the symbols
used by the safe pthread wrappers.

> +/hugetlb/hugemmap/hugemmap42

Low: Could this entry be moved to a leaf
testcases/kernel/mem/hugetlb/hugemmap/.gitignore?

New test binaries should be ignored in their own test directory rather
than in testcases/kernel/mem/.gitignore.

> +	.hugepages = {2, TST_NEEDS},
> +	.forks_child = 1,
> +	.needs_checkpoints = 1,
> +	.min_cpus = 2,
> +};

Low: Could the kernel fix for this regression be added as a linux-git
tag so that failures provide the missing-fix hint?

> + * other racing process.
> + */
> [...]
> +	.needs_root = 1,

Low: Could the exported description explain that root is needed to
reserve hugepages and mount hugetlbfs?

> +	SAFE_CLOSE(fd_race);
> +	fd_race = -1;
> [...]
> +	if (fd_race >= 0)
> +		SAFE_CLOSE(fd_race);

Low: Could the redundant assignment be removed and the cleanup guard use
fd_race != -1, with the same changes for fd_sync?

SAFE_CLOSE() already sets the descriptor to -1, and != -1 is the LTP
descriptor-validity convention.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.