From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH v1 net-next 6/7] af_unix: Introduce SO_INQ.
Date: Sun, 06 Jul 2025 10:02:25 -0400 [thread overview]
Message-ID: <686a81f1ec754_3aa65429440@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20250702223606.1054680-7-kuniyu@google.com>
Kuniyuki Iwashima wrote:
> We have an application that uses almost the same code for TCP and
> AF_UNIX (SOCK_STREAM).
>
> TCP can use TCP_INQ, but AF_UNIX doesn't have it and requires an
> extra syscall, ioctl(SIOCINQ) or getsockopt(SO_MEMINFO) as an
> alternative.
>
> Let's introduce the generic version of TCP_INQ.
>
> If SO_INQ is enabled, recvmsg() will put a cmsg of SCM_INQ that
> contains the exact value of ioctl(SIOCINQ). The cmsg is also
> included when msg->msg_get_inq is non-zero to make sockets
> io_uring-friendly.
>
> Note that SOCK_CUSTOM_SOCKOPT is flagged only for SOCK_STREAM to
> override setsockopt() for SOL_SOCKET.
>
> By having the flag in struct unix_sock, instead of struct sock, we
> can later add SO_INQ support for TCP and reuse tcp_sk(sk)->recvmsg_inq.
>
> Note also that supporting custom getsockopt() for SOL_SOCKET will need
> preparation for other SOCK_CUSTOM_SOCKOPT users (UDP, vsock, MPTCP).
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
> +static int unix_setsockopt(struct socket *sock, int level, int optname,
> + sockptr_t optval, unsigned int optlen)
> +{
> + struct unix_sock *u = unix_sk(sock->sk);
> + struct sock *sk = sock->sk;
> + int val;
> +
> + if (level != SOL_SOCKET)
> + return -EOPNOTSUPP;
> +
> + if (!unix_custom_sockopt(optname))
> + return sock_setsockopt(sock, level, optname, optval, optlen);
> +
> + if (optlen != sizeof(int))
> + return -EINVAL;
> +
> + if (copy_from_sockptr(&val, optval, sizeof(val)))
> + return -EFAULT;
> +
> + switch (optname) {
> + case SO_INQ:
> + if (sk->sk_type != SOCK_STREAM)
> + return -EINVAL;
Sanity check, but technically not needed as SOCK_CUSTOM_SOCKOPT is
only set for SOCK_STREAM?
> +
> + if (val > 1 || val < 0)
> + return -EINVAL;
> +
> + WRITE_ONCE(u->recvmsg_inq, val);
> + break;
> + default:
> + return -ENOPROTOOPT;
> + }
> +
> + return 0;
> +}
> +
next prev parent reply other threads:[~2025-07-06 14:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 22:35 [PATCH v1 net-next 0/7] af_unix: Introduce SO_INQ & SCM_INQ Kuniyuki Iwashima
2025-07-02 22:35 ` [PATCH v1 net-next 1/7] af_unix: Don't hold unix_state_lock() in __unix_dgram_recvmsg() Kuniyuki Iwashima
2025-07-06 14:10 ` Willem de Bruijn
2025-07-02 22:35 ` [PATCH v1 net-next 2/7] af_unix: Don't check SOCK_DEAD in unix_stream_read_skb() Kuniyuki Iwashima
2025-07-02 22:35 ` [PATCH v1 net-next 3/7] af_unix: Don't use skb_recv_datagram() " Kuniyuki Iwashima
2025-07-02 22:35 ` [PATCH v1 net-next 4/7] af_unix: Use cached value for SOCK_STREAM in unix_inq_len() Kuniyuki Iwashima
2025-07-06 13:53 ` Willem de Bruijn
2025-07-06 14:13 ` Willem de Bruijn
2025-07-02 22:35 ` [PATCH v1 net-next 5/7] af_unix: Cache state->msg in unix_stream_read_generic() Kuniyuki Iwashima
2025-07-02 22:35 ` [PATCH v1 net-next 6/7] af_unix: Introduce SO_INQ Kuniyuki Iwashima
2025-07-06 14:02 ` Willem de Bruijn [this message]
2025-07-06 19:21 ` Kuniyuki Iwashima
2025-07-02 22:35 ` [PATCH v1 net-next 7/7] selftest: af_unix: Add test for SO_INQ Kuniyuki Iwashima
2025-07-06 14:04 ` Willem de Bruijn
2025-07-09 1:30 ` [PATCH v1 net-next 0/7] af_unix: Introduce SO_INQ & SCM_INQ patchwork-bot+netdevbpf
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=686a81f1ec754_3aa65429440@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).