public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@kernel.org>
To: Brent Pappas <bpappas@pappasbrent.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	 "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	linux-wireless@vger.kernel.org,  netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wifi: mac80211: tx: Add __must_hold() annotation
Date: Sat, 13 Jan 2024 08:32:26 +0200	[thread overview]
Message-ID: <87sf31hhfp.fsf@kernel.org> (raw)
In-Reply-To: <20240113011145.10888-2-bpappas@pappasbrent.com> (Brent Pappas's message of "Fri, 12 Jan 2024 20:11:45 -0500")

Brent Pappas <bpappas@pappasbrent.com> writes:

> Annotates ieee80211_set_beacon_cntdwn() with a __must_hold() annotation to
> make it clear that ieee80211_set_beacon_cntdwn() is only intended to be
> called when the caller has a lock on the argument "link."
>
> Signed-off-by: Brent Pappas <bpappas@pappasbrent.com>
> ---
>
> Currently, ieee80211_set_beacon_cntdwn() calls rcu_dereference(), but
> without calling rcu_read_lock() beforehand and rcu_read_unlock()
> afterward.  At first I thought this was a bug, since (if I understand the
> RCU API correctly) rcu_dereference() should only be called in RCU
> read-side critical sections. However, upon closer inspection of the code,
> I realized that ieee80211_set_beacon_cntdwn() is only ever called inside
> critical sections. Therefore it seems appropriate to me to annotate
> ieee80211_set_beacon_cntdwn() with a __must_hold() annotation to make this
> apparent precondition explicit.
>
> This is my first time submitting an RCU-related patch so please tell me if
> I am misunderstanding the RCU API.
>
>  net/mac80211/tx.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
> index 314998fdb1a5..7245f2e641ba 100644
> --- a/net/mac80211/tx.c
> +++ b/net/mac80211/tx.c
> @@ -10,6 +10,7 @@
>   * Transmit and frame generation functions.
>   */
>  
> +#include "linux/compiler_types.h"
>  #include <linux/kernel.h>
>  #include <linux/slab.h>
>  #include <linux/skbuff.h>
> @@ -4974,6 +4975,7 @@ static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
>  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

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

  reply	other threads:[~2024-01-13  6:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-13  1:11 [PATCH] wifi: mac80211: tx: Add __must_hold() annotation Brent Pappas
2024-01-13  6:32 ` Kalle Valo [this message]
2024-01-15 13:13   ` Johannes Berg
2024-01-17 20:00     ` Brent Pappas
2024-01-17 23:07       ` Johannes Berg
2024-01-13 17:27 ` [PATCH v2] " Brent Pappas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sf31hhfp.fsf@kernel.org \
    --to=kvalo@kernel.org \
    --cc=bpappas@pappasbrent.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox