2021-03-27 09:16:56

by Lorenzo Bianconi

[permalink] [raw]
Subject: [PATCH] mt76: mt7921: fix key set/delete issue

Similar to the mt7915 driver, deleting a key with the previous key index
deletes the current key. Rework the code to better keep track of
multiple keys and check for the key index before deleting the current
key

Signed-off-by: Lorenzo Bianconi <[email protected]>
---
.../net/wireless/mediatek/mt76/mt7921/main.c | 25 +++++++++++++------
1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 92775f98a80c..c0ebb6077fa8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -418,7 +418,8 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
struct mt7921_sta *msta = sta ? (struct mt7921_sta *)sta->drv_priv :
&mvif->sta;
struct mt76_wcid *wcid = &msta->wcid;
- int idx = key->keyidx;
+ u8 *wcid_keyidx = &wcid->hw_key_idx;
+ int idx = key->keyidx, err = 0;

/* The hardware does not support per-STA RX GTK, fallback
* to software mode for these.
@@ -434,6 +435,7 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
switch (key->cipher) {
case WLAN_CIPHER_SUITE_AES_CMAC:
key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
+ wcid_keyidx = &wcid->hw_key_idx2;
break;
case WLAN_CIPHER_SUITE_TKIP:
case WLAN_CIPHER_SUITE_CCMP:
@@ -448,16 +450,23 @@ static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
return -EOPNOTSUPP;
}

- if (cmd == SET_KEY) {
- key->hw_key_idx = wcid->idx;
- wcid->hw_key_idx = idx;
- } else if (idx == wcid->hw_key_idx) {
- wcid->hw_key_idx = -1;
- }
+ mt7921_mutex_acquire(dev);
+
+ if (cmd == SET_KEY)
+ *wcid_keyidx = idx;
+ else if (idx == *wcid_keyidx)
+ *wcid_keyidx = -1;
+ else
+ goto out;
+
mt76_wcid_key_setup(&dev->mt76, wcid,
cmd == SET_KEY ? key : NULL);

- return mt7921_mcu_add_key(dev, vif, msta, key, cmd);
+ err = mt7921_mcu_add_key(dev, vif, msta, key, cmd);
+out:
+ mt7921_mutex_release(dev);
+
+ return err;
}

static int mt7921_config(struct ieee80211_hw *hw, u32 changed)
--
2.30.2


2021-03-27 11:44:03

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] mt76: mt7921: fix key set/delete issue

Hi Lorenzo,

I love your patch! Yet something to improve:

[auto build test ERROR on wireless-drivers-next/master]
[also build test ERROR on wireless-drivers/master v5.12-rc4 next-20210326]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Lorenzo-Bianconi/mt76-mt7921-fix-key-set-delete-issue/20210327-171231
base: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/wireless-drivers-next.git master
config: riscv-allmodconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9c49e0759aa10119efd7808db8dc9ed4d870921c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Lorenzo-Bianconi/mt76-mt7921-fix-key-set-delete-issue/20210327-171231
git checkout 9c49e0759aa10119efd7808db8dc9ed4d870921c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

drivers/net/wireless/mediatek/mt76/mt7921/main.c: In function 'mt7921_set_key':
>> drivers/net/wireless/mediatek/mt76/mt7921/main.c:433:24: error: 'struct mt76_wcid' has no member named 'hw_key_idx2'; did you mean 'hw_key_idx'?
433 | wcid_keyidx = &wcid->hw_key_idx2;
| ^~~~~~~~~~~
| hw_key_idx


vim +433 drivers/net/wireless/mediatek/mt76/mt7921/main.c

406
407 static int mt7921_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
408 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
409 struct ieee80211_key_conf *key)
410 {
411 struct mt7921_dev *dev = mt7921_hw_dev(hw);
412 struct mt7921_vif *mvif = (struct mt7921_vif *)vif->drv_priv;
413 struct mt7921_sta *msta = sta ? (struct mt7921_sta *)sta->drv_priv :
414 &mvif->sta;
415 struct mt76_wcid *wcid = &msta->wcid;
416 u8 *wcid_keyidx = &wcid->hw_key_idx;
417 int idx = key->keyidx, err = 0;
418
419 /* The hardware does not support per-STA RX GTK, fallback
420 * to software mode for these.
421 */
422 if ((vif->type == NL80211_IFTYPE_ADHOC ||
423 vif->type == NL80211_IFTYPE_MESH_POINT) &&
424 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
425 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
426 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
427 return -EOPNOTSUPP;
428
429 /* fall back to sw encryption for unsupported ciphers */
430 switch (key->cipher) {
431 case WLAN_CIPHER_SUITE_AES_CMAC:
432 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
> 433 wcid_keyidx = &wcid->hw_key_idx2;
434 break;
435 case WLAN_CIPHER_SUITE_TKIP:
436 case WLAN_CIPHER_SUITE_CCMP:
437 case WLAN_CIPHER_SUITE_CCMP_256:
438 case WLAN_CIPHER_SUITE_GCMP:
439 case WLAN_CIPHER_SUITE_GCMP_256:
440 case WLAN_CIPHER_SUITE_SMS4:
441 break;
442 case WLAN_CIPHER_SUITE_WEP40:
443 case WLAN_CIPHER_SUITE_WEP104:
444 default:
445 return -EOPNOTSUPP;
446 }
447
448 mt7921_mutex_acquire(dev);
449
450 if (cmd == SET_KEY)
451 *wcid_keyidx = idx;
452 else if (idx == *wcid_keyidx)
453 *wcid_keyidx = -1;
454 else
455 goto out;
456
457 mt76_wcid_key_setup(&dev->mt76, wcid,
458 cmd == SET_KEY ? key : NULL);
459
460 err = mt7921_mcu_add_key(dev, vif, msta, key, cmd);
461 out:
462 mt7921_mutex_release(dev);
463
464 return err;
465 }
466

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (4.12 kB)
.config.gz (67.24 kB)
Download all attachments