Thread (11 messages) flat view 11 messages, 6 authors, 2026-03-19

Re: [PATCH net] ipv6: sr: Add unlikely hint to idev NULL check in seg6_hmac_validate_skb

From: Eric Dumazet <edumazet@google.com>
Date: 2026-03-11 08:57:53
Also in: lkml

On Wed, Mar 11, 2026 at 8:23 AM Minhong He [off-list ref] wrote:
In seg6_hmac_validate_skb(), the pointer returned by __in6_dev_get()
can theoretically be NULL if the network device lacks proper IPv6
initialization or is being torn down. However, this is an exceptional
error path; in normal operation, the device will always have a valid
inet6_dev structure.

Marking this NULL check with unlikely() helps the compiler optimize
branch prediction and code layout. It ensures that the common case
(valid idev) remains in the hot path, while the error handling code
is placed out of line, improving CPU pipeline efficiency for high-speed
SRv6 packet processing.
This section is unnecessary and dubious ?
Note that both clang and gcc already generate the correct code without
the unlikely()
So your claim about "CPU pipeline efficiency" is quite strange to me.

Let's keep the changelogs concise and focused on the real issue at hand.

Thanks.
quoted hunk ↗ jump to hunk
Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
Signed-off-by: Minhong He <redacted>
---
 net/ipv6/seg6_hmac.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index ee6bac0160ac..a8f279ffb678 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -184,6 +184,8 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb)
        int require_hmac;

        idev = __in6_dev_get(skb->dev);
+       if (unlikely(!idev))
+               return false;

        srh = (struct ipv6_sr_hdr *)skb_transport_header(skb);

--
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help