Skip to contentSkip to conversation

udp: add drop count for packets in udp_prod_queue

PATCH In review Mahdi Faramarzpour 3 participants 6 messages Jan 28

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

PATCH 1/1 udp: add drop count for packets in udp_prod_queue

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +4 -1
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 			skb = to_drop;
 			to_drop = skb->next;
 			skb_mark_not_on_list(skb);
-			/* TODO: update SNMP values. */
 			sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
 		}
 		numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+		SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+			       UDP_MIB_MEMERRORS, nb);
+		SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+			       UDP_MIB_INERRORS, nb);
 	}
 
 	atomic_sub(total_size, &udp_prod_queue->rmem_alloc);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 32 lines · Mahdi Faramarzpour

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +0 -0
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
                        skb = to_drop;
                        to_drop = skb->next;

net/ipv4/udp.c int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) · line 1807

Quoted 10 lines
net/ipv4/udp.c +4 -1
                        skb_mark_not_on_list(skb);
-                       /* TODO: update SNMP values. */
                        sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
                }
                numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_MEMERRORS, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_INERRORS, nb);
        }

Hmm.. I have not followed your prior attempts, sorry for coming late.

Note that an UDP AF_INET6 socket for which ipv6_only_sock(sk) is false can receive
IPv4 and IPv6 UDP packets, if bound to any addresses.

The to_drop list could contain a mix of IPv4 and IPv6 packets.

Ideally we should track SNMP values in the proper space (Ipv4 , IPv6).

See IPV6_V6ONLY and /proc/sys/net/ipv6/bindv6only for reference.

#2 lore raw
Quoted 51 lines · Eric Dumazet
Quoted 32 lines · Mahdi Faramarzpour

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +0 -0
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
                        skb = to_drop;
                        to_drop = skb->next;

net/ipv4/udp.c int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) · line 1807

Quoted 10 lines
net/ipv4/udp.c +4 -1
                        skb_mark_not_on_list(skb);
-                       /* TODO: update SNMP values. */
                        sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
                }
                numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_MEMERRORS, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_INERRORS, nb);
        }

Hmm.. I have not followed your prior attempts, sorry for coming late.

Note that an UDP AF_INET6 socket for which ipv6_only_sock(sk) is false can receive
IPv4 and IPv6 UDP packets, if bound to any addresses.

Quoted 5 lines

The to_drop list could contain a mix of IPv4 and IPv6 packets.

Ideally we should track SNMP values in the proper space (Ipv4 , IPv6).

See IPV6_V6ONLY and /proc/sys/net/ipv6/bindv6only for reference.

This is the exact discussion I had with Willem de Bruijn:
https://lore.kernel.org/netdev/[email protected]/

#3 lore raw
Quoted 53 lines · Mahdi Faramarzpour
Quoted 51 lines · Eric Dumazet
Quoted 32 lines · Mahdi Faramarzpour

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +0 -0
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
                        skb = to_drop;
                        to_drop = skb->next;

net/ipv4/udp.c int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) · line 1807

Quoted 10 lines
net/ipv4/udp.c +4 -1
                        skb_mark_not_on_list(skb);
-                       /* TODO: update SNMP values. */
                        sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
                }
                numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_MEMERRORS, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_INERRORS, nb);
        }

Hmm.. I have not followed your prior attempts, sorry for coming late.

Note that an UDP AF_INET6 socket for which ipv6_only_sock(sk) is false can receive
IPv4 and IPv6 UDP packets, if bound to any addresses.

Quoted 7 lines
Quoted 5 lines

The to_drop list could contain a mix of IPv4 and IPv6 packets.

Ideally we should track SNMP values in the proper space (Ipv4 , IPv6).

See IPV6_V6ONLY and /proc/sys/net/ipv6/bindv6only for reference.

This is the exact discussion I had with Willem de Bruijn:
https://lore.kernel.org/netdev/[email protected]/

I think Willem was wrong :)

__udp_enqueue_schedule_skb() is called either from __udp_queue_rcv_skb() for IPv4 packets,
or __udpv6_queue_rcv_skb() for IPv6 packets, and they both can feed packets to a single and shared UDP socket.

An IPv4 packet will not go through __udpv6_queue_rcv_skb().

It would be deceptive to increment IPV6 UDP counters if a host only receives IPv4 UDP packets.

#4 lore raw
Quoted 70 lines · Eric Dumazet
Quoted 53 lines · Mahdi Faramarzpour
Quoted 51 lines · Eric Dumazet
Quoted 32 lines · Mahdi Faramarzpour

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +0 -0
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
                        skb = to_drop;
                        to_drop = skb->next;

net/ipv4/udp.c int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) · line 1807

Quoted 10 lines
net/ipv4/udp.c +4 -1
                        skb_mark_not_on_list(skb);
-                       /* TODO: update SNMP values. */
                        sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
                }
                numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_MEMERRORS, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_INERRORS, nb);
        }

Hmm.. I have not followed your prior attempts, sorry for coming late.

Note that an UDP AF_INET6 socket for which ipv6_only_sock(sk) is false can receive
IPv4 and IPv6 UDP packets, if bound to any addresses.

