From patchwork Wed Jul 31 20:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749149 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-9105.amazon.com (smtp-fw-9105.amazon.com [207.171.188.204]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98DE2381AD for ; Wed, 31 Jul 2024 20:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.188.204 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456482; cv=none; b=ToV0uM9odv7z42HuTnZ9bSpdYHagNu5SaCaX/nKoi/lo/FiLMGimKDyfNUYPZkphoa/cL4jixc0R5RBkBw5ukUP/RP6ptm4YM0npJ067b0ZIxHeB/GS7hB490WUdsz2VMCrTwUNl+k7h9gLwkuoAQlP0B+Eh572PZDHqR9ldJfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456482; c=relaxed/simple; bh=I5o0+o8KY54oi2PFYWwVrLgeao+FnfVRWbHdV4FV7IU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mLeIlRgxPWt+L1/BgvJObuy36aN07W9YdOeTTCCNcBYvwv2kSDVRwpkddBuok9uAx4ywIsjX6OsEUBVEEcWHUrIeTdLtq8WlNnyHuDpbftLjujjIiPu1+r0EhijdiMCYY5OoK6SlfFiN1qHEas1inDMnC9GUlyU6xZ4jk+JXDCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=dtL8rXed; arc=none smtp.client-ip=207.171.188.204 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="dtL8rXed" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456481; x=1753992481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Bv5NstBA2yGtcwzxZY7S6eZgmMVkUc9NsbL33DDAFZs=; b=dtL8rXedbYQqrV5DCbOhef5H4qBc1O95pyolP2M0r8qvqgDW5V5x2Nik XX7VwpPUb73gyZSU642/yGKqPA81rJG2z1i7FBcCH1yU/uxH3nHEoMKEO kVYJl0DSxafZxqepqokKTaqmEx2hMBbxBioZEu8j63iMbkponIo0JNish 4=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="746777502" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:08:00 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:3367] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.63.84:2525] with esmtp (Farcaster) id 60c77429-386f-4951-914a-fa6f30858ace; Wed, 31 Jul 2024 20:07:59 +0000 (UTC) X-Farcaster-Flow-ID: 60c77429-386f-4951-914a-fa6f30858ace Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:07:59 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:07:56 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , Simon Horman Subject: [PATCH v2 net-next 1/6] l2tp: Don't assign net->gen->ptr[] for pppol2tp_net_ops. Date: Wed, 31 Jul 2024 13:07:16 -0700 Message-ID: <20240731200721.70601-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D046UWB001.ant.amazon.com (10.13.139.187) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Commit fd558d186df2 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts") converted net->gen->ptr[pppol2tp_net_id] in l2tp_ppp.c to net->gen->ptr[l2tp_net_id] in l2tp_core.c. Now the leftover wastes one entry of net->gen->ptr[] in each netns. Let's avoid the unwanted allocation. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Simon Horman Reviewed-by: James Chapman --- net/l2tp/l2tp_ppp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 3596290047b2..246089b17910 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -1406,8 +1406,6 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname, * L2TPv2, we dump only L2TPv2 tunnels and sessions here. *****************************************************************************/ -static unsigned int pppol2tp_net_id; - #ifdef CONFIG_PROC_FS struct pppol2tp_seq_data { @@ -1641,7 +1639,6 @@ static __net_exit void pppol2tp_exit_net(struct net *net) static struct pernet_operations pppol2tp_net_ops = { .init = pppol2tp_init_net, .exit = pppol2tp_exit_net, - .id = &pppol2tp_net_id, }; /***************************************************************************** From patchwork Wed Jul 31 20:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749150 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93B1E381AD for ; Wed, 31 Jul 2024 20:08:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456510; cv=none; b=NpqNAyZTh1QXKaCQ3DLON3ZCgRnbMTEHRxnGYWmjwCvwfgXfadwXp5oPaD09A52nR0E2AoRZThS/t7HxNBO8u1aM1/kUm5swpHCjzonKIHnMSwEQcMLbZvU8gxAsbhdquLu0VU1ALtnnLNcbwxv13Oe0wpPW8b4R2kj3TpEnFD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456510; c=relaxed/simple; bh=aBHFXUTnb8TQUoI6mH3at7zpujXlyUxBwI4ZyEdfPGc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qm1VQJenj65PZLdxiORn3UNqoCXZJpxk5wDAWMRRsz0dLRQcwbggOD8N09L5awJNslK8iYeHStWZ3QNc+zmdtlmlkQhHuvrnDuzQVIvSdaoxL+zjgmf/uShCsRYqjRNwn37L5cQl2zFp5SuCqX6GtYdDYLelOxdSsXjx67oiTps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=Ca1RWSwh; arc=none smtp.client-ip=52.119.213.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Ca1RWSwh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456508; x=1753992508; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vxXtyAxAD1NiENGc2umwMm+RTGJGGCl9fYzTyZ+1ZkE=; b=Ca1RWSwhP9iLlKZukx7+4CNfNPIU2mg+iKj5tLSxm3pmJNPEgQ1wgSTm b0hJ/gBk3wZ2IJlrW0ydVxinI2UnD+G2k77gEgXStI9iFVx6mISkl+CO0 ddg8YOiv/EdUYDQJTiJXWDj/60AmlrCHTWuqvPg7FS3A6k1KSW/tDXljt I=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="671232422" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:08:25 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.21.151:38929] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.107:2525] with esmtp (Farcaster) id e8947b03-b413-4f0a-928a-66d4fcfe9833; Wed, 31 Jul 2024 20:08:25 +0000 (UTC) X-Farcaster-Flow-ID: e8947b03-b413-4f0a-928a-66d4fcfe9833 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:08:24 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:08:21 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 2/6] net: Don't register pernet_operations if only one of id or size is specified. Date: Wed, 31 Jul 2024 13:07:17 -0700 Message-ID: <20240731200721.70601-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D040UWA004.ant.amazon.com (10.13.139.93) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We can allocate per-netns memory for struct pernet_operations by specifying id and size. register_pernet_operations() assigns an id to pernet_operations and later ops_init() allocates the specified size of memory as net->gen->ptr[id]. If id is missing, no memory is allocated. If size is not specified, pernet_operations just wastes an entry of net->gen->ptr[] for every netns. net_generic is available only when both id and size are specified, so let's ensure that. While we are at it, we add const to both fields. Signed-off-by: Kuniyuki Iwashima --- include/net/net_namespace.h | 4 ++-- net/core/net_namespace.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 20c34bd7a077..e67b483cc8bb 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -451,8 +451,8 @@ struct pernet_operations { /* Following method is called with RTNL held. */ void (*exit_batch_rtnl)(struct list_head *net_exit_list, struct list_head *dev_kill_list); - unsigned int *id; - size_t size; + unsigned int * const id; + const size_t size; }; /* diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 6a823ba906c6..1cd87df13f39 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -125,7 +125,7 @@ static int ops_init(const struct pernet_operations *ops, struct net *net) int err = -ENOMEM; void *data = NULL; - if (ops->id && ops->size) { + if (ops->id) { data = kzalloc(ops->size, GFP_KERNEL); if (!data) goto out; @@ -140,7 +140,7 @@ static int ops_init(const struct pernet_operations *ops, struct net *net) if (!err) return 0; - if (ops->id && ops->size) { + if (ops->id) { ng = rcu_dereference_protected(net->gen, lockdep_is_held(&pernet_ops_rwsem)); ng->ptr[*ops->id] = NULL; @@ -182,7 +182,8 @@ static void ops_free_list(const struct pernet_operations *ops, struct list_head *net_exit_list) { struct net *net; - if (ops->size && ops->id) { + + if (ops->id) { list_for_each_entry(net, net_exit_list, exit_list) kfree(net_generic(net, *ops->id)); } @@ -1244,7 +1245,7 @@ static int __register_pernet_operations(struct list_head *list, LIST_HEAD(net_exit_list); list_add_tail(&ops->list, list); - if (ops->init || (ops->id && ops->size)) { + if (ops->init || ops->id) { /* We held write locked pernet_ops_rwsem, and parallel * setup_net() and cleanup_net() are not possible. */ @@ -1310,6 +1311,9 @@ static int register_pernet_operations(struct list_head *list, { int error; + if (WARN_ON(!!ops->id ^ !!ops->size)) + return -EINVAL; + if (ops->id) { error = ida_alloc_min(&net_generic_ids, MIN_PERNET_OPS_ID, GFP_KERNEL); From patchwork Wed Jul 31 20:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749151 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF4E1381AD for ; Wed, 31 Jul 2024 20:08:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456534; cv=none; b=eg/8FN+RHdkwkPCU4uJyG/Ey7x/8OnEqD4GcWYB1Nh7OUdMF2B5QKwRont5qUFInFDZ4o89Cer4LSVtcgXEsVGi/SFQu7OaJnPtsCkys63tj/KRiJocfUrMOPSR4LNbVeQXydAT08adKIC0cXbA5+y0pufHy6OJoNUQquxOa/5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456534; c=relaxed/simple; bh=RkBwQjUKB3zY2PsVwOVr+cdHzNJ9AnPmy2dvB6m9S0o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JPHiXgBQoE2N5mb5uWlFFd9gZMOEppPKDif/7o5S3IfKrNgUOGGN2p/B9fnzpSS55JbftkXqiNlTSx6oqXSzuZcromSlYzDJVFiAsk2uTmFW6IZz6jmTjclv4n1h2y4G/XzleNNInl3eE/ad2WZnkHAHA1c4+4RjXqWic8itVJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=Jp7cth6N; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Jp7cth6N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456533; x=1753992533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IKfqdNCa62dm409Z5Qprky+neCCptKvPVVZheYjXlQ4=; b=Jp7cth6N6Wi4o5BLCTdma96l43OScCvXJhJCJNgz1VigEgcQEfDFXyzq U/6qbWkQfJkilq1Kc/Jgot0WfLs16n1WUMd0vWEOMOiqPjqEHIeM9uioj AMsx+pec22/DAr9ZPOlQTX6X6ewf9nWapzNnY+mdB98qiaKQCpTBvVMM9 4=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="222621442" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:08:50 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.7.35:26683] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.107:2525] with esmtp (Farcaster) id 21fa24d2-efb3-4544-a86b-7c5cb950ce7c; Wed, 31 Jul 2024 20:08:49 +0000 (UTC) X-Farcaster-Flow-ID: 21fa24d2-efb3-4544-a86b-7c5cb950ce7c Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:08:49 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:08:46 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 3/6] net: Initialise net->passive once in preinit_net(). Date: Wed, 31 Jul 2024 13:07:18 -0700 Message-ID: <20240731200721.70601-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWB004.ant.amazon.com (10.13.139.150) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org When initialising the root netns, we set net->passive in setup_net(). However, we do it twice for non-root netns in copy_net_ns() and setup_net(). This is because we could bypass setup_net() in copy_net_ns() if down_read_killable() fails. preinit_net() is a better place to put such an operation. Let's initialise net->passive in preinit_net(). Signed-off-by: Kuniyuki Iwashima --- net/core/net_namespace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 1cd87df13f39..6c9acb086852 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -312,6 +312,7 @@ EXPORT_SYMBOL_GPL(get_net_ns_by_id); /* init code that must occur even if setup_net() is not called. */ static __net_init void preinit_net(struct net *net) { + refcount_set(&net->passive, 1); ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net notrefcnt"); } @@ -329,7 +330,6 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) refcount_set(&net->ns.count, 1); ref_tracker_dir_init(&net->refcnt_tracker, 128, "net refcnt"); - refcount_set(&net->passive, 1); get_random_bytes(&net->hash_mix, sizeof(u32)); preempt_disable(); net->net_cookie = gen_cookie_next(&net_cookie); @@ -498,7 +498,6 @@ struct net *copy_net_ns(unsigned long flags, } preinit_net(net); - refcount_set(&net->passive, 1); net->ucounts = ucounts; get_user_ns(user_ns); From patchwork Wed Jul 31 20:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749152 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84E5C381AD for ; Wed, 31 Jul 2024 20:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.48.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456560; cv=none; b=s51ffYYYMsK7A5A3h4M+zOOdM5yJlRe00AJuE1kM8a6I56uWC9jGyTpurN0D4fD44GSlDI1qKhkEk5Aw8pkiZVwX/ppucSJypVeUy8xKZO4E+GFe5JxLkIaEwNwSmGex1wzUeV+w6q5eBV66OZFezdNag6Z/HvFe+ReXQSpsKtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456560; c=relaxed/simple; bh=J5UqowP4cEjACltpNPKIXgMKy7UhqXvYc6Cxh5QgeMY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mSnqJJ2hEXzfyJVIFEsslFtr+gsKkjQeCH8xFcDQOIKpyCuVxwkyaRSwZNPQjgniYIsz+NvsdnSnKoQeGNO3lq3SzWrgEZ8sABE1cxqGrppiOzHrRhQiza6FK8jbvkpI1MsK8Sb18ids0PkgCa6J/66HOVRsovWhSIQK3SG0cQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=WAc5P8NQ; arc=none smtp.client-ip=52.95.48.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="WAc5P8NQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456559; x=1753992559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=idv4Y5IP1/LWej2Vczr9zZBeD/yAR6HkFYoBaYpbY/o=; b=WAc5P8NQ2p6shfTKgyleVv3hMGHe6U5F7bTVVFQtWsQY6/s4GU58wX7g y8GPdtFP6ZHr3QUZRQDGNSurMnzayHbfnQdxCv0XN2sD1QHp2eSJ9fgmI 3E5ULhJXAym6j1/OFv1GKEGRauWnlxuT56SYNMxbLUW402wKN6JXmH1qM g=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="414431688" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:09:15 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.38.20:50110] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.33.45:2525] with esmtp (Farcaster) id f8a430da-a151-4889-9763-6fdf60aa9e22; Wed, 31 Jul 2024 20:09:14 +0000 (UTC) X-Farcaster-Flow-ID: f8a430da-a151-4889-9763-6fdf60aa9e22 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:09:13 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:09:11 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 4/6] net: Call preinit_net() without pernet_ops_rwsem. Date: Wed, 31 Jul 2024 13:07:19 -0700 Message-ID: <20240731200721.70601-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D040UWB001.ant.amazon.com (10.13.138.82) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org When initialising the root netns, we call preinit_net() under pernet_ops_rwsem. However, the operations in preinit_net() do not require pernet_ops_rwsem. Also, we don't hold it for preinit_net() when initialising non-root netns. To be consistent, let's call preinit_net() without pernet_ops_rwsem in net_ns_init(). Signed-off-by: Kuniyuki Iwashima --- net/core/net_namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 6c9acb086852..b91c15b27fb2 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -1199,8 +1199,9 @@ void __init net_ns_init(void) #ifdef CONFIG_KEYS init_net.key_domain = &init_net_key_domain; #endif - down_write(&pernet_ops_rwsem); preinit_net(&init_net); + + down_write(&pernet_ops_rwsem); if (setup_net(&init_net, &init_user_ns)) panic("Could not setup the initial network namespace"); From patchwork Wed Jul 31 20:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749153 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7033B381AD for ; Wed, 31 Jul 2024 20:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.48.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456589; cv=none; b=OpNjCAbUI8wJDzlReHtWyF0MqoEGwspfRshjBuoKx4GXPn5m7CJ2H18ssNDDeGI9KyIztEzmWQArZ9P4WuaydmFBOKlDeuR6tyvswHHRx63Xzt5DrG23mozBT5i5WY9Eno9M+/aUdQnldRdpeuZu7PiBYg+WOvu8q9W44XUrtM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456589; c=relaxed/simple; bh=LsUXF/GV7Zfwzb2d6cqdnZCt6+GDCHP9xOgG6iqiCtA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R9NISu/MAwjV3NsYuKqDcLeO4NZbePFLZO4xP6sQnmBYmK2VQU6gEiaTSbEfQhiOX8bz3jreB/skkrW+AmwIRVFHGnEsSxAahSgMTGjbIam/tA8SxctQyh7OEqvvBzVtUs1I00aWyN5pLTM6qcTtpIGOibGnRK8vA+l7cXJupmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=ft4TLZCk; arc=none smtp.client-ip=52.95.48.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="ft4TLZCk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456588; x=1753992588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s6Cn2TLeqAxCGpnshWKjC8V+yOHdPHBLeflgZjOkg/U=; b=ft4TLZCkxOzgMvclPj+TXMm0spssbseYySUvH9s/DYzlUjNHefsEsENm v0S+ULkY6+vHd2DaUkIVAE0cWT8GKro45Ufi+is+UszK771kGFRrRVG98 n8nOP5zaXjw9PjGVAKOWuDBhZQbD6xN0NJPNtPjvDCALlFAAl7egwzfwt 8=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="414431779" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:09:46 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.21.151:40073] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.107:2525] with esmtp (Farcaster) id 84be512d-7ab2-4159-b9fc-3fd0160e23f6; Wed, 31 Jul 2024 20:09:45 +0000 (UTC) X-Farcaster-Flow-ID: 84be512d-7ab2-4159-b9fc-3fd0160e23f6 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:09:38 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:09:36 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 5/6] net: Slim down setup_net(). Date: Wed, 31 Jul 2024 13:07:20 -0700 Message-ID: <20240731200721.70601-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D037UWB002.ant.amazon.com (10.13.138.121) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Most initialisations in setup_net() do not require pernet_ops_rwsem and can be moved to preinit_net(). Signed-off-by: Kuniyuki Iwashima --- net/core/net_namespace.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index b91c15b27fb2..eed5a28e8ee3 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -310,16 +310,26 @@ struct net *get_net_ns_by_id(const struct net *net, int id) EXPORT_SYMBOL_GPL(get_net_ns_by_id); /* init code that must occur even if setup_net() is not called. */ -static __net_init void preinit_net(struct net *net) +static __net_init void preinit_net(struct net *net, struct user_namespace *user_ns) { refcount_set(&net->passive, 1); + refcount_set(&net->ns.count, 1); + ref_tracker_dir_init(&net->refcnt_tracker, 128, "net refcnt"); ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net notrefcnt"); + + get_random_bytes(&net->hash_mix, sizeof(u32)); + net->dev_base_seq = 1; + net->user_ns = user_ns; + + idr_init(&net->netns_ids); + spin_lock_init(&net->nsid_lock); + mutex_init(&net->ipv4.ra_mutex); } /* * setup_net runs the initializers for the network namespace object. */ -static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) +static __net_init int setup_net(struct net *net) { /* Must be called with pernet_ops_rwsem held */ const struct pernet_operations *ops, *saved_ops; @@ -327,18 +337,9 @@ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) LIST_HEAD(dev_kill_list); int error = 0; - refcount_set(&net->ns.count, 1); - ref_tracker_dir_init(&net->refcnt_tracker, 128, "net refcnt"); - - get_random_bytes(&net->hash_mix, sizeof(u32)); preempt_disable(); net->net_cookie = gen_cookie_next(&net_cookie); preempt_enable(); - net->dev_base_seq = 1; - net->user_ns = user_ns; - idr_init(&net->netns_ids); - spin_lock_init(&net->nsid_lock); - mutex_init(&net->ipv4.ra_mutex); list_for_each_entry(ops, &pernet_list, list) { error = ops_init(ops, net); @@ -497,7 +498,7 @@ struct net *copy_net_ns(unsigned long flags, goto dec_ucounts; } - preinit_net(net); + preinit_net(net, user_ns); net->ucounts = ucounts; get_user_ns(user_ns); @@ -505,7 +506,7 @@ struct net *copy_net_ns(unsigned long flags, if (rv < 0) goto put_userns; - rv = setup_net(net, user_ns); + rv = setup_net(net); up_read(&pernet_ops_rwsem); @@ -1199,10 +1200,10 @@ void __init net_ns_init(void) #ifdef CONFIG_KEYS init_net.key_domain = &init_net_key_domain; #endif - preinit_net(&init_net); + preinit_net(&init_net, &init_user_ns); down_write(&pernet_ops_rwsem); - if (setup_net(&init_net, &init_user_ns)) + if (setup_net(&init_net)) panic("Could not setup the initial network namespace"); init_net_initialized = true; From patchwork Wed Jul 31 20:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13749154 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F5B7381AD for ; Wed, 31 Jul 2024 20:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.49.90 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456610; cv=none; b=SnFe92EwUrl0TirNEqEp2+BbVrTigXwehz7iaAD0Qi5SBuYS1cCL6S7unkDWgSAyy4nVUmo1EO7KP85aJYbh7SbJ6Iv2mtNazz+OivLFxfxQvk6aM+i36k6xNCLZlfilnXDJM6loYKLd1n4u388lv9fAp/XO8h0FBsREUqSsSpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722456610; c=relaxed/simple; bh=NEuovyH31Nv5VC65zGtIfdmLhhe+4vEVDr+RuEV31uM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iht+b6C6zl5mLCfkohLdD1JRNJhw/EAqCekvFk6iUGY+WX1L1sXH/wPj/NeVlMMxrGnqFisNjVR0Fd8ZA9+44C9KHTtKGxvMjHy9hgudk+WzkLynyLxYOGDqamPZLqsLRGYjFph0e2HSJ0CzyYHXIkxgeH9Xo8koJzoUjD5b0eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=ccapJ8QT; arc=none smtp.client-ip=52.95.49.90 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="ccapJ8QT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722456609; x=1753992609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=32996MBZ3t87g3T1jX+/bFh7p6X4qPbnn7Q1KmZBlFU=; b=ccapJ8QTgdLIOaTG2d2/GSIUWPVH2zlUzYWZ3664CPMRZQhsfMGumCrc 95E/4fLFpUVq+84mqzXCIsXuCjSoUxpTYf4c9IfLxUCG2+Ln2pBdNe6y+ FRCh7940ztBuU8Pw8eeTJnDXCDa2gHcQgM1fHiuHJajwM9GGOpCbuMRST 0=; X-IronPort-AV: E=Sophos;i="6.09,251,1716249600"; d="scan'208";a="424195096" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2024 20:10:06 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.38.20:27071] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.3.107:2525] with esmtp (Farcaster) id 7ef6b39a-a5e3-4efa-af44-215fbea8f182; Wed, 31 Jul 2024 20:10:05 +0000 (UTC) X-Farcaster-Flow-ID: 7ef6b39a-a5e3-4efa-af44-215fbea8f182 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA001.ant.amazon.com (10.250.64.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:10:03 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.32) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Wed, 31 Jul 2024 20:10:00 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 6/6] net: Initialise net.core sysctl defaults in preinit_net(). Date: Wed, 31 Jul 2024 13:07:21 -0700 Message-ID: <20240731200721.70601-7-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240731200721.70601-1-kuniyu@amazon.com> References: <20240731200721.70601-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D035UWB003.ant.amazon.com (10.13.138.85) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Commit 7c3f1875c66f ("net: move somaxconn init from sysctl code") introduced net_defaults_ops to make sure that net.core sysctl knobs are always initialised even if CONFIG_SYSCTL is disabled. Such operations better fit preinit_net() added for a similar purpose by commit 6e77a5a4af05 ("net: initialize net->notrefcnt_tracker earlier"). Let's initialise the sysctl defaults in preinit_net(). Signed-off-by: Kuniyuki Iwashima --- net/core/net_namespace.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index eed5a28e8ee3..11e4dd4f09ed 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -309,6 +309,16 @@ struct net *get_net_ns_by_id(const struct net *net, int id) } EXPORT_SYMBOL_GPL(get_net_ns_by_id); +static __net_init void preinit_net_sysctl(struct net *net) +{ + net->core.sysctl_somaxconn = SOMAXCONN; + /* Limits per socket sk_omem_alloc usage. + * TCP zerocopy regular usage needs 128 KB. + */ + net->core.sysctl_optmem_max = 128 * 1024; + net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED; +} + /* init code that must occur even if setup_net() is not called. */ static __net_init void preinit_net(struct net *net, struct user_namespace *user_ns) { @@ -324,6 +334,7 @@ static __net_init void preinit_net(struct net *net, struct user_namespace *user_ idr_init(&net->netns_ids); spin_lock_init(&net->nsid_lock); mutex_init(&net->ipv4.ra_mutex); + preinit_net_sysctl(net); } /* @@ -384,32 +395,6 @@ static __net_init int setup_net(struct net *net) goto out; } -static int __net_init net_defaults_init_net(struct net *net) -{ - net->core.sysctl_somaxconn = SOMAXCONN; - /* Limits per socket sk_omem_alloc usage. - * TCP zerocopy regular usage needs 128 KB. - */ - net->core.sysctl_optmem_max = 128 * 1024; - net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED; - - return 0; -} - -static struct pernet_operations net_defaults_ops = { - .init = net_defaults_init_net, -}; - -static __init int net_defaults_init(void) -{ - if (register_pernet_subsys(&net_defaults_ops)) - panic("Cannot initialize net default settings"); - - return 0; -} - -core_initcall(net_defaults_init); - #ifdef CONFIG_NET_NS static struct ucounts *inc_net_namespaces(struct user_namespace *ns) {