On Tue, Aug 30, 2022 at 11:18 AM Moritz Buhl <[email protected]> wrote:
> the following diff only contains recvmmsg which should be the more useful
> syscall of the two.
>
Comments inline.
> --- sys/kern/syscalls.master 1 Aug 2022 14:56:59 -0000 1.229
> +++ sys/kern/syscalls.master 30 Aug 2022 15:44:29 -0000
> @@ -575,3 +575,6 @@
> 328 OBSOL __tfork51
> 329 STD NOLOCK { void sys___set_tcb(void *tcb); }
> 330 STD NOLOCK { void *sys___get_tcb(void); }
> +331 STD NOLOCK { int sys_recvmmsg(int s, struct mmsghdr *mmsg, \
> + unsigned int vlen, unsigned int flags, \
> + struct timespec *timeout); }
>
We believe in packing syscall numbers down, modulus having them group
nicely. So, instead of putting recvmmsg() as a new high-water mark, I
would put it at 116 ("t32_gettimeofday") and mark 117 ("t32_getrusage") as
sendmmsg(), UNIMPL if not part of this round.
(Typically, when a diff changes syscalls.master then you leave out the diff
chunks for the generated files when sending for review, because they are
100% implied and are just noise. Not a big deal)
--- sys/kern/uipc_syscalls.c 14 Aug 2022 01:58:28 -0000 1.201
> +++ sys/kern/uipc_syscalls.c 30 Aug 2022 17:03:09 -0000
> @@ -805,6 +805,135 @@ done:
> }
>
> int
> +sys_recvmmsg(struct proc *p, void *v, register_t *retval)
> +{
> + struct sys_recvmmsg_args /* {
> + syscallarg(int) s;
> + syscallarg(struct mmsghdr *) mmsg;
> + syscallarg(unsigned int) vlen;
> + syscallarg(unsigned int) flags;
> + syscallarg(struct timespec *) timeout;
> + } */ *uap = v;
> + struct mmsghdr mmsg;
> + struct timespec ts, now;
> + struct iovec aiov[UIO_SMALLIOV], *uiov, *iov = aiov;
> + struct file *fp;
> + struct socket *so;
> + struct timespec *timeout;
> + unsigned int vlen, dg;
> + int error = 0, flags, s;
> +
> + timeout = SCARG(uap, timeout);
> + if (timeout != NULL) {
> + error = copyin(SCARG(uap, timeout), &ts, sizeof(ts));
> + if (error != 0)
> + return error;
>
Should have a KTRACE ktrreltimmespec() block here.
Should validate the timespec.
(Follow what sys_kevent() does)
+ getnanotime(&now);
> + timespecadd(&now, &ts, &ts);
> + }
> +
> + s = SCARG(uap, s);
> + if ((error = getsock(p, s, &fp)) != 0)
> + return (error);
> + so = (struct socket *)fp->f_data;
> +
> + flags = SCARG(uap, flags);
> +
> + vlen = SCARG(uap, vlen);
> + if (vlen > 1024)
> + vlen = 1024;
> +
> + for (dg = 0; dg < vlen;) {
> + error = copyin(SCARG(uap, mmsg) + dg, &mmsg, sizeof(mmsg));
> + if (error != 0)
> + break;
>
Hmm. This copies in each mmsghdr structure when it gets to it. Is that
how the Linux version behaves, lazily accessing them such that an early
exit (from timeout, signal, whatever) means later values aren't read? Or
do they copy them all in, update any that are changed, then copy them out
at the end?
(Not sure it matters, but it's an interesting corner case to think
carefully about.)
...
> + mmsg.msg_hdr.msg_iov = uiov;
> + mmsg.msg_len = *retval;
> +#ifdef KTRACE
> + if (KTRPOINT(p, KTR_STRUCT)) {
> + ktrmsghdr(p, &mmsg.msg_hdr);
>
I think you should go ahead and define ktrmmsghdr() taking that full
struct, so kdump can report the msg_len value that is being returned.
> + if (iov != aiov) {
> + free(iov, M_IOV, sizeof(struct iovec) *
> + mmsg.msg_hdr.msg_iovlen);
> + iov = aiov;
> + }
>
The iov freeing, IMO,, should be done once, at the end of the loop. Just
keep growing as necessary (tracking the currently allocated size) and free
once.
kdump.c will need at least a SYS_recvmmsg line in the big table, and if you
do a ktrmmsghdr() bit in the kernel a matching decoder will be needed in
kdump.
Philip Guenther