Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp713700imm; Thu, 13 Sep 2018 06:42:40 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb/p8RKNmFyRysB8iHtibvGwuM16dGpi+2JUGcHhMWsh5JTfUnI6+n5z9G9zZKdJaHiAed4 X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr6389057pgc.431.1536846160039; Thu, 13 Sep 2018 06:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846160; cv=none; d=google.com; s=arc-20160816; b=g3/0OXYVJSh9YF737bXYh3bILx5F7EJbEjqDnrHneAhn1yUurufEDb/pY7LKAmE2y7 nOM18+N8b0pSGOT0v7zyAXZQMejEsTWodnIA7+QLa6ke4OxMvCFCC5FgdTFq855c4etl JpdKtiSU7lTbjXQGgR2iC+NGgtfGtaafvdGepFWlKzsg9sp/c1Q9USDLLeX7drbtGyw7 pHk9R2fYCJ4K/hSC7F0xIqm2Fu0eqGpM7/uL5pS3vSBqZTx9fWPkkqaPbybg0x7v0cud pR2uAOYLNLd8w3agGlkmVeHUtAbI1eVdrp338s1zBClE6pye3FsZelngi9UDKM/S+t6w FNXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=yrh4XMHPs4D2HB6FY8AorDb0BvW5Ywi6SdDelzuELdM=; b=URr0OWOW7rlLOpvVbXAyTnZadBKWp87UV2zyoQrXSBEkE5iEcNrZV2pGhrcsUR7Qp7 TxDGKHpnpUEfuWoe2Grzhh1I+trh7ucOcrmiU1lkhURRH/PV6Doqu3KAMFuQWtLVptA0 VHbyGlJnogiTvDVOefN1sVJg5vIVXtrduWudPa9H5AfBnPECZ/IutVgeWpjSe3neyM21 Z8AIhl+RrLQim4oxPefNGXR9aU08b2CscDNKqwePtakOJrJdTHCpzSyJTqg5HjigZyBR txjHhuabrw+/Bvh139AYvySE0KSua5mEY0V9cLuU8Pa0BI5pLHWrUndr0SafIvCm9B7S jI4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si4310873plm.34.2018.09.13.06.42.25; Thu, 13 Sep 2018 06:42:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729681AbeIMSvU (ORCPT + 99 others); Thu, 13 Sep 2018 14:51:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60072 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728471AbeIMSvT (ORCPT ); Thu, 13 Sep 2018 14:51:19 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 36E6BD19; Thu, 13 Sep 2018 13:41:47 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Petr Machata , "David S. Miller" Subject: [PATCH 4.14 014/115] mlxsw: spectrum_switchdev: Do not leak RIFs when removing bridge Date: Thu, 13 Sep 2018 15:30:34 +0200 Message-Id: <20180913131824.358865632@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131823.327472833@linuxfoundation.org> References: <20180913131823.327472833@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ido Schimmel [ Upstream commit 602b74eda81311dbdb5dbab08c30f789f648ebdc ] When a bridge device is removed, the VLANs are flushed from each configured port. This causes the ports to decrement the reference count on the associated FIDs (filtering identifier). If the reference count of a FID is 1 and it has a RIF (router interface), then this RIF is destroyed. However, if no port is member in the VLAN for which a RIF exists, then the RIF will continue to exist after the removal of the bridge. To reproduce: # ip link add name br0 type bridge vlan_filtering 1 # ip link set dev swp1 master br0 # ip link add link br0 name br0.10 type vlan id 10 # ip address add 192.0.2.0/24 dev br0.10 # ip link del dev br0 The RIF associated with br0.10 continues to exist. Fix this by iterating over all the bridge device uppers when it is destroyed and take care of destroying their RIFs. Fixes: 99f44bb3527b ("mlxsw: spectrum: Enable L3 interfaces on top of bridge devices") Signed-off-by: Ido Schimmel Reviewed-by: Petr Machata Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 2 + drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 11 ++++++++ drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 20 +++++++++++++++ 3 files changed, 33 insertions(+) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -395,6 +395,8 @@ int mlxsw_sp_netdevice_vrf_event(struct void mlxsw_sp_port_vlan_router_leave(struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan); void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif); +void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp, + struct net_device *dev); /* spectrum_kvdl.c */ int mlxsw_sp_kvdl_alloc(struct mlxsw_sp *mlxsw_sp, unsigned int entry_count, --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -5131,6 +5131,17 @@ void mlxsw_sp_rif_destroy(struct mlxsw_s mlxsw_sp_vr_put(vr); } +void mlxsw_sp_rif_destroy_by_dev(struct mlxsw_sp *mlxsw_sp, + struct net_device *dev) +{ + struct mlxsw_sp_rif *rif; + + rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev); + if (!rif) + return; + mlxsw_sp_rif_destroy(rif); +} + static void mlxsw_sp_rif_subport_params_init(struct mlxsw_sp_rif_params *params, struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c @@ -140,6 +140,24 @@ bool mlxsw_sp_bridge_device_is_offloaded return !!mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, br_dev); } +static int mlxsw_sp_bridge_device_upper_rif_destroy(struct net_device *dev, + void *data) +{ + struct mlxsw_sp *mlxsw_sp = data; + + mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev); + return 0; +} + +static void mlxsw_sp_bridge_device_rifs_destroy(struct mlxsw_sp *mlxsw_sp, + struct net_device *dev) +{ + mlxsw_sp_rif_destroy_by_dev(mlxsw_sp, dev); + netdev_walk_all_upper_dev_rcu(dev, + mlxsw_sp_bridge_device_upper_rif_destroy, + mlxsw_sp); +} + static struct mlxsw_sp_bridge_device * mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge, struct net_device *br_dev) @@ -176,6 +194,8 @@ static void mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge, struct mlxsw_sp_bridge_device *bridge_device) { + mlxsw_sp_bridge_device_rifs_destroy(bridge->mlxsw_sp, + bridge_device->dev); list_del(&bridge_device->list); if (bridge_device->vlan_enabled) bridge->vlan_enabled_exists = false;