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 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8882CC63777 for ; Mon, 30 Nov 2020 20:37:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 301A520706 for ; Mon, 30 Nov 2020 20:37:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Jrz7DRbt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730130AbgK3UhY (ORCPT ); Mon, 30 Nov 2020 15:37:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgK3UhX (ORCPT ); Mon, 30 Nov 2020 15:37:23 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD74C0613CF for ; Mon, 30 Nov 2020 12:36:43 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id qw4so14372663ejb.12 for ; Mon, 30 Nov 2020 12:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=zrsbyLjmEosf6VtQ8tH03AfMWawGL3ES5MWGalf6svU=; b=Jrz7DRbtwLvRmbbiyJn9ErwhSphgFJVoNcvkRAGd+x8mlXaEECcL8L9VwgEiDwTqTz VCId5HXn7ZM56ShoG1j6JMyTP5qPAIxaEg2hBegIxLBugchdojqf2jBfq1C1pQQvDYYi F/+4u007bi982XKst4oxWl20I4tcMoS3hnS6qboJuSI+V3/G4zaGITfc4Wo/GxdFL8Z6 FmdkgB2qrMHPwX7kauUaq+4RwKSS6NTdLA+403iKlFcIq2f8yRg3BHQFMk0N78M+muvx lThYPCUyUqmG3e3zul1/1msKd/MKGAZ640rSuFisKFfgomULHl3zXMSwkL7bYNZCbFqw R9DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zrsbyLjmEosf6VtQ8tH03AfMWawGL3ES5MWGalf6svU=; b=QkruA+e7FN1UVuWaw3JJzlarJwLzk45IR5mH47Z5ABhauuquomvNvPHiOFkpVUhTtS 8lXH/P410tx7lKs6shndvR9eOvarMfN10AnRfYy8JhU1M28FoGxvAv8GkLBnPcw5yaqd KoMNPuBNhgmideI4b3Jtf+MPgclSx5q62V1whjEFrr7uP/Isr69qJi9QyD25125XXLXq n9NFNWk0/PXlCLmmSKq3wWONHE/fHKbdZjV80n6WvvitevPZiTAWp1XGhykiWAfg5ie7 VQ5oV0xu5RiJfRxW2fpHY/WypoMygL/v9h/JjAcLB/G+I1+AJy/N3DOxu2NOvXwRQb5a y7Vg== X-Gm-Message-State: AOAM530BnlVIwSMCmlLOVUoVQCaCs0KSZj99uR8ceK+adkjiWT1FTYf2 94/9jdzPExC33Kt0T3rNIpU= X-Google-Smtp-Source: ABdhPJzsh/N4n38BwqzC2XpM08gEu6vGvTq+JtMugJMBO3eU02mQ/yg48OlAHa3Og4aCPFAUDF2tfQ== X-Received: by 2002:a17:906:4944:: with SMTP id f4mr22449858ejt.231.1606768602067; Mon, 30 Nov 2020 12:36:42 -0800 (PST) Received: from skbuf ([188.25.2.120]) by smtp.gmail.com with ESMTPSA id x15sm9531197edj.91.2020.11.30.12.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 12:36:41 -0800 (PST) Date: Mon, 30 Nov 2020 22:36:40 +0200 From: Vladimir Oltean To: Eric Dumazet Cc: Stephen Hemminger , Eric Dumazet , Jakub Kicinski , netdev , Paul Gortmaker , Jiri Benc , Or Gerlitz , Cong Wang , Jamal Hadi Salim , Andrew Lunn , Florian Fainelli Subject: Re: Correct usage of dev_base_lock in 2020 Message-ID: <20201130203640.3vspyoswd5r5n3es@skbuf> References: <20201130101405.73901b17@kicinski-fedora-pc1c0hjn.DHCP.thefacebook.com> <20201130184828.x56bwxxiwydsxt3k@skbuf> <20201130190348.ayg7yn5fieyr4ksy@skbuf> <20201130194617.kzfltaqccbbfq6jr@skbuf> <20201130122129.21f9a910@hermes.local> <20201130202626.cnwzvzc6yhd745si@skbuf> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Nov 30, 2020 at 09:29:15PM +0100, Eric Dumazet wrote: > On Mon, Nov 30, 2020 at 9:26 PM Vladimir Oltean wrote: > > > > On Mon, Nov 30, 2020 at 12:21:29PM -0800, Stephen Hemminger wrote: > > > if device is in a private list (in bond device), the way to handle > > > this is to use dev_hold() to keep a ref count. > > > > Correct, dev_hold is a tool that can also be used. But it is a tool that > > does not solve the general problem - only particular ones. See the other > > interesting callers of dev_get_stats in parisc, appldata, net_failover. > > We can't ignore that RTNL is used for write-side locking forever. > > dev_base_lock is used to protect the list of devices (eg for /proc/net/devices), > so this will need to be replaced by something. dev_hold() won't > protect the 'list' from changing under us. Yes, so as I was saying. I was thinking that I could add another locking mechanism, such as struct net::netdev_lists_mutex or something like that. A mutex does not really have a read-side and a write-side, but logically speaking, this one would. So as long as I take this mutex from all places that also take the write-side of dev_base_lock, I should get equivalent semantics on the read side as if I were to take the RTNL mutex. I don't even need to convert all instances of RTNL-holding, that could be spread out over a longer period of time. It's just that I can hold this new netdev_lists_mutex in new code that calls for_each_netdev and friends, and doesn't otherwise need the RTNL. Again, the reason why I opened this thread was that I wanted to get rid of dev_base_lock first, before I introduced the struct net::netdev_lists_mutex.