Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3920517rwi; Sat, 22 Oct 2022 02:13:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM47OX49kmucgUnG7KNwKF4OinZLWVNhxEF1xUlfGg488gThaI0I47E5cPO03Hj6y3bTdkvn X-Received: by 2002:a17:903:181:b0:185:5696:97c2 with SMTP id z1-20020a170903018100b00185569697c2mr23354018plg.160.1666430025579; Sat, 22 Oct 2022 02:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430025; cv=none; d=google.com; s=arc-20160816; b=PxiH5cDYkLY90Y9PGWr+Fi9RJFLOW0jED9DswO6WzJaoauRO0Ftz5T8OaPI4W90gYe WzvEf0317XgkT3U7LXPV67Ezz8048i9Na1zw4llaSuil21UbgfW+qdd1goW2zWjt07uM IuzUWfq9KaalRafbmDJ6STfcNLW0ltGsSNXPfhq1a8ZI106rmeSaFaGE1qlnIOhfR6yU QolHa6fypgW7QX70aKYpOPCMC3kaOFnHVX57stAQ5s+BHBtoqXK1yzG4LX091E+enhDn VZ6cernBbZKbEaXaNTfqH9zmmNvMu/bSSCGJqrQopXfgdqlrcF9Ohfr0/CqOYoQq/kQL rwDg== 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=uXKqchtCfBTfSsss0+Af3fHqgjk1R3VG8xPchCBv0RU=; b=thv/Bjb0FoAjUwQEzYtdaV5uxWLBmM3dgrcpPl14rv6b1KOaG/5dYDfh11A2i1KrLb 7Df3zbQj1NrixdmI11IrqiQ8Fi3PcuyVraPsqfA8PooE4/6jICJbjND2Klx0wkUu95My c9iOicjS9XnqJGhpRfda5d9lmPJ7AizUETfZVWTViHq1hiC8yhgYE/NUaYAwwq+MTUyi TYLC3Lua/Towv7bzvfYy3CNT86bfxUZf1MY50Vtk9qpmySXU7SHqjsUJyXPDOktPEu7I VIdPqovF6hu4EkTXyQ7UrGSPekRKkf4/DFQXQs1P+0bdfxap9E/oxbShkH4s+frEmHWo wbug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GsoShnUt; 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 b6-20020a639306000000b00461f10556b9si27073596pge.319.2022.10.22.02.13.33; Sat, 22 Oct 2022 02:13:45 -0700 (PDT) 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=GsoShnUt; 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 S230343AbiJVHjR (ORCPT + 99 others); Sat, 22 Oct 2022 03:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbiJVHin (ORCPT ); Sat, 22 Oct 2022 03:38:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5687029B88B; Sat, 22 Oct 2022 00:36:05 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id A65EFB82D9F; Sat, 22 Oct 2022 07:36:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F27B3C433C1; Sat, 22 Oct 2022 07:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424162; bh=qzNPjTgfZEYYgdxUncWZqKaKdlo8w1SbSuDFg3W8BnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsoShnUtufvycgSoX6JXO2BrK8EoeZInnkG38/zZ1SXTsVjTtncFZar/bR2Zx84WS R5Pv/NVnJmh9TcBvwlSQmGKARp//8cg69GNrdGkxHELBOVDgIOwfhTIXr0nZ2goy4N GpprgUDy6ReJjUuk2OJ/LVPZAZOqyuXrChvOHNcM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mika Westerberg , "David S. Miller" Subject: [PATCH 5.19 047/717] net: thunderbolt: Enable DMA paths only after rings are enabled Date: Sat, 22 Oct 2022 09:18:46 +0200 Message-Id: <20221022072423.447662635@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 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 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: Mika Westerberg commit ff7cd07f306406493f7b78890475e85b6d0811ed upstream. If the other host starts sending packets early on it is possible that we are still in the middle of populating the initial Rx ring packets to the ring. This causes the tbnet_poll() to mess over the queue and causes list corruption. This happens specifically when connected with macOS as it seems start sending various IP discovery packets as soon as its side of the paths are configured. To prevent this we move the DMA path enabling to happen after we have primed the Rx ring. This makes sure no incoming packets can arrive before we are ready to handle them. Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable") Cc: stable@vger.kernel.org Signed-off-by: Mika Westerberg Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/thunderbolt.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) --- a/drivers/net/thunderbolt.c +++ b/drivers/net/thunderbolt.c @@ -612,18 +612,13 @@ static void tbnet_connected_work(struct return; } - /* Both logins successful so enable the high-speed DMA paths and - * start the network device queue. + /* Both logins successful so enable the rings, high-speed DMA + * paths and start the network device queue. + * + * Note we enable the DMA paths last to make sure we have primed + * the Rx ring before any incoming packets are allowed to + * arrive. */ - ret = tb_xdomain_enable_paths(net->xd, net->local_transmit_path, - net->rx_ring.ring->hop, - net->remote_transmit_path, - net->tx_ring.ring->hop); - if (ret) { - netdev_err(net->dev, "failed to enable DMA paths\n"); - return; - } - tb_ring_start(net->tx_ring.ring); tb_ring_start(net->rx_ring.ring); @@ -635,10 +630,21 @@ static void tbnet_connected_work(struct if (ret) goto err_free_rx_buffers; + ret = tb_xdomain_enable_paths(net->xd, net->local_transmit_path, + net->rx_ring.ring->hop, + net->remote_transmit_path, + net->tx_ring.ring->hop); + if (ret) { + netdev_err(net->dev, "failed to enable DMA paths\n"); + goto err_free_tx_buffers; + } + netif_carrier_on(net->dev); netif_start_queue(net->dev); return; +err_free_tx_buffers: + tbnet_free_buffers(&net->tx_ring); err_free_rx_buffers: tbnet_free_buffers(&net->rx_ring); err_stop_rings: