From patchwork Wed Oct 18 20:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 155166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp5064255vqb; Wed, 18 Oct 2023 14:01:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsVRnjuw6rbWWhkkpPaVK6fBXSCek+J/aaaDg9ja8mquy1z6Vc8apTZe8TjBsvD86KW/ZV X-Received: by 2002:a05:6a21:9706:b0:16b:9541:85e6 with SMTP id ub6-20020a056a21970600b0016b954185e6mr248359pzb.60.1697662902290; Wed, 18 Oct 2023 14:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697662902; cv=none; d=google.com; s=arc-20160816; b=AelKDImQu0vlb7+qM1mKle03+O0+GOyM+ZPPOYpq+L8UwLhSAM82RYJLDuHuXmaCg3 R9rL64VIGWVtrj7AShsa2cU1BeqlCpEnOp03O/ulbrktTtfKqR7UL9S9LG/8X5/ohM3C BDWfRlHUbFMymkLLAQ2mJGQT4r9SxCS0Xf94Tm6leuakktCchLvqBC6IV7oY2ZTlHp44 U18js1l7H7PsGx7DxMg5O6GsRn1ynNx/CgGy7YUKq3ZlQOlUk+zIWM3LrvUrPMgAnVSE lEkY4OQ72IlT9c/xc6OdjNksH44D22cLxhhjDkSTlb3RBiKEiG0RfylIuabW6hQKQwWn xk5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fvDuAooczxx5mXgBpeaWHuz5QzyPAKub23jfuhCVJ9g=; fh=a8JK1LlV6fjkJ2GExjvEHYBwBHtgXArNx6ms6Kac6b4=; b=HpxdNVLOzRsmJsEmej2ug1pGG1HUD/oQ9Zo/SVKgm0GzYH5WMIBfkzdg6vrLWCrpp9 271199TBld6KdtpoVXa2s0YPqKvT9fUPQMMJX36SGNjxGsaV0ZBOvjBJ3sOWXJn68Z6t oFtjHWWZ1T1iwRgMGU69736q7DaGZFDmIFyhKme0o6wqJvb/WDpnNtV6LsCNWJk1cR+N /2lkJV3qspohUrVZEXK8kJerpKl+ox021z+rHbGzrYea4w5ZYBaQbOPdskpnekVjVd7J vewaz6LQULf2aL602056A8C6WF7HIWjU3U7zPaBURdgG1zM+tusu0Odb7dxn/H6TMUAu llvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=fsbyejto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id k190-20020a6384c7000000b005abac05ba94si2912820pgd.776.2023.10.18.14.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 14:01:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=fsbyejto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B0AE0807514B; Wed, 18 Oct 2023 14:01:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344895AbjJRVAC (ORCPT + 24 others); Wed, 18 Oct 2023 17:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbjJRU7b (ORCPT ); Wed, 18 Oct 2023 16:59:31 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C921187 for ; Wed, 18 Oct 2023 13:58:55 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40806e4106dso580575e9.1 for ; Wed, 18 Oct 2023 13:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1697662732; x=1698267532; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fvDuAooczxx5mXgBpeaWHuz5QzyPAKub23jfuhCVJ9g=; b=fsbyejtoau7S92m/PPymHCgML/ar1pcr4mvvXTGV7S+JUbtsLexeaymfrRIcr9Oxtx RlFt4Cwob0ARrujExtzDqcuqZtUoLKakmI8wkyvIkfALtIOhlzDnXrLaEQIXLKCzSO+x T7DERNuo/2rlLxum8ErIegKqlEx8Mtis/NMpv8fMZ4M1nby+KiciRgcRMdkftVfAb/Lc HAwh6cPdh76bQ+YF6SZkxA1+ESXMnbPLa+Thy5tL82i50OUEwWGS3INAeraK8YQ1YiWN CRrrNhjtqWvPKc+SOZ7fvipTIALNUq/0epjbTIoD0w3TKvGu8HsydpCz0rKN9uJ5MT+i kBvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697662732; x=1698267532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fvDuAooczxx5mXgBpeaWHuz5QzyPAKub23jfuhCVJ9g=; b=CyzYp1T2wnkyGDzoHlCrW9Mes35ODjQ0dmGeBm77O7oyCdm3g81kAhr+gQDI7y5UIC ador//wjsWi+9ymdesWj+r2pgRjRnSXwcIns7IfO6pyxq/UiHt8Kfn3S0QdNNhzhkFkd sId3I81u4C2SeoVWQD6no/GvOo6K0QUpZvgR7lYIWz42kXKRSmk9qR4xiqGSlGWXwjSO 4b/qn28qYokrUBEROwBSG/9uhkQyemJZAF75UQFLGMvtKho+nmdSKPZLiEr5DKvO1WkK rR6EJ8WQUKHxmNJpOHqRtV7zj4X/wd6ZcQu2EYHpINOUDOMNwf1Sgzpl281kanf+f9N8 uHtA== X-Gm-Message-State: AOJu0Yy3QHKItzVrTRDk9025MTschPCLMvoy6HluBvr7ma4DTGdZqzhT RVMVNWGDs1MnislmZcjoOskLTQ== X-Received: by 2002:a05:600c:4593:b0:401:c8b9:4b86 with SMTP id r19-20020a05600c459300b00401c8b94b86mr417120wmo.9.1697662732729; Wed, 18 Oct 2023 13:58:52 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id x19-20020a05600c421300b003fc16ee2864sm2569006wmh.48.2023.10.18.13.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:58:52 -0700 (PDT) From: Dmitry Safonov To: David Ahern , Eric Dumazet , Paolo Abeni , Jakub Kicinski , "David S. Miller" Cc: linux-kernel@vger.kernel.org, Dmitry Safonov , Andy Lutomirski , Ard Biesheuvel , Bob Gilligan , Dan Carpenter , David Laight , Dmitry Safonov <0x7f454c46@gmail.com>, Donald Cassidy , Eric Biggers , "Eric W. Biederman" , Francesco Ruggeri , "Gaillardetz, Dominik" , Herbert Xu , Hideaki YOSHIFUJI , Ivan Delalande , Leonard Crestez , "Nassiri, Mohammad" , Salam Noureddine , Simon Horman , "Tetreault, Francois" , netdev@vger.kernel.org Subject: [PATCH v15 net-next 19/23] net/tcp: Allow asynchronous delete for TCP-AO keys (MKTs) Date: Wed, 18 Oct 2023 21:57:33 +0100 Message-ID: <20231018205806.322831-20-dima@arista.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231018205806.322831-1-dima@arista.com> References: <20231018205806.322831-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 18 Oct 2023 14:01:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780128575126381852 X-GMAIL-MSGID: 1780128575126381852 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 Co-developed-by: Francesco Ruggeri Signed-off-by: Francesco Ruggeri Co-developed-by: Salam Noureddine Signed-off-by: Salam Noureddine Signed-off-by: Dmitry Safonov Acked-by: David Ahern --- include/uapi/linux/tcp.h | 3 ++- net/ipv4/tcp_ao.c | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index a411aef00318..25d62ecb9532 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -395,7 +395,8 @@ struct tcp_ao_del { /* setsockopt(TCP_AO_DEL_KEY) */ __s32 ifindex; /* L3 dev index for VRF */ __u32 set_current :1, /* corresponding ::current_key */ set_rnext :1, /* corresponding ::rnext */ - reserved :30; /* must be 0 */ + del_async :1, /* only valid for listen sockets */ + reserved :29; /* must be 0 */ __u16 reserved2; /* padding, must be 0 */ __u8 prefix; /* peer's address prefix */ __u8 sndid; /* SendID for outgoing segments */ diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c index cbc1ee0f5b9a..acbeb635fe29 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -1628,7 +1628,7 @@ static int tcp_ao_add_cmd(struct sock *sk, unsigned short int family, } static int tcp_ao_delete_key(struct sock *sk, struct tcp_ao_info *ao_info, - struct tcp_ao_key *key, + bool del_async, struct tcp_ao_key *key, struct tcp_ao_key *new_current, struct tcp_ao_key *new_rnext) { @@ -1636,11 +1636,24 @@ static int tcp_ao_delete_key(struct sock *sk, struct tcp_ao_info *ao_info, hlist_del_rcu(&key->node); + /* Support for async delete on listening sockets: as they don't + * need current_key/rnext_key maintaining, we don't need to check + * them and we can just free all resources in RCU fashion. + */ + if (del_async) { + atomic_sub(tcp_ao_sizeof_key(key), &sk->sk_omem_alloc); + call_rcu(&key->rcu, tcp_ao_key_free_rcu); + return 0; + } + /* At this moment another CPU could have looked this key up * while it was unlinked from the list. Wait for RCU grace period, * after which the key is off-list and can't be looked up again; * the rx path [just before RCU came] might have used it and set it * as current_key (very unlikely). + * Free the key with next RCU grace period (in case it was + * current_key before tcp_ao_current_rnext() might have + * changed it in forced-delete). */ synchronize_rcu(); if (new_current) @@ -1711,6 +1724,8 @@ static int tcp_ao_del_cmd(struct sock *sk, unsigned short int family, if (!new_rnext) return -ENOENT; } + if (cmd.del_async && sk->sk_state != TCP_LISTEN) + return -EINVAL; if (family == AF_INET) { 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, if (key == new_current || key == new_rnext) continue; - return tcp_ao_delete_key(sk, ao_info, key, - new_current, new_rnext); + return tcp_ao_delete_key(sk, ao_info, cmd.del_async, key, + new_current, new_rnext); } return -ENOENT; }