History

net/tcp: Allow asynchronous delete for TCP-AO keys (MKTs)

Delete becomes very, very fast - almost free, but after setsockopt() syscall returns, the key is still alive until next RCU grace period. Which is fine for listen sockets as userspace needs to be aware of setsockopt(TCP_AO) and accept() race and resolve it with verification by getsockopt() after TCP connection was accepted. The benchmark results (on non-loaded box, worse with more RCU work pending): > ok 33 Worst case delete 16384 keys: min=5ms max=10ms mean=6.93904ms stddev=0.263421 > ok 34 Add a new key 16384 keys: min=1ms max=4ms mean=2.17751ms stddev=0.147564 > ok 35 Remove random-search 16384 keys: min=5ms max=10ms mean=6.50243ms stddev=0.254999 > ok 36 Remove async 16384 keys: min=0ms max=0ms mean=0.0296107ms stddev=0.0172078

Dmitry Safonov committed 3 years ago

Commit d6732b91 parent ef847032 files · +20 −4Browse files

Unified · Split

2 files
  1. include/uapi/linux/tcp.h +2 −1
  2. net/ipv4/tcp_ao.c +18 −3
include/uapi/linux/tcp.h+2−1
@@ -396,7 +396,8 @@ struct tcp_ao_del { /* setsockopt(TCP_AO_DEL_KEY) */ · 395 unmodified lines
396 __s32 ifindex; /* L3 dev index for VRF */396 __s32 ifindex; /* L3 dev index for VRF */
397 __u32 set_current :1, /* corresponding ::current_key */397 __u32 set_current :1, /* corresponding ::current_key */
398 set_rnext :1, /* corresponding ::rnext */398 set_rnext :1, /* corresponding ::rnext */
399 reserved :30; /* must be 0 */399 del_async :1, /* only valid for listen sockets */
400 reserved :29; /* must be 0 */
400 __u16 reserved2; /* padding, must be 0 */401 __u16 reserved2; /* padding, must be 0 */
401 __u8 prefix; /* peer's address prefix */402 __u8 prefix; /* peer's address prefix */
402 __u8 sndid; /* SendID for outgoing segments */403 __u8 sndid; /* SendID for outgoing segments */
net/ipv4/tcp_ao.c+18−3
@@ -1628,7 +1628,7 @@ err_free_ao: · 1627 unmodified lines
1628}1628}
1629 1629
1630static int tcp_ao_delete_key(struct sock *sk, struct tcp_ao_info *ao_info,1630static int tcp_ao_delete_key(struct sock *sk, struct tcp_ao_info *ao_info,
1631 struct tcp_ao_key *key,1631 bool del_async, struct tcp_ao_key *key,
1632 struct tcp_ao_key *new_current,1632 struct tcp_ao_key *new_current,
1633 struct tcp_ao_key *new_rnext)1633 struct tcp_ao_key *new_rnext)
1634{1634{
@@ -1636,11 +1636,24 @@ static int tcp_ao_delete_key(struct sock *sk, struct tcp_ao_info *ao_info, · 1 unmodified line
1636 1636
1637 hlist_del_rcu(&key->node);1637 hlist_del_rcu(&key->node);
1638 1638
1639 /* Support for async delete on listening sockets: as they don't
1640 * need current_key/rnext_key maintaining, we don't need to check
1641 * them and we can just free all resources in RCU fashion.
1642 */
1643 if (del_async) {
1644 atomic_sub(tcp_ao_sizeof_key(key), &sk->sk_omem_alloc);
1645 call_rcu(&key->rcu, tcp_ao_key_free_rcu);
1646 return 0;
1647 }
1648
1639 /* At this moment another CPU could have looked this key up1649 /* At this moment another CPU could have looked this key up
1640 * while it was unlinked from the list. Wait for RCU grace period,1650 * while it was unlinked from the list. Wait for RCU grace period,
1641 * after which the key is off-list and can't be looked up again;1651 * after which the key is off-list and can't be looked up again;
1642 * the rx path [just before RCU came] might have used it and set it1652 * the rx path [just before RCU came] might have used it and set it
1643 * as current_key (very unlikely).1653 * as current_key (very unlikely).
1654 * Free the key with next RCU grace period (in case it was
1655 * current_key before tcp_ao_current_rnext() might have
1656 * changed it in forced-delete).
1644 */1657 */
1645 synchronize_rcu();1658 synchronize_rcu();
1646 if (new_current)1659 if (new_current)
@@ -1711,6 +1724,8 @@ static int tcp_ao_del_cmd(struct sock *sk, unsigned short int family, · 64 unmodified lines
1711 if (!new_rnext)1724 if (!new_rnext)
1712 return -ENOENT;1725 return -ENOENT;
1713 }1726 }
1727 if (cmd.del_async && sk->sk_state != TCP_LISTEN)
1728 return -EINVAL;
1714 1729
1715 if (family == AF_INET) {1730 if (family == AF_INET) {
1716 struct sockaddr_in *sin = (struct sockaddr_in *)&cmd.addr;1731 struct sockaddr_in *sin = (struct sockaddr_in *)&cmd.addr;
@@ -1758,8 +1773,8 @@ static int tcp_ao_del_cmd(struct sock *sk, unsigned short int family, · 41 unmodified lines
1758 if (key == new_current || key == new_rnext)1773 if (key == new_current || key == new_rnext)
1759 continue;1774 continue;
1760 1775
1761 return tcp_ao_delete_key(sk, ao_info, key,1776 return tcp_ao_delete_key(sk, ao_info, cmd.del_async, key,
1762 new_current, new_rnext);1777 new_current, new_rnext);
1763 }1778 }
1764 return -ENOENT;1779 return -ENOENT;
1765}1780}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t