Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2201821imm; Mon, 28 May 2018 03:51:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3Jg58++7Cckvhci2jW8Fe57j+ZVD1rCrNBxl3sAe5pSeQ2/49EKv46JR0fC0qb6oVU5mo X-Received: by 2002:a62:5841:: with SMTP id m62-v6mr12848722pfb.116.1527504660641; Mon, 28 May 2018 03:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527504660; cv=none; d=google.com; s=arc-20160816; b=tIscC4fZ7vaZvbBxmEOKkXaXvhebKfPE/JlOYoT/Xx7GmpbuIlzYHwzyS74dpm5M/h 50ZVdf+53TLX110rGw2JUImnHl8t+dw/ijRVb4n4e/a5Qyzu8o00gOQ72qX8ex60mTp1 +cNXAUTTE1YEhu8yNdoF+F2QdpdEpkavt87kIgXPTpFbMiTXHCmuIf0q283RVXmv89NH Fqa+0WdLFOFr6HUbR6tdhCPyL7nPJ7BWCdNiQO+/vs7lhdIfSCCXm5YjR0tEiGpimQUX 8mmsbK1ROahc4ipqgseM2GoM3fOmQcBO2IofkOzz6BmkTgwF9lEPT9ZC+aUmX4m7vYgY MIJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3IcvUiFTEF33qg3N2OjWZBybgZvlRkU5JrxxXMmKMgI=; b=nx4zXuU1X4ZiHqqdIqKbVocZcXGu02EVBfkdjQpFmihij7suUDDTV5kRH4eCJ6nX1w onNrSKu6kxC4+Z0c4LpAxepbNqvtH9QYgjVVsl9go3q6RRd94IqPLL248xPpCsiZJZno O1/KnU2KY1hg33tE/IsD9jRXDDIwdY9ne1drl/YXBhLheJ+DBEHEWQANLeDaWJiqKJOe 27MyhurMwO3PPT0g1S1a3zuWXWz99hUN6IfbgWTGTNHb7BObadSzZQ/AOJKlsL+n9KTJ uaUv/4UnRMCnnjQU1goMPcHydJtpqMwrAZC9BoWf2mSapM479EZTSiMlmsnaMZjq9IGy 6bXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UOV6G4MD; 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 g1-v6si28521030plm.268.2018.05.28.03.50.46; Mon, 28 May 2018 03:51:00 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UOV6G4MD; 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 S1163711AbeE1Kuk (ORCPT + 99 others); Mon, 28 May 2018 06:50:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:40084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163660AbeE1Kue (ORCPT ); Mon, 28 May 2018 06:50:34 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DB3F204EE; Mon, 28 May 2018 10:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504634; bh=aqOjSwC6zVDb6MUl66yqvrd8AoEsSajpbCafG0ib+pI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UOV6G4MDZPokUEJFb7qshB0WsYFj0YbwRckR3AFFlkrCecrU1cq4HsKIp3ddPGHZm UV1b9PC9+vS4keBeBhQYZRDQ1NUgKIXHkGzn24TmymIDw2M4epxVsOlGQrmh15w2iZ geB6BEY4rcC9xoB8XUlqkOVIRH/jD0oOZfvEvHaY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tal Bar , Ido Schimmel , Jiri Pirko , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 177/496] spectrum: Reference count VLAN entries Date: Mon, 28 May 2018 11:59:22 +0200 Message-Id: <20180528100327.328191207@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 b3529af6bb0d4fe72defdd539712ceffaa054fb3 ] One of the basic construct in the device is a port-VLAN pair, which can be bound to a FID or a RIF in order to direct packets to the bridge or the router, respectively. Since not all the netdevs are configured with a VLAN (e.g., sw1p1 vs. sw1p1.10), VID 1 is used to represent these and thus this VID can be used by both upper devices of mlxsw ports and by the driver itself. However, this VID is not reference counted and therefore might be freed prematurely, which can result in various WARNINGs. For example: $ ip link add name br0 type bridge vlan_filtering 1 $ teamd -t team0 -d -c '{"runner": {"name": "lacp"}}' $ ip link set dev team0 master br0 $ ip link set dev enp1s0np1 master team0 $ ip address add 192.0.2.1/24 dev enp1s0np1 The enslavement to team0 will fail because team0 already has an upper and thus vlan_vids_del_by_dev() will be executed as part of team's error path which will delete VID 1 from enp1s0np1 (added by br0 as PVID). The WARNING will be generated when the driver will realize it can't find VID 1 on the port and bind it to a RIF. Fix this by adding a reference count to the VLAN entries on the port, in a similar fashion to the reference counting used by the corresponding 'vlan_vid_info' structure in the 8021q driver. Fixes: c57529e1d5d8 ("mlxsw: spectrum: Replace vPorts with Port-VLAN") Reported-by: Tal Bar Signed-off-by: Ido Schimmel Tested-by: Tal Bar Signed-off-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 8 +++++++- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -1417,6 +1417,7 @@ mlxsw_sp_port_vlan_create(struct mlxsw_s } mlxsw_sp_port_vlan->mlxsw_sp_port = mlxsw_sp_port; + mlxsw_sp_port_vlan->ref_count = 1; mlxsw_sp_port_vlan->vid = vid; list_add(&mlxsw_sp_port_vlan->list, &mlxsw_sp_port->vlans_list); @@ -1444,8 +1445,10 @@ mlxsw_sp_port_vlan_get(struct mlxsw_sp_p struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan; mlxsw_sp_port_vlan = mlxsw_sp_port_vlan_find_by_vid(mlxsw_sp_port, vid); - if (mlxsw_sp_port_vlan) + if (mlxsw_sp_port_vlan) { + mlxsw_sp_port_vlan->ref_count++; return mlxsw_sp_port_vlan; + } return mlxsw_sp_port_vlan_create(mlxsw_sp_port, vid); } @@ -1454,6 +1457,9 @@ void mlxsw_sp_port_vlan_put(struct mlxsw { struct mlxsw_sp_fid *fid = mlxsw_sp_port_vlan->fid; + if (--mlxsw_sp_port_vlan->ref_count != 0) + return; + if (mlxsw_sp_port_vlan->bridge_port) mlxsw_sp_port_vlan_bridge_leave(mlxsw_sp_port_vlan); else if (fid) --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -194,6 +194,7 @@ struct mlxsw_sp_port_vlan { struct list_head list; struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_fid *fid; + unsigned int ref_count; u16 vid; struct mlxsw_sp_bridge_port *bridge_port; struct list_head bridge_vlan_node;