From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D23ABC433FE for ; Tue, 15 Feb 2022 05:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbiBOFEW (ORCPT ); Tue, 15 Feb 2022 00:04:22 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiBOFEV (ORCPT ); Tue, 15 Feb 2022 00:04:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2B6A1029DB; Mon, 14 Feb 2022 21:04:12 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 57FF5612CF; Tue, 15 Feb 2022 05:04:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F3D2C340EC; Tue, 15 Feb 2022 05:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644901451; bh=PX9u+6e9QNinBvycdzgGx+KcKDyFl4Dcs+o64X5VPL8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CMb2PgLzLXx7wKXCZVsLow2ZhDlkO9pq/g3CjzFkE7ipJn5Q4wlwr6qrLTEUXhxNG 9El6rqnXP3dbmSiNMtoKv8UyvEYMyf5i0t9a20Nfl2Y0nLYAsPshDy1uKHPqPFn+pC 8oawFRliEkgadAhzmWM9Th4K3CHjn9Z+eFFGVaYcLJzY11sTvkjGYxSj6uITANU0xv XVZGggC3N6WY5XrD/s2F3jMzwaZFYD+RhlCGeJPWfyvRNrPHS2Tf5h3dDLvS+czwMA 8L1T9qp24uqGztSfri0cMsRV6jMXat25ySPHO15HLfakKsnDDyvqk6U45J2LplbunI mU+kzA48hJ98w== Date: Mon, 14 Feb 2022 21:04:10 -0800 From: Jakub Kicinski To: Matt Johnston Cc: Wolfram Sang , "David S . Miller" , Jeremy Kerr , linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Zev Weiss Subject: Re: [PATCH net-next v5 2/2] mctp i2c: MCTP I2C binding driver Message-ID: <20220214210410.2d49e55f@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: <20220210063651.798007-1-matt@codeconstruct.com.au> <20220210063651.798007-3-matt@codeconstruct.com.au> <20220211143815.55fb29e3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, 15 Feb 2022 12:22:14 +0800 Matt Johnston wrote: > On Fri, 2022-02-11 at 14:38 -0800, Jakub Kicinski wrote: > > > > > +// Removes and unregisters a mctp-i2c netdev > > > +static void mctp_i2c_free_netdev(struct mctp_i2c_dev *midev) > > > > > You're doing a lot before the unregister call, this is likely racy. > > The usual flow is to unregister the netdev, then do uninit, then free. > > For instance you purge the queue but someone may Tx afterwards. > > needs_free_netdev is a footgun. > > Thanks Jakub. I've reworked it here to do the work before register/after > unregister, without needs_free_netdev. > > One question, the tx thread calls netif_wake_queue() - is it safe to call > that after unregister_netdev()? (before free_netdev) I don't think so. > I've moved the kthread_stop() to the post-unregister cleanup. The usual way to deal with Tx would be to quiesce the worker in ndo_stop. Maybe keep it simple and add a mutex around the worker? You can then take the same mutex around: stop queue purge queue Thanks to the mutex you'd know the worker is not running and as long as worker does its !skb_queue_empty() under the same mutex it will not wake the queue.