Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1776334pxp; Mon, 7 Mar 2022 02:03:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUamjk8j6/JUNzZH3bll8Dg+0dOUPLaHjbLcFZFLzfFs4Gb7iAXvpWfmJyctZre/4Ii8gO X-Received: by 2002:a17:906:facf:b0:6cd:ed0e:ed7 with SMTP id lu15-20020a170906facf00b006cded0e0ed7mr8206908ejb.376.1646647414800; Mon, 07 Mar 2022 02:03:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647414; cv=none; d=google.com; s=arc-20160816; b=eHaE3qHHi7E+4pr6plHS5MOuaiiLbTRT/ShCmMpHXa7slq2LcTXmTaJfuDXvwt8YXr dj4aFLN/uia7cgG38gYWTsu5YDn8azCY/NjkORDbIjPk+h1l8PvFNR5r713I7Ma+jTfa NEw4DxlHKw4ysmJOuP5x573c8TP0lt8UcnZA/ZTp3yDvjvC6IdD25v1Z2sQZuAD1a0IW kQn06Tsz+CtZsN+egqR4lJRTk9V+GcZWgaYAHpYAzzu1G7f3am5va3QeIQB7aCAxjICh 23SvGU0ocwseQuVtuz6f9scl3nZEiEWfdzLp1L3DKnNRFZe2JA9Cq70zA0aZVTiFuwKO Bo4g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pPlXBc++9vNtMaXzoUE0FOs135mgvgty1/baidO1n80=; b=koSLFD7WEtJxdMEg149v5VLLxhpkeT1LEng8G1NYYRfLxPuqndInIbIwuIFn/oCGD5 Z8SE2TG7C0Dibnb+wh7lGdbuNLoLKoppo5kOi54Tm8CpZHbJGD/7D1TMvpM05IO/gKq5 Cl+EFfs22kEPxSpUKh5XFZs8IxSeQ4GATIn7w7ThJHwDVSsjmPJvq2KDYa8VwYd6A2fR CWXbI4/UBUfCgxY29/BTFX7utETg+b7KTkMbsA0sFxZK4G2KQ/w1CJN+wo63C9ly7x1r L63e3RaKrc4zHGEfMWyJSOjww+XsuSb51G1tfJ+pwJkQTpzY5lb8E9FhTudZLQs4EYGO bnxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t+vKloSw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i22-20020a1709064fd600b006db34a66d19si1134194ejw.497.2022.03.07.02.03.12; Mon, 07 Mar 2022 02:03:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t+vKloSw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236293AbiCGJ1E (ORCPT + 99 others); Mon, 7 Mar 2022 04:27:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237362AbiCGJXv (ORCPT ); Mon, 7 Mar 2022 04:23:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6950D52B25; Mon, 7 Mar 2022 01:22:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF4496112D; Mon, 7 Mar 2022 09:22:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9B46C340E9; Mon, 7 Mar 2022 09:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644976; bh=aCBeWPp7bnSby4Ti1baDZe/W50GUMgCuhTNjb9FNlsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t+vKloSwGXTo4t31DgeU5h1kvgDTei8y1IRyVDWJjAXcw6LlctyFH3lI3Jnz8mqxu YtlxcyufoawAkfQ0N7evZfZ8nUMLV32PBC2kPxCamFYuNXPH7MaYtKxPI8A0wF6620 ek6emdPGQytNfQfkutB5liqzG1lulzhdapWYyNJ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Oltean , "David S. Miller" Subject: [PATCH 4.14 23/42] net: dcb: flush lingering app table entries for unregistered devices Date: Mon, 7 Mar 2022 10:18:57 +0100 Message-Id: <20220307091636.826709536@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Oltean commit 91b0383fef06f20b847fa9e4f0e3054ead0b1a1b upstream. If I'm not mistaken (and I don't think I am), the way in which the dcbnl_ops work is that drivers call dcb_ieee_setapp() and this populates the application table with dynamically allocated struct dcb_app_type entries that are kept in the module-global dcb_app_list. However, nobody keeps exact track of these entries, and although dcb_ieee_delapp() is supposed to remove them, nobody does so when the interface goes away (example: driver unbinds from device). So the dcb_app_list will contain lingering entries with an ifindex that no longer matches any device in dcb_app_lookup(). Reclaim the lost memory by listening for the NETDEV_UNREGISTER event and flushing the app table entries of interfaces that are now gone. In fact something like this used to be done as part of the initial commit (blamed below), but it was done in dcbnl_exit() -> dcb_flushapp(), essentially at module_exit time. That became dead code after commit 7a6b6f515f77 ("DCB: fix kconfig option") which essentially merged "tristate config DCB" and "bool config DCBNL" into a single "bool config DCB", so net/dcb/dcbnl.c could not be built as a module anymore. Commit 36b9ad8084bd ("net/dcb: make dcbnl.c explicitly non-modular") recognized this and deleted dcbnl_exit() and dcb_flushapp() altogether, leaving us with the version we have today. Since flushing application table entries can and should be done as soon as the netdevice disappears, fundamentally the commit that is to blame is the one that introduced the design of this API. Fixes: 9ab933ab2cc8 ("dcbnl: add appliction tlv handlers") Signed-off-by: Vladimir Oltean Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/dcb/dcbnl.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) --- a/net/dcb/dcbnl.c +++ b/net/dcb/dcbnl.c @@ -1939,10 +1939,54 @@ int dcb_ieee_delapp(struct net_device *d } EXPORT_SYMBOL(dcb_ieee_delapp); +static void dcbnl_flush_dev(struct net_device *dev) +{ + struct dcb_app_type *itr, *tmp; + + spin_lock(&dcb_lock); + + list_for_each_entry_safe(itr, tmp, &dcb_app_list, list) { + if (itr->ifindex == dev->ifindex) { + list_del(&itr->list); + kfree(itr); + } + } + + spin_unlock(&dcb_lock); +} + +static int dcbnl_netdevice_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + + switch (event) { + case NETDEV_UNREGISTER: + if (!dev->dcbnl_ops) + return NOTIFY_DONE; + + dcbnl_flush_dev(dev); + + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +static struct notifier_block dcbnl_nb __read_mostly = { + .notifier_call = dcbnl_netdevice_event, +}; + static int __init dcbnl_init(void) { + int err; + INIT_LIST_HEAD(&dcb_app_list); + err = register_netdevice_notifier(&dcbnl_nb); + if (err) + return err; + rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0); rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0);