Hi,
When we needed the kernel lock for local IP packet delivery, mpi@
introduced a queue to grab the lock for multiple packets.
Now we have only netlock for both IP and protocol input. So the
queue is not necessary anymore. It just switches CPU and decreases
performance.
To get TCP running on loopback, we have to queue once between TCP
input and output of the two sockets. So I queue unconditionally
looutput() instead.
The diff survived a full make regress.
ok?
bluhm
Index: net/if.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if.c,v
retrieving revision 1.586
diff -u -p -r1.586 if.c
--- net/if.c 30 Jun 2019 23:02:28 -0000 1.586
+++ net/if.c 30 Jul 2019 22:43:15 -0000
@@ -997,12 +997,6 @@ if_netisr(void *unused)
KERNEL_UNLOCK();
}
#endif
- if (n & (1 << NETISR_IP))
- ipintr();
-#ifdef INET6
- if (n & (1 << NETISR_IPV6))
- ip6intr();
-#endif
#if NPPP > 0
if (n & (1 << NETISR_PPP)) {
KERNEL_LOCK();
Index: net/if_loop.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/if_loop.c,v
retrieving revision 1.88
diff -u -p -r1.88 if_loop.c
--- net/if_loop.c 9 Sep 2018 10:11:41 -0000 1.88
+++ net/if_loop.c 30 Jul 2019 22:43:15 -0000
@@ -252,10 +252,10 @@ looutput(struct ifnet *ifp, struct mbuf
rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH);
}
- /* Use the quick path only once to avoid stack overflow. */
- if ((m->m_flags & M_LOOP) == 0)
- return (if_input_local(ifp, m, dst->sa_family));
-
+ /*
+ * Do not call if_input_local() directly. Queue the packet to avoid
+ * stack overflow and make TCP handshake over loopback work.
+ */
return (if_output_local(ifp, m, dst->sa_family));
}
Index: net/netisr.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/netisr.h,v
retrieving revision 1.50
diff -u -p -r1.50 netisr.h
--- net/netisr.h 31 Oct 2017 22:05:12 -0000 1.50
+++ net/netisr.h 30 Jul 2019 22:43:15 -0000
@@ -63,8 +63,6 @@ extern int netisr; /* scheduling bits
extern struct task if_input_task_locked;
void arpintr(void);
-void ipintr(void);
-void ip6intr(void);
void pppintr(void);
void bridgeintr(void);
void pppoeintr(void);
Index: netinet/ip_input.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_input.c,v
retrieving revision 1.343
diff -u -p -r1.343 ip_input.c
--- netinet/ip_input.c 10 Jun 2019 23:48:21 -0000 1.343
+++ netinet/ip_input.c 30 Jul 2019 22:43:15 -0000
@@ -109,8 +109,6 @@ int ip_frags = 0;
int *ipctl_vars[IPCTL_MAXID] = IPCTL_VARS;
-struct niqueue ipintrq = NIQUEUE_INITIALIZER(IPQ_MAXLEN, NETISR_IP);
-
struct pool ipqent_pool;
struct pool ipq_pool;
@@ -123,7 +121,6 @@ static struct mbuf_queue ipsend_mq;
extern struct niqueue arpinq;
int ip_ours(struct mbuf **, int *, int, int);
-int ip_local(struct mbuf **, int *, int, int);
int ip_dooptions(struct mbuf *, struct ifnet *);
int in_ouraddr(struct mbuf *, struct ifnet *, struct rtentry **);
@@ -205,43 +202,6 @@ ip_init(void)
}
/*
- * Enqueue packet for local delivery. Queuing is used as a boundary
- * between the network layer (input/forward path) running without
- * KERNEL_LOCK() and the transport layer still needing it.
- */
-int
-ip_ours(struct mbuf **mp, int *offp, int nxt, int af)
-{
- /* We are already in a IPv4/IPv6 local deliver loop. */
- if (af != AF_UNSPEC)
- return ip_local(mp, offp, nxt, af);
-
- niq_enqueue(&ipintrq, *mp);
- *mp = NULL;
- return IPPROTO_DONE;
-}
-
-/*
- * Dequeue and process locally delivered packets.
- */
-void
-ipintr(void)
-{
- struct mbuf *m;
- int off, nxt;
-
- while ((m = niq_dequeue(&ipintrq)) != NULL) {
-#ifdef DIAGNOSTIC
- if ((m->m_flags & M_PKTHDR) == 0)
- panic("ipintr no HDR");
-#endif
- off = 0;
- nxt = ip_local(&m, &off, IPPROTO_IPV4, AF_UNSPEC);
- KASSERT(nxt == IPPROTO_DONE);
- }
-}
-
-/*
* IPv4 input routine.
*
* Checksum and byte swap header. Process options. Forward or deliver.
@@ -497,7 +457,7 @@ ip_input_if(struct mbuf **mp, int *offp,
* If fragmented try to reassemble. Pass to next level.
*/
int
-ip_local(struct mbuf **mp, int *offp, int nxt, int af)
+ip_ours(struct mbuf **mp, int *offp, int nxt, int af)
{
struct mbuf *m = *mp;
struct ip *ip = mtod(m, struct ip *);
@@ -1640,8 +1600,7 @@ ip_sysctl(int *name, u_int namelen, void
newlen));
#endif
case IPCTL_IFQUEUE:
- return (sysctl_niq(name + 1, namelen - 1,
- oldp, oldlenp, newp, newlen, &ipintrq));
+ return (EOPNOTSUPP);
case IPCTL_ARPQUEUE:
return (sysctl_niq(name + 1, namelen - 1,
oldp, oldlenp, newp, newlen, &arpinq));
Index: netinet6/ip6_input.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/ip6_input.c,v
retrieving revision 1.217
diff -u -p -r1.217 ip6_input.c
--- netinet6/ip6_input.c 10 Jun 2019 23:48:22 -0000 1.217
+++ netinet6/ip6_input.c 30 Jul 2019 22:43:15 -0000
@@ -115,14 +115,11 @@
#include <netinet/ip_carp.h>
#endif
-struct niqueue ip6intrq = NIQUEUE_INITIALIZER(IPQ_MAXLEN, NETISR_IPV6);
-
struct cpumem *ip6counters;
uint8_t ip6_soiikey[IP6_SOIIKEY_LEN];
int ip6_ours(struct mbuf **, int *, int, int);
-int ip6_local(struct mbuf **, int *, int, int);
int ip6_check_rh0hdr(struct mbuf *, int *);
int ip6_hbhchcheck(struct mbuf *, int *, int *, int *);
int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *);
@@ -165,43 +162,6 @@ ip6_init(void)
ip6counters = counters_alloc(ip6s_ncounters);
}
-/*
- * Enqueue packet for local delivery. Queuing is used as a boundary
- * between the network layer (input/forward path) running without
- * KERNEL_LOCK() and the transport layer still needing it.
- */
-int
-ip6_ours(struct mbuf **mp, int *offp, int nxt, int af)
-{
- /* We are already in a IPv4/IPv6 local deliver loop. */
- if (af != AF_UNSPEC)
- return ip6_local(mp, offp, nxt, af);
-
- niq_enqueue(&ip6intrq, *mp);
- *mp = NULL;
- return IPPROTO_DONE;
-}
-
-/*
- * Dequeue and process locally delivered packets.
- */
-void
-ip6intr(void)
-{
- struct mbuf *m;
- int off, nxt;
-
- while ((m = niq_dequeue(&ip6intrq)) != NULL) {
-#ifdef DIAGNOSTIC
- if ((m->m_flags & M_PKTHDR) == 0)
- panic("ip6intr no HDR");
-#endif
- off = 0;
- nxt = ip6_local(&m, &off, IPPROTO_IPV6, AF_UNSPEC);
- KASSERT(nxt == IPPROTO_DONE);
- }
-}
-
void
ipv6_input(struct ifnet *ifp, struct mbuf *m)
{
@@ -548,7 +508,7 @@ ip6_input_if(struct mbuf **mp, int *offp
}
int
-ip6_local(struct mbuf **mp, int *offp, int nxt, int af)
+ip6_ours(struct mbuf **mp, int *offp, int nxt, int af)
{
if (ip6_hbhchcheck(*mp, offp, &nxt, NULL))
return IPPROTO_DONE;
@@ -1459,8 +1419,7 @@ ip6_sysctl(int *name, u_int namelen, voi
NET_UNLOCK();
return (error);
case IPV6CTL_IFQUEUE:
- return (sysctl_niq(name + 1, namelen - 1,
- oldp, oldlenp, newp, newlen, &ip6intrq));
+ return (EOPNOTSUPP);
case IPV6CTL_SOIIKEY:
return (ip6_sysctl_soiikey(oldp, oldlenp, newp, newlen));
default: