Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565430lkm; Mon, 20 Sep 2021 18:51:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5N3yzey/aul2WiOc06G8lYZFIKoR83BpeYa5xnLKG0+hKWNT5rHJrcD14Z+V9MrqquB1A X-Received: by 2002:a05:6e02:20c3:: with SMTP id 3mr14796178ilq.269.1632189100084; Mon, 20 Sep 2021 18:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189100; cv=none; d=google.com; s=arc-20160816; b=uNt+X0jutH0yu3bYgpm9318zz0Nt1lzBrREgSQpGYDIXj7O7aDeXUlKsBCh4jRRE6B coJ/ZMp0YqFEexhHTnv+QmyPpDMg/B2ZTlat2BSZX/kYYRLUA4VLqW+XKG1KTyrbnEwJ 4H7HHbnj8P3X1PPdofogqzlHdINJxcXEKq1ec8olyLnoeYPcxkMysgkog2unv8PokxDG uLeDN/6Tce0SzSXQB64uaCsfG9VJiuEd/V32ZM6ylgYowaEQUt7MQEl10LzHWnjcvEY2 zbM0R4kb+xG6r6rn0J7+Yu0cSKy81Dplo4yMkGG+mUNyPqFBVMEslE9anl7+OKZcafcB 1D1Q== 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=wUzRkl9yhfky4DJ5hI84s0+hk2/WGxYnQGr5MFmY9VE=; b=YxmehWbWSb1rDtPanhJeDRavnnk3YZuvQPMxn9uK1+UmAa+8U4DpSQgt7T0RW7DGMF U+LyyhsRZJhEiWlghitikFEoIB9ihucnmPY3YRbAG5ZC+S9tmm1fFX42+ehcn7HQ1iKA V9LZvKpoM9cPrPz5SAmMfunAZSuhvnM0LpkuvMm/CvjKOCkJohjHDldjejPBG/OAQjPX nx7DC+s+Cen5m+dq1telfL/EAf0zqe+NH47jKp0z8Us4cdYwpUAYJoB2NV5bh4XKgXOS gSKWL6VMzH0Qlr/Ul0nECSYs98etIPo3glwFd/pph5bR3DFGTNCwCr0XgMPALc0fYqTr mmZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dFxlX6Ko; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si16024291ilc.144.2021.09.20.18.51.28; Mon, 20 Sep 2021 18:51:40 -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=@linuxfoundation.org header.s=korg header.b=dFxlX6Ko; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376345AbhITSNY (ORCPT + 99 others); Mon, 20 Sep 2021 14:13:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:35758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359206AbhITSJU (ORCPT ); Mon, 20 Sep 2021 14:09:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 42F376325A; Mon, 20 Sep 2021 17:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158349; bh=6GEVfw7vZfopUGRg2JPt3lCF1iqxYlN92cwC0NlRvgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dFxlX6Kow/6BYbNY+TyYIEKpGAmTz/EXR1/r8GoR/A4CY/LGqo+90tfSs97f8OSCO Q/vb69BQfEnKE3BBHhYpGbroSpLhhAP+V2eij/YWQl2F7cYskeoGWGylxj9cgQwP6q EOVqxPf2l8yjRAKnWqanXRXg8N7FbHRTiR0amR6E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yufeng Mo , Jay Vosburgh , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 114/260] bonding: 3ad: fix the concurrency between __bond_release_one() and bond_3ad_state_machine_handler() Date: Mon, 20 Sep 2021 18:42:12 +0200 Message-Id: <20210920163935.012456775@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 e21643377162..1949f631e1bc 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -1926,7 +1926,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. */ @@ -1935,6 +1934,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