Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1498925rdb; Fri, 1 Dec 2023 20:47:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtUysl2UJs4ExjdbDJpYmPvMT8cAAhH+ELoQHvBYC/a+kAdexb1RM5X0mD2WSK2LG1ghAe X-Received: by 2002:a17:90a:72cd:b0:286:6f56:5263 with SMTP id l13-20020a17090a72cd00b002866f565263mr512096pjk.6.1701492446919; Fri, 01 Dec 2023 20:47:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701492446; cv=none; d=google.com; s=arc-20160816; b=PBtWhOvDXr1O8VJ5WKgWx9OXvJUQYhwozjIv3PuUJnNtMG9iRLxmtxg5Z9QgifY9AJ yeEzGnlrnXX2xUV2qUdv9oI2WNtt8A7k4Xyb7Mxmzu5aXp0KXLtxd7PJRVI/7wb08O/1 RnUFDGGdI+ra9sF0/40Uy6eF+oHBGtdJecBAqOZ/++JyXg9A6yM6h5Rz7ISUUX5bBl0L UY3BDv2Uc22HewsODKJZRyJTHTDINb3voQ+xEYorcFr3OF+GElgD5E0N+L2bMDJCPGPo vo9GdF1tsNvNeET5cYZ6IhoyQANoR7b/Z6oGVKE+VPMnq1aJCMAVoaOkKg4ExVsmJ0XI VXMA== 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:subject:cc:to:from:date :dkim-signature; bh=TITXIhg7scGGTy/DBAeHmgF9N64ESzQTmvuzp/2DbKg=; fh=nBRkKoPzv1EVN3Jb/D/RjswmGw/Kw4GMZ4IkH0pKOz0=; b=pxGCqsgnQ5pmvKAiOn/nJAxympn0jsiWZxxYF3la8H3iCSHWXdyhQL+Dna3y1ZYmjC D+sgj9tT1xwuOVwWtDExf48QknAwgCWNltZJnhqjX0RaBkG88mfI2Bso/MrpL8RTXCls jLvSe64m8MQVvUpfGXGWiLkA7mW+olnX7KLiV18XxdQ6KyGFsJsoKfTAhhVDrTpCt4xd voCzOOoAJwI0B4wm6+FtaasiTEPIO6+i9H9jYVsp/HOFnWC5nXBR7atPmdi7eRk4AeWf srJTq7RVSseCPEWi6W14sSEw/4fzhRsowOaku2n3gk/5thCuC8EEPKre7414PZ4IcIez 7aOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CscYVbRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b3-20020a17090a800300b0028644ca706dsi3819596pjn.171.2023.12.01.20.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 20:47:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CscYVbRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id AB6EE836C038; Fri, 1 Dec 2023 20:47:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbjLBErL (ORCPT + 99 others); Fri, 1 Dec 2023 23:47:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjLBErJ (ORCPT ); Fri, 1 Dec 2023 23:47:09 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55A58D7E for ; Fri, 1 Dec 2023 20:47:16 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AF4DC433C7; Sat, 2 Dec 2023 04:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701492435; bh=O5MsatmLjCIH3y5kNOZnBieUoRybd+cftsMxmoL19IM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CscYVbReNDZ8qotPJtXbn3qj1nIfd0nib1LkrGYXrSlH0IQWhCasA3wUQo2PtCgDx LLxV6/zA4ZOgwfaUbLigTuToX2MUGt5GjD3MnlLHgxgchFAtcD5idFIQvSnjObXJlp ZDuVpYfXo6HVqZ9cA8Nubuf/6rh78mCNBWirjGzcenUeuDC8IJPpB6jwPgx7tASax5 Wzt6+dTi/HIZnFyd3t5P20+9N1opE0mYDp0bsj+aoDtIAq4RW5u2PVKdo4YNjijgGE knxgfhsyuGUX+juGk2jk837F22vWitao0m7fl71b/jz1zEV7mvgTl8mhwyTvZ3sv+D V9YDEZL74lRFA== Date: Fri, 1 Dec 2023 20:47:14 -0800 From: Jakub Kicinski To: Stefan Wahren Cc: "David S. Miller" , Eric Dumazet , Paolo Abeni , Lino Sanfilippo , Florian Fainelli , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2 1/3] qca_debug: Prevent crash on TX ring changes Message-ID: <20231201204714.21f7124c@kernel.org> In-Reply-To: <20231129095241.31302-2-wahrenst@gmx.net> References: <20231129095241.31302-1-wahrenst@gmx.net> <20231129095241.31302-2-wahrenst@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 01 Dec 2023 20:47:24 -0800 (PST) On Wed, 29 Nov 2023 10:52:39 +0100 Stefan Wahren wrote: > The qca_spi driver stop and restart the SPI kernel thread > (via ndo_stop & ndo_open) in case of TX ring changes. This is > a big issue because it allows userspace to prevent restart of > the SPI kernel thread (via signals). A subsequent change of > TX ring wrongly assume a valid spi_thread pointer which result > in a crash. > > So prevent this by stopping the network queue and temporary park > the SPI thread. Because this could happen during transmission > we also need to call qcaspi_flush_tx_ring(). > > Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000") > Signed-off-by: Stefan Wahren Still looks a bit racy. > diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c b/drivers/net/ethernet/qualcomm/qca_debug.c > index 6f2fa2a42770..9777dbb17ac2 100644 > --- a/drivers/net/ethernet/qualcomm/qca_debug.c > +++ b/drivers/net/ethernet/qualcomm/qca_debug.c > @@ -263,22 +263,29 @@ qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring, > struct kernel_ethtool_ringparam *kernel_ring, > struct netlink_ext_ack *extack) > { > - const struct net_device_ops *ops = dev->netdev_ops; > struct qcaspi *qca = netdev_priv(dev); > + bool queue_active = !netif_queue_stopped(dev); nothing prevents stopped -> running or running -> stopped transitions at this point, so this check can be meaningful > if ((ring->rx_pending) || > (ring->rx_mini_pending) || > (ring->rx_jumbo_pending)) > return -EINVAL; > > - if (netif_running(dev)) > - ops->ndo_stop(dev); > + if (queue_active) > + netif_stop_queue(dev); This doesn't wait for xmit to finish, it just sets a bit. You probably want something like netif_tx_disable(). Also - the thread may still be running and wake the queue up right after we stop it. -- pw-bot: cr