From patchwork Wed Oct 19 08:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp203724wrs; Wed, 19 Oct 2022 01:43:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76oNAxlV9/hBYsU/8uKrCz8Rn9RLLfPBm+/FiC0XMCFOTpBiS12JVgp5pPJwArb8JMQlUD X-Received: by 2002:a05:6a00:998:b0:563:3428:65a0 with SMTP id u24-20020a056a00099800b00563342865a0mr7432067pfg.22.1666169034061; Wed, 19 Oct 2022 01:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169034; cv=none; d=google.com; s=arc-20160816; b=0+/cTsNCrzjMlzxtW7TGKwNq2CvWW5WCrNHdIZpXvAzkV3y7vffWohrJ3TC/f+Ld7c UvAdPzmvKJn6uK5jTvHxNhjuj8On451EI7UqLQpIbxnwMBwVJwB9dfjHtdvxt9+sr3gn RcrS536fRxhP1Qp0pMmQI+50T7vxg5HgRVCSxUnNUB/Ir7f9orz44BMGAQ42vkngZeK9 4R8dStH1IUCr+yqKN6bknirYLlVm+8EPGk4re2F7M/FLnCTB0nwuoYCH7X7aX3c7knZG PUublW1h39YvgIoaTknHKJ38GMUGzFgqF2UBFXXhBvQQHQ4hE3Mb+MZc9sn6FJ6uKFaL Oi2g== 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=WRkAG0cJGWG6t0Rws9oa65QTv1K7LXNnWAgx6SdDl3mb4jcJaqAR/mRsBuBnxcTpva 8dmxybgHqsyP3VR9FoCCrI7fznn9LSVj880BoQYorHd/6MLnScfsb42xR8PUWsra2iU/ wHXmmOJCsScnQVZF2gqOl2qXcJcjCdELRAml0pPE1smISDm70djVtb4qZlPcH9SBUAOO n1/EDoECTuUO4g8Ikp4XZrhWewmpdQeUGyUO04i2nuYvTTIbcoqpVN7JuBkkQSofoKVf rggoAQ4PhVhUES1hBPhCmJMa94NFw7wy22x6gb2r7/7JioUdOh6+fUYg3G5/q/reWatT roAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mUqwV65b; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f23-20020a63dc57000000b004197e33daf5si16829937pgj.863.2022.10.19.01.43.41; Wed, 19 Oct 2022 01:43:54 -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=mUqwV65b; 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 S230442AbiJSInP (ORCPT + 99 others); Wed, 19 Oct 2022 04:43:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbiJSImW (ORCPT ); Wed, 19 Oct 2022 04:42:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D023A48CBF; Wed, 19 Oct 2022 01:39:50 -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 7B216B821CD; Wed, 19 Oct 2022 08:39:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9218C433D6; Wed, 19 Oct 2022 08:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168787; bh=qzNPjTgfZEYYgdxUncWZqKaKdlo8w1SbSuDFg3W8BnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUqwV65buO035u8oCYlVYs/sh4QLan3nkLc5vaQYskmLmA86FiUmTBLAx9ErZM0xh l3v3DyLcn48Lg6LJPBoBgwJQRvOqGr/25W26iFvj6wjDGovobBy5YCk0T0Fgaa+1Xj fW4qgCoE5rn7Pwq6cwGp666i1W1aEIr1LUJ9XKk4= 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 6.0 053/862] net: thunderbolt: Enable DMA paths only after rings are enabled Date: Wed, 19 Oct 2022 10:22:20 +0200 Message-Id: <20221019083252.323733118@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104860762239312?= X-GMAIL-MSGID: =?utf-8?q?1747104860762239312?= 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: