Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2904427rdb; Wed, 4 Oct 2023 15:38:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgzDW3ajgjhezcP20qdBPT6nkIDmohSM6xoOchJsaqVXwVj3jj1qwJOnNncpmmQLT6tYVO X-Received: by 2002:a17:902:f541:b0:1c4:13cd:b85f with SMTP id h1-20020a170902f54100b001c413cdb85fmr4353757plf.5.1696459096461; Wed, 04 Oct 2023 15:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696459096; cv=none; d=google.com; s=arc-20160816; b=a8J7p8hr0DzOdfKe/Vxh+9SOodpF1XkXgZTZr1GWvDnw5jydB/En1QW+ThMmmvJON4 eRj7Bu5VQ3OnbjDKVJJQiSlyMMs8feDjz0G4JtReypp2GZeJbi2urpj084Dw4DbREPgK Z7vz1w7NhXsscnVK4skVsqmIh3jh5al/rwx7oMTbq4rj6WVzp7eSmVju4M10Q6pPjo8r ChBRenk6W/adhLjD3rdkv8KeO9X1jd9Z8VzBFbCaxkxDy1EIpuvKvlpNxyM90V2pLOWU Sb5spALrR4eYciZ7EN/pZBI7I9+g64UNTJlv9yPpo6dQMIOWfcdlOHxrNuV8tsMcGOLj vsiA== 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=f8/tbOtzLwzXjPoSok4+tQw2t+A47VbB70M6WtqpG8s=; fh=58X8Twod/aefd4Yph/F0FPyIOMSYi96Sqi5HmPAz0To=; b=tEDDB0ysI5IJkvU2lmyfuJc0mJA1E76yQ2CQh5p+Ae6UCXxYy4er7SpQyQrnXkLT+K 1YzpQ297WEVQUvh4/qurf7GWAxo/zGztJGJlJdq5XgbAIAITKrmJzmoN12m++cDYlqNm DyIyJWFIl5peRQtiFkCgtgmqsvShvaJnp2kcB210lZ/lAB3H7gLmEMEUTGUtzmAyCr94 /khmZ1zc3gE0up91F3xi6l9xolVzsYtC2XHMYBAfALgwuFjSbdDe7UEfOGidQu0kshQ8 5hHiQcPFYSqm05b7P8fbaMkCiqCZ+1+AzFKJvuAFI0ap0an0BnVpcGvde43glOOyOyJq /kYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Zik82oG0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x11-20020a1709028ecb00b001c46467a211si158960plo.193.2023.10.04.15.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:38:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Zik82oG0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 147408514B04; Wed, 4 Oct 2023 15:38:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240843AbjJDWiG (ORCPT + 99 others); Wed, 4 Oct 2023 18:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240321AbjJDWhk (ORCPT ); Wed, 4 Oct 2023 18:37:40 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA861728 for ; Wed, 4 Oct 2023 15:37:12 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4066241289bso3205625e9.0 for ; Wed, 04 Oct 2023 15:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1696459030; x=1697063830; 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=f8/tbOtzLwzXjPoSok4+tQw2t+A47VbB70M6WtqpG8s=; b=Zik82oG0wV17keBl4Egc7tnzFWfgUHQBYpI4hhaO6P5EhhSh8C8+T1GhpIEadzZ8qp 4bpcLGtbh2yeBeGyBOTRG1dSRcVziNqMjVNmDYhA7XPR7R+9rqO222+ziXOzejquAKtu UBRzfPtdeN0c5wRTTDAxFgJPe1EY0sv2GFn34h0mvW15NRs7GayKsYh2AW6YlD5f46Yv TpfzvlI1p5KY/yJTG7j4n3Z6ERAaxXz4ijbuC1RklKqlzQOe8jOlT3mGHuWZksTq4WxP I+RorAjbw02U6vey0zqbRqMm47Bu4NsUQGSt9A6BCy5A09W3AluU5KIgpMFpBwMvlI4p Fa5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696459030; x=1697063830; 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=f8/tbOtzLwzXjPoSok4+tQw2t+A47VbB70M6WtqpG8s=; b=IL7YQr520ImhfqESm5UwjcSWlOzY0Kjni8aDuPGxlLI8RDTPG6SjmaF5GM4O39JP60 kABdfQJz9txrW1srohTbCUu/ov5slIdm/4MJI2fv+0QQ8OYB8vWqRulTOD9DwA+YtZNh +BhG/8aSN/BZYnSIybqD561+knWyUJZoPPc7GURvoZbj/jcGY/IO2PoGiZK8rjFuGXyo 8zi2IsTo9LhVN0Y6JrCLKv5PCBMGvMLiEGDD3IwfFMTbQpv03PBTR6TkSOow5CUvX6nb s+gXllv932NvB/ln79gBjycvkyDlGKkMFBRULWIf8qTJB9UPI0dQ8OkVVMjxrs1OmK8r ZNKw== X-Gm-Message-State: AOJu0Yy0+2ZAAqPnjeRbPyUPwkVxnxhKib6XyfSpU0g7O+dVFS+7Wo7f H5pOpCQZJFCWCHQiNHnUXnYuWA== X-Received: by 2002:a7b:cc99:0:b0:405:39b4:313e with SMTP id p25-20020a7bcc99000000b0040539b4313emr3375063wma.13.1696459030650; Wed, 04 Oct 2023 15:37:10 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id z11-20020a5d4d0b000000b0031ff89af0e4sm181412wrt.99.2023.10.04.15.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:37:10 -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 v13 net-next 19/23] net/tcp: Allow asynchronous delete for TCP-AO keys (MKTs) Date: Wed, 4 Oct 2023 23:36:23 +0100 Message-ID: <20231004223629.166300-20-dima@arista.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231004223629.166300-1-dima@arista.com> References: <20231004223629.166300-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:38:15 -0700 (PDT) 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 5962df17ecbe..afd5943a9972 100644 --- a/net/ipv4/tcp_ao.c +++ b/net/ipv4/tcp_ao.c @@ -1625,7 +1625,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) { @@ -1633,11 +1633,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) @@ -1708,6 +1721,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; @@ -1755,8 +1770,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; } -- 2.42.0