selftests/bpf: Replace %pK output with 0
Subsystems (3)
PATCH 1/1 selftests/bpf: Replace %pK output with 0
Networking used to print the socket pointer with %p as output in the /proc interface. This was later changed to %pK in order not to reveal the actual pointer value. The output format has then been copied to bpf tests which produce the same format including the %pK format modifier.
Networking recently replaced the socket output with a plain 0 because the socket pointer added no value to the output and the %pK should be removed fom library handling. The format remained otherwise unchanged in order not to break any tools which are parsing this information.
This change removes the %pK modifier from bpf, following the change in networking.
---
The networking change is in net-next as commit 7c0ec6288b497 ("net:
Replace %pK output with 0")
tools/testing/selftests/bpf/README.rst | 2 +- tools/testing/selftests/bpf/prog_tests/snprintf.c | 2 +- tools/testing/selftests/bpf/progs/bpf_iter_netlink.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c | 11 +++++------ tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c | 11 +++++------ tools/testing/selftests/bpf/progs/bpf_iter_udp4.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_udp6.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 3 +-- tools/testing/selftests/bpf/progs/test_snprintf.c | 4 ++-- 9 files changed, 21 insertions(+), 24 deletions(-)
tools/testing/selftests/bpf/README.rst +1 -1
@@ -187,7 +187,7 @@ The symptom for ``bpf_iter/netlink`` looks like ... 15: (bf) r2 = r7 16: (0f) r2 += r1 - ; BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol); + ; BPF_SEQ_PRINTF(seq, "%p %-3d ", s, s->sk_protocol); 17: (7b) *(u64 *)(r7 +0) = r2 only read is supported
tools/testing/selftests/bpf/prog_tests/snprintf.c +1 -1
@@ -16,7 +16,7 @@#define MIN_SYM_RET sizeof(EXP_SYM_OUT)/* The third specifier, %p, is a hashed pointer which changes on every reboot */ -#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " +#define EXP_ADDR_OUT "ffff00000add4e55 "#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr")#define EXP_STR_OUT "str1 a b c d e longstr"
tools/testing/selftests/bpf/progs/bpf_iter_netlink.c +2 -2
@@ -25,12 +25,12 @@ int dump_netlink(struct bpf_iter__netlink *ctx)return 0 ;if (ctx->meta->seq_num ==0 ) -BPF_SEQ_PRINTF (seq,"sk Eth Pid Groups " +BPF_SEQ_PRINTF (seq,"sk Eth Pid Groups " "Rmem Wmem Dump Locks Drops " "Inode\n" ); s = &nlk->sk; -BPF_SEQ_PRINTF (seq,"%pK %-3d " , s, s->sk_protocol); +BPF_SEQ_PRINTF (seq,"0 %-3d " , s->sk_protocol);if (!nlk->groups) { group =0 ;
tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c +5 -6
@@ -131,8 +131,7 @@ static int dump_tcp_sock(struct seq_file *seq, struct tcp_sock *tp, icsk->icsk_probes_out,sock_i_ino (sp), sp->sk_refcnt.refs.counter); - BPF_SEQ_PRINTF(seq, "%pK %lu %lu %u %u %d\n", - tp, + BPF_SEQ_PRINTF(seq, "0 %lu %lu %u %u %d\n", jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(icsk),
@@ -161,10 +160,10 @@ static int dump_tw_sock(struct seq_file *seq, struct tcp_timewait_sock *ttw,BPF_SEQ_PRINTF (seq,"%4d: %08X:%04X %08X:%04X " , seq_num, src, srcp, dest, destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" , tw->tw_substate,0 ,0 ,3 ,jiffies_delta_to_clock_t (delta),0 ,0 ,0 ,0 , - tw->tw_refcnt.refs.counter, tw); + tw->tw_refcnt.refs.counter);return 0 ; }
@@ -185,9 +184,9 @@ static int dump_req_sock(struct seq_file *seq, struct tcp_request_sock *treq, seq_num, irsk->ir_loc_addr, irsk->ir_num, irsk->ir_rmt_addr, bpf_ntohs(irsk->ir_rmt_port)); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" ,TCP_SYN_RECV ,0 ,0 ,1 ,jiffies_to_clock_t (ttd), - req->num_timeout, uid,0 ,0 ,0 , req); + req->num_timeout, uid,0 ,0 ,0 );return 0 ; }
tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c +5 -6
@@ -135,8 +135,7 @@ static int dump_tcp6_sock(struct seq_file *seq, struct tcp6_sock *tp, icsk->icsk_probes_out,sock_i_ino (sp), sp->sk_refcnt.refs.counter); - BPF_SEQ_PRINTF(seq, "%pK %lu %lu %u %u %d\n", - tp, + BPF_SEQ_PRINTF(seq, "0 %lu %lu %u %u %d\n", jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(icsk),
@@ -170,10 +169,10 @@ static int dump_tw_sock(struct seq_file *seq, struct tcp_timewait_sock *ttw, dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" , tw->tw_substate,0 ,0 ,3 ,jiffies_delta_to_clock_t (delta),0 ,0 ,0 ,0 , - tw->tw_refcnt.refs.counter, tw); + tw->tw_refcnt.refs.counter);return 0 ; }
@@ -201,9 +200,9 @@ static int dump_req_sock(struct seq_file *seq, struct tcp_request_sock *treq, dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2 ], dest->s6_addr32[3 ], bpf_ntohs(irsk->ir_rmt_port)); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" ,TCP_SYN_RECV ,0 ,0 ,1 ,jiffies_to_clock_t (ttd), - req->num_timeout, uid,0 ,0 ,0 , req); + req->num_timeout, uid,0 ,0 ,0 );return 0 ; }
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c +2 -2
@@ -57,13 +57,13 @@ int dump_udp4(struct bpf_iter__udp *ctx)BPF_SEQ_PRINTF (seq,"%5d: %08X:%04X %08X:%04X " , ctx->bucket, src, srcp, dest, destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n" , inet->sk.sk_state, inet->sk.sk_wmem_alloc.refs.counter -1 , rqueue,0 ,0L ,0 , ctx->uid,0 ,sock_i_ino (&inet->sk), - inet->sk.sk_refcnt.refs.counter, udp_sk, + inet->sk.sk_refcnt.refs.counter,0 , udp_sk->drop_counters.drops0.counter + udp_sk->drop_counters.drops1.counter);
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c +2 -2
@@ -65,13 +65,13 @@ int dump_udp6(struct bpf_iter__udp *ctx) dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n" , inet->sk.sk_state, inet->sk.sk_wmem_alloc.refs.counter -1 , rqueue,0 ,0L ,0 , ctx->uid,0 ,sock_i_ino (&inet->sk), - inet->sk.sk_refcnt.refs.counter, udp_sk, + inet->sk.sk_refcnt.refs.counter,0 , udp_sk->drop_counters.drops0.counter + udp_sk->drop_counters.drops1.counter);return 0 ;
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +1 -2
@@ -44,8 +44,7 @@ int dump_unix(struct bpf_iter__unix *ctx)if (seq_num ==0 )BPF_SEQ_PRINTF (seq,"Num RefCount Protocol Flags Type St Inode Path\n" ); - BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu", - unix_sk, + BPF_SEQ_PRINTF(seq, "%08u: %08X %08X %08X %04X %02X %8lu", 0, sk->sk_refcnt.refs.counter, 0, sk->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
tools/testing/selftests/bpf/progs/test_snprintf.c +2 -2
@@ -57,8 +57,8 @@ int handler(const void *ctx) sym_ret =BPF_SNPRINTF (sym_out,sizeof (sym_out),"%ps %pS %pB" , &schedule, &schedule, &schedule);/* Kernel pointers */ - addr_ret =BPF_SNPRINTF (addr_out,sizeof (addr_out),"%pK %px %p" , -0 ,0xFFFF00000ADD4E55 ,0xFFFF00000ADD4E55 ); + addr_ret =BPF_SNPRINTF (addr_out,sizeof (addr_out),"%px %p" , +0xFFFF00000ADD4E55 ,0xFFFF00000ADD4E55 );/* Strings and single-byte character embedding */ str_ret =BPF_SNPRINTF (str_out,sizeof (str_out),"%s % 9c %+2c %-3c %04c %0c %+05s" , str1,'a' ,'b' ,'c' ,'d' ,'e' , longstr);
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Incorrect replacement of `%pK` with padded format specifier `%8d` for UDP sockets causes a mismatch…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Incorrect replacement of %pK with padded format specifier %8d for UDP sockets causes a mismatch with native /proc/net/ output. --
commit c1f7209e53e018927a70341e583a110e2a63d48e
Author: Sebastian Andrzej Siewior <[email protected]>
selftests/bpf: Replace %pK output with 0
This commit replaces the %pK format modifier with 0 in BPF iterator tests to match a recent change in the networking subsystem. The socket pointers are removed from the output formatting to align with native /proc/net/ interfaces.
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c int dump_udp4(struct bpf_iter__udp *ctx) · line 60
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c +1
-1@@ -57,13 +57,13 @@ int dump_udp4(struct bpf_iter__udp *ctx)BPF_SEQ_PRINTF (seq,"%5d: %08X:%04X %08X:%04X " , ctx->bucket, src, srcp, dest, destp); - BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n", + BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n",
[Severity: Low]
Does this %8d format incorrectly pad the 0 with spaces?
The networking subsystem replaced %pK with a literal 0, but replacing it with %8d here in dump_udp4() causes a mismatch with the native /proc/net/ output. Since BPF iterators are designed as exact drop-in replacements, could this mismatch break parsers that rely on strict spacing?
[ ... ]
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c int dump_udp6(struct bpf_iter__udp *ctx) · line 68
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c +1
-1@@ -65,13 +65,13 @@ int dump_udp6(struct bpf_iter__udp *ctx) dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); - BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n", + BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n",
[Severity: Low]
Is the use of %8d here in dump_udp6() introducing the same formatting mismatch as in dump_udp4()?
It seems it should use a literal 0 instead of %8d to exactly match the networking subsystem's native output format.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 14 lines · On 2026-09-11 15:03:37 [+0000], [email protected] wrote:
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c int dump_udp4(struct bpf_iter__udp *ctx) · line 60
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c +1
-1@@ -57,13 +57,13 @@ int dump_udp4(struct bpf_iter__udp *ctx)BPF_SEQ_PRINTF (seq,"%5d: %08X:%04X %08X:%04X " , ctx->bucket, src, srcp, dest, destp); - BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n", + BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n",[Severity: Low]
Does this %8d format incorrectly pad the 0 with spaces?
Quoted 4 lines
The networking subsystem replaced %pK with a literal 0, but replacing it with %8d here in
dump_udp4()causes a mismatch with the native/proc/net/output. Since BPF iterators are designed as exact drop-in replacements, could this mismatch break parsers that rely on strict spacing?
Indeed. I tried to match the pointer spacing for some reason. The formatting in net does not align with the columns starting with the inode which is %lu instead having 5 width same goes for ref. So I just ignored and moved on with a plain 0. I could update if this is considered important.
Quoted 17 lines
[ ... ]
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c int dump_udp6(struct bpf_iter__udp *ctx) · line 68
Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c +1
-1@@ -65,13 +65,13 @@ int dump_udp6(struct bpf_iter__udp *ctx) dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); - BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n", + BPF_SEQ_PRINTF(seq, "%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n",[Severity: Low]
Is the use of %8d here indump_udp6()introducing the same formatting mismatch as indump_udp4()?
Quoted 2 lines
It seems it should use a literal 0 instead of %8d to exactly match the networking subsystem's native output format.
Yes it does but the extra spacing intends to align with the columns…
Sebastian
[email protected]
AI reviewThis excerpt is a historical clang-10 verifier log illustrating an old failure case. The patch rewrites the quoted source to "%p %-3d ", but the actual code now reads BPF_SEQ_PRINTF(seq, "0 %-3d "…
tools/testing/selftests/bpf/README.rst The symptom for ``bpf_iter/netlink`` looks like · line 192
Quoted 12 lines
tools/testing/selftests/bpf/README.rst +1
-1@@ -187,7 +187,7 @@ The symptom for ``bpf_iter/netlink`` looks like 15: (bf) r2 = r7 16: (0f) r2 += r1 - ; BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol); + ; BPF_SEQ_PRINTF(seq, "%p %-3d ", s, s->sk_protocol); 17: (7b) *(u64 *)(r7 +0) = r2 only read is supported
This excerpt is a historical clang-10 verifier log illustrating an old failure case. The patch rewrites the quoted source to "%p %-3d ", but the actual code now reads BPF_SEQ_PRINTF(seq, "0 %-3d ", s->sk_protocol) in bpf_iter_netlink.c - the sock pointer argument is gone entirely.
Should the historical log remain untouched, or should it be updated to reflect that the netlink iterator no longer passes a pointer to BPF_SEQ_PRINTF?
tools/testing/selftests/bpf/prog_tests/snprintf.c line 20
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/snprintf.c +1
-1@@ -16,7 +16,7 @@#define MIN_SYM_RET sizeof(EXP_SYM_OUT)/* The third specifier, %p, is a hashed pointer which changes on every reboot */ -#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " +#define EXP_ADDR_OUT "ffff00000add4e55 "#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr")
The comment says %p is the third specifier, but after removing %pK from the BPF program (test_snprintf.c:59), %p is now the second specifier in the format string "%px %p".
Should this comment be updated to say "The second specifier"?
[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +0
-0
tools/testing/selftests/bpf/progs/bpf_iter_unix.c int dump_unix(struct bpf_iter__unix *ctx) · line 50
Quoted 9 lines
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +1
-2@@ -44,8 +44,7 @@ int dump_unix(struct bpf_iter__unix *ctx)if (seq_num ==0 )BPF_SEQ_PRINTF (seq,"Num RefCount Protocol Flags Type St Inode Path\n" ); - BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu", - unix_sk, + BPF_SEQ_PRINTF(seq, "%08u: %08X %08X %08X %04X %02X %8lu", 0, sk->sk_refcnt.refs.counter, 0, sk->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
The header shows "Num RefCount" (18 columns before RefCount).
The old format "%pK: " produced 18 columns (16 hex digits + ':' + ' '), matching the header width.
The new format "%08u: " with argument 0 produces "00000000: " (10 columns), so every column from RefCount onward is now shifted 8 characters left of its header label.
Should the header be updated to match the new field width, similar to howbpf_iter_netlink.c was adjusted from "sk Eth" to "sk Eth"?
Regarding the commit message:
Quoted 4 lines
Networking recently replaced the socket output with a plain 0 because the socket pointer added no value to the output and the %pK should be removed fom library handling. The format remained otherwise unchanged in order not to break any tools which are parsing this information.
There's a typo: "fom library handling" should be "from library handling".
Also, the statement "The format remained otherwise unchanged" is
contradicted by the netlink header change from "sk Eth Pid"
to "sk Eth Pid", and by the field width changes across all modified files (varying from 1 to 10 columns vs the original 16-17 columns).
If maintaining format stability for parsers is the stated goal, should the width-preserving spelling be used consistently?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34614571384
Quoted 18 lines · On 2026-09-11 15:41:45 [+0000], [email protected] wrote:
tools/testing/selftests/bpf/README.rst The symptom for ``bpf_iter/netlink`` looks like · line 192
Quoted 12 lines
tools/testing/selftests/bpf/README.rst +1
-1@@ -187,7 +187,7 @@ The symptom for ``bpf_iter/netlink`` looks like 15: (bf) r2 = r7 16: (0f) r2 += r1 - ; BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol); + ; BPF_SEQ_PRINTF(seq, "%p %-3d ", s, s->sk_protocol); 17: (7b) *(u64 *)(r7 +0) = r2 only read is supportedThis excerpt is a historical clang-10 verifier log illustrating an old failure case. The patch rewrites the quoted source to "%p %-3d ", but the actual code now reads
BPF_SEQ_PRINTF(seq, "0 %-3d ", s->sk_protocol)inbpf_iter_netlink.c- the sock pointer argument is gone entirely.
Quoted 3 lines
Should the historical log remain untouched, or should it be updated to reflect that the netlink iterator no longer passes a pointer to
BPF_SEQ_PRINTF?
I would prefer to remove the K and the plain %p should provide the same historical input. Replacing it with 0 (and removing the argument) might no longer do the job. As of commit ce3267a39a92b ("kbuild: Bump minimum version of LLVM for building the kernel to 17.0.1") the minimum required version is way passed 10. I don't know if this also applies to BPF here (but why not?). If the required version is 17+, then there is probably no need to reference a fix for llvm which is included as 11+.
Quoted 16 lines
tools/testing/selftests/bpf/prog_tests/snprintf.c line 20
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/snprintf.c +1
-1@@ -16,7 +16,7 @@#define MIN_SYM_RET sizeof(EXP_SYM_OUT)/* The third specifier, %p, is a hashed pointer which changes on every reboot */ -#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " +#define EXP_ADDR_OUT "ffff00000add4e55 "#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr")The comment says %p is the third specifier, but after removing %pK from the BPF program (test_snprintf.c:59), %p is now the second specifier in the format string "%px %p".
Quoted 1 line
Should this comment be updated to say "The second specifier"?
Yeah, that makes sense.
Quoted 21 lines
[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +0
-0tools/testing/selftests/bpf/progs/bpf_iter_unix.c int dump_unix(struct bpf_iter__unix *ctx) · line 50
Quoted 9 lines
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +1
-2@@ -44,8 +44,7 @@ int dump_unix(struct bpf_iter__unix *ctx)if (seq_num ==0 )BPF_SEQ_PRINTF (seq,"Num RefCount Protocol Flags Type St Inode Path\n" ); - BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu", - unix_sk, + BPF_SEQ_PRINTF(seq, "%08u: %08X %08X %08X %04X %02X %8lu", 0, sk->sk_refcnt.refs.counter, 0, sk->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,The header shows "Num RefCount" (18 columns before RefCount).
The old format "%pK: " produced 18 columns (16 hex digits + ':' + ' '), matching the header width.
Quoted 6 lines
The new format "%08u: " with argument 0 produces "00000000: " (10 columns), so every column from RefCount onward is now shifted 8 characters left of its header label.
Should the header be updated to match the new field width, similar to how
bpf_iter_netlink.cwas adjusted from "sk Eth" to "sk Eth"?
Missed that. The net: version expected a 32bit pointer while the bpf one expects always a 64bit pointer. I tried to shrink the net one to something smaller but there was a selftest somewhere expecting the exact size so I just went with it.
Let me align everything with net then shrink this one including the description, too.
Quoted 8 lines
Regarding the commit message:
Quoted 4 lines
Networking recently replaced the socket output with a plain 0 because the socket pointer added no value to the output and the %pK should be removed fom library handling. The format remained otherwise unchanged in order not to break any tools which are parsing this information.
There's a typo: "fom library handling" should be "from library handling".
Thank you.
Quoted 7 lines
Also, the statement "The format remained otherwise unchanged" is
contradicted by the netlink header change from "sk Eth Pid"
to "sk Eth Pid", and by the field width changes across all modified files (varying from 1 to 10 columns vs the original 16-17 columns).If maintaining format stability for parsers is the stated goal, should the width-preserving spelling be used consistently?
"stability for parsers" means not to remove pointer and therefore a column so it will work for the human eye but the parse would expect a certain column. The padding here is just for the human eye and the parser does not care.
Sebastian
Quoted 10 lines · Sebastian Andrzej Siewior
Networking used to print the socket pointer with %p as output in the /proc interface. This was later changed to %pK in order not to reveal the actual pointer value. The output format has then been copied to bpf tests which produce the same format including the %pK format modifier.
Networking recently replaced the socket output with a plain 0 because the socket pointer added no value to the output and the %pK should be removed fom library handling. The format remained otherwise unchanged in order not to break any tools which are parsing this information.
Quoted 4 lines
This change removes the %pK modifier from bpf, following the change in networking.
Signed-off-by Sebastian Andrzej Siewior <[email protected]>
The bots are being overly picky bere, the tests pass fine and these are selftests anyway.
Quoted 208 lines
---
The networking change is in net-next as commit
7c0ec6288b497("net:
Replace %pK output with 0")tools/testing/selftests/bpf/README.rst | 2 +- tools/testing/selftests/bpf/prog_tests/snprintf.c | 2 +- tools/testing/selftests/bpf/progs/bpf_iter_netlink.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c | 11 +++++------ tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c | 11 +++++------ tools/testing/selftests/bpf/progs/bpf_iter_udp4.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_udp6.c | 4 ++-- tools/testing/selftests/bpf/progs/bpf_iter_unix.c | 3 +-- tools/testing/selftests/bpf/progs/test_snprintf.c | 4 ++-- 9 files changed, 21 insertions(+), 24 deletions(-)tools/testing/selftests/bpf/README.rst +1
-1@@ -187,7 +187,7 @@ The symptom for ``bpf_iter/netlink`` looks like 15: (bf) r2 = r7 16: (0f) r2 += r1 - ; BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol); + ; BPF_SEQ_PRINTF(seq, "%p %-3d ", s, s->sk_protocol); 17: (7b) *(u64 *)(r7 +0) = r2 only read is supportedtools/testing/selftests/bpf/prog_tests/snprintf.c +1
-1@@ -16,7 +16,7 @@#define MIN_SYM_RET sizeof(EXP_SYM_OUT)/* The third specifier, %p, is a hashed pointer which changes on every reboot */ -#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " +#define EXP_ADDR_OUT "ffff00000add4e55 "#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr")#define EXP_STR_OUT "str1 a b c d e longstr"tools/testing/selftests/bpf/progs/bpf_iter_netlink.c +2
-2@@ -25,12 +25,12 @@ int dump_netlink(struct bpf_iter__netlink *ctx)return 0 ;if (ctx->meta->seq_num ==0 ) -BPF_SEQ_PRINTF (seq,"sk Eth Pid Groups " +BPF_SEQ_PRINTF (seq,"sk Eth Pid Groups " "Rmem Wmem Dump Locks Drops " "Inode\n" ); s = &nlk->sk; -BPF_SEQ_PRINTF (seq,"%pK %-3d " , s, s->sk_protocol); +BPF_SEQ_PRINTF (seq,"0 %-3d " , s->sk_protocol);if (!nlk->groups) { group =0 ;tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c +5
-6@@ -131,8 +131,7 @@ static int dump_tcp_sock(struct seq_file *seq, struct tcp_sock *tp, icsk->icsk_probes_out,sock_i_ino (sp), sp->sk_refcnt.refs.counter); - BPF_SEQ_PRINTF(seq, "%pK %lu %lu %u %u %d\n", - tp, + BPF_SEQ_PRINTF(seq, "0 %lu %lu %u %u %d\n", jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(icsk),@@ -161,10 +160,10 @@ static int dump_tw_sock(struct seq_file *seq, struct tcp_timewait_sock *ttw,BPF_SEQ_PRINTF (seq,"%4d: %08X:%04X %08X:%04X " , seq_num, src, srcp, dest, destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" , tw->tw_substate,0 ,0 ,3 ,jiffies_delta_to_clock_t (delta),0 ,0 ,0 ,0 , - tw->tw_refcnt.refs.counter, tw); + tw->tw_refcnt.refs.counter);return 0 ; }@@ -185,9 +184,9 @@ static int dump_req_sock(struct seq_file *seq, struct tcp_request_sock *treq, seq_num, irsk->ir_loc_addr, irsk->ir_num, irsk->ir_rmt_addr, bpf_ntohs(irsk->ir_rmt_port)); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" ,TCP_SYN_RECV ,0 ,0 ,1 ,jiffies_to_clock_t (ttd), - req->num_timeout, uid,0 ,0 ,0 , req); + req->num_timeout, uid,0 ,0 ,0 );return 0 ; }tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c +5
-6@@ -135,8 +135,7 @@ static int dump_tcp6_sock(struct seq_file *seq, struct tcp6_sock *tp, icsk->icsk_probes_out,sock_i_ino (sp), sp->sk_refcnt.refs.counter); - BPF_SEQ_PRINTF(seq, "%pK %lu %lu %u %u %d\n", - tp, + BPF_SEQ_PRINTF(seq, "0 %lu %lu %u %u %d\n", jiffies_to_clock_t(icsk->icsk_rto), jiffies_to_clock_t(icsk->icsk_ack.ato), (icsk->icsk_ack.quick << 1) | inet_csk_in_pingpong_mode(icsk),@@ -170,10 +169,10 @@ static int dump_tw_sock(struct seq_file *seq, struct tcp_timewait_sock *ttw, dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" , tw->tw_substate,0 ,0 ,3 ,jiffies_delta_to_clock_t (delta),0 ,0 ,0 ,0 , - tw->tw_refcnt.refs.counter, tw); + tw->tw_refcnt.refs.counter);return 0 ; }@@ -201,9 +200,9 @@ static int dump_req_sock(struct seq_file *seq, struct tcp_request_sock *treq, dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2 ], dest->s6_addr32[3 ], bpf_ntohs(irsk->ir_rmt_port)); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d 0\n" ,TCP_SYN_RECV ,0 ,0 ,1 ,jiffies_to_clock_t (ttd), - req->num_timeout, uid,0 ,0 ,0 , req); + req->num_timeout, uid,0 ,0 ,0 );return 0 ; }tools/testing/selftests/bpf/progs/bpf_iter_udp4.c +2
-2@@ -57,13 +57,13 @@ int dump_udp4(struct bpf_iter__udp *ctx)BPF_SEQ_PRINTF (seq,"%5d: %08X:%04X %08X:%04X " , ctx->bucket, src, srcp, dest, destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n" , inet->sk.sk_state, inet->sk.sk_wmem_alloc.refs.counter -1 , rqueue,0 ,0L ,0 , ctx->uid,0 ,sock_i_ino (&inet->sk), - inet->sk.sk_refcnt.refs.counter, udp_sk, + inet->sk.sk_refcnt.refs.counter,0 , udp_sk->drop_counters.drops0.counter + udp_sk->drop_counters.drops1.counter);tools/testing/selftests/bpf/progs/bpf_iter_udp6.c +2
-2@@ -65,13 +65,13 @@ int dump_udp6(struct bpf_iter__udp *ctx) dest->s6_addr32[0 ], dest->s6_addr32[1 ], dest->s6_addr32[2], dest->s6_addr32[3], destp); -BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u\n" , +BPF_SEQ_PRINTF (seq,"%02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %8d %u\n" , inet->sk.sk_state, inet->sk.sk_wmem_alloc.refs.counter -1 , rqueue,0 ,0L ,0 , ctx->uid,0 ,sock_i_ino (&inet->sk), - inet->sk.sk_refcnt.refs.counter, udp_sk, + inet->sk.sk_refcnt.refs.counter,0 , udp_sk->drop_counters.drops0.counter + udp_sk->drop_counters.drops1.counter);return 0 ;tools/testing/selftests/bpf/progs/bpf_iter_unix.c +1
-2@@ -44,8 +44,7 @@ int dump_unix(struct bpf_iter__unix *ctx)if (seq_num ==0 )BPF_SEQ_PRINTF (seq,"Num RefCount Protocol Flags Type St Inode Path\n" ); - BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu", - unix_sk, + BPF_SEQ_PRINTF(seq, "%08u: %08X %08X %08X %04X %02X %8lu", 0, sk->sk_refcnt.refs.counter, 0, sk->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,tools/testing/selftests/bpf/progs/test_snprintf.c +2
-2@@ -57,8 +57,8 @@ int handler(const void *ctx) sym_ret =BPF_SNPRINTF (sym_out,sizeof (sym_out),"%ps %pS %pB" , &schedule, &schedule, &schedule);/* Kernel pointers */ - addr_ret =BPF_SNPRINTF (addr_out,sizeof (addr_out),"%pK %px %p" , -0 ,0xFFFF00000ADD4E55 ,0xFFFF00000ADD4E55 ); + addr_ret =BPF_SNPRINTF (addr_out,sizeof (addr_out),"%px %p" , +0xFFFF00000ADD4E55 ,0xFFFF00000ADD4E55 );/* Strings and single-byte character embedding */ str_ret =BPF_SNPRINTF (str_out,sizeof (str_out),"%s % 9c %+2c %-3c %04c %0c %+05s" , str1,'a' ,'b' ,'c' ,'d' ,'e' , longstr);
Quoted 14 lines · Emil Tsalapatis
Quoted 13 lines · Sebastian Andrzej Siewior
Networking used to print the socket pointer with %p as output in the /proc interface. This was later changed to %pK in order not to reveal the actual pointer value. The output format has then been copied to bpf tests which produce the same format including the %pK format modifier.
Networking recently replaced the socket output with a plain 0 because the socket pointer added no value to the output and the %pK should be removed fom library handling. The format remained otherwise unchanged in order not to break any tools which are parsing this information.
This change removes the %pK modifier from bpf, following the change in networking.
Quoted 6 lines
Quoted 1 line
Signed-off-by Sebastian Andrzej Siewior <[email protected]>Reviewed-by Emil Tsalapatis <[email protected]>The bots are being overly picky bere, the tests pass fine and these are selftests anyway.
I would repost it with comment updated. I am just unsure about README.rst part. Should that pointer about llvm 10 be removed (because outdated) or kept as I have it?
Sebastian