From: linuxtestproject.agent@gmail.com
To: Stephen Bertram <sbertram@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] semctl01: look up SEM_STAT index for this test's sem_id
Date: Tue, 28 Jul 2026 21:12:14 +0000 [thread overview]
Message-ID: <20260728211214.8732-1-linuxtestproject.agent@gmail.com> (raw)
In-Reply-To: <20260728203333.3949671-1-sbertram@redhat.com>
Hi Stephen,
On Jul 28, 2026, Stephen Bertram wrote:
> semctl01: look up SEM_STAT index for this test's sem_id
> Walk 0..max_idx with SEM_STAT until the returned id equals this test's
> sem_id.
The body describes what the code does, but not why it is needed. Could it
state the root cause instead, e.g. that IPC_INFO returns the globally
highest used index, which may belong to another process's semaphore set,
so SAFE_SEMCTL(sem_index, 0, SEM_STAT, ...) can fail with EINVAL/EIDRM/
EACCES and abort the test with TBROK when IPC tests run in parallel?
> Test: ./kirk -w 4 -f syscalls_8 -p semctl01 -i 1000
>
> Results summary before:
[...]
This is test-run metadata rather than part of the change log. Would it be
better placed below the "---" line?
> +static int sem_stat_for_id(int id, union semun arg)
> +{
> + struct seminfo info;
> + union semun info_arg;
> + int max_idx, i, ret;
> +
> + info_arg.__buf = &info;
> + max_idx = SAFE_SEMCTL(id, 0, IPC_INFO, info_arg);
> +
> + for (i = 0; i <= max_idx; i++) {
> + ret = semctl(i, 0, SEM_STAT, arg);
> + if (ret == id)
> + return ret;
The helper returns the semid, not the index, and it only returns when
ret == id. Combined with do_sem_stat() aborting otherwise, the value
reaching func_sstat() is always sem_id.
> +static int do_sem_stat(union semun arg)
> +{
> + int ret;
> +
> + ret = sem_stat_for_id(sem_id, arg);
> + if (ret < 0)
> + tst_brk(TBROK, "Failed to find SEM_STAT for sem_id %d",
> + sem_id);
> +
> + return ret;
> +}
> static void func_sstat(int semidx)
> {
> - if (semidx >= 0)
> + if (semidx == sem_id)
> tst_res(TPASS, "id of the semaphore set is correct");
> else
> - tst_res(TFAIL, "id of the semaphore set is incorrect");
> + tst_res(TFAIL, "expected sem_id %d, got %d", sem_id, semidx);
> }
Doesn't this make the check tautological? semidx == sem_id holds by
construction, so the TFAIL branch is unreachable and the SEM_STAT test
case no longer asserts anything about the syscall result. A kernel
returning a wrong id would now show up as TBROK ("Failed to find
SEM_STAT for sem_id") rather than TFAIL.
testcases/kernel/syscalls/shmctl/shmctl01.c already solves the same
problem with get_shm_idx_from_id(), which returns the *index*:
static int get_shm_idx_from_id(int shm_id)
{
struct shm_info dummy;
struct shmid_ds dummy_ds;
int max_idx, i;
max_idx = SAFE_SHMCTL(shm_id, SHM_INFO, (void *)&dummy);
for (i = 0; i <= max_idx; i++) {
if (shmctl(i, SHM_STAT, &dummy_ds) == shm_id)
return i;
}
return -1;
}
Following that shape here would keep the assertion intact: resolve
sem_idx, then keep SAFE_SEMCTL(sem_idx, 0, SEM_STAT, tc->arg) in
verify_semctl() so func_sstat() compares an actual syscall return value
against sem_id.
It would also collapse sem_stat_for_id() and do_sem_stat() into a single
helper. As it stands, do_sem_stat() is a one-line wrapper and
sem_stat_for_id() is only ever called with the global sem_id, so the
"id" parameter adds no flexibility.
> + if (ret == -1 && errno != EIDRM && errno != EINVAL &&
> + errno != EACCES)
> + tst_brk(TBROK | TERRNO, "semctl(%d, SEM_STAT)", i);
This aborts on any errno outside the allow-list while probing IPC objects
owned by other processes, which is a new source of TBROK. shmctl01
ignores every failure in the scan loop and simply continues. Is there a
reason to be stricter here?
> +/*
> + * SEM_STAT takes an idr index. Walk 0..max_idx until SEM_STAT
> + * returns this test's sem_id so parallel IPC tests cannot make us exercise
> + * some other process's set (EIDRM/EINVAL/EACCES on a moving max_idx).
> + * Returns that semid.
> + */
The parenthetical looks inaccurate. Per ipc/sem.c semctl_stat(), EINVAL
comes from an unused index, EIDRM from a set removed concurrently, and
EACCES from a set the caller cannot read - none of them from "a moving
max_idx".
Also, semctl(2) describes the argument as an index into the kernel's
internal array; "idr index" is kernel-internal terminology.
> if (sem_id == -1)
> sem_id = SAFE_SEMGET(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
> +
> if (tc->func_setup) {
This blank line is unrelated to the change. Could it be dropped to keep
the patch to one logical change?
Verdict - Needs revision
Pre-existing issues, not introduced by this patch:
- func_iinfo(): "hidx >= 0" is always true, since SAFE_SEMCTL() already
aborts when semctl() returns -1.
- cleanup(): "if (sem_id >= 0)" rather than the "!= -1" convention used
for the initialiser.
---
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
prev parent reply other threads:[~2026-07-28 21:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 16:49 [LTP] [PATCH v2] semctl: updates for multi worker testing Stephen Bertram via ltp
2026-04-14 17:15 ` [LTP] " linuxtestproject.agent
2026-07-20 22:49 ` [LTP] [PATCH v3] semctl01: tolerate SEM_STAT races under parallel LTP runs Stephen Bertram via ltp
2026-07-20 23:13 ` [LTP] " linuxtestproject.agent
2026-07-20 23:56 ` [LTP] [PATCH v4] " Stephen Bertram via ltp
2026-07-21 2:38 ` [LTP] " linuxtestproject.agent
2026-07-21 13:55 ` [LTP] [PATCH v5] " Stephen Bertram via ltp
2026-07-21 14:40 ` [LTP] " linuxtestproject.agent
2026-07-28 13:06 ` [LTP] [PATCH v5] " Andrea Cervesato via ltp
2026-07-28 16:23 ` [LTP] [PATCH v6] " Stephen Bertram via ltp
2026-07-28 17:31 ` [LTP] " linuxtestproject.agent
2026-07-28 20:33 ` [LTP] [PATCH v7] semctl01: look up SEM_STAT index for this test's sem_id Stephen Bertram via ltp
2026-07-28 21:12 ` linuxtestproject.agent [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=20260728211214.8732-1-linuxtestproject.agent@gmail.com \
--to=linuxtestproject.agent@gmail.com \
--cc=ltp@lists.linux.it \
--cc=sbertram@redhat.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.