Re: [PATCH] mqueue: introduce new do_mq_timedreceive2() [ mq_peek syscall] for non-destructive receive and inspection,fix minor issue,prepared doc.

From: Randy Dunlap

Date: Thu Mar 05 2026 - 19:07:46 EST


Hi,

On 3/5/26 10:09 AM, Mathura_Kumar wrote:
> First of all Thanks for constructive response,I am new to kernel development
> so in earlier patch has some style issue
>

That ^^^ should be in a cover letter or below the "---" line,
The Subject: should say [PATCH v2].
This (following) list of changes from v1 to v2 should also be
below the "---" line and not part of the patch description.
For v3, leave the v1->v2 changes and add v2->v3 changes, etc.

> what changed now:-
>
> 1)As per my estimate all style issue fixed
> 2)Doc was prepared in Documentation/userspace-api/syscall.rst, for better
> consistency, i was not making inline comment for doc in source code
> 3)I am squashing previous three commit in this latest one for convenience in applying
> and merging
>
> Required Attention:-As per mail from bot
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on shuah-kselftest/next]
> [also build test ERROR on shuah-kselftest/fixes next-20260304]
> [cannot apply to arnd-asm-generic/master linus/master tip/x86/asm v6.16-rc1]
>
> As per my guess bot failed to apply all earlier patch in order,now As Squashed,
> it should not come but if it then required manual intervention, I tested Successfully
> on x86-64 bit host arch for x86-64,arm64,risc-v and all test.
>
> some note:-macro and header guard are extermally sensetive for order of sys call number

extremely sensitive

> on risc-v ,after of hour testing ,hit and trail and i fix that
>
> Short Description:
>
> POSIX message queues currently lack a mechanism to read
> a message without removing it from the queue. This is a
> long-standing limitation,when we require inspection of queue state
> without altering it.
>
> Modifying existing mq_receive() semantics via additional
> flags was considered. However, altering behavior of an
> existing syscall risks breaking backward compatibility
> for applications relying on current semantics. Since
> mq_receive() guarantees message removal, changing this
> contract is not safe.
>
> To preserve ABI stability, this patch introduces a new
> system call that performs a non-destructive receive
> operation (peek). The existing behavior remains unchanged.
>
> Design considerations:
>
> Two approaches for copying message data to userspace
> were evaluated:
>
> 1) Refcount-based message lifecycle handling
> - This can help us Avoids intermediate temp kernel copy
> - Extends message lifetime
> -But this may increase writer starvation under heavy load and
> add unneassery complication on priority management and

unnecessary

> delay more time to free space in inode due refcount may prevent
>
> 2) Temporary kernel buffer copy
> - Copies message into a bounded kernel buffer
> - Reduces time message remains locked
> - Improves fairness under write-heavy workloads
> - Simpler lifetime management
>
> My implementation adopts the temporary buffer approach
> to minimize starvation and reduce locking complexity.
> The design allows future transition if refcounting is
> deemed preferable.
>
> Architecture support: ALL
>
> Testing:
> - 15+ functional test cases
> - Multi-threaded producer/consumer scenarios
> - concurrent pop and peek
> - Edge cases: empty queue, FIFO
> invalid flags, signal interruption etc.

Is there a use case or user for this syscall?
If so, please describe it (or them) here.

>
> Signed-off-by: Mathura_Kumar <academic1mathura@xxxxxxxxx>
>
> ---

> diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
> index a68b1bea57a8..119f820a5a1d 100644
> --- a/Documentation/userspace-api/index.rst
> +++ b/Documentation/userspace-api/index.rst
> @@ -22,6 +22,7 @@ System calls
> ioctl/index
> mseal
> rseq
> + syscall
>
> Security-related interfaces
> ===========================

It would be more appropriate to name this file mqueue.rst or maybe ipc.rst.
This section of index.rst already has a heading of "System calls", so just
use a name that tells what system call it is.

> diff --git a/Documentation/userspace-api/syscall.rst b/Documentation/userspace-api/syscall.rst
> new file mode 100644
> index 000000000000..236c4cb88544
> --- /dev/null
> +++ b/Documentation/userspace-api/syscall.rst
> @@ -0,0 +1,273 @@
> +mq_timedreceive2 system call
> +=============================
> +
...
> +8) Concurrent access: verify that simultaneous peek from multiple
> + threads returns consistent results and does not corrupt queue
> + state. Verify that a concurrent mq_receive() and mq_peek() do
> + not race or oops.
> \ No newline at end of file

Add a newline, please.

--
~Randy