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: 1276075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ZMd3S5RW; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497ZK70lD0z9sSK for ; Fri, 24 Apr 2020 10:08:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 66A76886F4; Fri, 24 Apr 2020 00:08:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fRviXk0jaIFJ; Fri, 24 Apr 2020 00:08:55 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id E60C0886E4; Fri, 24 Apr 2020 00:08:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D0DD6C1797; Fri, 24 Apr 2020 00:08:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id E6CC4C0175 for ; Fri, 24 Apr 2020 00:08:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id D0DC8886DF for ; Fri, 24 Apr 2020 00:08:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i3uKzTEhYAzO for ; Fri, 24 Apr 2020 00:08:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by hemlock.osuosl.org (Postfix) with ESMTPS id 9BF27886D5 for ; Fri, 24 Apr 2020 00:08:51 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id r4so3742135pgg.4 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=sVP6tbFhGbkkb46pEhqEskONU8vu2krLW3pBXG9tDe0NctJfG4UePWa0kBsVakRpPN zftlixHzCzx1G/B561bBKa8I8feD7BrDuPF4LVOFITru5GrztO3zaYAXwVNUp+IqyRV1 /NuyrXdolO9rH+dYBbk9LAlFsRV2WI+cKewZX+mvJRXCEofz9y0Sf+EKf0fwa5u/dN66 V9PE/ViIyi1wQXhwW3CXNQrwfcXN2Q4lyLg760GFTa2aCM2POB6Pjc8IHYq/3mw6kH97 PJte1hfrnnJqv0/R8QF5MAy/Xy0dLXzRmZKkhqHyiDvx9l5YCxOD9hZKrz9WYBY/LSW0 kVGA== X-Gm-Message-State: AGi0PuaZ2yRTjYdNsDAFRZ2p8aDMd3hSXMkCEfUcJrbeqM8oF6XX5Wsn +YyMAXPTVKyz1g/PHY+trWY= 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 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> Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 1/5] net: openvswitch: expand the meters supported number X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Fri Apr 24 00:08:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1276082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=p5b/6PiD; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497ZKj0dQqz9sRN for ; Fri, 24 Apr 2020 10:09:28 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B2A0086FA3; Fri, 24 Apr 2020 00:09:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y_njgo-5WhEU; Fri, 24 Apr 2020 00:09:07 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5695C86F0A; Fri, 24 Apr 2020 00:09:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3768AC1DCE; Fri, 24 Apr 2020 00:09:05 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0305CC1DD7 for ; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 4FD7D2442C for ; Fri, 24 Apr 2020 00:08:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SDjY9gLtM7ll for ; Fri, 24 Apr 2020 00:08:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by silver.osuosl.org (Postfix) with ESMTPS id 6B846203A0 for ; Fri, 24 Apr 2020 00:08:54 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id o185so3753928pgo.3 for ; Thu, 23 Apr 2020 17:08:54 -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=PnDLkt9Mny0Ug5XbHtPtHnoEVp1JJPW8pEJUgNgzREk=; b=p5b/6PiDR57XGeSX7AXBBaBAniKraEPG1j++xLvmmBnkONUR0ajLm2cakGIoi5zipP a0JjDjk4yTiBwFTsq11e2xC9VsKVF4weqJkVZSmGfRe8PMAxlOnQutrmBHDITscXHBXL NQNUIkz/zRSGK6qzkI8ixYgIZ0gtY930foTBxy5D1Q3i3ApUoL0UDBUQqT8zbDM/hQUe Zv7v8YT2eRTbC/upz1oMPWjWuocgvvnDvJyTZGBNCFiCdSlybuKmFEevU8TzCTWPRMXK WAZx372/MkTazYJQdlUsJIPl3MC1cTVReTDxdLLA7X+4uAtiZBhlir3VdLvGSnACIc3y pVIQ== 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=PnDLkt9Mny0Ug5XbHtPtHnoEVp1JJPW8pEJUgNgzREk=; b=B8fvSX7AItenlzi6aBmyL6FBr9xUzJ74kPgUPHdmM0lUg5YNww94u6AdIa2TOH2GM+ 3PHPtwS13qaqEYjAkKuzqSp/Kt5BgTpx1iXlZaoC8kR6Mjl096YoR53Gr8MPkwMZPx0R WmK92wgCoOj2M7BIflYJaS3X0TcMa0IAV79EPnn0YvwGu5dh70qblfnqqp9CVk713XMh aVcgweYMWU+/Y3f2/g9wVu3KJhOO3yMqExhIQN/GvQz2IzxjbXIlFPFbICots51jm4jc wyvZxlJUU40wr3sMbk3LKHzMa4p5ozYPw5u98K/RxeG5s6sFZnjn+YHm0mEiNjeiDAI1 0Adw== X-Gm-Message-State: AGi0PuZwcG4t9LRQNlN27Sx3Y+nHVidhDrdT/JCNDa06hZWwFxqoJrTf tgAm3EXUTN1V6+U+2V7ocgc= X-Google-Smtp-Source: APiQypInE/EovtRVq9hQpUY/ochnc87sRKBw8CUAuZKpTyMRDd5LpEOCK/TL2mftCqa+MLAZe07o3g== X-Received: by 2002:a62:6807:: with SMTP id d7mr6623566pfc.296.1587686934009; Thu, 23 Apr 2020 17:08:54 -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.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 17:08:53 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Date: Fri, 24 Apr 2020 08:08:03 +0800 Message-Id: <1587686886-16347-3-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> MIME-Version: 1.0 Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 2/5] net: openvswitch: set max limitation to meters X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang Don't allow user to create meter unlimitedly, which may cause to consume a large amount of kernel memory. The max number supported is decided by physical memory and 20K meters as default. Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- net/openvswitch/meter.c | 57 +++++++++++++++++++++++++++++++++-------- net/openvswitch/meter.h | 2 ++ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index f806ded1dd0a..372f4565872d 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -137,6 +138,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, slots selected should be empty, because * OvS uses id-pool to fetch a available id. @@ -147,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 >= tbl->max_meters_allowed) { + 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 int detach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) @@ -266,18 +276,32 @@ static int ovs_meter_cmd_reply_stats(struct sk_buff *reply, u32 meter_id, static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info) { - struct sk_buff *reply; + struct ovs_header *ovs_header = info->userhdr; struct ovs_header *ovs_reply_header; struct nlattr *nla, *band_nla; - int err; + struct sk_buff *reply; + struct datapath *dp; + int err = -EMSGSIZE; reply = ovs_meter_cmd_reply_start(info, OVS_METER_CMD_FEATURES, &ovs_reply_header); if (IS_ERR(reply)) return PTR_ERR(reply); - if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, U32_MAX) || - nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS)) + ovs_lock(); + dp = get_dp(sock_net(skb->sk), ovs_header->dp_ifindex); + if (!dp) { + err = -ENODEV; + goto exit_unlock; + } + + if (nla_put_u32(reply, OVS_METER_ATTR_MAX_METERS, + dp->meter_tbl.max_meters_allowed)) + goto exit_unlock; + + ovs_unlock(); + + if (nla_put_u32(reply, OVS_METER_ATTR_MAX_BANDS, DP_MAX_BANDS)) goto nla_put_failure; nla = nla_nest_start_noflag(reply, OVS_METER_ATTR_BANDS); @@ -296,9 +320,10 @@ static int ovs_meter_cmd_features(struct sk_buff *skb, struct genl_info *info) genlmsg_end(reply, ovs_reply_header); return genlmsg_reply(reply, info); +exit_unlock: + ovs_unlock(); nla_put_failure: nlmsg_free(reply); - err = -EMSGSIZE; return err; } @@ -699,15 +724,27 @@ int ovs_meters_init(struct datapath *dp) { struct dp_meter_table *tbl = &dp->meter_tbl; struct dp_meter_instance *ti; + unsigned long free_mem_bytes; ti = dp_meter_instance_alloc(DP_METER_ARRAY_SIZE_MIN); if (!ti) return -ENOMEM; + /* Allow meters in a datapath to use ~3.12% of physical memory. */ + free_mem_bytes = nr_free_buffer_pages() * (PAGE_SIZE >> 5); + tbl->max_meters_allowed = min(free_mem_bytes / sizeof(struct dp_meter), + DP_METER_NUM_MAX); + if (!tbl->max_meters_allowed) + goto out_err; + rcu_assign_pointer(tbl->ti, ti); tbl->count = 0; return 0; + +out_err: + dp_meter_instance_free(ti); + return -ENOMEM; } void ovs_meters_exit(struct datapath *dp) diff --git a/net/openvswitch/meter.h b/net/openvswitch/meter.h index f52052d30a16..61a3ca43cd77 100644 --- a/net/openvswitch/meter.h +++ b/net/openvswitch/meter.h @@ -20,6 +20,7 @@ struct datapath; #define DP_MAX_BANDS 1 #define DP_METER_ARRAY_SIZE_MIN BIT_ULL(10) +#define DP_METER_NUM_MAX (200000UL) struct dp_meter_band { u32 type; @@ -50,6 +51,7 @@ struct dp_meter_instance { struct dp_meter_table { struct dp_meter_instance __rcu *ti; u32 count; + u32 max_meters_allowed; }; extern struct genl_family dp_meter_genl_family; 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: 1276078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=BPkJ1Boc; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497ZKG0W6gz9sPF for ; Fri, 24 Apr 2020 10:09:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C9B4988702; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4bxVZSBWUvMq; Fri, 24 Apr 2020 00:09:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id EE56288708; Fri, 24 Apr 2020 00:08:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D953CC1D87; Fri, 24 Apr 2020 00:08:59 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id A9C48C1D7D for ; Fri, 24 Apr 2020 00:08:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 98B59886EF for ; Fri, 24 Apr 2020 00:08:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o-Sx5WQlNDOR for ; Fri, 24 Apr 2020 00:08:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by hemlock.osuosl.org (Postfix) with ESMTPS id 71E2D886D5 for ; Fri, 24 Apr 2020 00:08:57 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id v63so3879973pfb.10 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=dXsNVLkdCzeTh7YZnnqkb7LWmD56wFCTgl6nYMwIFZYUkYKazodKYAL5DG6A+IUbR5 u8rmHLvjHcLOzCr2HLJyG8mqXj+eNA4T95fWr+vK1TR/locc0PnV5yW3UoVAl+T23REU FK8WXkwZxSQpUZJz/ovM4bcqpJ20STUOMz6GMBMlffuPKdfnOeBXTEGmHzBENJhKmqpb a3hC9EIq6bE7BkbYWld6RbYF12qVFG8bwI/rhB34mthYJAAV9aiVMxABVXYmm8JTM0AR wgjkJWdiV+Xil++x5Ze735MNqq+uKvg5N8RjJ3N9h6f/Q+xXQiC5qiQPorujntMth74P FkWw== X-Gm-Message-State: AGi0PuaHJl6wZFv+mAVXV7XmRVdGC3DdP05zlyHXxjB/8EiVbjtSAJ4D y+hGnAfQ3tGDdI5Zk8o1fZw= 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 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> Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 3/5] net: openvswitch: remove the unnecessary check X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 Fri Apr 24 00:08:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1276080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=JfP6q/PC; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497ZKR67trz9sPF for ; Fri, 24 Apr 2020 10:09:15 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2BC03248A1; Fri, 24 Apr 2020 00:09:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VjiKkL9n6+et; Fri, 24 Apr 2020 00:09:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 8B28124AF1; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6AB75C1DCF; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8DA4EC1D92 for ; Fri, 24 Apr 2020 00:09:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7DE6D86EE3 for ; Fri, 24 Apr 2020 00:09:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JSjsHApHIdut for ; Fri, 24 Apr 2020 00:09:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 8392E86EE8 for ; Fri, 24 Apr 2020 00:09:00 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id x77so3904578pfc.0 for ; Thu, 23 Apr 2020 17:09:00 -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=Cmy1vOw0+c/YYshZ1hVi1eYwZLLSggt6maHk9MyIK+4=; b=JfP6q/PC+qj0NGHzuMR61bAqCriaFb5Dg2lm0BLvywLvGUvLPX7rHVx26PpKzvutg4 KFFFgW4SRf4ka4SQV0m/NL+7xhNOY2cYZV86iaF1LoDa1n1e41prkD8nRwhmSTYVjqCg l4zmPVKTLzgLlAPy9xhW5cYRPEtnCoxm7bjtoiu8fo7mzhU4hSNRd1hv0AgvpaEfHr8z F322xTKrRjrzY6fdJdoLs06xjuiKSzyzdFm0/5rs5PamgNNfuzJH8J3GIUB0ICneXi1H cEhgrfd42VguSv+q7uDzPeTAfRY8AZ6SjyVolf0SMuOWTxZbC8DXpvi6sGwyZO3zyCj9 kvfw== 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=Cmy1vOw0+c/YYshZ1hVi1eYwZLLSggt6maHk9MyIK+4=; b=jtq+sqUZOniqgomj6D4Jd/A1lbyoGGJaCC/arGDvydk5qsFrYjfXg9XEbV4gipyvJe RTC2iybVJnGosDDBdHbYAmC7ZqM3Qr75zWbCKRWoRTd7ChBjwORdgHqAC+MaXQOmhLPu JWg2j2dAc5afVX64z4fNLqsGsqDr9fcBVC+GErmQflOnxbNvivrOLMxbTkAao/FK2GFC TSuJzB7t3aatfUPFdh9ao/wShl2aJtPpeOKbJNTJnoWGB7jCjWEmNkckUVeu80U3QBAO DIgGDRmSQZQhHMciZ8p4cUvr04I3p77rVJMgz0RaBRT1IvKcpvQwVpM141nfyzHlnktm Mx9w== X-Gm-Message-State: AGi0Pua5JzblkMtiGVQQcAgobR0teUZP6V5M7eaqjpFct9mM9UNImkIx O4K9yg8ekRL/NNInadwQWZY= X-Google-Smtp-Source: APiQypKXdZCK6jujTn3MWS23DnKZV5Ta+Gs3iNHotdfAofw+IL73J9DVYgmMW1PZoS2Nq1L4eIdQzQ== X-Received: by 2002:a63:b256:: with SMTP id t22mr6071757pgo.92.1587686940093; Thu, 23 Apr 2020 17:09:00 -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.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 17:08:59 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: pshelar@ovn.org, azhou@ovn.org, blp@ovn.org, u9012063@gmail.com Date: Fri, 24 Apr 2020 08:08:05 +0800 Message-Id: <1587686886-16347-5-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> Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 4/5] net: openvswitch: make EINVAL return value more obvious X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang Cc: Pravin B Shelar Cc: Andy Zhou Signed-off-by: Tonghao Zhang Acked-by: Pravin B Shelar --- 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 b7893b0d6423..e36b464b32a5 100644 --- a/net/openvswitch/meter.c +++ b/net/openvswitch/meter.c @@ -419,9 +419,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: 1276081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QV3Bh3JX; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 497ZKX31wXz9sPF for ; Fri, 24 Apr 2020 10:09:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id AE0EF24A82; Fri, 24 Apr 2020 00:09:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XN97ySFlANz5; Fri, 24 Apr 2020 00:09:15 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 2440824B04; Fri, 24 Apr 2020 00:09:08 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0AD98C1DCE; Fri, 24 Apr 2020 00:09:08 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 602E1C1DCF for ; Fri, 24 Apr 2020 00:09:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 47FA986EDF for ; Fri, 24 Apr 2020 00:09:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xJfxtnE5mdhE for ; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 7BF2186EC4 for ; Fri, 24 Apr 2020 00:09:03 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id x77so3904635pfc.0 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=SZpzyC/Kd+NEypuhm2WX0xkVDO+LtdKthR3MBogey6G4WoTdefcLiG8ItAa3pU53gg AMptT67uCcFLBlVdLUxuH1xhfbwMQypHb/8OrNcNY/2e4vQsNfZ4Z4LfrjcOizKZh6Eq KdKA1JbJ/uH5WAchXoEMwGApgTbqh56BWk6IfwMTun8Qh2RAR88qvKjLrmjPff7i6TfD WAs4IsU245qCpjXEcRvQ8ADB3R6on5Dqi+zzBpkf7/vC+vpTLEScH8gB9BhKBhI6POj0 sEGWMhkDNGH3V8I08GB3ZDeiukxyFisYFsZnU66/KjvrwqeQ8SazZK/WZN+QbKH8/vUL 6sdA== X-Gm-Message-State: AGi0Pubt/LlafppxFvdwNn8tPlS+rRIFozUHBmVs8RrF+mD1Asxy/9Fi enDpNw8IEi2SIzsu2mCcFI8= 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 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> Cc: dev@openvswitch.org, netdev@vger.kernel.org Subject: [ovs-dev] [PATCH net-next v4 5/5] net: openvswitch: use u64 for meter bucket X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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; };