Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp621447rdb; Wed, 17 Jan 2024 12:01:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8K/j+5zvgxDM7BkVNbYNaqhwCFPMgMdyiYXTXNbBWOoVPaoZIffZfA/itBatc0ZJJ8GCI X-Received: by 2002:a17:90b:903:b0:28e:7930:c1d5 with SMTP id bo3-20020a17090b090300b0028e7930c1d5mr2139942pjb.85.1705521684086; Wed, 17 Jan 2024 12:01:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705521684; cv=pass; d=google.com; s=arc-20160816; b=EX3Nm1YfFDDzpsEAbnP8jieMTkp+65fQqPClgSjFZ14WntRcLdBYVpT7m2JGiFDUXa 3oVeS8PHe9zqjzZSau0C6rZXvd8Im52pr9Mob6hVVDiiQ71W4WcuK6Wkz+ESnTMsoH8i W/xT29E5xcdaBOLiMKgoacw0OsTmHJ6QT1if8ns2TB3rhSg1PYfj4PEz7iX0onLrZHfP LXdj4QtGXmjeRWFcM0s5cS9ECL/kg9Y4ZIlmzwC+HJcW/yLDYV9vYPQXCigjQqzJWifs DmxNP5DXYSd4Qbx2Q4fNmYZ6LbSVDPOTjLCRxjqAMc/FoCiuDQIfTHeC5IRFJ4MdJx/9 6NjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sJ5z/zk84qYGk3zFNnn8vdbVyeAi/0t7Jje7b1B9nuE=; fh=zcq/3Dkiu8gghWBlM7ZaOq+q+khkLO3h4xoRhnK6o98=; b=FmFMfaESIJPnm36uWnkh4YBL1ZPYYbG46T6/RbHVuGFcA4ArmqH3VACXxaxQf7KRBY 2v5VlYDBL0gRh+zBG2juj4ijAHZ2JcTWTGjHXhKso1pGO+xoovOStOKh9niE/WdLb0yr sq0mb2hsOBgaWvNT6SbH5uCPHnNXOFrPA+HxY843HCRsSzA1kV4FYZ1P3cI94K0+RLJW FOSAfNaGFWK5AmtVzgNJZZr6R9rTcvN0UzwpX6urC/NbaxTjbRnzdVwkQl5n3c/WbvyH Hdgl7PxdD8FMD3/VmqFwOax10WbmPRE7Jdd5SNogmy670fc9m1GprktH030aeiEtmlnf /CDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pappasbrent.com header.s=default header.b=OtPPLGUi; arc=pass (i=1 spf=pass spfdomain=pappasbrent.com dkim=pass dkdomain=pappasbrent.com); spf=pass (google.com: domain of linux-wireless+bounces-2123-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2123-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id t24-20020a17090aba9800b0028c58693f96si91838pjr.70.2024.01.17.12.01.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 12:01:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-2123-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@pappasbrent.com header.s=default header.b=OtPPLGUi; arc=pass (i=1 spf=pass spfdomain=pappasbrent.com dkim=pass dkdomain=pappasbrent.com); spf=pass (google.com: domain of linux-wireless+bounces-2123-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-wireless+bounces-2123-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 629A4B23F0C for ; Wed, 17 Jan 2024 20:00:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04D9D24A0B; Wed, 17 Jan 2024 20:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pappasbrent.com header.i=@pappasbrent.com header.b="OtPPLGUi" X-Original-To: linux-wireless@vger.kernel.org Received: from MTA-12-4.privateemail.com (mta-12-4.privateemail.com [198.54.127.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42FEA24A00; Wed, 17 Jan 2024 20:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.107 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705521626; cv=none; b=AEPpO1juVRQUxOeQWYoF9yi+WG8vw54J8CWj47X0Oo42/m8L/wolPIhQuqj+G4uCAqjuBxiF/+sfK9k1WgGcE5K+W9V2Al0U8IMIUjPFN9UWTQg/j2uoGjWPwRJavh1Yht7v13TZS81zAVHrT2mNTwwm9Xup8F1Wi4iA7Hc7TUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705521626; c=relaxed/simple; bh=YVcIYhmkjZDzczcsw0If+iQoXd/UI9stcIz62mPaVPg=; h=Received:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Virus-Scanned; b=W3mesiM9EKZ3Y2H/o4jJ3uhrzvjs7Na3+yCBzleL7M67VnmeQp1WghPfaMDTfEaLwPw0MF/nlNfjOfYzgjtHZ7E4wzlfRIuhLGbnrZRNeWALTo6nbKnYVwKAFthouGeqYMAd/EHj67QBIq20Kk1B1zsA31wVylLa2jpfiJi0MkU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pappasbrent.com; spf=pass smtp.mailfrom=pappasbrent.com; dkim=pass (2048-bit key) header.d=pappasbrent.com header.i=@pappasbrent.com header.b=OtPPLGUi; arc=none smtp.client-ip=198.54.127.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pappasbrent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pappasbrent.com Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 736051800046; Wed, 17 Jan 2024 15:00:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=pappasbrent.com; s=default; t=1705521616; bh=YVcIYhmkjZDzczcsw0If+iQoXd/UI9stcIz62mPaVPg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OtPPLGUi2sxy5zPEQ45+tx8wpT2Kyjm8lc4idSwuV1jaXN3PLxOKr1uRndAw2QN4n +Mp3v2BT4i1+77NusW+08hG7LRXDdaPVdGWgpLcqRbw3N9CNhszYvIlRIQb/jm2buS j+onlQY5XNkHOWtUTyBsh4SF+BCA/xw61ETYbypLwcgtwAdBVo7jrc0kBxgdlhW0/N WHuJJogZmUGptz+SuqBVjUMNIIx8hJsBtiMF3wHQCUFgeoiAp7XlCTHSXM9//vPPSm lw/zN5TO22JTrpiQ1Z26+nS15QCSxpD87o0ae9So87/QdF0qZbhDL5CkZLBjZq4XHS i2+sGnuVWVUTA== Received: from pappasbrent.com (050-088-208-203.res.spectrum.com [50.88.208.203]) by mta-12.privateemail.com (Postfix) with ESMTPA; Wed, 17 Jan 2024 15:00:06 -0500 (EST) Date: Wed, 17 Jan 2024 15:00:03 -0500 From: Brent Pappas To: Johannes Berg Cc: Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] wifi: mac80211: tx: Add __must_hold() annotation Message-ID: References: <20240113011145.10888-2-bpappas@pappasbrent.com> <87sf31hhfp.fsf@kernel.org> <26d364547d3bbb04800877e899cfebe0e1ec4dc0.camel@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <26d364547d3bbb04800877e899cfebe0e1ec4dc0.camel@sipsolutions.net> X-Virus-Scanned: ClamAV using ClamSMTP Thanks for the feedback Johannes. As I mentioned in my original email, I'm still learning the RCU API, so I appreciate the insight from someone more knowledgeable. > Much better to put something lockdep_assert_held() or similar into the right > places. I'm not committed to using __must_hold(); would you be willing to accept this patch if I change it to use lockdep_assert_held() instead? > The function ieee80211_set_beacon_cntdwn() is called from a number of places > in this file, some of which acquire RCU critical section, and some of which > acquire no locks nor RCU critical section at all. Grepping through tx.c, I see ieee80211_set_beacon_cntdwn() is invoked in three places: - Line 5285: Inside the definition of ieee80211_beacon_get_ap(), which is only invoked in critical sections (both directly and in another nested call). - Line 5439: Directly inside a critical section. - Line 5471: Directly inside a critical section (same as previous). > I tried to fix this in sparse many years ago, some code even got merged (and > then reverted), and if the experience tells me anything then that it's pretty > much not fixable. I'm sorry to hear that; a solution to this problem sounds very useful. I'm currently working on making my own static analyzer for performing more checks than what sparse currently provides. Since you've worked on this problem and have deeper insight into than I do, what sort of checks would you like to see added to a tool like sparse (besides checking whether specific locks are held)? Thank you, Brent The 01/15/2024 14:13, Johannes Berg wrote: > On Sat, 2024-01-13 at 08:32 +0200, Kalle Valo wrote: > > > > > static void ieee80211_set_beacon_cntdwn(struct ieee80211_sub_if_data *sdata, > > > struct beacon_data *beacon, > > > struct ieee80211_link_data *link) > > > + __must_hold(link) > > > > Oh, never seen __must_hold() before and looks very useful. So does this > > work with RCU, mutexes and spinlocks? > > > > In case others are interested, here's the documentation I was able to find: > > > > https://docs.kernel.org/dev-tools/sparse.html#using-sparse-for-lock-checking > > > > Except it's not actually useful, and looks more useful than it is. IMHO > it's actually more harmful than anything else. > > One might even consider this patch a good example! The function > ieee80211_set_beacon_cntdwn() is called from a number of places in this > file, some of which acquire RCU critical section, and some of which > acquire no locks nor RCU critical section at all. Most of them nest and > are called in RCU. > > However, there's basically no way to get sparse to warn on this. Even > inserting a function > > void test(void); > void test(void) > { > ieee80211_set_beacon_cntdwn(NULL, NULL, NULL); > } > > will not cause sparse to complain, where this *clearly* doesn't hold an > locks. > > > Also, as we (should) all know, the argument to __acquires(), > __releases() and __must_check() is pretty much ignored. I tried to fix > this in sparse many years ago, some code even got merged (and then > reverted), and if the experience tells me anything then that it's pretty > much not fixable. > > __acquires() and __releases() at least are useful for tracking that you > don't have a mismatch, e.g. a function that __acquires() but then takes > a lock in most paths but forgot one, for example. With __must_hold(), > this really isn't the case. > > And then we could argue that at least it has a documentation effect, but > ... what does it even mean to "hold 'link'"? There isn't even a lock, > mutex or otherwise, in the link. You can't "own" a reference to it, or > anything like that. The closest thing in current kernels would be to > maybe see if you have the wiphy mutex, but that's likely not the case in > these paths and RCU was used to get to the link struct ... > > > IOW, I find this lacking from an implementation/validation point of > view, and lacking if not outright confusing from a documentation point > of view. Much better to put something lockdep_assert_held() or similar > into the right places. > > As for your comment about RCU in ath11k (which points back to this > thread): I don't find > > RCU_LOCKDEP_WARN(!rcu_read_lock_held()); > or > WARN_ON_ONCE(!rcu_read_lock_held()); > > very persuasive, it's much better to have it checked with > rcu_dereference_protected(), rcu_dereference_check(), the condition > argument to list_for_each_rcu(), or (in the case of wiphy) our wrappers > around these like wiphy_dereference(). I cannot think of any case where > you'd want to ensure that some code is in an RCU critical section > without it actually using RCU - and if it does you have > rcu_dereference() and all those things that (a) check anyway, and also > (b) serve as their own documentation. > > > Anyway, long story short: I don't see value in this patch and won't be > applying it unless somebody here can convince me otherwise, ideally > addressing the concerns stated above. > > johannes