Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2135915pxb; Fri, 25 Mar 2022 11:43:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxweV9ucXrcsdP3jZ1EEE4xo1uD1OpPLg/ic1UgZkWMzHc9qiYALdstuaVGwb1feq3wfEqQ X-Received: by 2002:a63:4e4d:0:b0:381:640e:a373 with SMTP id o13-20020a634e4d000000b00381640ea373mr719306pgl.379.1648233816364; Fri, 25 Mar 2022 11:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648233816; cv=none; d=google.com; s=arc-20160816; b=vRbqjssqpiVWEu0JvGkAumlB/dJ13wWFFv5+gMYNY6xmT87jLHFt7P8zKIpIBJeUGB uXRTRstzzmiZI55ZXGiAJAi/2BBDE7QHmLdAAglEQlUz9p37LtLOcqfiGykyDhkYQaO5 jZ+K/Ig/T1xxPMnmfIF8j0qdUnA6zgc7VdmItXsjyorRpljMr4O4WznU3n3Ft/pfa+eK SyZgzfKhWV5E5vu+9F5Aa3fgom5bMZ4GyhCM/m17NChRijnKnEYVOpempp+76NOr+7NM oogzpJCX7dM5C8LZD816Yq47sDQTGTil9Zv/ZS6oN7OcV/WlGAOvWdCGsb2MJ5fqIC59 lu0w== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=KIBXOVtkmOwL5E0vgfaT6N95rJNQ6um0hl1Uz1iYDsM=; b=gGL2gIb5Ns4pTxbB0qMBppQXb+7jMhpPYVWSg5zQPBMi54Uob5MycGz+4fvmRTJyd/ erTnSYkOJQX5uOgZlmS6SSuriMPw2STtfc3OpE46XRnHhWDHzVXMg8pUl55WWsH7R+n8 QoR4lUZVuj9cb+3OHXoiu4i00aApJLFTR2Cu5aGjS+bV+IoC9Bghe8infB/x5ejr7Aku hNpZp3dwR/TaQaclN8QthXQPq4VkZ9Jl6XtYq5XVSvipeK/6crxUxmjHDUsyzTfhwEQR SueBI84doVvJEuXzNrJ+kB2L4UBuFh82HmO3FM33p6VQe7KGUP4gfxmdfTWmO9jCdxP8 l2gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=L4IdXzV4; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u10-20020a654c0a000000b003816043f064si3097737pgq.601.2022.03.25.11.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:43:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=L4IdXzV4; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5C1D1A1291; Fri, 25 Mar 2022 11:00:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354394AbiCYRDV (ORCPT + 70 others); Fri, 25 Mar 2022 13:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377352AbiCYRDS (ORCPT ); Fri, 25 Mar 2022 13:03:18 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54FB84D268; Fri, 25 Mar 2022 10:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=KIBXOVtkmOwL5E0vgfaT6N95rJNQ6um0hl1Uz1iYDsM=; t=1648227704; x=1649437304; b=L4IdXzV4ge3lc5bsXEejWvQ+wEuLPal+k1jKGIH27lTUjuR IvfvmSc8C1Pqh8/U4PW9DHWjMJfPMkCEPNWUiZMHWwLy5zP7GNPMKfaePQnPqYqAMs/8JB92NPezM CphOYxPiukqTAlkYdh12K+LAXVQKjErK0AkYpfA/klWVb2lrL+XmTwL/J2nQLRfcktIfAXK01BSLM wl6AME5PCbw9DuWOyNvMEzjhu2oU2v+3mX6sJPTqmdCQzzKqhAW5nDaWtfNXlJ4OlT32BjWp8w0D3 fAbn4ccGC7+42EPk7jw8Hno5bQknFTqFOIrVtFR/gKIRb4PcmsjIlzRLXjl8fWDA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.95) (envelope-from ) id 1nXnJb-000QWH-Nz; Fri, 25 Mar 2022 18:01:31 +0100 Message-ID: Subject: Re: [BUG] deadlock in nl80211_vendor_cmd From: Johannes Berg To: Jakub Kicinski Cc: William McVicker , linux-wireless@vger.kernel.org, Marek Szyprowski , Kalle Valo , "David S. Miller" , netdev@vger.kernel.org, Amitkumar Karwar , Ganapathi Bhat , Xinming Hu , kernel-team@android.com, Paolo Abeni Date: Fri, 25 Mar 2022 18:01:30 +0100 In-Reply-To: <20220325094952.10c46350@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> References: <0000000000009e9b7105da6d1779@google.com> <99eda6d1dad3ff49435b74e539488091642b10a8.camel@sipsolutions.net> <5d5cf050-7de0-7bad-2407-276970222635@quicinc.com> <19e12e6b5f04ba9e5b192001fbe31a3fc47d380a.camel@sipsolutions.net> <20220325094952.10c46350@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-malware-bazaar: not-scanned X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-wireless@vger.kernel.org On Fri, 2022-03-25 at 09:49 -0700, Jakub Kicinski wrote: > On Fri, 25 Mar 2022 13:04:23 +0100 Johannes Berg wrote: > > So we can avoid the potential deadlock in cfg80211 in a few ways: > > > > 1) export rtnl_lock_unregistering_all() or maybe a variant after > > refactoring the two versions, to allow cfg80211 to use it, that way > > netdev_run_todo() can never have a non-empty todo list > > > > 2) export __rtnl_unlock() so cfg80211 can avoid running > > netdev_run_todo() in the unlock, personally I like this less because > > it might encourage random drivers to use it > > > > 3) completely rework cfg80211's locking, adding a separate mutex for > > the wiphy list so we don't need to acquire the RTNL at all here > > (unless the ops need it, but there's no issue if we don't drop it), > > something like https://p.sipsolutions.net/27d08e1f5881a793.txt > > > > > > I think I'm happy with 3) now (even if it took a couple of hours), so I > > think we can go with it, just need to go through all the possibilities. > > I like 3) as well. FWIW a few places (e.g. mlx5, devlink, I think I've > seen more) had been converting to xarray for managing the "registered" > objects. It may be worth looking into if you're re-doing things, anyway. > That's not a bad idea, but I think I wouldn't want to backport that, so separately :) I don't think that fundamentally changes the locking properties though. Couple of more questions I guess: First, are we assuming that the cfg80211 code *is* actually broken, even if it looks like nothing can cause the situation, due to the empty todo list? Given that we have rtnl_lock_unregistering() (and also rtnl_lock_unregistering_all()), it looks like we *do* in fact at least not want to make an assumption that no user of __rtnl_unlock() can have added a todo item. I mean, there's technically yet *another* thing we could do - something like this: [this doesn't compile, need to suitably make net_todo_list non-static] --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -95,6 +95,7 @@ void __rtnl_unlock(void) defer_kfree_skb_list = NULL; + WARN_ON(!list_empty(&net_todo_list)); mutex_unlock(&rtnl_mutex); while (head) { and actually that would allow us to get rid of rtnl_lock_unregistering() and rtnl_lock_unregistering_all() simply because we'd actually guarantee the invariant that when the RTNL is freshly locked, the list is empty (by guaranteeing that it's always empty when it's unlocked, since it can only be added to under RTNL). With some suitable commentary, that might also be a reasonable thing? __rtnl_unlock() is actually rather pretty rare, and not exported. However, if you don't like that ... I've been testing with this patch, to make lockdep complain: --- a/net/core/dev.c +++ b/net/core/dev.c @@ -9933,6 +9933,11 @@ void netdev_run_todo(void) if (!list_empty(&list)) rcu_barrier(); +#ifdef CONFIG_LOCKDEP + rtnl_lock(); + __rtnl_unlock(); +#endif + while (!list_empty(&list)) { struct net_device *dev = list_first_entry(&list, struct net_device, todo_list); That causes lockdep to complain for cfg80211 even if the list *is* in fact empty. Would you be open to adding something like that? Perhaps if I don't just do the easy rtnl_lock/unlock, but try to find the corresponding lockdep- only things to do there, to cause lockdep to do things without really locking? OTOH, the locking overhead of the RTNL we just unlocked is probably minimal, vs. the actual work *lockdep* is doing to track all this ... Thanks, johannes