Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp447520pxb; Thu, 9 Sep 2021 04:49:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjvLI0kUWpDZI/9m8SGyl3Lu2nJYj+g2pfAofmPQxjiL6h61xbTb8AVbuvqARWWWn2EBrD X-Received: by 2002:a05:6638:185:: with SMTP id a5mr2377003jaq.31.1631188159008; Thu, 09 Sep 2021 04:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188159; cv=none; d=google.com; s=arc-20160816; b=l6ux+v+8ge4doGjcPRGhKeBMABokgnFUItnXDX+iE34sgrmkLR+asyIXia1mEIAY4Z RLqrnjwcXO7aDIHNFhiGgXdcRlnRuor2yjS+Zc2lSXGizHHpz3kNbz5dJgW3FZZnk/b3 p40uoHevZl5v7L6dwDS7efTbfMpX0Els6MZ0sZY5OUMJ6QwEn0hdr5X0ZoyNciy9hBzd AIno44+aQ7CrwxiEUNPj4ojnHedool7+31xTNvhl9Beyaurpp/jCmVcddQoTcuOsQh2R 2AJJo5zVBNZLObRqzg+v4kkzeNYUoHjCTDmJPulkrY8cg/wAZpmyANap8RwLcq+lUbMy Ez2w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wHmqTGdRS95AEwjVprpN5p0N3yCFSb7vvsVfU1M3lzM=; b=tfTVkxAt6oVtPEpE5zMp6SZPCJnXx0hDXq+vhhhztBs9+3hs17496ruCVptq/sW/FW owFa+S/dcIl/ZVTyAafJaRP2GJSCdt/c7tW64Y+nj5454aEdAT0HK0lAzCY1WNqc1ukt EPCN7pHAx26Jjg+idz5iZosab8Tu0YLRgN5L2WwRbc1lagUM3T4gvw4zzC2jplnfLWpF wv8k95R/h/1/wTjI5xTxLB4WgW6RQnXG5RGbG58HEJxfAHD3fVB/9jmCBFo6l5/Rr+oO nxxO9e0DKuMbgSPdENjntH6dCDX7Uu5PBMXmk5/URlLrausT+CicpBXAcVwTAcpQlitG GrrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F4l/KoPw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y6si1370947ion.66.2021.09.09.04.49.07; Thu, 09 Sep 2021 04:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="F4l/KoPw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237545AbhIILt1 (ORCPT + 99 others); Thu, 9 Sep 2021 07:49:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:46894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238570AbhIILrM (ORCPT ); Thu, 9 Sep 2021 07:47:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 47554611F2; Thu, 9 Sep 2021 11:43:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187791; bh=pn9fs2GKzV0OI1Ji/u2SQzHXl8xWsYh+M+rDU/ATigs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F4l/KoPwTTyVJgRh9BuVrtRQMLaHtSdwBUsNBafj1XlP1RbcvKBMG+7csss90RUrO 37HyX/l+cOQpAV1FkGVVofWTHql3szftbX0B7ml40FY27Y0LRTkoyCKdzZvta4Uu/Q 2m62Eb0kT1slG8HvXZEgqojhgfngRwvEHv8bkAIdKei40KLSOwuXNq1x6328ewTqpq UAkKgdNJDc5ECWKS/dqququXJvikHMxfJ1w7NfD8TdN3dKPO4NGmW3uHmcmmDvh+HM cRmsV+aJVIAlowTXzezKvN07dmUcQHxHdf2IRDZcM0KJduldcA8xuJ7ltAfmzesOUt t19HcCB+zG29Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yufeng Mo , Jay Vosburgh , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 097/252] bonding: 3ad: fix the concurrency between __bond_release_one() and bond_3ad_state_machine_handler() Date: Thu, 9 Sep 2021 07:38:31 -0400 Message-Id: <20210909114106.141462-97-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yufeng Mo [ Upstream commit 220ade77452c15ecb1ab94c3f8aaeb6d033c3582 ] Some time ago, I reported a calltrace issue "did not find a suitable aggregator", please see[1]. After a period of analysis and reproduction, I find that this problem is caused by concurrency. Before the problem occurs, the bond structure is like follows: bond0 - slaver0(eth0) - agg0.lag_ports -> port0 - port1 \ port0 \ slaver1(eth1) - agg1.lag_ports -> NULL \ port1 If we run 'ifenslave bond0 -d eth1', the process is like below: excuting __bond_release_one() | bond_upper_dev_unlink()[step1] | | | | | bond_3ad_lacpdu_recv() | | ->bond_3ad_rx_indication() | | spin_lock_bh() | | ->ad_rx_machine() | | ->__record_pdu()[step2] | | spin_unlock_bh() | | | | bond_3ad_state_machine_handler() | spin_lock_bh() | ->ad_port_selection_logic() | ->try to find free aggregator[step3] | ->try to find suitable aggregator[step4] | ->did not find a suitable aggregator[step5] | spin_unlock_bh() | | | | bond_3ad_unbind_slave() | spin_lock_bh() spin_unlock_bh() step1: already removed slaver1(eth1) from list, but port1 remains step2: receive a lacpdu and update port0 step3: port0 will be removed from agg0.lag_ports. The struct is "agg0.lag_ports -> port1" now, and agg0 is not free. At the same time, slaver1/agg1 has been removed from the list by step1. So we can't find a free aggregator now. step4: can't find suitable aggregator because of step2 step5: cause a calltrace since port->aggregator is NULL To solve this concurrency problem, put bond_upper_dev_unlink() after bond_3ad_unbind_slave(). In this way, we can invalid the port first and skip this port in bond_3ad_state_machine_handler(). This eliminates the situation that the slaver has been removed from the list but the port is still valid. [1]https://lore.kernel.org/netdev/10374.1611947473@famine/ Signed-off-by: Yufeng Mo Acked-by: Jay Vosburgh Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/bonding/bond_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 31730efa7538..8aef6005bfee 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2252,7 +2252,6 @@ static int __bond_release_one(struct net_device *bond_dev, /* recompute stats just before removing the slave */ bond_get_stats(bond->dev, &bond->bond_stats); - bond_upper_dev_unlink(bond, slave); /* unregister rx_handler early so bond_handle_frame wouldn't be called * for this slave anymore. */ @@ -2261,6 +2260,8 @@ static int __bond_release_one(struct net_device *bond_dev, if (BOND_MODE(bond) == BOND_MODE_8023AD) bond_3ad_unbind_slave(slave); + bond_upper_dev_unlink(bond, slave); + if (bond_mode_can_use_xmit_hash(bond)) bond_update_slave_arr(bond, slave); -- 2.30.2