From patchwork Fri Apr 24 00:08:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 220669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EEF4C2BA19 for ; Fri, 24 Apr 2020 00:08:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31AB520706 for ; Fri, 24 Apr 2020 00:08:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZMd3S5RW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728224AbgDXAIw (ORCPT ); Thu, 23 Apr 2020 20:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728046AbgDXAIv (ORCPT ); Thu, 23 Apr 2020 20:08:51 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1BF5C09B042 for ; Thu, 23 Apr 2020 17:08:51 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id o185so3753890pgo.3 for ; Thu, 23 Apr 2020 17:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bgrcJbdAM54yhCvKWN7+hyKwB+AZzyGWHKRZCgw0NO4=; b=ZMd3S5RWOZ0ajxUUsL7bwEGKFbcg5Lo4huXEV9eKBtoCrnnAz4FEXlNiB3eIJpnEwC jQQOcm515nwEBdEGdp15u5X2yvtWILNaF8+JG6Oe+hcyMnk7P6b1vloN/xD+lIeiyaOS i4+gWs+IGQ73/VpWpAErBAOXfciUC+YSwdArB8Q47v8RqcPQV3XOqjchcruX1fsJv1Dw JyoL4GgWmtoGJtWHtFQnCiqCApNPn1X/kswHdFqNtHnPHB2uQsIrNbJLkFnsjnWFxgHk GPw7AnTKWhGNTG1iDtzcKyTxSxRmG1ZoaSHplYwIABPgH6j4RNBm2AsOfEBN+JVoB48R s9aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bgrcJbdAM54yhCvKWN7+hyKwB+AZzyGWHKRZCgw0NO4=; b=gHogtobgdDeOY18HmtEmWqR7QiXfbzZaZGEFCWxmu3wOjCUNU+oRfuEC6IyFzrU4jF 54u1GE05dqiDtPSkRQOOoAPkxW3Xd1vEaAl9hfEcBJ72XI+d679x9Au2uoz4tDDM3TVD KRlCtiCqV6lxs+qQp2POBT4MOwDs3Gk/iAQbELwqiynRCXntR73k7QQBTTZh9WdjmaKZ bDU4j/cISV3MNlgLF57ZdWDW6k+M2aGcm2Z/zi1pNeeJSL7GgXlPSi+NOVyLTAW18Nyh 5/TCoHSSH9F1WvG+w/MnjxvwuPLk4ySz+UJgZRdvxmKN3p+rrf/WmZNbHTeN1CXiLlgt hbQA== X-Gm-Message-State: AGi0PuZ4D/DsN8XLSgl5rJmEgurfDyDwGRoz80RQ5sOp6GTad9DzF1a6 7yCE9OcSESsSjXp7J+V5BNCzr3lv X-Google-Smtp-Source: APiQypK4u+3Ucuxtih4kEL9xrM4lhEGznPXwNsUXQpjmnm1ihghmMqweTnUnr6+e4YQe43JU5+7BgQ== X-Received: by 2002:a63:e749:: with SMTP id j9mr6124018pgk.319.1587686930975; Thu, 23 Apr 2020 17:08:50 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([219.142.146.4]) by smtp.gmail.com with ESMTPSA id p10sm3836100pff.210.2020.04.23.17.08.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 17:08:50 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Cc: netdev@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang Subject: [PATCH net-next v4 1/5] net: openvswitch: expand the meters supported number Date: Fri, 24 Apr 2020 08:08:02 +0800 Message-Id: <1587686886-16347-2-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang In kernel datapath of Open vSwitch, there are only 1024 buckets of meter in one datapath. If installing more than 1024 (e.g. 8192) meters, it may lead to the performance drop. But in some case, for example, Open vSwitch used as edge gateway, there should be 20K at least, where meters used for IP address bandwidth limitation. [Open vSwitch userspace datapath has this issue too.] For more scalable meter, this patch use meter array instead of hash tables, and expand/shrink the array when necessary. So we can install more meters than before in the datapath. Introducing the struct *dp_meter_instance, it's easy to expand meter though changing the *ti point in the struct *dp_meter_table. Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- net/openvswitch/datapath.h | 2 +- net/openvswitch/meter.c | 240 ++++++++++++++++++++++++++++--------- net/openvswitch/meter.h | 16 ++- 3 files changed, 195 insertions(+), 63 deletions(-) diff --git a/net/openvswitch/datapath.h b/net/openvswitch/datapath.h index e239a46c2f94..2016dd107939 100644 --- a/net/openvswitch/datapath.h +++ b/net/openvswitch/datapath.h @@ -82,7 +82,7 @@ struct datapath { u32 max_headroom; /* Switch meters. */ - struct hlist_head *meters; + struct dp_meter_table meter_tbl; }; /** diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index 5010d1ddd4bd..f806ded1dd0a 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -19,8 +19,6 @@ #include "datapath.h" #include "meter.h" -#define METER_HASH_BUCKETS 1024 - static const struct nla_policy meter_policy[OVS_METER_ATTR_MAX + 1] = { [OVS_METER_ATTR_ID] = { .type = NLA_U32, }, [OVS_METER_ATTR_KBPS] = { .type = NLA_FLAG }, @@ -39,6 +37,11 @@ static const struct nla_policy band_policy[OVS_BAND_ATTR_MAX + 1] = { [OVS_BAND_ATTR_STATS] = { .len = sizeof(struct ovs_flow_stats) }, }; +static u32 meter_hash(struct dp_meter_instance *ti, u32 id) +{ + return id % ti->n_meters; +} + static void ovs_meter_free(struct dp_meter *meter) { if (!meter) @@ -47,40 +50,153 @@ static void ovs_meter_free(struct dp_meter *meter) kfree_rcu(meter, rcu); } -static struct hlist_head *meter_hash_bucket(const struct datapath *dp, - u32 meter_id) -{ - return &dp->meters[meter_id & (METER_HASH_BUCKETS - 1)]; -} - /* Call with ovs_mutex or RCU read lock. */ -static struct dp_meter *lookup_meter(const struct datapath *dp, +static struct dp_meter *lookup_meter(const struct dp_meter_table *tbl, u32 meter_id) { + struct dp_meter_instance *ti = rcu_dereference_ovsl(tbl->ti); + u32 hash = meter_hash(ti, meter_id); struct dp_meter *meter; - struct hlist_head *head; - head = meter_hash_bucket(dp, meter_id); - hlist_for_each_entry_rcu(meter, head, dp_hash_node, - lockdep_ovsl_is_held()) { - if (meter->id == meter_id) - return meter; - } + meter = rcu_dereference_ovsl(ti->dp_meters[hash]); + if (meter && likely(meter->id == meter_id)) + return meter; + return NULL; } -static void attach_meter(struct datapath *dp, struct dp_meter *meter) +static struct dp_meter_instance *dp_meter_instance_alloc(const u32 size) +{ + struct dp_meter_instance *ti; + + ti = kvzalloc(sizeof(*ti) + + sizeof(struct dp_meter *) * size, + GFP_KERNEL); + if (!ti) + return NULL; + + ti->n_meters = size; + + return ti; +} + +static void dp_meter_instance_free(struct dp_meter_instance *ti) +{ + kvfree(ti); +} + +static void dp_meter_instance_free_rcu(struct rcu_head *rcu) +{ + struct dp_meter_instance *ti; + + ti = container_of(rcu, struct dp_meter_instance, rcu); + kvfree(ti); +} + +static int +dp_meter_instance_realloc(struct dp_meter_table *tbl, u32 size) +{ + struct dp_meter_instance *ti = rcu_dereference_ovsl(tbl->ti); + int n_meters = min(size, ti->n_meters); + struct dp_meter_instance *new_ti; + int i; + + new_ti = dp_meter_instance_alloc(size); + if (!new_ti) + return -ENOMEM; + + for (i = 0; i < n_meters; i++) + new_ti->dp_meters[i] = + rcu_dereference_ovsl(ti->dp_meters[i]); + + rcu_assign_pointer(tbl->ti, new_ti); + call_rcu(&ti->rcu, dp_meter_instance_free_rcu); + + return 0; +} + +static void dp_meter_instance_insert(struct dp_meter_instance *ti, + struct dp_meter *meter) +{ + u32 hash; + + hash = meter_hash(ti, meter->id); + rcu_assign_pointer(ti->dp_meters[hash], meter); +} + +static void dp_meter_instance_remove(struct dp_meter_instance *ti, + struct dp_meter *meter) { - struct hlist_head *head = meter_hash_bucket(dp, meter->id); + u32 hash; - hlist_add_head_rcu(&meter->dp_hash_node, head); + hash = meter_hash(ti, meter->id); + RCU_INIT_POINTER(ti->dp_meters[hash], NULL); } -static void detach_meter(struct dp_meter *meter) +static int attach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) { + struct dp_meter_instance *ti = rcu_dereference_ovsl(tbl->ti); + u32 hash = meter_hash(ti, meter->id); + + /* In generally, slots selected should be empty, because + * OvS uses id-pool to fetch a available id. + */ + if (unlikely(rcu_dereference_ovsl(ti->dp_meters[hash]))) + return -EBUSY; + + dp_meter_instance_insert(ti, meter); + + /* That function is thread-safe. */ + if (++tbl->count >= ti->n_meters) + if (dp_meter_instance_realloc(tbl, ti->n_meters * 2)) + goto expand_err; + + return 0; + +expand_err: + dp_meter_instance_remove(ti, meter); + tbl->count--; + return -ENOMEM; +} + +static int detach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) +{ + struct dp_meter_instance *ti; + ASSERT_OVSL(); - if (meter) - hlist_del_rcu(&meter->dp_hash_node); + if (!meter) + return 0; + + ti = rcu_dereference_ovsl(tbl->ti); + dp_meter_instance_remove(ti, meter); + + tbl->count--; + + /* Shrink the meter array if necessary. */ + if (ti->n_meters > DP_METER_ARRAY_SIZE_MIN && + tbl->count <= (ti->n_meters / 4)) { + int half_size = ti->n_meters / 2; + int i; + + /* Avoid hash collision, don't move slots to other place. + * Make sure there are no references of meters in array + * which will be released. + */ + for (i = half_size; i < ti->n_meters; i++) + if (rcu_dereference_ovsl(ti->dp_meters[i])) + goto out; + + if (dp_meter_instance_realloc(tbl, half_size)) + goto shrink_err; + } + +out: + return 0; + +shrink_err: + dp_meter_instance_insert(ti, meter); + tbl->count++; + return -ENOMEM; } static struct sk_buff * @@ -273,6 +389,7 @@ static int ovs_meter_cmd_set(struct sk_buff *skb, struct genl_info *info) struct sk_buff *reply; struct ovs_header *ovs_reply_header; struct ovs_header *ovs_header = info->userhdr; + struct dp_meter_table *meter_tbl; struct datapath *dp; int err; u32 meter_id; @@ -300,12 +417,18 @@ static int ovs_meter_cmd_set(struct sk_buff *skb, struct genl_info *info) goto exit_unlock; } + meter_tbl = &dp->meter_tbl; meter_id = nla_get_u32(a[OVS_METER_ATTR_ID]); - /* Cannot fail after this. */ - old_meter = lookup_meter(dp, meter_id); - detach_meter(old_meter); - attach_meter(dp, meter); + old_meter = lookup_meter(meter_tbl, meter_id); + err = detach_meter(meter_tbl, old_meter); + if (err) + goto exit_unlock; + + err = attach_meter(meter_tbl, meter); + if (err) + goto exit_unlock; + ovs_unlock(); /* Build response with the meter_id and stats from @@ -337,14 +460,14 @@ static int ovs_meter_cmd_set(struct sk_buff *skb, struct genl_info *info) static int ovs_meter_cmd_get(struct sk_buff *skb, struct genl_info *info) { - struct nlattr **a = info->attrs; - u32 meter_id; struct ovs_header *ovs_header = info->userhdr; struct ovs_header *ovs_reply_header; + struct nlattr **a = info->attrs; + struct dp_meter *meter; + struct sk_buff *reply; struct datapath *dp; + u32 meter_id; int err; - struct sk_buff *reply; - struct dp_meter *meter; if (!a[OVS_METER_ATTR_ID]) return -EINVAL; @@ -365,7 +488,7 @@ static int ovs_meter_cmd_get(struct sk_buff *skb, struct genl_info *info) } /* Locate meter, copy stats. */ - meter = lookup_meter(dp, meter_id); + meter = lookup_meter(&dp->meter_tbl, meter_id); if (!meter) { err = -ENOENT; goto exit_unlock; @@ -390,18 +513,17 @@ static int ovs_meter_cmd_get(struct sk_buff *skb, struct genl_info *info) static int ovs_meter_cmd_del(struct sk_buff *skb, struct genl_info *info) { - struct nlattr **a = info->attrs; - u32 meter_id; struct ovs_header *ovs_header = info->userhdr; struct ovs_header *ovs_reply_header; + struct nlattr **a = info->attrs; + struct dp_meter *old_meter; + struct sk_buff *reply; struct datapath *dp; + u32 meter_id; int err; - struct sk_buff *reply; - struct dp_meter *old_meter; if (!a[OVS_METER_ATTR_ID]) return -EINVAL; - meter_id = nla_get_u32(a[OVS_METER_ATTR_ID]); reply = ovs_meter_cmd_reply_start(info, OVS_METER_CMD_DEL, &ovs_reply_header); @@ -416,14 +538,19 @@ static int ovs_meter_cmd_del(struct sk_buff *skb, struct genl_info *info) goto exit_unlock; } - old_meter = lookup_meter(dp, meter_id); + meter_id = nla_get_u32(a[OVS_METER_ATTR_ID]); + old_meter = lookup_meter(&dp->meter_tbl, meter_id); if (old_meter) { spin_lock_bh(&old_meter->lock); err = ovs_meter_cmd_reply_stats(reply, meter_id, old_meter); WARN_ON(err); spin_unlock_bh(&old_meter->lock); - detach_meter(old_meter); + + err = detach_meter(&dp->meter_tbl, old_meter); + if (err) + goto exit_unlock; } + ovs_unlock(); ovs_meter_free(old_meter); genlmsg_end(reply, ovs_reply_header); @@ -443,16 +570,16 @@ static int ovs_meter_cmd_del(struct sk_buff *skb, struct genl_info *info) bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb, struct sw_flow_key *key, u32 meter_id) { - struct dp_meter *meter; - struct dp_meter_band *band; long long int now_ms = div_u64(ktime_get_ns(), 1000 * 1000); long long int long_delta_ms; - u32 delta_ms; - u32 cost; + struct dp_meter_band *band; + struct dp_meter *meter; int i, band_exceeded_max = -1; u32 band_exceeded_rate = 0; + u32 delta_ms; + u32 cost; - meter = lookup_meter(dp, meter_id); + meter = lookup_meter(&dp->meter_tbl, meter_id); /* Do not drop the packet when there is no meter. */ if (!meter) return false; @@ -570,32 +697,27 @@ struct genl_family dp_meter_genl_family __ro_after_init = { int ovs_meters_init(struct datapath *dp) { - int i; + struct dp_meter_table *tbl = &dp->meter_tbl; + struct dp_meter_instance *ti; - dp->meters = kmalloc_array(METER_HASH_BUCKETS, - sizeof(struct hlist_head), GFP_KERNEL); - - if (!dp->meters) + ti = dp_meter_instance_alloc(DP_METER_ARRAY_SIZE_MIN); + if (!ti) return -ENOMEM; - for (i = 0; i < METER_HASH_BUCKETS; i++) - INIT_HLIST_HEAD(&dp->meters[i]); + rcu_assign_pointer(tbl->ti, ti); + tbl->count = 0; return 0; } void ovs_meters_exit(struct datapath *dp) { + struct dp_meter_table *tbl = &dp->meter_tbl; + struct dp_meter_instance *ti = rcu_dereference_raw(tbl->ti); int i; - for (i = 0; i < METER_HASH_BUCKETS; i++) { - struct hlist_head *head = &dp->meters[i]; - struct dp_meter *meter; - struct hlist_node *n; - - hlist_for_each_entry_safe(meter, n, head, dp_hash_node) - kfree(meter); - } + for (i = 0; i < ti->n_meters; i++) + ovs_meter_free(ti->dp_meters[i]); - kfree(dp->meters); + dp_meter_instance_free(ti); } diff --git a/net/openvswitch/meter.h b/net/openvswitch/meter.h index f645913870bd..f52052d30a16 100644 --- a/net/openvswitch/meter.h +++ b/net/openvswitch/meter.h @@ -13,11 +13,13 @@ #include #include #include +#include #include "flow.h" struct datapath; #define DP_MAX_BANDS 1 +#define DP_METER_ARRAY_SIZE_MIN BIT_ULL(10) struct dp_meter_band { u32 type; @@ -30,9 +32,6 @@ struct dp_meter_band { struct dp_meter { spinlock_t lock; /* Per meter lock */ struct rcu_head rcu; - struct hlist_node dp_hash_node; /*Element in datapath->meters - * hash table. - */ u32 id; u16 kbps:1, keep_stats:1; u16 n_bands; @@ -42,6 +41,17 @@ struct dp_meter { struct dp_meter_band bands[]; }; +struct dp_meter_instance { + struct rcu_head rcu; + u32 n_meters; + struct dp_meter __rcu *dp_meters[]; +}; + +struct dp_meter_table { + struct dp_meter_instance __rcu *ti; + u32 count; +}; + extern struct genl_family dp_meter_genl_family; int ovs_meters_init(struct datapath *dp); void ovs_meters_exit(struct datapath *dp); From patchwork Thu Apr 16 10:17:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 221044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38946C38A29 for ; Sat, 18 Apr 2020 17:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1466E20776 for ; Sat, 18 Apr 2020 17:25:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sMwjRoaK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbgDRRZS (ORCPT ); Sat, 18 Apr 2020 13:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgDRRZP (ORCPT ); Sat, 18 Apr 2020 13:25:15 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA75CC061A0C for ; Sat, 18 Apr 2020 10:25:13 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id t11so2826478pgg.2 for ; Sat, 18 Apr 2020 10:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O10wsNpA1gLWNdvNreUMORJ05p7egTtAGrOIi2dZc1U=; b=sMwjRoaKQFjt8ke4hLUjpKQ98jAMuVh2Q26dgBdwIjEcA3ICI4Qq0wB5zqQLujC5g8 FIyQQ/6mhUlNyJvfOTBd/mqzw5vIt487E8qrmFC1Y0n1d/UEPATP4sGitsIup5SWqAra OfbjCRTiu9ncpeflpKqvnobGA4w7VDegvJ/JxaUQBoKL+tyzqsrhQdqHYmsLusHbXt/F TFWayaQnyyMHzglAPxKAhewYQXPC3w68MTC58JH1aqZs3exuVU2Qq8+X58OrwAIMBil0 thX1UNZ4QsAjsbV1DW1coUcpyhqcXq7u4SX4P9/SLYPTIK7WcJsuAyvRBhljlVKYSUoU /dmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O10wsNpA1gLWNdvNreUMORJ05p7egTtAGrOIi2dZc1U=; b=soHpzFMpNW23ffSJQY1AgVoPprZR1P45eApXSm9dGkQAI+zjfTIi/A1KJ0zM1VrZgU nLlUhW6Tui23BT3ePjbTnlIDrV/4pWC4Oq//aTT6jtUd8PRS3c1g/sheoTRAmnuhb+D2 A33jfMB9npo2GMFSrT8EnOgSUYzjQMc/xSpwaC1jfYLpWlp5iNqoVsgR9BQqRu43gl+4 QgrTCbP26SAJIOgm8Z9mL3TabX5QDNSAC2TGNnv8bdxqfNYCf8rIL+cDlzsF9dy8uxxq nYZxbP7kXSyVAGEfrNrik3Et/w+z8XJXumt82vLJvUOc7VaGteCW4sPqXB89hwISmNO6 EhTg== X-Gm-Message-State: AGi0PualQG3tVciDnrn/yMUqvLazXI+ZQBBmFgBFj5wex1BXlA0jkFiK 09E+lgpvh4N8MjBYn+uqjraDQEDcwBM= X-Google-Smtp-Source: APiQypLdh6m0YUFYRoJM3Pz1IW/VCVqbVtD53FiV723XXXOS9WBWbtqYTIs4Rz8h/GSPgjoj/EyygQ== X-Received: by 2002:a63:cd08:: with SMTP id i8mr8612631pgg.55.1587230713493; Sat, 18 Apr 2020 10:25:13 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([115.171.63.184]) by smtp.gmail.com with ESMTPSA id s44sm9329251pjc.28.2020.04.18.10.25.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Apr 2020 10:25:13 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Cc: netdev@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang Subject: [PATCH net-next v2 2/5] net: openvswitch: set max limitation to meters Date: Thu, 16 Apr 2020 18:17:00 +0800 Message-Id: <1587032223-49460-3-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587032223-49460-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> <1587032223-49460-1-git-send-email-xiangxia.m.yue@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang Don't allow user to create meter unlimitedly, which may cause to consume a large amount of kernel memory. The 200,000 meters may be fine in general case. Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang --- net/openvswitch/meter.c | 21 +++++++++++++++------ net/openvswitch/meter.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index 494a0014ecd8..1b6776f9c109 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -137,6 +137,7 @@ static int attach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) { struct dp_meter_instance *ti = rcu_dereference_ovsl(tbl->ti); u32 hash = meter_hash(ti, meter->id); + int err; /* * In generally, slot selected should be empty, because @@ -148,16 +149,24 @@ static int attach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) dp_meter_instance_insert(ti, meter); /* That function is thread-safe. */ - if (++tbl->count >= ti->n_meters) - if (dp_meter_instance_realloc(tbl, ti->n_meters * 2)) - goto expand_err; + tbl->count++; + if (tbl->count > DP_METER_NUM_MAX) { + err = -EFBIG; + goto attach_err; + } + + if (tbl->count >= ti->n_meters && + dp_meter_instance_realloc(tbl, ti->n_meters * 2)) { + err = -ENOMEM; + goto attach_err; + } return 0; -expand_err: +attach_err: dp_meter_instance_remove(ti, meter); tbl->count--; - return -ENOMEM; + return err; } static void detach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) @@ -264,7 +273,7 @@ static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info) if (IS_ERR(reply)) return PTR_ERR(reply); - if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, U32_MAX) || + if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, DP_METER_NUM_MAX) || nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS)) goto nla_put_failure; diff --git a/net/openvswitch/meter.h b/net/openvswitch/meter.h index d91940383bbe..cdfc6b9dbd42 100644 --- a/net/openvswitch/meter.h +++ b/net/openvswitch/meter.h @@ -19,6 +19,7 @@ struct datapath; #define DP_MAX_BANDS 1 #define DP_METER_ARRAY_SIZE_MIN (1ULL << 10) +#define DP_METER_NUM_MAX (200000ULL) struct dp_meter_band { u32 type; From patchwork Fri Apr 24 00:08:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 220668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B6A6C54FCB for ; Fri, 24 Apr 2020 00:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 270DE20706 for ; Fri, 24 Apr 2020 00:09:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BPkJ1Boc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbgDXAI7 (ORCPT ); Thu, 23 Apr 2020 20:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728046AbgDXAI5 (ORCPT ); Thu, 23 Apr 2020 20:08:57 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B51EC09B042 for ; Thu, 23 Apr 2020 17:08:57 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id j7so3727576pgj.13 for ; Thu, 23 Apr 2020 17:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IXe+9LopwWCD3B+slewPaY/Avt60n4lB3vL4raMN3g4=; b=BPkJ1Boc5TKfvePqYut2uhqmghqz/gX8v1SN8G+3TJM1JdPb2D++FIG55UxGUHdLgL aXcQuHAKAieTAPiqGBUvXCDQ/13TtTBU/m0ndtpotLmRHyo91VQlMOnKwv39QRuBfszM NhvrQERE1+ZxunfpyhG4tBO0DSytghleGpWGBF5I0mKY7R8kTpx/YCIj8WM040rx1lAm f8Dh19qETp6li/ybVsGZfPPad5xRn5cmmH6pWn1RBjIvy6Lh6GXdiH2+CS+r4NpPBU0L 7zA1vTWrd3YEk4trZzLE5xgu6y9hXSW1Df24ZaJn/gPf+g2DCIshuoU+GNnorK7SmxMh 1q8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IXe+9LopwWCD3B+slewPaY/Avt60n4lB3vL4raMN3g4=; b=Y1cQUEYbYbdQ4p+mkw7KC+H0npGJ/ENCr0CicELUl0jnSYJunYIaCy0MfS+vw6tRns LC9JlNJIzrBx4ywdI+O7Ti7OJCOccR67ERO7KjJjQiE6CUYnC7T5JQyZeYxzNRT5sTdN kzx7uHKPZ2ipJYkFW+woigoz2JUig/dIQjNxncHjAa3g6qAcYWE8+Hqh/gZbTYYf/f/1 9v7xLLPg8UpAhK61vD1Zk+/hT0c3q0XdR0QB2bXsKvSyXdJIuBopXGq6wJJUzs5CUGlt /RC5DEskrdsqef+qf15F9KWJB/9nWI2ryJaRjxxONCfa9uKXqcm32smuEcDNOQTmbxkL J8FQ== X-Gm-Message-State: AGi0PuaDZKk9etbPsOqp1rhoAQSpJyEWifdfvLGJPSpa4VOSyBBNzkl9 lgPpq0BzWDn6oT3ObMdzndU= X-Google-Smtp-Source: APiQypJpgnzafTiYiVmWREbokIBvL7HMZsDf9A1IzGOj2nT3QyHo5Gj/7ZQLdnu339Hmz+KI+cPN9g== X-Received: by 2002:a63:f30a:: with SMTP id l10mr6471865pgh.372.1587686937161; Thu, 23 Apr 2020 17:08:57 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([219.142.146.4]) by smtp.gmail.com with ESMTPSA id p10sm3836100pff.210.2020.04.23.17.08.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 17:08:56 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Cc: netdev@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang Subject: [PATCH net-next v4 3/5] net: openvswitch: remove the unnecessary check Date: Fri, 24 Apr 2020 08:08:04 +0800 Message-Id: <1587686886-16347-4-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang Before invoking the ovs_meter_cmd_reply_stats, "meter" was checked, so don't check it agin in that function. Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- net/openvswitch/meter.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index 372f4565872d..b7893b0d6423 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -242,12 +242,11 @@ static int ovs_meter_cmd_reply_stats(struct sk_buff *reply, u32 meter_id, if (nla_put_u32(reply, OVS_METER_ATTR_ID, meter_id)) goto error; - if (!meter) - return 0; - if (nla_put(reply, OVS_METER_ATTR_STATS, - sizeof(struct ovs_flow_stats), &meter->stats) || - nla_put_u64_64bit(reply, OVS_METER_ATTR_USED, meter->used, + sizeof(struct ovs_flow_stats), &meter->stats)) + goto error; + + if (nla_put_u64_64bit(reply, OVS_METER_ATTR_USED, meter->used, OVS_METER_ATTR_PAD)) goto error; From patchwork Thu Apr 16 10:17:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 221043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBBA3C38A29 for ; Sat, 18 Apr 2020 17:25:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B002E20776 for ; Sat, 18 Apr 2020 17:25:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mquaNX+c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgDRRZX (ORCPT ); Sat, 18 Apr 2020 13:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726089AbgDRRZV (ORCPT ); Sat, 18 Apr 2020 13:25:21 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06EC6C061A0C for ; Sat, 18 Apr 2020 10:25:21 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t16so2254921plo.7 for ; Sat, 18 Apr 2020 10:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bH74zxtX/vcy0zyG68W3c+H7KPCmC8DmyViHStZiUyI=; b=mquaNX+cax7RUE+nYsAkCjJg0m0fEP4YdSWvffS/L5goMkclezk1Froc9KjABWxbVm LLWkBRveofV1yty+sk47EqkcJCmlkiBViXeFBZJB5SHVD2sQFOcxzNdaPXbo+7ohX31v LvZ49E15hQ24DL3l+44cthlKWXVm1r3IHahvZDBSmAX8I4k4d+DusTZagJFZiGJa/UO/ cV/dnJEs2Wm8aZRsRbK9uCUMBPjSloVlzpCDftdna8cPGQSEW7O1Xc3LYbxHK7DK8pcb PWmsZVBhblPyuZa4rrY1FDKWfMCldQg4Y4Af+hTaJQ5NvBG/aIniQXkNr8bCJZ5q5D2l o0dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bH74zxtX/vcy0zyG68W3c+H7KPCmC8DmyViHStZiUyI=; b=aF0neqRvGlX7PCzTgeJNVzMUWtblHoE8eFkZ4v7KJVb+UqoSqOWDUZhqkeEc49lOK7 Xxgj/EvBUliHQfO42iquaaUT2DKMdX6g1Mibs0ddzAuf6FXySnGFCls4BJTuRraH6uwD upzFzRtjasJI7/3wsn/hHoRZS+4OZUOSKxfGQj+S4CqdSuvG4nwKII7tGe9HZEwtiXw9 qAD7L2K6kxu2DeTzpMHu2E56CIQC9f7ZEh4CNtUHr4TKCJsaOWThYcxQv/N4C+dfVxJ5 5sikw0cb93BiRfc7YB0IJldhfzbd3SXwlOm7PSPChgUNhVrSqOafcaLU+gnTIhwNtN15 6oQQ== X-Gm-Message-State: AGi0Pub2bmrMs1eNhXNROB7d4H0CamojV02sX3sYCxQutKp8o2CKr/9Z 1MT7/MO70vbTzhoI9P/WiQg= X-Google-Smtp-Source: APiQypJimfkLFhVELRhCAqMfnd2DIwLKYjh3RBNKgBDeePTYAcuqkI3It8sOxIH/3aiMqryuWLr5jw== X-Received: by 2002:a17:90a:fc89:: with SMTP id ci9mr4543928pjb.140.1587230720637; Sat, 18 Apr 2020 10:25:20 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([115.171.63.184]) by smtp.gmail.com with ESMTPSA id s44sm9329251pjc.28.2020.04.18.10.25.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Apr 2020 10:25:20 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Cc: netdev@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang Subject: [PATCH net-next v2 4/5] net: openvswitch: make EINVAL return value more obvious Date: Thu, 16 Apr 2020 18:17:02 +0800 Message-Id: <1587032223-49460-5-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587032223-49460-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> <1587032223-49460-1-git-send-email-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang --- net/openvswitch/meter.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index f552c64ae8df..77fe39cf4f18 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -390,9 +390,8 @@ static int ovs_meter_cmd_set(struct sk_buff *skb, struct genl_info *info) u32 meter_id; bool failed; - if (!a[OVS_METER_ATTR_ID]) { - return -ENODEV; - } + if (!a[OVS_METER_ATTR_ID]) + return -EINVAL; meter = dp_meter_create(a); if (IS_ERR_OR_NULL(meter)) From patchwork Fri Apr 24 00:08:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 220667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2CC7C2BA19 for ; Fri, 24 Apr 2020 00:09:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CB9B2087E for ; Fri, 24 Apr 2020 00:09:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QV3Bh3JX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728292AbgDXAJH (ORCPT ); Thu, 23 Apr 2020 20:09:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728046AbgDXAJD (ORCPT ); Thu, 23 Apr 2020 20:09:03 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 892FEC09B042 for ; Thu, 23 Apr 2020 17:09:03 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x15so3903961pfa.1 for ; Thu, 23 Apr 2020 17:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=if37bc8Wf0UXgYVdHWU4Qs3EVJtjkz/5gKswODLVgIE=; b=QV3Bh3JXYsZZjx0J7Zbn/QB5Jn31R/UBu+4fPDAIwZaQobtF0XglcdJymcR1Y95X5P RpJOBH7rJ425YI/IyBiBlv5cBMJtHeOFUPKwqz03iaQyn1p8mFXcbUynW33LCi/lcK13 Mx21VJji4VmFxfDL4uXg7McakzPiD2vzX1aYDVWhDTpEkr8uNl4VDg20G0GRJL3+b2sz LJRuHRfqqgzvqEAdqsve6lURULFz/U3Teas2jO7uJwxrQUG79PRvt54OvVbOqHIEsleO 2ELXOet1uWOKcQjf02bwbohGMFp4YXI76A5ryFOWYfqRjgRCwEtuH6q+jPk40+P5LiTn wURg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=if37bc8Wf0UXgYVdHWU4Qs3EVJtjkz/5gKswODLVgIE=; b=JPZgTcyxGhQ0f/fp7tapRfgOr/qxGxqSk6TgSuXmdgvCj1Cv1yj+Bsu+0VzJU3nHfa HbRbIZzKUM1/Ic1XR5yAHCV2XLdfqOPzVz0V8xT+KB7gqGh+V83gfssj1t7aupAHTZpr 8tEoOeCrVROfPNWtlpAhTJpVdHDs2YRRWf7wfFoL8blWjcIsHXO5A1N1h/z+sJ4EO7km 6sZ+o1PiE3WITpH1FRi3fR35a3WyFP7rAU9+nfyxk+UtLXcuw2oY4wJRCHr4DbsFPfbK xUmyH8oFbmI+LOjA2FS+l1XhVPRILVFsAy0LmY1XPHzvHVJmZVEXIixs+QC1ChZNsyaX jRTw== X-Gm-Message-State: AGi0PuYakIFgbI9TnBwn0opnOE5PC4s2ldXdetPgsTOYVI8E5WUcWyrT ppSBSZlGUwHJ55OHSR7juZs= X-Google-Smtp-Source: APiQypKkJRyVJvgv9jxJWEDO9i/4UmF15aN8VCtNX/7iitowJ6EwLtkzAGZZw0MxFE+2utwsYo8Lyg== X-Received: by 2002:a62:5ac2:: with SMTP id o185mr6494613pfb.148.1587686943120; Thu, 23 Apr 2020 17:09:03 -0700 (PDT) Received: from local.opencloud.tech.localdomain ([219.142.146.4]) by smtp.gmail.com with ESMTPSA id p10sm3836100pff.210.2020.04.23.17.09.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 17:09:02 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Cc: netdev@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang Subject: [PATCH net-next v4 5/5] net: openvswitch: use u64 for meter bucket Date: Fri, 24 Apr 2020 08:08:06 +0800 Message-Id: <1587686886-16347-6-git-send-email-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> References: <1584969039-74113-1-git-send-email-xiangxia.m.yue@gmail.com> <1587686886-16347-1-git-send-email-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang When setting the meter rate to 4+Gbps, there is an overflow, the meters don't work as expected. Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- net/openvswitch/meter.c | 2 +- net/openvswitch/meter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index e36b464b32a5..915f31123f23 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -392,7 +392,7 @@ static struct dp_meter *dp_meter_create(struct nlattr **a) * * Start with a full bucket. */ - band->bucket = (band->burst_size + band->rate) * 1000; + band->bucket = (band->burst_size + band->rate) * 1000ULL; band_max_delta_t = band->bucket / band->rate; if (band_max_delta_t > meter->max_delta_t) meter->max_delta_t = band_max_delta_t; diff --git a/net/openvswitch/meter.h b/net/openvswitch/meter.h index 61a3ca43cd77..0c33889a8515 100644 --- a/net/openvswitch/meter.h +++ b/net/openvswitch/meter.h @@ -26,7 +26,7 @@ struct dp_meter_band { u32 type; u32 rate; u32 burst_size; - u32 bucket; /* 1/1000 packets, or in bits */ + u64 bucket; /* 1/1000 packets, or in bits */ struct ovs_flow_stats stats; };