Skip to contentSkip to conversation

ipv4: route: do not allocate unreachable dst for non-IP packets

PATCH In review Sam McNally 2 participants 2 messages Nov 26 – Nov 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv4: route: do not allocate unreachable dst for non-IP packets

When ip_route_input_slow() reaches no_route: (from a missing FIB entry or !IN_DEV_FORWARD(in_dev) for a non-local target), falling through to
local_input: allocates an uncached RTN_UNREACHABLE rtable (dst.input = ip_error), increments in_slow_tot, inserts it into rt_uncached_list under spin_lock_bh(), and attaches it via skb_dst_set().

Non-IPv4 callers such as arp_process() never invoke dst_input(skb) to send ICMP errors; they ignore RTN_UNREACHABLE and release the dst in consume_skb(), unlinking it from rt_uncached_list under spin_lock_bh() and queuing dst_destroy_rcu() via call_rcu_hurry(), which wakes RCU kthreads immediately since
commit 483c26ff63f4 ("net: Use call_rcu_hurry() for dst_release()").

Return SKB_DROP_REASON_INVALID_PROTO at no_route: when skb->protocol != htons(ETH_P_IP), matching brd_input: and ip_mc_validate_source(), while preserving ip_route_input_noref() rp_filter source validation when tip is RTN_LOCAL.

Observed during idle power testing on CONFIG_RCU_LAZY=y systems, where background broadcast ARP traffic with IPv4 forwarding disabled repeatedly woke RCU kthreads. Tested on x86_64 and arm64 under synthetic broadcast ARP load (~45 ARPs/s) and live /16 network traffic (~20-40 ARPs/s): live in_slow_tot dropped by >95% and 60s idle rcu_preempt wakeups fell by ~70% on arm64 and ~75-88% on x86_64, raising x86_64 package C10 residency from 62.5% to 84.6% and saving ~100-250 mW of SoC package power. An AI coding assistant was used to help analyze the code path and draft the patch and changelog.

---
 net/ipv4/route.c | 4 ++++
 1 file changed, 4 insertions(+)
net/ipv4/route.c +4 -0
index 11d990703d31..1f1b09b4ac8d 100644
@@ -2463,6 +2463,10 @@ ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 
 no_route:
 	RT_CACHE_STAT_INC(in_no_route);
+	if (skb->protocol != htons(ETH_P_IP)) {
+		reason = SKB_DROP_REASON_INVALID_PROTO;
+		goto out;
+	}
 	res->type = RTN_UNREACHABLE;
 	res->fi = NULL;
 	res->table = NULL;
Signature · 1 line
2.56.1.911.g883d8bcb20-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Sam McNally

When ip_route_input_slow() reaches no_route: (from a missing FIB entry or !IN_DEV_FORWARD(in_dev) for a non-local target), falling through to
local_input: allocates an uncached RTN_UNREACHABLE rtable (dst.input = ip_error), increments in_slow_tot, inserts it into rt_uncached_list under spin_lock_bh(), and attaches it via skb_dst_set().

Non-IPv4 callers such as arp_process() never invoke dst_input(skb) to send ICMP errors; they ignore RTN_UNREACHABLE and release the dst in consume_skb(), unlinking it from rt_uncached_list under spin_lock_bh() and queuing dst_destroy_rcu() via call_rcu_hurry(), which wakes RCU kthreads immediately since
commit 483c26ff63f4 ("net: Use call_rcu_hurry() for dst_release()").

Return SKB_DROP_REASON_INVALID_PROTO at no_route: when skb->protocol != htons(ETH_P_IP), matching brd_input: and ip_mc_validate_source(), while preserving ip_route_input_noref() rp_filter source validation when tip is RTN_LOCAL.

Observed during idle power testing on CONFIG_RCU_LAZY=y systems, where background broadcast ARP traffic with IPv4 forwarding disabled repeatedly woke RCU kthreads. Tested on x86_64 and arm64 under synthetic broadcast ARP load (~45 ARPs/s) and live /16 network traffic (~20-40 ARPs/s): live in_slow_tot dropped by >95% and 60s idle rcu_preempt wakeups fell by ~70% on arm64 and ~75-88% on x86_64, raising x86_64 package C10 residency from 62.5% to 84.6% and saving ~100-250 mW of SoC package power. An AI coding assistant was used to help analyze the code path and draft the patch and changelog.

Quoted 1 line