Skip to content

Commit b48c80e

Browse files
committed
inet: Add family scope inetpeer flushes.
This implementation can deal with having many inetpeer roots, which is a necessary prerequisite for per-FIB table rooted peer tables. Each family (AF_INET, AF_INET6) has a sequence number which we bump when we get a family invalidation request. Each peer lookup cheaply checks whether the flush sequence of the root we are using is out of date, and if so flushes it and updates the sequence number. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4651700 commit b48c80e

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎include/net/inetpeer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct inet_peer {
6868
struct inet_peer_base {
6969
struct inet_peer __rcu *root;
7070
seqlock_t lock;
71+
u32 flush_seq;
7172
int total;
7273
};
7374

@@ -168,6 +169,7 @@ extern void inet_putpeer(struct inet_peer *p);
168169
extern bool inet_peer_xrlim_allow(struct inet_peer *peer, int timeout);
169170

170171
extern void inetpeer_invalidate_tree(struct inet_peer_base *);
172+
extern void inetpeer_invalidate_family(int family);
171173

172174
/*
173175
* temporary check to make sure we dont access rid, ip_id_count, tcp_ts,

‎net/ipv4/inetpeer.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,36 @@ void inet_peer_base_init(struct inet_peer_base *bp)
8686
{
8787
bp->root = peer_avl_empty_rcu;
8888
seqlock_init(&bp->lock);
89+
bp->flush_seq = ~0U;
8990
bp->total = 0;
9091
}
9192
EXPORT_SYMBOL_GPL(inet_peer_base_init);
9293

94+
static atomic_t v4_seq = ATOMIC_INIT(0);
95+
static atomic_t v6_seq = ATOMIC_INIT(0);
96+
97+
static atomic_t *inetpeer_seq_ptr(int family)
98+
{
99+
return (family == AF_INET ? &v4_seq : &v6_seq);
100+
}
101+
102+
static inline void flush_check(struct inet_peer_base *base, int family)
103+
{
104+
atomic_t *fp = inetpeer_seq_ptr(family);
105+
106+
if (unlikely(base->flush_seq != atomic_read(fp))) {
107+
inetpeer_invalidate_tree(base);
108+
base->flush_seq = atomic_read(fp);
109+
}
110+
}
111+
112+
void inetpeer_invalidate_family(int family)
113+
{
114+
atomic_t *fp = inetpeer_seq_ptr(family);
115+
116+
atomic_inc(fp);
117+
}
118+
93119
#define PEER_MAXDEPTH 40 /* sufficient for about 2^27 nodes */
94120

95121
/* Exported for sysctl_net_ipv4. */
@@ -437,6 +463,8 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base,
437463
unsigned int sequence;
438464
int invalidated, gccnt = 0;
439465

466+
flush_check(base, daddr->family);
467+
440468
/* Attempt a lockless lookup first.
441469
* Because of a concurrent writer, we might not find an existing entry.
442470
*/

‎net/ipv4/route.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
935935

936936
get_random_bytes(&shuffle, sizeof(shuffle));
937937
atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
938-
inetpeer_invalidate_tree(net->ipv4.peers);
938+
inetpeer_invalidate_family(AF_INET);
939939
}
940940

941941
/*

0 commit comments

Comments
 (0)