Quoted 7 lines
Quoted 5 lines

The to_drop list could contain a mix of IPv4 and IPv6 packets.

Ideally we should track SNMP values in the proper space (Ipv4 , IPv6).

See IPV6_V6ONLY and /proc/sys/net/ipv6/bindv6only for reference.

This is the exact discussion I had with Willem de Bruijn:
https://lore.kernel.org/netdev/[email protected]/

I think Willem was wrong :)

__udp_enqueue_schedule_skb() is called either from __udp_queue_rcv_skb() for IPv4 packets,
or __udpv6_queue_rcv_skb() for IPv6 packets, and they both can feed packets to a single and shared UDP socket.

Quoted 4 lines

An IPv4 packet will not go through __udpv6_queue_rcv_skb().

It would be deceptive to increment IPV6 UDP counters if a host only receives IPv4 UDP packets.

Ok, in case other people wonder which logic is in fact true, refer to net/core/dev.c in which
netif_receive_skb is defined that's called from device drivers. This routine checks the packet
against a list of struct packet_types, ultimately finding the matched type and calling its
registered func field, that are ip_rcv & ip6_rcv in case of the two ipv4 & ipv6 types. So, the
appropriate routine is chosen based on packet type, not socket family.

That being said, I think the previous patch was just fine, unless Willem wants the newline
after variable declarations:
https://lore.kernel.org/netdev/[email protected]/

maintainer
#5 lore raw
Quoted 64 lines · Mahdi Faramarzpour
Quoted 63 lines · Eric Dumazet
Quoted 60 lines · Mahdi Faramarzpour
Quoted 51 lines · Eric Dumazet
Quoted 32 lines · Mahdi Faramarzpour

This commit adds SNMP drop count increment for the packets in per NUMA queues which were introduced in commit b650bf0977d3 ("udp: remove busylock and add per NUMA queues"). note that SNMP counters are incremented currently by the caller for skb. And that these skbs on the intermediate queue cannot be counted there so need similar logic in their error path.

---
v6:
- increasing a single counter based on socket family
v5: https://lore.kernel.org/netdev/[email protected]/
- check if drop counts are non-zero before increasing countrers
v4: https://lore.kernel.org/netdev/[email protected]/
- move all changes to unlikely(to_drop) branch
v3: https://lore.kernel.org/netdev/[email protected]/
- remove the unreachable UDP_MIB_RCVBUFERRORS code
v2: https://lore.kernel.org/netdev/[email protected]/
- change ENOMEM to ENOBUFS
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/udp.c +0 -0
index ffe074cb5..dd302f5fb 100644
@@ -1797,10 +1797,13 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
                        skb = to_drop;
                        to_drop = skb->next;

net/ipv4/udp.c int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb) · line 1807

Quoted 10 lines
net/ipv4/udp.c +4 -1
                        skb_mark_not_on_list(skb);
-                       /* TODO: update SNMP values. */
                        sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);
                }
                numa_drop_add(&udp_sk(sk)->drop_counters, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_MEMERRORS, nb);
+               SNMP_ADD_STATS(__UDPX_MIB(sk, (sk->sk_family == PF_INET)),
+                              UDP_MIB_INERRORS, nb);
        }

Hmm.. I have not followed your prior attempts, sorry for coming late.

Note that an UDP AF_INET6 socket for which ipv6_only_sock(sk) is false can receive
IPv4 and IPv6 UDP packets, if bound to any addresses.

Quoted 5 lines

The to_drop list could contain a mix of IPv4 and IPv6 packets.

Ideally we should track SNMP values in the proper space (Ipv4 , IPv6).

See IPV6_V6ONLY and /proc/sys/net/ipv6/bindv6only for reference.

This is the exact discussion I had with Willem de Bruijn:
https://lore.kernel.org/netdev/[email protected]/

Quoted 8 lines
Quoted 8 lines

I think Willem was wrong :)

__udp_enqueue_schedule_skb() is called either from __udp_queue_rcv_skb() for IPv4 packets,
or __udpv6_queue_rcv_skb() for IPv6 packets, and they both can feed packets to a single and shared UDP socket.

An IPv4 packet will not go through __udpv6_queue_rcv_skb().

Happy to be wrong :) Thanks for the correction.

Quoted 13 lines
Quoted 3 lines

It would be deceptive to increment IPV6 UDP counters if a host only receives IPv4 UDP packets.

Ok, in case other people wonder which logic is in fact true, refer to net/core/dev.c in which
netif_receive_skb is defined that's called from device drivers. This routine checks the packet
against a list of struct packet_types, ultimately finding the matched type and calling its
registered func field, that are ip_rcv & ip6_rcv in case of the two ipv4 & ipv6 types. So, the
appropriate routine is chosen based on packet type, not socket family.

Quoted 4 lines

That being said, I think the previous patch was just fine, unless Willem wants the newline
after variable declarations:
https://lore.kernel.org/netdev/[email protected]/

You'll have to resubmit anyway. Then please address the minor stylistic point.