From: Yogesh Ashok Powar <yogeshp@marvell.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"John W. Linville" <linville@tuxdriver.com>,
Andreas Hartmann <andihartmann@01019freenet.de>
Subject: Re: [PATCH 2/2] mac80211: Fixing Races for skipping tailroom reservation
Date: Mon, 20 Jun 2011 20:00:52 +0530 [thread overview]
Message-ID: <20110620143051.GA31035@hertz.marvell.com> (raw)
In-Reply-To: <1308331485.7329.2.camel@Nokia-N900-51-1>
On Fri, Jun 17, 2011 at 10:24:45AM -0700, Johannes Berg wrote:
> > Using spinlocks in TX/RX path is not allowed because spinlocks will make
> > TX/RX path to block and its illegal to block while in an RCU read-side
> > critical section. I think, I got the joke here :(.
>
> No, that'd be allowed, but you can't spinlock all the TX path because of performance.
>
> I think the way to solve it would be to use synchronize_net() somehow maybe; not really sure.
Following patch avoids tailroom skip check for RCU readside
critical sections that begin inside the synchronize_rcu's grace
period, without grabbing any lock in the TX patch and there by avoiding
the race conditions.
I will request Andreas to test this patch on his testbed if the changes
are fine with you.
Thanks
Yogesh
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 2025af5..56c7751b 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -777,6 +777,7 @@ struct ieee80211_local {
/* count for keys needing tailroom space allocation */
int crypto_tx_tailroom_needed_cnt;
+ struct mutex tailroom_skip;
/* Tasklet and skb queue to process calls from IRQ mode. All frames
* added to skb_queue will be processed, but frames in
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 31afd712..d59837a 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -390,14 +390,20 @@ static void __ieee80211_key_destroy(struct ieee80211_key *key)
if (!key)
return;
+ if (key->local && !(key->local->crypto_tx_tailroom_needed_cnt))
+ mutex_lock(&key->local->tailroom_skip);
+
/*
* Synchronize so the TX path can no longer be using
* this key before we free/remove it.
*/
synchronize_rcu();
- if (key->local)
+ if (key->local) {
ieee80211_key_disable_hw_accel(key);
+ if (mutex_is_locked(&key->local->tailroom_skip))
+ mutex_unlock(&key->local->tailroom_skip);
+ }
if (key->conf.cipher == WLAN_CIPHER_SUITE_CCMP)
ieee80211_aes_key_free(key->u.ccmp.tfm);
@@ -468,8 +474,16 @@ int ieee80211_key_link(struct ieee80211_key *key,
ieee80211_debugfs_key_add(key);
+ if (!key->local->crypto_tx_tailroom_needed_cnt) {
+ mutex_lock(&key->local->tailroom_skip);
+ synchronize_rcu();
+ }
+
key->local->crypto_tx_tailroom_needed_cnt++;
+ if (mutex_is_locked(&key->local->tailroom_skip))
+ mutex_unlock(&key->local->tailroom_skip);
+
ret = ieee80211_key_enable_hw_accel(key);
mutex_unlock(&sdata->local->key_mtx);
@@ -513,11 +527,17 @@ void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
sdata->local->crypto_tx_tailroom_needed_cnt = 0;
+ mutex_lock(&sdata->local->tailroom_skip);
+
+ synchronize_rcu();
+
list_for_each_entry(key, &sdata->key_list, list) {
sdata->local->crypto_tx_tailroom_needed_cnt++;
ieee80211_key_enable_hw_accel(key);
}
+ mutex_unlock(&sdata->local->tailroom_skip);
+
mutex_unlock(&sdata->local->key_mtx);
}
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 866f269..c70b26d 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -625,6 +625,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
spin_lock_init(&local->filter_lock);
spin_lock_init(&local->queue_stop_reason_lock);
+ mutex_init(&local->tailroom_skip);
+
/*
* The rx_skb_queue is only accessed from tasklets,
* but other SKB queues are used from within IRQ
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 64e0f75..ce2ee4a 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1480,7 +1480,8 @@ static int ieee80211_skb_resize(struct ieee80211_local *local,
{
int tail_need = 0;
- if (may_encrypt && local->crypto_tx_tailroom_needed_cnt) {
+ if (may_encrypt && (local->crypto_tx_tailroom_needed_cnt ||
+ mutex_is_locked(&local->tailroom_skip))) {
tail_need = IEEE80211_ENCRYPT_TAILROOM;
tail_need -= skb_tailroom(skb);
tail_need = max_t(int, tail_need, 0);
next prev parent reply other threads:[~2011-06-20 14:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-16 10:21 [PATCH 0/2] mac80211: Fixing races for hw crypto skipping tailroom Yogesh Ashok Powar
2011-06-16 10:25 ` [PATCH 1/2] Revert "Revert "mac80211: Skip tailroom reservation for full HW-crypto devices"" Yogesh Ashok Powar
2011-06-16 10:27 ` [PATCH 2/2] mac80211: Fixing Races for skipping tailroom reservation Yogesh Ashok Powar
2011-06-16 15:36 ` Johannes Berg
2011-06-17 13:25 ` Yogesh Ashok Powar
2011-06-17 17:24 ` Johannes Berg
2011-06-20 14:30 ` Yogesh Ashok Powar [this message]
2011-06-20 15:29 ` Johannes Berg
2011-06-20 16:49 ` Yogesh Powar
2011-06-20 17:29 ` Johannes Berg
2011-06-21 13:03 ` Yogesh Ashok Powar
2011-06-21 13:43 ` Johannes Berg
2011-06-21 14:10 ` Yogesh Ashok Powar
2011-06-21 14:40 ` Johannes Berg
2011-06-21 16:33 ` Yogesh Ashok Powar
2011-06-21 17:44 ` Andreas Hartmann
2011-06-22 7:17 ` Yogesh Ashok Powar
2011-06-22 12:31 ` Yogesh Ashok Powar
2011-06-22 12:49 ` Johannes Berg
2011-06-22 12:58 ` Yogesh Ashok Powar
2011-06-22 13:12 ` Johannes Berg
2011-06-23 11:52 ` Yogesh Powar
2011-06-24 9:04 ` yogeshp
2011-06-25 13:07 ` Johannes Berg
2011-06-27 6:02 ` [PATCH] nl80211: use netlink consistent dump feature for BSS dumps Walter Goldens
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=20110620143051.GA31035@hertz.marvell.com \
--to=yogeshp@marvell.com \
--cc=andihartmann@01019freenet.de \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.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;
as well as URLs for NNTP newsgroup(s).