* [PATCH net v3 0/2] af_unix: Fix inq_len update issue
@ 2026-06-01 11:36 jianyu.li
2026-06-01 11:36 ` [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read jianyu.li
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: jianyu.li @ 2026-06-01 11:36 UTC (permalink / raw)
To: kuniyu, davem, edumazet, kuba, pabeni, horms
Cc: willemb, netdev, linux-kernel, linux-mediatek, black-ch.chen,
ivan.tseng, jianyu.li
From: Jianyu Li <jianyu.li@mediatek.com>
This series fix the problem that inq_len is inconsistent with
actual remaining byte count when only part of a skb is consumed.
Changes:
v3:
- Patch 2: Align macro definitions
v2: https://lore.kernel.org/netdev/20260528110033.3327744-1-jianyu.li@mediatek.com/
- Patch 1: Improve lock usage in unix_stream_read_generic()
- Patch 2: Follow reverse xmas tree ordering in partial_read test case
v1: https://lore.kernel.org/netdev/20260527065342.2463433-1-jianyu.li@mediatek.com/
Jianyu Li (2):
af_unix: Fix inq_len update problem in partial read
af_unix: Add test for SCM_INQ on partial read
net/unix/af_unix.c | 11 ++--
tools/testing/selftests/net/af_unix/scm_inq.c | 54 ++++++++++++++++++-
2 files changed, 58 insertions(+), 7 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read
2026-06-01 11:36 [PATCH net v3 0/2] af_unix: Fix inq_len update issue jianyu.li
@ 2026-06-01 11:36 ` jianyu.li
2026-06-01 18:34 ` Kuniyuki Iwashima
2026-06-01 11:36 ` [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on " jianyu.li
2026-06-04 2:00 ` [PATCH net v3 0/2] af_unix: Fix inq_len update issue patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: jianyu.li @ 2026-06-01 11:36 UTC (permalink / raw)
To: kuniyu, davem, edumazet, kuba, pabeni, horms
Cc: willemb, netdev, linux-kernel, linux-mediatek, black-ch.chen,
ivan.tseng, jianyu.li
From: Jianyu Li <jianyu.li@mediatek.com>
Currently inq_len is updated only when the whole skb is consumed.
If only part of the data is read, following SIOCINQ query would
get value greater than what actually left.
This change update inq_len timely in unix_stream_read_generic(),
and adjust unix_stream_read_skb() accordingly to prevent
repetitive update.
Fixes: f4e1fb04c123 ("af_unix: Use cached value for SOCK_STREAM in unix_inq_len().")
Signed-off-by: Jianyu Li <jianyu.li@mediatek.com>
---
v2: Improve lock usage in unix_stream_read_generic()
---
net/unix/af_unix.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index dc71ed79be..0d9cd977c7 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2886,7 +2886,7 @@ static int unix_stream_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
return -EAGAIN;
}
- WRITE_ONCE(u->inq_len, u->inq_len - skb->len);
+ WRITE_ONCE(u->inq_len, u->inq_len - unix_skb_len(skb));
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
if (skb == u->oob_skb) {
@@ -3063,11 +3063,12 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
unix_detach_fds(&scm, skb);
}
- if (unix_skb_len(skb))
- break;
-
spin_lock(&sk->sk_receive_queue.lock);
- WRITE_ONCE(u->inq_len, u->inq_len - skb->len);
+ WRITE_ONCE(u->inq_len, u->inq_len - chunk);
+ if (unix_skb_len(skb)) {
+ spin_unlock(&sk->sk_receive_queue.lock);
+ break;
+ }
__skb_unlink(skb, &sk->sk_receive_queue);
spin_unlock(&sk->sk_receive_queue.lock);
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on partial read
2026-06-01 11:36 [PATCH net v3 0/2] af_unix: Fix inq_len update issue jianyu.li
2026-06-01 11:36 ` [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read jianyu.li
@ 2026-06-01 11:36 ` jianyu.li
2026-06-01 18:35 ` Kuniyuki Iwashima
2026-06-04 2:00 ` [PATCH net v3 0/2] af_unix: Fix inq_len update issue patchwork-bot+netdevbpf
2 siblings, 1 reply; 6+ messages in thread
From: jianyu.li @ 2026-06-01 11:36 UTC (permalink / raw)
To: kuniyu, davem, edumazet, kuba, pabeni, horms
Cc: willemb, netdev, linux-kernel, linux-mediatek, black-ch.chen,
ivan.tseng, jianyu.li
From: Jianyu Li <jianyu.li@mediatek.com>
Add test to verify that when a skb is partially consumed,
unix_inq_len() return correct remaining byte count.
Before:
# RUN scm_inq.stream.partial_read ...
# scm_inq.c:165:partial_read:Expected remain (512) == *(int *)CMSG_DATA(cmsg) (768)
# partial_read: Test terminated by assertion
# FAIL scm_inq.stream.partial_read
not ok 2 scm_inq.stream.partial_read
After:
# RUN scm_inq.stream.partial_read ...
# OK scm_inq.stream.partial_read
ok 2 scm_inq.stream.partial_read
Signed-off-by: Jianyu Li <jianyu.li@mediatek.com>
---
v3: Align macro definitions
v2: Follow reverse xmas tree ordering in partial_read test case
---
tools/testing/selftests/net/af_unix/scm_inq.c | 54 ++++++++++++++++++-
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/af_unix/scm_inq.c b/tools/testing/selftests/net/af_unix/scm_inq.c
index 3a86be9bda..6268b5bf50 100644
--- a/tools/testing/selftests/net/af_unix/scm_inq.c
+++ b/tools/testing/selftests/net/af_unix/scm_inq.c
@@ -8,8 +8,9 @@
#include "kselftest_harness.h"
-#define NR_CHUNKS 100
-#define MSG_LEN 256
+#define NR_CHUNKS 100
+#define MSG_LEN 256
+#define NR_PARTIAL_READS 3
FIXTURE(scm_inq)
{
@@ -120,4 +121,53 @@ TEST_F(scm_inq, basic)
recv_chunks(_metadata, self);
}
+TEST_F(scm_inq, partial_read)
+{
+ char buf[MSG_LEN * NR_PARTIAL_READS] = {};
+ char cmsg_buf[CMSG_SPACE(sizeof(int))];
+ struct msghdr msg = {};
+ struct iovec iov = {};
+ struct cmsghdr *cmsg;
+ int err, inq, ret, i;
+ int remain;
+
+ err = setsockopt(self->fd[1], SOL_SOCKET, SO_INQ, &(int){1}, sizeof(int));
+ if (variant->type != SOCK_STREAM) {
+ ASSERT_EQ(-ENOPROTOOPT, -errno);
+ return;
+ }
+ ASSERT_EQ(0, err);
+
+ ret = send(self->fd[0], buf, sizeof(buf), 0);
+ ASSERT_EQ(sizeof(buf), ret);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = cmsg_buf;
+ msg.msg_controllen = sizeof(cmsg_buf);
+
+ iov.iov_base = buf;
+ iov.iov_len = MSG_LEN;
+
+ for (i = 0; i < NR_PARTIAL_READS; i++) {
+ remain = MSG_LEN * (NR_PARTIAL_READS - 1 - i);
+
+ memset(buf, 0, MSG_LEN);
+ memset(cmsg_buf, 0, sizeof(cmsg_buf));
+ ret = recvmsg(self->fd[1], &msg, 0);
+ ASSERT_EQ(MSG_LEN, ret);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ ASSERT_NE(NULL, cmsg);
+ ASSERT_EQ(CMSG_LEN(sizeof(int)), cmsg->cmsg_len);
+ ASSERT_EQ(SOL_SOCKET, cmsg->cmsg_level);
+ ASSERT_EQ(SCM_INQ, cmsg->cmsg_type);
+ ASSERT_EQ(remain, *(int *)CMSG_DATA(cmsg));
+
+ ret = ioctl(self->fd[1], SIOCINQ, &inq);
+ ASSERT_EQ(0, ret);
+ ASSERT_EQ(remain, inq);
+ }
+}
+
TEST_HARNESS_MAIN
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read
2026-06-01 11:36 ` [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read jianyu.li
@ 2026-06-01 18:34 ` Kuniyuki Iwashima
0 siblings, 0 replies; 6+ messages in thread
From: Kuniyuki Iwashima @ 2026-06-01 18:34 UTC (permalink / raw)
To: jianyu.li
Cc: davem, edumazet, kuba, pabeni, horms, willemb, netdev,
linux-kernel, linux-mediatek, black-ch.chen, ivan.tseng
On Mon, Jun 1, 2026 at 4:37 AM <jianyu.li@mediatek.com> wrote:
>
> From: Jianyu Li <jianyu.li@mediatek.com>
>
> Currently inq_len is updated only when the whole skb is consumed.
> If only part of the data is read, following SIOCINQ query would
> get value greater than what actually left.
>
> This change update inq_len timely in unix_stream_read_generic(),
> and adjust unix_stream_read_skb() accordingly to prevent
> repetitive update.
>
> Fixes: f4e1fb04c123 ("af_unix: Use cached value for SOCK_STREAM in unix_inq_len().")
> Signed-off-by: Jianyu Li <jianyu.li@mediatek.com>
> ---
> v2: Improve lock usage in unix_stream_read_generic()
For future submissions, since this patch has no change
since v2, you could carry my tag from v2.
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Thanks !
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on partial read
2026-06-01 11:36 ` [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on " jianyu.li
@ 2026-06-01 18:35 ` Kuniyuki Iwashima
0 siblings, 0 replies; 6+ messages in thread
From: Kuniyuki Iwashima @ 2026-06-01 18:35 UTC (permalink / raw)
To: jianyu.li
Cc: davem, edumazet, kuba, pabeni, horms, willemb, netdev,
linux-kernel, linux-mediatek, black-ch.chen, ivan.tseng
On Mon, Jun 1, 2026 at 4:37 AM <jianyu.li@mediatek.com> wrote:
>
> From: Jianyu Li <jianyu.li@mediatek.com>
>
> Add test to verify that when a skb is partially consumed,
> unix_inq_len() return correct remaining byte count.
>
> Before:
>
> # RUN scm_inq.stream.partial_read ...
> # scm_inq.c:165:partial_read:Expected remain (512) == *(int *)CMSG_DATA(cmsg) (768)
> # partial_read: Test terminated by assertion
> # FAIL scm_inq.stream.partial_read
> not ok 2 scm_inq.stream.partial_read
>
> After:
>
> # RUN scm_inq.stream.partial_read ...
> # OK scm_inq.stream.partial_read
> ok 2 scm_inq.stream.partial_read
>
> Signed-off-by: Jianyu Li <jianyu.li@mediatek.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 0/2] af_unix: Fix inq_len update issue
2026-06-01 11:36 [PATCH net v3 0/2] af_unix: Fix inq_len update issue jianyu.li
2026-06-01 11:36 ` [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read jianyu.li
2026-06-01 11:36 ` [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on " jianyu.li
@ 2026-06-04 2:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-04 2:00 UTC (permalink / raw)
To: =?utf-8?b?Smlhbnl1IExpICjmnY7lgaXnkYApIDxqaWFueXUubGlAbWVkaWF0ZWsuY29tPg==?=
Cc: kuniyu, davem, edumazet, kuba, pabeni, horms, willemb, netdev,
linux-kernel, linux-mediatek, black-ch.chen, ivan.tseng
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 1 Jun 2026 19:36:38 +0800 you wrote:
> From: Jianyu Li <jianyu.li@mediatek.com>
>
> This series fix the problem that inq_len is inconsistent with
> actual remaining byte count when only part of a skb is consumed.
>
> Changes:
> v3:
> - Patch 2: Align macro definitions
> v2: https://lore.kernel.org/netdev/20260528110033.3327744-1-jianyu.li@mediatek.com/
> - Patch 1: Improve lock usage in unix_stream_read_generic()
> - Patch 2: Follow reverse xmas tree ordering in partial_read test case
> v1: https://lore.kernel.org/netdev/20260527065342.2463433-1-jianyu.li@mediatek.com/
>
> [...]
Here is the summary with links:
- [net,v3,1/2] af_unix: Fix inq_len update problem in partial read
https://git.kernel.org/netdev/net/c/c1f07a7f2d47
- [net,v3,2/2] af_unix: Add test for SCM_INQ on partial read
https://git.kernel.org/netdev/net/c/dd8975ad710e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-04 2:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01 11:36 [PATCH net v3 0/2] af_unix: Fix inq_len update issue jianyu.li
2026-06-01 11:36 ` [PATCH net v3 1/2] af_unix: Fix inq_len update problem in partial read jianyu.li
2026-06-01 18:34 ` Kuniyuki Iwashima
2026-06-01 11:36 ` [PATCH net v3 2/2] af_unix: Add test for SCM_INQ on " jianyu.li
2026-06-01 18:35 ` Kuniyuki Iwashima
2026-06-04 2:00 ` [PATCH net v3 0/2] af_unix: Fix inq_len update issue patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox