Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp365346rwb; Wed, 10 Aug 2022 09:25:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HoC6rMBsvelnJCryKilIjHa4lzFEjQBQo+rX39JaQHS4rD640Y2ZM6vYkkbQ/w2khYBy4 X-Received: by 2002:a17:902:e748:b0:16f:953e:2770 with SMTP id p8-20020a170902e74800b0016f953e2770mr23528754plf.156.1660148748715; Wed, 10 Aug 2022 09:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660148748; cv=none; d=google.com; s=arc-20160816; b=FbQydAqhixYsS/3WQX0VZ4fB6twACSZ0sxI8LbDn1lRswxaUFf6RTd05gqCeOUYqOL rF9kOsr9PkOf4ccVlCVMmGqWNZEfIMPdHW9i4jxn4tyvq+iSmH/XORb5iReIHLlBGwek NyRnri1Jz0fumXgLnxi8HX+Xt464CHUNTfavZqQ3yJ8/EN12oF2LNGaJpIJ4LNrjYTkM TVzKQO5GHOPgXKJGfD9WkN2u00ZEdiiB/wRhvKBrHe08Xeoa1ypW1RfT3/OViAe5vHsP g6FWRa8HiVPQSUpjadstE2EFYXDK3q/ZXInmSswvGWhESYRiHi5A6zxWviX+eNnR4qtE O7AA== 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; bh=qTrdi/OWmCo4We7Wz9W9Fjp1Q3YDOYCY692N2JbzTB4=; b=GV21jHU78YDksqIwesntjByk0MBQXizreEcVcyK541+TaousAzLJGvN3zEx8uzpRTM PGjahMFyNtdPEcu2wHvyG4vsKqhJCAxtL3Ug7tT3e5nrKKSAI0H6Lx9HfAXm/J/wG+u3 l63BgwsLQE9PTdZusf1PBHLkbvgKpM1hCvisryblEtIIXk3VBIT74cij+ekRtAUX54ka u4IKvNZsQa5uj4h6Skfu8IOLcmx+f6CSLyGAixL3Z5DAllH71choWjjN2s3TK+9t3aZT psRltaErnbmgf2u7MeQOsHpBfcFKRkVR6TunrouAb2SRWfqQA503dYXfRlYUoOSHPvgO jC4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb3-20020a17090b4a4300b001f4f595b12esi2573553pjb.124.2022.08.10.09.25.32; Wed, 10 Aug 2022 09:25:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232992AbiHJQKV (ORCPT + 99 others); Wed, 10 Aug 2022 12:10:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233130AbiHJQKI (ORCPT ); Wed, 10 Aug 2022 12:10:08 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E37877C74D; Wed, 10 Aug 2022 09:10:06 -0700 (PDT) Received: from dev010.ch-qa.sw.ru ([172.29.1.15]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oLoFD-00F6Pf-G7; Wed, 10 Aug 2022 18:08:42 +0200 From: Alexander Mikhalitsyn To: netdev@vger.kernel.org Cc: Alexander Mikhalitsyn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Daniel Borkmann , David Ahern , Yajun Deng , Roopa Prabhu , Christian Brauner , linux-kernel@vger.kernel.org, Alexey Kuznetsov , Konstantin Khorenko , kernel@openvz.org, devel@openvz.org, "Denis V . Lunev" Subject: [PATCH v2 2/2] neighbour: make proxy_queue.qlen limit per-device Date: Wed, 10 Aug 2022 19:08:40 +0300 Message-Id: <20220810160840.311628-3-alexander.mikhalitsyn@virtuozzo.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220810160840.311628-1-alexander.mikhalitsyn@virtuozzo.com> References: <20220729103559.215140-1-alexander.mikhalitsyn@virtuozzo.com> <20220810160840.311628-1-alexander.mikhalitsyn@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Right now we have a neigh_param PROXY_QLEN which specifies maximum length of neigh_table->proxy_queue. But in fact, this limitation doesn't work well because check condition looks like: tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN) The problem is that p (struct neigh_parms) is a per-device thing, but tbl (struct neigh_table) is a system-wide global thing. It seems reasonable to make proxy_queue limit per-device based. Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: Daniel Borkmann Cc: David Ahern Cc: Yajun Deng Cc: Roopa Prabhu Cc: Christian Brauner Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Alexey Kuznetsov Cc: Alexander Mikhalitsyn Cc: Konstantin Khorenko Cc: kernel@openvz.org Cc: devel@openvz.org Suggested-by: Denis V. Lunev Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Denis V. Lunev --- include/net/neighbour.h | 1 + net/core/neighbour.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 87419f7f5421..bc3fbec70d10 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -82,6 +82,7 @@ struct neigh_parms { struct rcu_head rcu_head; int reachable_time; + int qlen; int data[NEIGH_VAR_DATA_MAX]; DECLARE_BITMAP(data_state, NEIGH_VAR_DATA_MAX); }; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 19d99d1eff53..0469fafffd5d 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -316,9 +316,18 @@ static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net) skb = skb_peek(list); while (skb != NULL) { struct sk_buff *skb_next = skb_peek_next(skb, list); - if (net == NULL || net_eq(dev_net(skb->dev), net)) { + struct net_device *dev = skb->dev; + if (net == NULL || net_eq(dev_net(dev), net)) { + struct in_device *in_dev; + + rcu_read_lock(); + in_dev = __in_dev_get_rcu(dev); + if (in_dev) + in_dev->arp_parms->qlen--; + rcu_read_unlock(); __skb_unlink(skb, list); - dev_put(skb->dev); + + dev_put(dev); kfree_skb(skb); } skb = skb_next; @@ -1606,8 +1615,15 @@ static void neigh_proxy_process(struct timer_list *t) if (tdif <= 0) { struct net_device *dev = skb->dev; + struct in_device *in_dev; + rcu_read_lock(); + in_dev = __in_dev_get_rcu(dev); + if (in_dev) + in_dev->arp_parms->qlen--; + rcu_read_unlock(); __skb_unlink(skb, &tbl->proxy_queue); + if (tbl->proxy_redo && netif_running(dev)) { rcu_read_lock(); tbl->proxy_redo(skb); @@ -1632,7 +1648,7 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, unsigned long sched_next = jiffies + prandom_u32_max(NEIGH_VAR(p, PROXY_DELAY)); - if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) { + if (p->qlen > NEIGH_VAR(p, PROXY_QLEN)) { kfree_skb(skb); return; } @@ -1648,6 +1664,7 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, skb_dst_drop(skb); dev_hold(skb->dev); __skb_queue_tail(&tbl->proxy_queue, skb); + p->qlen++; mod_timer(&tbl->proxy_timer, sched_next); spin_unlock(&tbl->proxy_queue.lock); } @@ -1680,6 +1697,7 @@ struct neigh_parms *neigh_parms_alloc(struct net_device *dev, refcount_set(&p->refcnt, 1); p->reachable_time = neigh_rand_reach_time(NEIGH_VAR(p, BASE_REACHABLE_TIME)); + p->qlen = 0; dev_hold_track(dev, &p->dev_tracker, GFP_KERNEL); p->dev = dev; write_pnet(&p->net, net); @@ -1745,6 +1763,7 @@ void neigh_table_init(int index, struct neigh_table *tbl) refcount_set(&tbl->parms.refcnt, 1); tbl->parms.reachable_time = neigh_rand_reach_time(NEIGH_VAR(&tbl->parms, BASE_REACHABLE_TIME)); + tbl->parms.qlen = 0; tbl->stats = alloc_percpu(struct neigh_statistics); if (!tbl->stats) -- 2.36.1