From patchwork Mon Nov 15 17:11:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12620049 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5A3FC433F5 for ; Mon, 15 Nov 2021 17:16:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF4D76327B for ; Mon, 15 Nov 2021 17:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236341AbhKORRv (ORCPT ); Mon, 15 Nov 2021 12:17:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236836AbhKORQI (ORCPT ); Mon, 15 Nov 2021 12:16:08 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F71C079781 for ; Mon, 15 Nov 2021 09:11:57 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id x5so4946852pfr.0 for ; Mon, 15 Nov 2021 09:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qayLb2xV/LFUDq1f3MKbLUkAQUL6V+68jcfEVuc4xqs=; b=RRa8MvwpTkr5qVypRG5DMnyh+aFzJf/39/a7rKNErMECzM1zoslAxL0PKwMNZ0rYFi EZl5G0Si07JfBCtXnkS5etmXZKCyF6YoIhU5oETcx3+3y8j+4r9AXSf262mcCNQM2a8P J03pr7GS7aFoItLz+Esl+0no8S0L93flLNnvZ7Ek+EM/d8zTUs0WAcM0g2Jaqup2twxG /nPEIPy04e06xEhhjmqKv3C3F/LEJVlTkbn7pyfAwy5SLwQyM0gzAbTnzHKFqSibmQyO wCe/hBc8FiFe3c/K21kWL/3TBoFvHcGFomy89tFsE7ah9etyEgQZlcZNFMa5I+T5SGez PkcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qayLb2xV/LFUDq1f3MKbLUkAQUL6V+68jcfEVuc4xqs=; b=NQOZCSCOs99ym/v5CbPPZKfD+Kz3HTCAerEaxQdmaDs1ydeTjDEiDz3V/ApbT+vpq6 RUsFmX1sDoa3fnr8f+uxNI0uJSZbFufAZUXPdor75DrdmaBN4lk0DqVNf8FxYEcUlWP0 v8UTW+nDJJIA1w/VsGQZidlFJyO8nc58o7TSpJ9k5z8dupGAtyTyjctqBxkY1HNsnlPa jroH9mIr5imiuFwMTuwKsTMS++QcAdcNdJAb6UM5SziLBehShcSmkb7JLasdcFMaCYEh 6t8hC811p2z3Zu1gwy6U6KcWCzx+JpnyKhIAf10Lb886xplo4JxzqP2KuprIk2CVGG08 QAPw== X-Gm-Message-State: AOAM532J2li68olMTc1GCad3ue+h5uu6/MbieLdt+4gebgkWFEbT+5T/ EGZMJ/fs1/oNOiw5XsmYPkc= X-Google-Smtp-Source: ABdhPJzYwsRCqYRoYG5YZSRxW1JDRVCsrSupd7zbAT0JdP9dr0DXzWD85+ozggcA4QwKtZvGbHEGbA== X-Received: by 2002:aa7:84d7:0:b0:49f:aa6d:8745 with SMTP id x23-20020aa784d7000000b0049faa6d8745mr34340047pfn.50.1636996315587; Mon, 15 Nov 2021 09:11:55 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:4994:f3d6:2eb1:61cb]) by smtp.gmail.com with ESMTPSA id j127sm16466632pfg.14.2021.11.15.09.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 09:11:55 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 1/4] net: inline sock_prot_inuse_add() Date: Mon, 15 Nov 2021 09:11:47 -0800 Message-Id: <20211115171150.3646016-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211115171150.3646016-1-eric.dumazet@gmail.com> References: <20211115171150.3646016-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet sock_prot_inuse_add() is very small, we can inline it. Signed-off-by: Eric Dumazet --- include/net/sock.h | 14 +++++++++++--- net/core/sock.c | 11 ----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index b32906e1ab55527b5418f203d3de05853863f166..3f08e9d55f0ceed4ec4593012e6c856b400fc33f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1419,13 +1419,21 @@ proto_memory_pressure(struct proto *prot) #ifdef CONFIG_PROC_FS +#define PROTO_INUSE_NR 64 /* should be enough for the first time */ +struct prot_inuse { + int val[PROTO_INUSE_NR]; +}; /* Called with local bh disabled */ -void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc); +static inline void sock_prot_inuse_add(const struct net *net, + const struct proto *prot, int val) +{ + __this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); +} int sock_prot_inuse_get(struct net *net, struct proto *proto); int sock_inuse_get(struct net *net); #else -static inline void sock_prot_inuse_add(struct net *net, struct proto *prot, - int inc) +static inline void sock_prot_inuse_add(const struct net *net, + const struct proto *prot, int val) { } #endif diff --git a/net/core/sock.c b/net/core/sock.c index 8f2b2f2c0e7b1decdb4a5c8d86327ed7caa62c99..fac46efd31fd44b4105c6004b4491aa11e1ed67c 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3532,19 +3532,8 @@ void sk_get_meminfo(const struct sock *sk, u32 *mem) } #ifdef CONFIG_PROC_FS -#define PROTO_INUSE_NR 64 /* should be enough for the first time */ -struct prot_inuse { - int val[PROTO_INUSE_NR]; -}; - static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR); -void sock_prot_inuse_add(struct net *net, struct proto *prot, int val) -{ - __this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); -} -EXPORT_SYMBOL_GPL(sock_prot_inuse_add); - int sock_prot_inuse_get(struct net *net, struct proto *prot) { int cpu, idx = prot->inuse_idx; From patchwork Mon Nov 15 17:11:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12621109 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E035C4332F for ; Tue, 16 Nov 2021 02:27:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E92C160EFE for ; Tue, 16 Nov 2021 02:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243303AbhKPC3s (ORCPT ); Mon, 15 Nov 2021 21:29:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237026AbhKORQM (ORCPT ); Mon, 15 Nov 2021 12:16:12 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8815EC06120C for ; Mon, 15 Nov 2021 09:11:58 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso13737945pji.0 for ; Mon, 15 Nov 2021 09:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v9sQDD/4/Q8DJlCorQNfKu6150bTPmEtz37IdYnRvKY=; b=Lrx8pdO4QmetG9vTbYCwYD7pU1xvquwvb3qoSX4Ozl/1LMBD5rOAQ+Fl1Rf9Qvwzbu BnnVIg7wMdr9gQNs1EhT/lIeE4AsTMkLmgQsSTh/fRHsy4BUt2+JeL0LrrNE7G3vskDj 4Vry7k1lrvp83ZdOqEtQAcEmogmp/fbIQULggxwqCUk8vSIiLGgjwNWBQH9ujfz2CMof D04uRGBW9V2Z7tjLkhPscaCmYUbqUyChSzpxw75WfMl4K3roSf5YAGwiNeN184af42Fd twuS1/uSquFvW70q6qvkjdFX2RnPB2PqJaifwkWyTY23PM2Hebzmq9BYJLlImIgDggO7 Kp+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v9sQDD/4/Q8DJlCorQNfKu6150bTPmEtz37IdYnRvKY=; b=jND1f1vmKYCasmxYPAmZp/9Jn5OXhEASfchS2exfd2xewKY/UtGYHAy3rd3JNrNtUu L7GZThaCrc4iZGaBWSdL+rMKKXD3mgVUqtRLBsYlVo4AvZy1pAbDswwxoVeiEKU52yBH XXM5u6OwmBWrQsWoYIC438wYnie8Q9sw+BLeq/FV8EyCGOflQlUTeJ8dYN0Qsn7dFZdP 5YXpJuhqMHiubQpmYF5GDGWqMSZftInI7p/0LZZc9AZXMrJiV/RqrE47QWL5MeiuEnRf vBPPdYgfMjDfIzx7foaoUdHtpRszrIbPGBXptekLaQRrSJddJQMdVStMhiomecinM2wS HAOw== X-Gm-Message-State: AOAM531IAped5Uog08S5s0MB49PwoQrR+yw2Z3diTz3NkUrIMz39Pash A1BQUMd/Mi9DONVxMNNXKYo= X-Google-Smtp-Source: ABdhPJyC1bHhBSwGPU/ekoPpiXeAylG69a6kidwEX5JcKhMxw4JZzrOwS42KHgv3dcNzC10y31RScQ== X-Received: by 2002:a17:90b:314c:: with SMTP id ip12mr133285pjb.162.1636996318130; Mon, 15 Nov 2021 09:11:58 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:4994:f3d6:2eb1:61cb]) by smtp.gmail.com with ESMTPSA id j127sm16466632pfg.14.2021.11.15.09.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 09:11:57 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 2/4] net: make sock_inuse_add() available Date: Mon, 15 Nov 2021 09:11:48 -0800 Message-Id: <20211115171150.3646016-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211115171150.3646016-1-eric.dumazet@gmail.com> References: <20211115171150.3646016-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet MPTCP hard codes it, let us instead provide this helper. Signed-off-by: Eric Dumazet --- include/net/sock.h | 10 ++++++++++ net/core/sock.c | 10 ---------- net/mptcp/subflow.c | 4 +--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 3f08e9d55f0ceed4ec4593012e6c856b400fc33f..cdc7ebc049b41b00aa7c851a6f1df6e58bae8430 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1429,6 +1429,12 @@ static inline void sock_prot_inuse_add(const struct net *net, { __this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); } + +static inline void sock_inuse_add(const struct net *net, int val) +{ + this_cpu_add(*net->core.sock_inuse, val); +} + int sock_prot_inuse_get(struct net *net, struct proto *proto); int sock_inuse_get(struct net *net); #else @@ -1436,6 +1442,10 @@ static inline void sock_prot_inuse_add(const struct net *net, const struct proto *prot, int val) { } + +static inline void sock_inuse_add(const struct net *net, int val) +{ +} #endif diff --git a/net/core/sock.c b/net/core/sock.c index fac46efd31fd44b4105c6004b4491aa11e1ed67c..214c2e816c63dba9146557a622516e73c1da142e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -144,8 +144,6 @@ static DEFINE_MUTEX(proto_list_mutex); static LIST_HEAD(proto_list); -static void sock_inuse_add(struct net *net, int val); - /** * sk_ns_capable - General socket capability test * @sk: Socket to use a capability on or through @@ -3546,11 +3544,6 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot) } EXPORT_SYMBOL_GPL(sock_prot_inuse_get); -static void sock_inuse_add(struct net *net, int val) -{ - this_cpu_add(*net->core.sock_inuse, val); -} - int sock_inuse_get(struct net *net) { int cpu, res = 0; @@ -3629,9 +3622,6 @@ static inline void release_proto_idx(struct proto *prot) { } -static void sock_inuse_add(struct net *net, int val) -{ -} #endif static void tw_prot_cleanup(struct timewait_sock_ops *twsk_prot) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 6172f380dfb763b43c6d996b4896215cad9c7d7b..49787a1d7b3467acdfe284fd1494ac4c4a6eaf5c 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -1534,9 +1534,7 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock) */ sf->sk->sk_net_refcnt = 1; get_net(net); -#ifdef CONFIG_PROC_FS - this_cpu_add(*net->core.sock_inuse, 1); -#endif + sock_inuse_add(net, 1); err = tcp_set_ulp(sf->sk, "mptcp"); release_sock(sf->sk); From patchwork Mon Nov 15 17:11:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12621111 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E159C4321E for ; Tue, 16 Nov 2021 02:27:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CD8460EFE for ; Tue, 16 Nov 2021 02:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243701AbhKPC34 (ORCPT ); Mon, 15 Nov 2021 21:29:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236770AbhKORQf (ORCPT ); Mon, 15 Nov 2021 12:16:35 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72DDC061220 for ; Mon, 15 Nov 2021 09:11:59 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id x7so13351128pjn.0 for ; Mon, 15 Nov 2021 09:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ztiZtpvaPEESRC+ARrg5moYa1E+yP0K/qu/oBI/4DRE=; b=pNZ1JIHCUGbBz0R0xepzgkii0ulprOHCuUUjAa9NWraJIajU0WSxxEayO6pT0IICRs ZOQ6a5+w1rBzfs9RG7pZ5hHayvqtbN4vhKz1VIVMWKv5uKHEjWFjFLacJUKo4P97Iz4y nsdxPetw0KcEBHWImbjyaeHYUlINzRiU4kJnCFJjq32GOZ1w/US19FehSNg3MUCgptRN Rk/yoz19Lbxgr7HoE7ATKh1NlQn0+6Hf2wmabJaOd2rN92twpbd2yEbjH7HuyqJe6g4O jcREE6I+Yu0b3SGS0qhfgucLxRb1ijAcVTQrISEorW43c7PrmPhFPIKDfWb+ErWIEGqf FHzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ztiZtpvaPEESRC+ARrg5moYa1E+yP0K/qu/oBI/4DRE=; b=ml6CqGNrMjOHpwjpSis2zpC90PmSIyiDl/ivGz7oIHa/hLUKtccbJmAjNYJmAUWzkh Od0XooENkUikIS8QD2lwLb9KlXC/CjJXCeWVEw5lhirjS1uU3H4cJCf4FY/CI5UyZoHP wSRlTKNvhpdcD0Sure6xHB7j7g0BoGZg+h6qdKdbK1d2cNcQEx8UWKywVvB4bBwQrVpy hqxkjKp6xr6dmnYOzm2N1zi81FSS6KlAtRAkhmmcI/kPD95+yK4OQLPMrVvxni5tLX/c d+dpDFy3dJ/S2bA3yR8XwAWmiZhTXI+NTadb93zCtvXom+1BvF6ttqtSleMoarTikHF5 i1ng== X-Gm-Message-State: AOAM530Us3/aWP750O3BwMDytRPn1qNGRXWBQ5qBTu/STPqcnr1V3ws/ 5WiDiidEJ/BNFdKHQ1lclEfbOFDEchw= X-Google-Smtp-Source: ABdhPJzLhrXFe0/yyqjswPdHvEDSNNtxcSZIQxX42gJTwC9NE7T33kOD0c1uYPc4XDeBxTRR4Yocyw== X-Received: by 2002:a17:90a:d48f:: with SMTP id s15mr161188pju.64.1636996319379; Mon, 15 Nov 2021 09:11:59 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:4994:f3d6:2eb1:61cb]) by smtp.gmail.com with ESMTPSA id j127sm16466632pfg.14.2021.11.15.09.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 09:11:59 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 3/4] net: merge net->core.prot_inuse and net->core.sock_inuse Date: Mon, 15 Nov 2021 09:11:49 -0800 Message-Id: <20211115171150.3646016-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211115171150.3646016-1-eric.dumazet@gmail.com> References: <20211115171150.3646016-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet net->core.sock_inuse is a per cpu variable (int), while net->core.prot_inuse is another per cpu variable of 64 integers. per cpu allocator tend to place them in very different places. Grouping them together makes sense, since it makes updates potentially faster, if hitting the same cache line. Signed-off-by: Eric Dumazet --- include/net/netns/core.h | 1 - include/net/sock.h | 3 ++- net/core/sock.c | 12 +----------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/include/net/netns/core.h b/include/net/netns/core.h index 36c2d998a43c015c4b917428ec33f5839cde89b1..552bc25b19335e2ee07effa2550bbe5944eb33aa 100644 --- a/include/net/netns/core.h +++ b/include/net/netns/core.h @@ -12,7 +12,6 @@ struct netns_core { int sysctl_somaxconn; #ifdef CONFIG_PROC_FS - int __percpu *sock_inuse; struct prot_inuse __percpu *prot_inuse; #endif }; diff --git a/include/net/sock.h b/include/net/sock.h index cdc7ebc049b41b00aa7c851a6f1df6e58bae8430..fefffeb1cc3d5a11615afbc34e5cd7521bd6f502 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1421,6 +1421,7 @@ proto_memory_pressure(struct proto *prot) #ifdef CONFIG_PROC_FS #define PROTO_INUSE_NR 64 /* should be enough for the first time */ struct prot_inuse { + int all; int val[PROTO_INUSE_NR]; }; /* Called with local bh disabled */ @@ -1432,7 +1433,7 @@ static inline void sock_prot_inuse_add(const struct net *net, static inline void sock_inuse_add(const struct net *net, int val) { - this_cpu_add(*net->core.sock_inuse, val); + this_cpu_add(net->core.prot_inuse->all, val); } int sock_prot_inuse_get(struct net *net, struct proto *proto); diff --git a/net/core/sock.c b/net/core/sock.c index 214c2e816c63dba9146557a622516e73c1da142e..2f58e4d3e76296280aece28314b8695d0d40cf02 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3549,7 +3549,7 @@ int sock_inuse_get(struct net *net) int cpu, res = 0; for_each_possible_cpu(cpu) - res += *per_cpu_ptr(net->core.sock_inuse, cpu); + res += per_cpu_ptr(net->core.prot_inuse, cpu)->all; return res; } @@ -3561,22 +3561,12 @@ static int __net_init sock_inuse_init_net(struct net *net) net->core.prot_inuse = alloc_percpu(struct prot_inuse); if (net->core.prot_inuse == NULL) return -ENOMEM; - - net->core.sock_inuse = alloc_percpu(int); - if (net->core.sock_inuse == NULL) - goto out; - return 0; - -out: - free_percpu(net->core.prot_inuse); - return -ENOMEM; } static void __net_exit sock_inuse_exit_net(struct net *net) { free_percpu(net->core.prot_inuse); - free_percpu(net->core.sock_inuse); } static struct pernet_operations net_inuse_ops = { From patchwork Mon Nov 15 17:11:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12621113 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05A4EC433F5 for ; Tue, 16 Nov 2021 02:27:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E50F860F38 for ; Tue, 16 Nov 2021 02:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240521AbhKPC37 (ORCPT ); Mon, 15 Nov 2021 21:29:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236897AbhKORQh (ORCPT ); Mon, 15 Nov 2021 12:16:37 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1421C079789 for ; Mon, 15 Nov 2021 09:12:01 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id 200so15151915pga.1 for ; Mon, 15 Nov 2021 09:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WO8dTR6SDc0ydvzmoCXtSF00V+odJLso1OiEVZFx7X0=; b=JSAgaJlf+SMDXLQdCZo+F0xtasZDpsrhHm8LXq2HUiX2CLTxfCtzSRjk3OPQieQqxe h+zBsx2N0U/0lNCNtcrStON236apACp0Hu4AK4c7lGjuMs3m6KKK/ZDE+w9YhFkq3Xcb medX4laKaLcXujZ1+FQ+7Csp8rsCQPSy3UdbogqCHr/Pq5s+O12e+0hQUkZwiHZHrGAU 5AWlWKnnK49Rw5dIx/kHtK79E75SBjWJuKujsVYVlC3FJBFF7jFKSm3O5KxbAidACvla QaKgUOOn7VoaMuzuyuuCl+MinXsal02h+owpsV1Ab6oFz6jQXFiAIYAGodl0M7toMUqh zIWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WO8dTR6SDc0ydvzmoCXtSF00V+odJLso1OiEVZFx7X0=; b=PdCVnFw5aW1d1v8Im+1z9p3F4frh4yuCH9vtYLRJgw4HSaAl5OGUyBx4KxOP52baxF BttH7eB5vOKTg46fGJucMSSu/arZCIvld5GJozFgcdcX/JoE/V9hNuKyixazYymbDDOP rs3F89o4I9iPBcD3j3n8XMcwWhYVuurTAkf82xgTxgqr0HEdzl+TErrucXGzSFiBpEBN pTPmoSTEW8BxWY+ZXkbLt0RqM5/YMfcKMCaZnSgUuy0fw67FdIPxbvWf5hKSWKJe+GXw QAP6fCYentS5kraZcLvUwvbY1w9K+0vq5MUdZrW0i00VKDk7su45nItZxofP0CpOPzl4 Mg4Q== X-Gm-Message-State: AOAM533BjphHgypGwWjsy1v7rHga68ehudGf1UNy5UvDFYnUadQrhKju ueqRYWQ+gaOud6M7o6ko78ob3WPlSks= X-Google-Smtp-Source: ABdhPJxZcyVG2df96ixqIX1kIkmwVLhgn6348GI/AvZhCpYW7lfXhUHvdZjaIKWk8Ch684jfwiQhDw== X-Received: by 2002:a05:6a00:2351:b0:47b:d092:d2e4 with SMTP id j17-20020a056a00235100b0047bd092d2e4mr33514168pfj.76.1636996321315; Mon, 15 Nov 2021 09:12:01 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:4994:f3d6:2eb1:61cb]) by smtp.gmail.com with ESMTPSA id j127sm16466632pfg.14.2021.11.15.09.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 09:12:01 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 4/4] net: drop nopreempt requirement on sock_prot_inuse_add() Date: Mon, 15 Nov 2021 09:11:50 -0800 Message-Id: <20211115171150.3646016-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211115171150.3646016-1-eric.dumazet@gmail.com> References: <20211115171150.3646016-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This is distracting really, let's make this simpler, because many callers had to take care of this by themselves, even if on x86 this adds more code than really needed. Signed-off-by: Eric Dumazet --- include/net/sock.h | 4 ++-- net/ieee802154/socket.c | 4 ++-- net/ipv4/raw.c | 2 +- net/ipv6/ipv6_sockglue.c | 8 ++++---- net/netlink/af_netlink.c | 4 ---- net/packet/af_packet.c | 4 ---- net/sctp/socket.c | 5 ----- net/smc/af_smc.c | 2 +- net/unix/af_unix.c | 4 ---- net/xdp/xsk.c | 4 ---- 10 files changed, 10 insertions(+), 31 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index fefffeb1cc3d5a11615afbc34e5cd7521bd6f502..7e8330599f633c5029e15e9c5e859d183ae87127 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1424,11 +1424,11 @@ struct prot_inuse { int all; int val[PROTO_INUSE_NR]; }; -/* Called with local bh disabled */ + static inline void sock_prot_inuse_add(const struct net *net, const struct proto *prot, int val) { - __this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); + this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val); } static inline void sock_inuse_add(const struct net *net, int val) diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c index 7bb9ef35c57076252c700617dad4cc6cf275987a..3b2366a88c3ccbae787669c58a2827048aa4552c 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -174,8 +174,8 @@ static int raw_hash(struct sock *sk) { write_lock_bh(&raw_lock); sk_add_node(sk, &raw_head); - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); write_unlock_bh(&raw_lock); + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); return 0; } @@ -453,8 +453,8 @@ static int dgram_hash(struct sock *sk) { write_lock_bh(&dgram_lock); sk_add_node(sk, &dgram_head); - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); write_unlock_bh(&dgram_lock); + sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); return 0; } diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index bb446e60cf58057b448f094b4d6f48d6e91d113c..3910bb08a986f37984ad1a5eebca14c706deb315 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -99,8 +99,8 @@ int raw_hash_sk(struct sock *sk) write_lock_bh(&h->lock); sk_add_node(sk, head); + write_unlock_bh(&h->lock); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); - write_unlock_bh(&h->lock); return 0; } diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index 41efca817db4228f265235a471449a3790075ce7..04683ad6d3df83bbe8ff6c10885b3bf16483688c 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -471,10 +471,10 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, if (sk->sk_protocol == IPPROTO_TCP) { struct inet_connection_sock *icsk = inet_csk(sk); - local_bh_disable(); + sock_prot_inuse_add(net, sk->sk_prot, -1); sock_prot_inuse_add(net, &tcp_prot, 1); - local_bh_enable(); + sk->sk_prot = &tcp_prot; icsk->icsk_af_ops = &ipv4_specific; sk->sk_socket->ops = &inet_stream_ops; @@ -485,10 +485,10 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, if (sk->sk_protocol == IPPROTO_UDPLITE) prot = &udplite_prot; - local_bh_disable(); + sock_prot_inuse_add(net, sk->sk_prot, -1); sock_prot_inuse_add(net, prot, 1); - local_bh_enable(); + sk->sk_prot = prot; sk->sk_socket->ops = &inet_dgram_ops; sk->sk_family = PF_INET; diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 4c575324a98528bec4188acf27eecc2f98ae5e0a..1a19d179e913a3cf973aebab54af71b665345e0f 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -707,9 +707,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, if (err < 0) goto out_module; - local_bh_disable(); sock_prot_inuse_add(net, &netlink_proto, 1); - local_bh_enable(); nlk = nlk_sk(sock->sk); nlk->module = module; @@ -809,9 +807,7 @@ static int netlink_release(struct socket *sock) netlink_table_ungrab(); } - local_bh_disable(); sock_prot_inuse_add(sock_net(sk), &netlink_proto, -1); - local_bh_enable(); call_rcu(&nlk->rcu, deferred_put_nlk_sk); return 0; } diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 46943a18a10d5413db57955dbd24302af7ef1d97..a1ffdb48cc474dcf91bddfd1ab96386a89c20375 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -3102,9 +3102,7 @@ static int packet_release(struct socket *sock) sk_del_node_init_rcu(sk); mutex_unlock(&net->packet.sklist_lock); - preempt_disable(); sock_prot_inuse_add(net, sk->sk_prot, -1); - preempt_enable(); spin_lock(&po->bind_lock); unregister_prot_hook(sk, false); @@ -3368,9 +3366,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol, sk_add_node_tail_rcu(sk, &net->packet.sklist); mutex_unlock(&net->packet.sklist_lock); - preempt_disable(); sock_prot_inuse_add(net, &packet_proto, 1); - preempt_enable(); return 0; out2: diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 33391254fa82b2277551387bfcdf95259bea7e0d..055a6d3ec6e2e90e31a21c4303e912168c8afe5b 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -5068,12 +5068,9 @@ static int sctp_init_sock(struct sock *sk) SCTP_DBG_OBJCNT_INC(sock); - local_bh_disable(); sk_sockets_allocated_inc(sk); sock_prot_inuse_add(net, sk->sk_prot, 1); - local_bh_enable(); - return 0; } @@ -5099,10 +5096,8 @@ static void sctp_destroy_sock(struct sock *sk) list_del(&sp->auto_asconf_list); } sctp_endpoint_free(sp->ep); - local_bh_disable(); sk_sockets_allocated_dec(sk); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); - local_bh_enable(); } /* Triggered when there are no references on the socket anymore */ diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 59284da9116d787b95704be7fda6d62e351e36aa..ff5cd0c30741c0b562e66ce49a60bbc8d260f3b5 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -89,8 +89,8 @@ int smc_hash_sk(struct sock *sk) write_lock_bh(&h->lock); sk_add_node(sk, head); + write_unlock_bh(&h->lock); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); - write_unlock_bh(&h->lock); return 0; } diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 78e08e82c08c423ff2112fcef9e27995a6d39984..54e5553a150ec58d07b61a15f4823bc0622a0b6e 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -522,9 +522,7 @@ static void unix_sock_destructor(struct sock *sk) unix_release_addr(u->addr); atomic_long_dec(&unix_nr_socks); - local_bh_disable(); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); - local_bh_enable(); #ifdef UNIX_REFCNT_DEBUG pr_debug("UNIX %p is destroyed, %ld are still alive.\n", sk, atomic_long_read(&unix_nr_socks)); @@ -889,9 +887,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, memset(&u->scm_stat, 0, sizeof(struct scm_stat)); unix_insert_socket(unix_sockets_unbound(sk), sk); - local_bh_disable(); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); - local_bh_enable(); return sk; diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index f16074eb53c72a7040421d23028d5762e0c5658d..28ef3f4465ae9e63bc5326311f923260b88f0fe8 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -794,9 +794,7 @@ static int xsk_release(struct socket *sock) sk_del_node_init_rcu(sk); mutex_unlock(&net->xdp.lock); - local_bh_disable(); sock_prot_inuse_add(net, sk->sk_prot, -1); - local_bh_enable(); xsk_delete_from_maps(xs); mutex_lock(&xs->mutex); @@ -1396,9 +1394,7 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol, sk_add_node_rcu(sk, &net->xdp.list); mutex_unlock(&net->xdp.lock); - local_bh_disable(); sock_prot_inuse_add(net, &xsk_proto, 1); - local_bh_enable(); return 0; }