From nobody Mon Apr 29 07:53:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614942697; cv=none; d=zohomail.com; s=zohoarc; b=aVTIosgOActGTnZi/E7jY8oL6IwvfzbGgQqVrz5wM8pDYgkKDqJgL2A9b5Qd9Z0il8yk1B6ADq6se3JjJUqtZWFjW+vZqRnekBgntwkqdzaGFxA/k4fytYSWvcnzKrZRXlwKBf/USYW0EeYA2VbuHWI+UJ8FZRd+D2BxIEL+5+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614942697; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=5+Jn0Rn8iYjyga7oB2vzk9ZnLV1Ywn7ff36Mzow0jQM=; b=nh4GfXaK9zWnUEJ3+WxgqWNvSQhR7g+0V0tx2q4Mnczh+DjjEmjSzYJI3znUGepnGh2Nabh1pty9K+1LdmlH0SfpyHZvp1mQ4j1huBTYu+fiVOo495OGQ5/QaOKytWXkayj8lGZiI59IRYkKEg0Om5xmNPBaAua/ZOjzY9s8b3E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 16149426974191001.9763138367575; Fri, 5 Mar 2021 03:11:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-308-1eS3IknlMpCYXCxvXUkO4Q-1; Fri, 05 Mar 2021 06:11:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB2911005D4C; Fri, 5 Mar 2021 11:11:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57EBD58821; Fri, 5 Mar 2021 11:11:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 757AE5002E; Fri, 5 Mar 2021 11:11:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 125BBOcc012765 for ; Fri, 5 Mar 2021 06:11:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id D56A45DA2D; Fri, 5 Mar 2021 11:11:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 599E25D9C6 for ; Fri, 5 Mar 2021 11:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614942696; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5+Jn0Rn8iYjyga7oB2vzk9ZnLV1Ywn7ff36Mzow0jQM=; b=J0FU8sdyeP9ajmiE/7R3ddxAJoetyPNbWSfow1yDpKVN6AbxNX5+txrLv+9ij+un8vDafV yedMeuE1u4Iyhhv5Ak5Bc7LnLTrdOKVRXMKpschyZxjdwJI6orDjLbXcjiOr1sg6aZk4fw N4BFLNuLD8a+82Yy5Nd+odrijS4Xco8= X-MC-Unique: 1eS3IknlMpCYXCxvXUkO4Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virnetdevbandwidth: Don't generate burst outside of boundaries Date: Fri, 5 Mar 2021 12:11:19 +0100 Message-Id: <11935b5733df616ada3e617930b465ae953e0aca.1614942679.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When generating TC rules for domain's outbound traffic, Libvirt will use the 'average' as the default for 'burst' - it's been this way since the feature introduction in v0.9.4-rc1~22. The reason is that 'average' considers 'burst' for policing. However, when parsing its command line TC uses an unsigned int (with overflow detection) to store the 'burst' size. This means, that the upper limit for the value is UINT_MAX, well UINT_MAX / 1024 because we are putting the value in KiB onto the command line. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1912210 Signed-off-by: Michal Privoznik Reviewed-by: Laine Stump --- src/util/virnetdevbandwidth.c | 12 +++++++++++- tests/virnetdevbandwidthtest.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 612e8f985c..77a97176b0 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -358,7 +358,17 @@ virNetDevBandwidthSet(const char *ifname, =20 if (rx) { average =3D g_strdup_printf("%llukbps", rx->average); - burst =3D g_strdup_printf("%llukb", rx->burst ? rx->burst : rx->av= erage); + + if (rx->burst) { + burst =3D g_strdup_printf("%llukb", rx->burst); + } else { + /* Internally, tc uses uint to store burst size (in bytes). + * Therefore, the largest value we can set is UINT_MAX bytes. + * We're outputting the vale in KiB though. */ + unsigned long long avg =3D MIN(rx->average, UINT_MAX / 1024); + + burst =3D g_strdup_printf("%llukb", avg); + } =20 virCommandFree(cmd); cmd =3D virCommandNew(TC); diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 2e76af3d0c..7c236f50f3 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -156,6 +156,21 @@ mymain(void) TC " filter add dev eth0 parent ffff: protocol all u32 ma= tch u32 0 0 " "police rate 5kbps burst 7kb mtu 64kb drop flowid :1\n")); =20 + DO_TEST_SET(("" + " " + " " + ""), + (TC " qdisc del dev eth0 root\n" + TC " qdisc del dev eth0 ingress\n" + TC " qdisc add dev eth0 root handle 1: htb default 1\n" + TC " class add dev eth0 parent 1: classid 1:1 htb rate 42= 94967295kbps quantum 366503875\n" + TC " qdisc add dev eth0 parent 1:1 handle 2: sfq perturb = 10\n" + TC " filter add dev eth0 parent 1:0 protocol all prio 1 h= andle 1 fw flowid 1\n" + TC " qdisc add dev eth0 ingress\n" + TC " filter add dev eth0 parent ffff: protocol all u32 ma= tch " + "u32 0 0 police rate 4294967295kbps burst 4194303kb mtu 6= 4kb " + "drop flowid :1\n")); + return ret; } =20 --=20 2.26.2