From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2079AC7EE36 for ; Fri, 3 Mar 2023 01:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbjCCBVr (ORCPT ); Thu, 2 Mar 2023 20:21:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCCBVq (ORCPT ); Thu, 2 Mar 2023 20:21:46 -0500 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D79515E5 for ; Thu, 2 Mar 2023 17:21:44 -0800 (PST) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 322KUcba013692 for ; Thu, 2 Mar 2023 17:21:43 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=s2048-2021-q4; bh=VomEQLuecW7pJaqnczPHW87f9seSSUZXEb3h+43/qBc=; b=MocY9bO43ArklCS/PotxcaauE0fkXatwgLkNC4qA7p9BVf4qJPvd9CX0tyF80JFfk/6A AFaUwrB1nr+osNBnnodSCY+/TruHxvHG5X0tsHTnKyRpTwD4sbdm4W/ACUVqrHsPOyYB 8hDrp/JKPfi1dEykFJbn7A1b2ketKtiGCA5rzluOAg8prSFswY/Lfi9MHF5XRrUgzS0C qiDB7frZJ4zoFQ0xn5jfCi6X9nln0lHBB3li+fAt6jkNdODZ3JO7N90xzie48gzgHN2K PG2Fc2cfg+5LaTc5mZv/IBi7cO/JjUyCsVIjTtZ3eW4UUzl2ZGom6AZ65Wx6sKzzrMIp Eg== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3p2tfhdfsg-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 02 Mar 2023 17:21:43 -0800 Received: from twshared21760.39.frc1.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Thu, 2 Mar 2023 17:21:40 -0800 Received: by devbig931.frc1.facebook.com (Postfix, from userid 460691) id 93DE56644D7E; Thu, 2 Mar 2023 17:21:30 -0800 (PST) From: Kui-Feng Lee To: , , , , , , CC: Kui-Feng Lee Subject: [PATCH bpf-next v3 0/8] Transit between BPF TCP congestion controls. Date: Thu, 2 Mar 2023 17:21:14 -0800 Message-ID: <20230303012122.852654-1-kuifeng@meta.com> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: qKZybGUY2Fr6gbrYSglORMP1HvMiHTTF X-Proofpoint-ORIG-GUID: qKZybGUY2Fr6gbrYSglORMP1HvMiHTTF Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-03_01,2023-03-02_02,2023-02-09_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Major changes: - Create bpf_links in the kernel for BPF struct_ops to register and unregister it. - Enables switching between implementations of bpf-tcp-cc under a name instantly by replacing the backing struct_ops map of a bpf_link. Previously, BPF struct_ops didn't go off, as even when the user program creating it was terminated, none of these ever were pinned. For instance, the TCP congestion control subsystem indirectly maintains a reference count on the struct_ops of any registered BPF implemented algorithm. Thus, the algorithm won't be deactivated until someone deliberately unregisters it. For compatibility with other BPF programs, bpf_links have been created to work in coordination with struct_ops maps. This ensures that the registration and unregistration of these respective maps is carried out at the start and end of the bpf_link. We also faced complications when attempting to replace an existing TCP congestion control algorithm with a new implementation on the fly. A struct_ops map was used to register a TCP congestion control algorithm with a unique name. We had to either register the alternative implementation with a new name and move over or unregister the current one before being able to reregistration with the same name. To fix this problem, we can an option to migrate the registration of the algorithm from struct_ops maps to bpf_links. By modifying the backing map of a bpf_link, it suddenly becomes possible to replace an existing TCP congestion control algorithm with ease. The major differences from v2: - Simplify states - Remove TOBEUNREG. - Rename UNREG to READY. - Stop using the refcnt of the kvalue of a struct_ops. Explicitly increase and decrease the refcount of struct_ops. - Prepare kernel vdata during the load phase of libbpf. The major differences from v1: - Added bpf_struct_ops_link to replace the previous union-based approach. - Added UNREG and TOBEUNREG to the state of bpf_struct_ops_map. - bpf_struct_ops_transit_state() maintains state transitions. - Fixed synchronization issue. - Prepare kernel vdata of struct_ops during the loading phase of bpf_object. - Merged previous patch 3 to patch 1. v2: https://lore.kernel.org/bpf/20230223011238.12313-1-kuifeng@meta.com/ v1: https://lore.kernel.org/bpf/20230214221718.503964-1-kuifeng@meta.com/ Kui-Feng Lee (8): bpf: Maintain the refcount of struct_ops maps directly. bpf: Create links for BPF struct_ops maps. net: Update an existing TCP congestion control algorithm. libbpf: Create a bpf_link in bpf_map__attach_struct_ops(). bpf: Update the struct_ops of a bpf_link. libbpf: Update a bpf_link with another struct_ops. libbpf: Use .struct_ops.link section to indicate a struct_ops with a link. selftests/bpf: Test switching TCP Congestion Control algorithms. include/linux/bpf.h | 16 ++ include/net/tcp.h | 2 + include/uapi/linux/bpf.h | 20 +- kernel/bpf/bpf_struct_ops.c | 236 +++++++++++++++--- kernel/bpf/syscall.c | 91 +++++-- net/bpf/bpf_dummy_struct_ops.c | 6 + net/ipv4/bpf_tcp_ca.c | 8 +- net/ipv4/tcp_cong.c | 57 ++++- tools/include/uapi/linux/bpf.h | 12 +- tools/lib/bpf/libbpf.c | 184 +++++++++++--- tools/lib/bpf/libbpf.h | 1 + tools/lib/bpf/libbpf.map | 2 + .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 38 +++ .../selftests/bpf/progs/tcp_ca_update.c | 62 +++++ 14 files changed, 634 insertions(+), 101 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/tcp_ca_update.c --=20 2.30.2