public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: Samir <samir@linux.ibm.com>
Cc: Samir <samir@linux.ibm.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v5] Migrating the libhugetlbfs/testcases/truncate_sigbus_versus_oom.c test
Date: Thu, 26 Mar 2026 12:54:45 +0000	[thread overview]
Message-ID: <69c52c96.050a0220.3d9c1f.4146@mx.google.com> (raw)
In-Reply-To: <20260317102059.6699-1-samir@linux.ibm.com>

Hi Samir,

Thanks for the migration. This is just a first line review on the major
issues related to this patch. Probably more will come with time if these
issues won't be achieved.

> Subject: [PATCH] Migrating the
>  libhugetlbfs/testcases/truncate_sigbus_versus_oom.c test

The subject should use imperative mood, e.g.:

  hugemmap37: Migrate truncate_sigbus_versus_oom from libhugetlbfs

> In this test case, we are verifying the bug fix commit that is attached as a part of the test case structure,
>
> Some kernel have a bug in the positioning of the test against

"Some kernel have" -> "Some kernels have". The first sentence ends with
a dangling comma and is vague. Consider dropping it entirely — the
second paragraph already explains the test clearly.

[...]

> +void setup(void)
> +{
> +	struct sigaction sa;

Two issues here:

1) setup() and cleanup() are missing the 'static' keyword.

2) 'sa' is uninitialized — sa_mask and other fields contain garbage.
   Zero-initialize it:

       struct sigaction sa = {};
       sigemptyset(&sa.sa_mask);

> +	sa.sa_flags = SA_SIGINFO;
> +	sa.sa_handler = sigbus_handler;

SA_SIGINFO tells the kernel to use sa_sigaction (3-argument handler),
but you assign to sa_handler (1-argument). This is undefined behavior
per POSIX. Since sigbus_handler() takes a single int, drop SA_SIGINFO:

    sa.sa_flags = 0;
    sa.sa_handler = sigbus_handler;

> +	totpages = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
> +	hpage_size = tst_get_hugepage_size();

The totpages assignment here is dead code — it gets overwritten in
run_test() before use. Remove it from setup().

[...]

> +	fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

[...]

> +	fdx = tst_creat_unlinked(MNTPOINT, 0, 0600);

[...]

> +	q = SAFE_MMAP(NULL, totpages * hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED,
> +			fdx, 0);

fd and fdx are opened each iteration but only closed in cleanup(). On
-i N runs the previous fds leak. Similarly, p and q are mmap'd but
never munmapped, leaking virtual memory each iteration.

Close the fds and munmap both regions at the end of run_test(), resetting
fd/fdx to -1.

[...]

> +void cleanup(void)
> +{
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
> +	if (fdx > 0)
> +		SAFE_CLOSE(fdx);

if (fd != -1) and fd should be initialized to -1. zero is a valid value.

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-26 12:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 10:20 [LTP] [PATCH v5] Migrating the libhugetlbfs/testcases/truncate_sigbus_versus_oom.c test Samir
2026-03-26 12:54 ` 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=69c52c96.050a0220.3d9c1f.4146@mx.google.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    --cc=samir@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