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 65BD2C433F5 for ; Mon, 25 Apr 2022 15:36:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242839AbiDYPjS (ORCPT ); Mon, 25 Apr 2022 11:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235542AbiDYPjQ (ORCPT ); Mon, 25 Apr 2022 11:39:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95AF31902A; Mon, 25 Apr 2022 08:36:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 333AC60F93; Mon, 25 Apr 2022 15:36:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBD13C385A4; Mon, 25 Apr 2022 15:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650900971; bh=j4T4tzFLyGor89gVYJw5+jljXkHMPTRarsu0jWHlSH0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=bndG88er+LDI8V6fb84Cc0KIyf3Fv3dc36AeTYXOL9OL7no6S0UYbDRelwadvuJ2v a6kBSmEmC0xBuIM7j4CKVKCZVwRQ6E3/NZRWZIV5VoAOkNtHpYiiwDNDkjMDFa8m3+ tvZfdv3RY0zCplCujZc6JBgHqLFEyLhCNCgQoio3KuriO9JKRs/bUGzqCmnfEDbW7n 6BopL3O+qympjzEEbIVY6Z8E7fYB0TE3+H89DEesZLcIsYZJRNv/Puw2OpNQ6T6tZK BkGzgPCx8OKgfE0UVDV4dBrOGG5gk4qu/gEi1Dg0DcYDa1C3mHJnlF1fh30veEFzdc RqrQKhwgC6Q1w== Date: Mon, 25 Apr 2022 08:36:09 -0700 From: Jakub Kicinski To: Eric Dumazet Cc: Jann Horn , Lukas Wunner , Paolo Abeni , Oliver Neukum , "David S. Miller" , Oleksij Rempel , netdev , USB list , Andrew Lunn , Jacky Chou , Willy Tarreau , Lino Sanfilippo , Philipp Rosenberger , Heiner Kallweit , Greg Kroah-Hartman Subject: Re: [PATCH] net: linkwatch: ignore events for unregistered netdevs Message-ID: <20220425083609.0c4bf0d4@kernel.org> In-Reply-To: References: <18b3541e5372bc9b9fc733d422f4e698c089077c.1650177997.git.lukas@wunner.de> <9325d344e8a6b1a4720022697792a84e545fef62.camel@redhat.com> <20220423160723.GA20330@wunner.de> <20220425074146.1fa27d5f@kernel.org> <20220425080057.0fc4ef66@kernel.org> <20220425082804.209e3676@kernel.org> 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 Mon, 25 Apr 2022 08:31:23 -0700 Eric Dumazet wrote: > > Jann described a case where someone does > > > > CPU 0 CPU 1 CPU 2 > > > > dev_hold() > > ------ #unregister ------- > > dev_hold() > > dev_put() > > > > Our check for refcount == 0 goes over the CPUs one by one, > > so if it sums up CPUs 0 and 1 at the "unregister" point above > > and CPU2 after the CPU1 hold and CPU2 release it will "miss" > > one refcount. > > > > That's a problem unless doing a dev_hold() on a netdev we only have > > a reference on is illegal. > > What is 'illegal' is trying to keep using the device after #unregister. > > We have barriers to prevent that. > > Somehow a layer does not care about the barriers and pretends the > device is still good to use. > > It is of course perfectly fine to stack multiple dev_hold() from one > path (if these do not leak, but this is a different issue) So we'd need something like WARN_ON(dev->reg_state != NETREG_REGISTERED && !rtnl_held()) in dev_hold()?