Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2155924pxb; Fri, 25 Mar 2022 12:05:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySpRar4IVLpaZTgFDVSiuW+iUnL4SnQ3U0w6mBQVTrQNTMc1xyh3IMP4su9y4iTDJvKNnl X-Received: by 2002:a05:620a:146a:b0:67d:6c34:6bb1 with SMTP id j10-20020a05620a146a00b0067d6c346bb1mr7733621qkl.761.1648235119318; Fri, 25 Mar 2022 12:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648235119; cv=none; d=google.com; s=arc-20160816; b=mIIyXekepoR5iDNtnpHitDPlq/Y5VcIJDmtx4dczaUz68geyBZfLazm6E+UeLAgBNY 2L1KKLUFXu8doBPOgdJwpyzO7z3Ooz6mpbzhuOitVrZV4VV3k+HkqXJg/M4x88wUOQRT lJOn96pc/gLdIGdhHgXCHhyDLTcwfMfl/sueEXZlRQ7BPViKT297Buz9pp8A5zXVKgxy k4dwtH98h/pTI8ssleNGBWJh61CM7hhrMm7Mw3wqHQZZN2bUKUGBDUoN4tHAbeolQ0Ep NPSA4bR0kmjByzKakHuq6IcVq5MAMQ+X4P/jxly2RP+nLWuVQoY6vB5yFMVYZpF7MBUp ZXLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=P98EhcKlXlIoxjs8lUpPIr0xnMSUtUyiRS9iVnjcbyE=; b=NKW2UU822uiA+5Sa0aFOyyRVHHcN3XUi1XOi5Gav9g/5eMBNxtUAL2Xh9MDD0qjjNd NU0Uu6uemQpP3aPlmoaTlRTYM0UBXxiNKNReeEbXVtkCMpBo2hn39/UmS3zXjTuBX0dV Gr5zyX0qJTEk0nUgOBUgUEp2vjZP7tfsLioGKndwUnjB/XGYN19dNWdLRo2DJlDoiZhX +6RbmwD9uP5AyjC6ljjUGLxszCn2xO1bxwSOTMAtrQQIk2JXsAPEFfFlk4f2v9ZptcFH WJyLEcZ0VB8js5++9T2t+a0oAbQvRl0947xAAiic2Z7RjcVs22vb/FZ7Vn+NiSPBUExq MeHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="O41y2ze/"; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m13-20020a05620a24cd00b0067ec123b9d2si2601359qkn.109.2022.03.25.12.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:05:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="O41y2ze/"; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB8BC1DE6DC; Fri, 25 Mar 2022 11:13:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353272AbiCXWAj (ORCPT + 70 others); Thu, 24 Mar 2022 18:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352678AbiCXWAi (ORCPT ); Thu, 24 Mar 2022 18:00:38 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75236220CD for ; Thu, 24 Mar 2022 14:59:04 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id g19so4976093pfc.9 for ; Thu, 24 Mar 2022 14:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=P98EhcKlXlIoxjs8lUpPIr0xnMSUtUyiRS9iVnjcbyE=; b=O41y2ze/U6Vpqs7adbkoUxMD8XLOCfhiIIaXq7rhRYPvmxkGkMim3d2fF618kL9HOf vAkrkAzSlHKwyNyF9j637VbIl1qEsthq17MbaZ+3SWawM/5xryuI02LXlJfBpYSxLlw5 jr8w2Vs8gA3CBzeY26HTHD4skCSziuGSQ7i/5c3bZBe9W2Vw6BmlInasUn0/EHqV9qMv 6B6JtSMX+58nTY5PE1ZyJIpzJXKRBc+WDlZdaVnHyeAdxT1KD0XqSthKI/yGSW6mC0/V Grdgf+MVNkU8CeJyjvEdEtNw1PKvaWMpgvIToIyxVswDd2JFOKDGbbuUfnE2iENEVfFd 1+Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=P98EhcKlXlIoxjs8lUpPIr0xnMSUtUyiRS9iVnjcbyE=; b=K9KhjjmrbtUSMPS60vmJ4uxnluLQoPxbU3QEBxKstzO2WOkI/9sUkmoEbeRp/F9DtI AI1A8GbG6m6l6H8wEP+8/LLHWqutuHjnOFBvXBNRAlHoaQb791pz58yUCUExZhZUHM5x PDz2FiL7bQ4kQ59m1DHCiAm0l4LFJXaDpXS0ZB679gXrqW7FT/rurXC4C7qnL2IYVuh5 DTKS3QR7pk8SvAhJBPUaAuO9r43aKYmoZDjmEnC+JsGX+khR/TB8huIY6cg5PvhOL2KS XwHWNWmFrsSFmWthZiBm/rVX/70w1m7S0F5PDP1nkMPx1lEl5y6DOr1nuTo/ZeBeMiHn cQ/A== X-Gm-Message-State: AOAM531tXe99Ffq88DyLPecTWQmwEQquWiGKbjYZgv6UlaEEvcjB8xfc PQ5qn3rqd967zdjLOlE5lYTA5A== X-Received: by 2002:a65:6855:0:b0:382:59e5:b6e5 with SMTP id q21-20020a656855000000b0038259e5b6e5mr5524859pgt.586.1648159143727; Thu, 24 Mar 2022 14:59:03 -0700 (PDT) Received: from google.com (249.189.233.35.bc.googleusercontent.com. [35.233.189.249]) by smtp.gmail.com with ESMTPSA id cd20-20020a056a00421400b004fa7d1b35b6sm4260979pfb.80.2022.03.24.14.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 14:59:03 -0700 (PDT) Date: Thu, 24 Mar 2022 21:58:59 +0000 From: William McVicker To: Johannes Berg , linux-wireless@vger.kernel.org Cc: Marek Szyprowski , Kalle Valo , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, Amitkumar Karwar , Ganapathi Bhat , Xinming Hu , kernel-team@android.com, Paolo Abeni Subject: Re: [BUG] deadlock in nl80211_vendor_cmd Message-ID: References: <0000000000009e9b7105da6d1779@google.com> <99eda6d1dad3ff49435b74e539488091642b10a8.camel@sipsolutions.net> <5d5cf050-7de0-7bad-2407-276970222635@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, HK_RANDOM_FROM,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 03/23/2022, Jeff Johnson wrote: > On 3/22/2022 2:58 PM, William McVicker wrote: > > On 03/22/2022, Jeff Johnson wrote: > > > On 3/21/2022 1:07 PM, Johannes Berg wrote: > > > [..snip..] > > > > > > > > I'm not an networking expert. So my main question is if I'm allowed to take > > > > > the RTNL lock inside the nl80211_vendor_cmd callbacks? > > > > > > > > Evidently, you're not. It's interesting though, it used to be that we > > > > called these with the RTNL held, now we don't, and the driver you're > > > > using somehow "got fixed" to take it, but whoever fixed it didn't take > > > > into account that this is not possible? > > > > > > On this point I just want to remind that prior to the locking change that a > > > driver would specify on a per-vendor command basis whether or not it wanted > > > the rtnl_lock to be held via NL80211_FLAG_NEED_RTNL. I'm guessing for the > > > command in question the driver did not set this flag since the driver wanted > > > to explicitly take the lock itself, otherwise it would have deadlocked on > > > itself with the 5.10 kernel. > > > > > > /jeff > > > > On the 5.10 kernel, the core kernel sets NL80211_FLAG_NEED_RTNL as part of > > the internal_flags for NL80211_CMD_VENDOR: > > > > net/wireless/nl80211.c: > > { > > .cmd = NL80211_CMD_VENDOR, > > .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, > > .doit = nl80211_vendor_cmd, > > .dumpit = nl80211_vendor_cmd_dump, > > .flags = GENL_UNS_ADMIN_PERM, > > .internal_flags = NL80211_FLAG_NEED_WIPHY | > > NL80211_FLAG_NEED_RTNL | > > NL80211_FLAG_CLEAR_SKB, > > }, > > > > So the 5.10 version of this driver doesn't need to directly call rtnl_lock() > > within the vendor command doit() functions since pre_doit() handles the RTNL > > locking. > > > > It would be nice if nl80211_vendor_cmd() could support taking the RTNL lock if > > requested via the vendor flags. That would require moving the wiphy lock to > > nl80211_vendor_cmds() so that it could take the RTNL and wiphy lock in the > > correct order. Is that something you'd be open to Johannes? > > > > --Will > > Thanks for correcting my understanding. I concur that it would be useful for > vendor commands to be able to specify that a given command needs the RTNL > lock to be held. > > Hi Johannes, I found that we can hit this same ABBA deadlock within the nl80211 code before ever even calling into the vendor doit() function. The issue I found is caused by the way we unlock the RTNL mutex. Here is the call flow that leads to the deadlock: Thread 1 Thread 2 nl80211_pre_doit(): rtnl_lock() wiphy_lock() nl80211_pre_doit(): rtnl_lock() // blocked by Thread 1 rtnl_unlock(): netdev_run_todo(): __rtnl_unlock() wiphy_lock() // blocked by Thread 1 rtnl_lock(); // DEADLOCK doit() nl80211_post_doit(): wiphy_unlock(); Basically, unlocking the RTNL within netdev_run_todo() gives another thread that is waiting for the RTNL in nl80211_pre_doit() a chance to grab the RTNL lock leading to the deadlock. I found that there are multiple instances where rtnl_lock() is called within netdev_run_todo(): a couple of times inside netdev_wait_allrefs() and directly by netdev_run_todo(). Since I'm not really familiar with all the RNTL locking requirements, I was hoping you could take a look at netdev_run_todo() to see if it's possible to refactor it to avoid this deadlock. If not, then I don't think we can call rtnl_unlock() while still holding the wiphy mutex. Thanks, Will