Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp657205pxy; Wed, 21 Apr 2021 11:37:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRAhZL93Q7pA5k/1enmtZVa9IZUJ/1Trif67lqLEDpGwMs4VVuNUwQN1jgOBXF4fqXNKHJ X-Received: by 2002:a05:6402:2794:: with SMTP id b20mr22413524ede.48.1619030229174; Wed, 21 Apr 2021 11:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619030229; cv=none; d=google.com; s=arc-20160816; b=hEl06m6vwHWdS7xxDhQMUzE6VIhBRrSqXSyYnXhO5GOSQXKas7ovYe1OwCq98XNCWf 2p51QAcrJr7sO1+KDH46MeQx1aERh6uONTD3G5Cn49lgfNNrKh1huhghaEhmlxca9eR6 aUW/xYU5ekoO8YJtm7W5285NZAeWQsZMCrS56zstsk9o2Aqe94uQ1eZJnIjVclmj+hoA w5dbxgc6c3+ktTovCJrzxeYhIbbajBkdPOWYgfLTtCp8TVBLFlHYr6f4dBULX4k/D+50 MZ5jgTXGhsb6R9pF5t0Q6LAAZZbDMx+ojh89LVc6LYDCx0xXOXZ72Kdu/vplDvYkvaa8 49VA== 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 :message-id:date:subject:cc:to:from; bh=EnJvDwsl7YJYB5I++SBk9gPRejX1/2w4H4XIKSBiJw0=; b=pSfkPGllVs1SfJYMpKeu4S5Tx81J8KESGIQO7hez4dzxyCrjzd6REbZk21GkiMC+1c miAH/QoKyPyf7Jpp/4MHZrUDTDPxdKHV1ZunFAcmh5teSpwyRQG/etUlwwq2T1nuNl6T M3OFFYJIKvWsNgFOQnGTJOPT32FKlA6FDaeNqGakjQS2pjV/jShWaGZWOytR8OaWCvcq Ztov08On4nSu7Ft35BrJLZCFPiq78BojSKpeTMF7A3ZYPsHSHv2H128c7f4ySYVSEooC IQ9/pxoC0hNU29FYczMag8nKO4Wy29na+QDqnWQMhY0I9sqOo/BDYer8yZYHozVoXejq NYqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si21842ejp.635.2021.04.21.11.36.44; Wed, 21 Apr 2021 11:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243085AbhDUN60 (ORCPT + 99 others); Wed, 21 Apr 2021 09:58:26 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:40039 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238217AbhDUN60 (ORCPT ); Wed, 21 Apr 2021 09:58:26 -0400 X-Originating-IP: 78.45.89.65 Received: from im-t490s.redhat.com (ip-78-45-89-65.net.upcbroadband.cz [78.45.89.65]) (Authenticated sender: i.maximets@ovn.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 89E21240007; Wed, 21 Apr 2021 13:57:49 +0000 (UTC) From: Ilya Maximets To: Pravin B Shelar Cc: "David S. Miller" , Jakub Kicinski , Andy Zhou , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dev@openvswitch.org, Tonghao Zhang , William Tu , Jean Tourrilhes , Ilya Maximets Subject: [PATCH net] openvswitch: meter: remove rate from the bucket size calculation Date: Wed, 21 Apr 2021 15:57:47 +0200 Message-Id: <20210421135747.312095-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implementation of meters supposed to be a classic token bucket with 2 typical parameters: rate and burst size. Burst size in this schema is the maximum number of bytes/packets that could pass without being rate limited. Recent changes to userspace datapath made meter implementation to be in line with the kernel one, and this uncovered several issues. The main problem is that maximum bucket size for unknown reason accounts not only burst size, but also the numerical value of rate. This creates a lot of confusion around behavior of meters. For example, if rate is configured as 1000 pps and burst size set to 1, this should mean that meter will tolerate bursts of 1 packet at most, i.e. not a single packet above the rate should pass the meter. However, current implementation calculates maximum bucket size as (rate + burst size), so the effective bucket size will be 1001. This means that first 1000 packets will not be rate limited and average rate might be twice as high as the configured rate. This also makes it practically impossible to configure meter that will have burst size lower than the rate, which might be a desirable configuration if the rate is high. Inability to configure low values of a burst size and overall inability for a user to predict what will be a maximum and average rate from the configured parameters of a meter without looking at the OVS and kernel code might be also classified as a security issue, because drop meters are frequently used as a way of protection from DoS attacks. This change removes rate from the calculation of a bucket size, making it in line with the classic token bucket algorithm and essentially making the rate and burst tolerance being predictable from a users' perspective. Same change proposed for the userspace implementation. Fixes: 96fbc13d7e77 ("openvswitch: Add meter infrastructure") Signed-off-by: Ilya Maximets --- The same patch for the userspace datapath: https://patchwork.ozlabs.org/project/openvswitch/patch/20210421134816.311584-1-i.maximets@ovn.org/ net/openvswitch/meter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/meter.c b/net/openvswitch/meter.c index 15424d26e85d..96b524ceabca 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) * 1000ULL; + band->bucket = band->burst_size * 1000ULL; band_max_delta_t = div_u64(band->bucket, band->rate); if (band_max_delta_t > meter->max_delta_t) meter->max_delta_t = band_max_delta_t; @@ -641,7 +641,7 @@ bool ovs_meter_execute(struct datapath *dp, struct sk_buff *skb, long long int max_bucket_size; band = &meter->bands[i]; - max_bucket_size = (band->burst_size + band->rate) * 1000LL; + max_bucket_size = band->burst_size * 1000LL; band->bucket += delta_ms * band->rate; if (band->bucket > max_bucket_size) -- 2.26.3