From patchwork Fri May 26 11:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?5byg56WW5bu6?= X-Patchwork-Id: 1786575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.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=20221208 header.b=Zw5xbzJy; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QSSNK5mbGz20QF for ; Sat, 27 May 2023 00:43:45 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 97D5E42CD4; Fri, 26 May 2023 14:43:43 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 97D5E42CD4 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=Zw5xbzJy X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CINv3l0gFxUs; Fri, 26 May 2023 14:43:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id A461940598; Fri, 26 May 2023 14:43:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A461940598 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 798ABC002A; Fri, 26 May 2023 14:43:41 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 66CDEC002A for ; Fri, 26 May 2023 11:49:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 41BCC40207 for ; Fri, 26 May 2023 11:49:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 41BCC40207 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2q9crUcxPR4G for ; Fri, 26 May 2023 11:49:14 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E59CD40194 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by smtp2.osuosl.org (Postfix) with ESMTPS id E59CD40194 for ; Fri, 26 May 2023 11:49:13 +0000 (UTC) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f6cbf02747so4615795e9.1 for ; Fri, 26 May 2023 04:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685101752; x=1687693752; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=hNXDM/B7I7eTJksNJ4nbfc5glWunEpblakPon0ht+1g=; b=Zw5xbzJyr6h1bBAnOFUMNeG+ccLlnuRQmhBRYU+tAsjeWaF8cPjGbYtdes1v50fPT4 X9d5iIYOcHPrzouXZy69qbnIPTusBqlAZpFQX6ouEAq5uvTki/rDh9s64gWdZDr9pLFJ pa7PLvdATdb/ESGcUkl3ZmW/F0vQpkq/F6YQk16cZOfBFGNTYC7OB1mU/L3UoBlsKIKq MPC3ORhbGxF5U3XA+yRuE8nKcCjvDdCmbO23hLMpF8zDDnQMORXlfSS2tkZSsVfGCixI FCbfZcJ4Fc2pg9uqhUJ8JVXW0Haen9d0dA57O4z6Q05GvyZ3gj0ynGLQkAVJpS/icKMT y1SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685101752; x=1687693752; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=hNXDM/B7I7eTJksNJ4nbfc5glWunEpblakPon0ht+1g=; b=kjWLFJOMdDgxYYueBuuX7cbKnS19UMsp6PFz8B25motoJA47ahdhlb04lfEQzR7gsu JLRUIq0FcYPifkQkSbx30ItCWWm+Deae8imIwB/hQP38MrLzz7fjUX8sSzcoIM1ZIaYN Pihx3+EiHfMuxTPghK/uZGAOhsqHPOSadWxwGh+1LMM5qLyrj/GOQfy+3xn8q5P9ZUkf BBI0rRw51Li+XsHN0+hpLe0gXwYtoHnP9skHL3ARfCU3n957EZ42OMNlv3S9HPluiVsx ZIP3P7R5kUVGDpemS2dO/ZCJuUVGl7ll0Z7sOWabPjMY6jdqiqYnI7c2FWbscysuploW OhPg== X-Gm-Message-State: AC+VfDwVbEk1VSe9Ynk+Y8X45sid3PR3ARhOSaMVDiEFbwi7IicxkMoa Qekrsvuq8K2pwsIBdr+bO1lAL+jj9AC2sfks/HDHNX2+ZC/HcjFv X-Google-Smtp-Source: ACHHUZ6Y3BuJKvMnH1qLrK1kF0lP0/cwiePkOHkzylTvaksziE9ERLNT4tu14zaR4Tn4+3xb6K9rBdm11GlweuarmmQ= X-Received: by 2002:a7b:cd15:0:b0:3f6:5cbf:a3a1 with SMTP id f21-20020a7bcd15000000b003f65cbfa3a1mr1556700wmj.14.1685101751423; Fri, 26 May 2023 04:49:11 -0700 (PDT) MIME-Version: 1.0 From: =?utf-8?b?5byg56WW5bu6?= Date: Fri, 26 May 2023 19:48:59 +0800 Message-ID: To: ovs-dev@openvswitch.org X-Mailman-Approved-At: Fri, 26 May 2023 14:43:40 +0000 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [PATCH] netdev-linux: fix memory leak in qos 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" Reported by Valgrind: ==00:00:00:46.715 951138== 56 bytes in 1 blocks are definitely lost in loss record 363 of 408 ==00:00:00:46.715 951138== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==00:00:00:46.715 951138== by 0x278E98: xmalloc__ (util.c:140) ==00:00:00:46.715 951138== by 0x2998C2: netem_install__ (netdev-linux.c:4365) ==00:00:00:46.715 951138== by 0x2998C2: netem_tc_install (netdev-linux.c:4454) ==00:00:00:46.715 951138== by 0x29A5E8: netdev_linux_set_qos (netdev-linux.c:2994) ==00:00:00:46.715 951138== by 0x1390AC: iface_configure_qos (bridge.c:4822) ==00:00:00:46.715 951138== by 0x1390AC: bridge_reconfigure (bridge.c:929) ==00:00:00:46.715 951138== by 0x13C3B8: bridge_run (bridge.c:3298) ==00:00:00:46.715 951138== by 0x131314: main (ovs-vswitchd.c:129) ==00:00:00:46.715 951138== ==00:00:00:46.715 951138== 56 bytes in 1 blocks are definitely lost in loss record 364 of 408 ==00:00:00:46.715 951138== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==00:00:00:46.715 951138== by 0x278E98: xmalloc__ (util.c:140) ==00:00:00:46.715 951138== by 0x293688: netem_install__ (netdev-linux.c:4365) ==00:00:00:46.715 951138== by 0x293688: netem_qdisc_set (netdev-linux.c:4504) ==00:00:00:46.715 951138== by 0x29A696: netdev_linux_set_qos (netdev-linux.c:2982) ==00:00:00:46.715 951138== by 0x1390AC: iface_configure_qos (bridge.c:4822) ==00:00:00:46.715 951138== by 0x1390AC: bridge_reconfigure (bridge.c:929) ==00:00:00:46.715 951138== by 0x13C3B8: bridge_run (bridge.c:3298) ==00:00:00:46.715 951138== by 0x131314: main (ovs-vswitchd.c:129) ==00:00:00:46.715 951138== Signed-off-by: 张祖建 --- lib/netdev-linux.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) codel->target = target; @@ -3967,6 +3974,13 @@ fqcodel_install__(struct netdev *netdev_, uint32_t target, uint32_t limit, struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct fqcodel *fqcodel; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + fqcodel = xmalloc(sizeof *fqcodel); tc_init(&fqcodel->tc, &tc_ops_fqcodel); fqcodel->target = target; @@ -4189,6 +4203,13 @@ sfq_install__(struct netdev *netdev_, uint32_t quantum, uint32_t perturb) struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct sfq *sfq; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + sfq = xmalloc(sizeof *sfq); tc_init(&sfq->tc, &tc_ops_sfq); sfq->perturb = perturb; @@ -4364,6 +4385,13 @@ netem_install__(struct netdev *netdev_, uint32_t latency, struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netem *netem; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + netem = xmalloc(sizeof *netem); tc_init(&netem->tc, &tc_ops_netem); netem->latency = latency; @@ -4554,6 +4582,13 @@ htb_install__(struct netdev *netdev_, uint64_t max_rate) struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct htb *htb; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + htb = xmalloc(sizeof *htb); tc_init(&htb->tc, &tc_ops_htb); htb->max_rate = max_rate; @@ -5039,6 +5074,13 @@ hfsc_install__(struct netdev *netdev_, uint32_t max_rate) struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct hfsc *hfsc; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + hfsc = xmalloc(sizeof *hfsc); tc_init(&hfsc->tc, &tc_ops_hfsc); hfsc->max_rate = max_rate; @@ -5510,6 +5552,13 @@ noop_install__(struct netdev *netdev_) struct netdev_linux *netdev = netdev_linux_cast(netdev_); static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_default); + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + netdev->tc = CONST_CAST(struct tc *, &tc); } @@ -5545,6 +5594,13 @@ default_install__(struct netdev *netdev_) struct netdev_linux *netdev = netdev_linux_cast(netdev_); static const struct tc tc = TC_INITIALIZER(&tc, &tc_ops_default); + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + /* Nothing but a tc class implementation is allowed to write to a tc. This * class never does that, so we can legitimately use a const tc object. */ netdev->tc = CONST_CAST(struct tc *, &tc); -- 2.40.1 diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 36620199e..6a90ce4c7 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -3756,6 +3756,13 @@ codel_install__(struct netdev *netdev_, uint32_t target, uint32_t limit, struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct codel *codel; + if (netdev->tc) { + if (netdev->tc->ops->tc_destroy) { + netdev->tc->ops->tc_destroy(netdev->tc); + } + netdev->tc = NULL; + } + codel = xmalloc(sizeof *codel); tc_init(&codel->tc, &tc_ops_codel);