From 35c6bba552a8469e6423727fba6a73616fcabd51 Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Fri, 2 Feb 2024 01:45:12 -0500 Subject: [PATCH 1/8] net: ieee802154: at86rf230: convert to use maple tree register cache The maple tree register cache is based on a much more modern data structure than the rbtree cache and makes optimisation choices which are probably more appropriate for modern systems than those made by the rbtree cache. Signed-off-by: Bo Liu Reviewed-by: Miquel Raynal Message-ID: <20240202064512.39259-1-liubo03@inspur.com> Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/at86rf230.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 164c7f605af5..6212164ffb36 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -316,7 +316,7 @@ static const struct regmap_config at86rf230_regmap_spi_config = { .val_bits = 8, .write_flag_mask = CMD_REG | CMD_WRITE, .read_flag_mask = CMD_REG, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .max_register = AT86RF2XX_NUMREGS, .writeable_reg = at86rf230_reg_writeable, .readable_reg = at86rf230_reg_readable, From b0f413bc63ea39358ec42a7f16526b097cf1f3b4 Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Fri, 2 Feb 2024 01:46:11 -0500 Subject: [PATCH 2/8] net: ieee802154: mcr20a: convert to use maple tree register cache The maple tree register cache is based on a much more modern data structure than the rbtree cache and makes optimisation choices which are probably more appropriate for modern systems than those made by the rbtree cache. Signed-off-by: Bo Liu Message-ID: <20240202064611.39346-1-liubo03@inspur.com> Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/mcr20a.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/mcr20a.c b/drivers/net/ieee802154/mcr20a.c index 87abe3b46316..efb1be3c644e 100644 --- a/drivers/net/ieee802154/mcr20a.c +++ b/drivers/net/ieee802154/mcr20a.c @@ -251,7 +251,7 @@ static const struct regmap_config mcr20a_dar_regmap = { .val_bits = 8, .write_flag_mask = REGISTER_ACCESS | REGISTER_WRITE, .read_flag_mask = REGISTER_ACCESS | REGISTER_READ, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .writeable_reg = mcr20a_dar_writeable, .readable_reg = mcr20a_dar_readable, .volatile_reg = mcr20a_dar_volatile, @@ -387,7 +387,7 @@ static const struct regmap_config mcr20a_iar_regmap = { .val_bits = 8, .write_flag_mask = REGISTER_ACCESS | REGISTER_WRITE | IAR_INDEX, .read_flag_mask = REGISTER_ACCESS | REGISTER_READ | IAR_INDEX, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .writeable_reg = mcr20a_iar_writeable, .readable_reg = mcr20a_iar_readable, .volatile_reg = mcr20a_iar_volatile, From 36cc392d1ae142e82b38d137daaac282dd1aced1 Mon Sep 17 00:00:00 2001 From: Bo Liu Date: Fri, 2 Feb 2024 01:46:59 -0500 Subject: [PATCH 3/8] net: ieee802154: mrf24j40: convert to use maple tree register cache The maple tree register cache is based on a much more modern data structure than the rbtree cache and makes optimisation choices which are probably more appropriate for modern systems than those made by the rbtree cache. Signed-off-by: Bo Liu Message-ID: <20240202064659.39434-1-liubo03@inspur.com> Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/mrf24j40.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c index ee4cfbf2c5cc..d3f42efc5d1a 100644 --- a/drivers/net/ieee802154/mrf24j40.c +++ b/drivers/net/ieee802154/mrf24j40.c @@ -388,7 +388,7 @@ static const struct regmap_config mrf24j40_short_regmap = { .pad_bits = 1, .write_flag_mask = MRF24J40_SHORT_WRITE, .read_flag_mask = MRF24J40_SHORT_READ, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .max_register = MRF24J40_SHORT_NUMREGS, .writeable_reg = mrf24j40_short_reg_writeable, .readable_reg = mrf24j40_short_reg_readable, @@ -495,7 +495,7 @@ static const struct regmap_config mrf24j40_long_regmap = { .pad_bits = 5, .write_flag_mask = MRF24J40_LONG_ACCESS, .read_flag_mask = MRF24J40_LONG_ACCESS, - .cache_type = REGCACHE_RBTREE, + .cache_type = REGCACHE_MAPLE, .max_register = MRF24J40_LONG_NUMREGS, .writeable_reg = mrf24j40_long_reg_writeable, .readable_reg = mrf24j40_long_reg_readable, From 42683294cc0a9ba010de5d978fd23fd1e778b192 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 5 Feb 2024 13:53:54 -1000 Subject: [PATCH 4/8] ieee802154: ca8210: Drop spurious WQ_UNBOUND from alloc_ordered_workqueue() call Workqueue is in the process of cleaning up the distinction between unbound workqueues w/ @nr_active==1 and ordered workqueues. Explicit WQ_UNBOUND isn't needed for alloc_ordered_workqueue() and will trigger a warning in the future. Let's remove it. This doesn't cause any functional changes. Signed-off-by: Tejun Heo Reviewed-by: Miquel Raynal Message-ID: Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/ca8210.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c index 4ec0dab38872..f102f26cb0e3 100644 --- a/drivers/net/ieee802154/ca8210.c +++ b/drivers/net/ieee802154/ca8210.c @@ -2857,19 +2857,13 @@ static int ca8210_interrupt_init(struct spi_device *spi) */ static int ca8210_dev_com_init(struct ca8210_priv *priv) { - priv->mlme_workqueue = alloc_ordered_workqueue( - "MLME work queue", - WQ_UNBOUND - ); + priv->mlme_workqueue = alloc_ordered_workqueue("MLME work queue", 0); if (!priv->mlme_workqueue) { dev_crit(&priv->spi->dev, "alloc of mlme_workqueue failed!\n"); return -ENOMEM; } - priv->irq_workqueue = alloc_ordered_workqueue( - "ca8210 irq worker", - WQ_UNBOUND - ); + priv->irq_workqueue = alloc_ordered_workqueue("ca8210 irq worker", 0); if (!priv->irq_workqueue) { dev_crit(&priv->spi->dev, "alloc of irq_workqueue failed!\n"); destroy_workqueue(priv->mlme_workqueue); From e8a1e58345cf40b7b272e08ac7b32328b2543e40 Mon Sep 17 00:00:00 2001 From: Fedor Pchelkin Date: Wed, 28 Feb 2024 19:38:39 +0300 Subject: [PATCH 5/8] mac802154: fix llsec key resources release in mac802154_llsec_key_del mac802154_llsec_key_del() can free resources of a key directly without following the RCU rules for waiting before the end of a grace period. This may lead to use-after-free in case llsec_lookup_key() is traversing the list of keys in parallel with a key deletion: refcount_t: addition on 0; use-after-free. WARNING: CPU: 4 PID: 16000 at lib/refcount.c:25 refcount_warn_saturate+0x162/0x2a0 Modules linked in: CPU: 4 PID: 16000 Comm: wpan-ping Not tainted 6.7.0 #19 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 RIP: 0010:refcount_warn_saturate+0x162/0x2a0 Call Trace: llsec_lookup_key.isra.0+0x890/0x9e0 mac802154_llsec_encrypt+0x30c/0x9c0 ieee802154_subif_start_xmit+0x24/0x1e0 dev_hard_start_xmit+0x13e/0x690 sch_direct_xmit+0x2ae/0xbc0 __dev_queue_xmit+0x11dd/0x3c20 dgram_sendmsg+0x90b/0xd60 __sys_sendto+0x466/0x4c0 __x64_sys_sendto+0xe0/0x1c0 do_syscall_64+0x45/0xf0 entry_SYSCALL_64_after_hwframe+0x6e/0x76 Also, ieee802154_llsec_key_entry structures are not freed by mac802154_llsec_key_del(): unreferenced object 0xffff8880613b6980 (size 64): comm "iwpan", pid 2176, jiffies 4294761134 (age 60.475s) hex dump (first 32 bytes): 78 0d 8f 18 80 88 ff ff 22 01 00 00 00 00 ad de x......."....... 00 00 00 00 00 00 00 00 03 00 cd ab 00 00 00 00 ................ backtrace: [] __kmem_cache_alloc_node+0x1e2/0x2d0 [] kmalloc_trace+0x25/0xc0 [] mac802154_llsec_key_add+0xac9/0xcf0 [] ieee802154_add_llsec_key+0x5a/0x80 [] nl802154_add_llsec_key+0x426/0x5b0 [] genl_family_rcv_msg_doit+0x1fe/0x2f0 [] genl_rcv_msg+0x531/0x7d0 [] netlink_rcv_skb+0x169/0x440 [] genl_rcv+0x28/0x40 [] netlink_unicast+0x53c/0x820 [] netlink_sendmsg+0x93b/0xe60 [] ____sys_sendmsg+0xac5/0xca0 [] ___sys_sendmsg+0x11d/0x1c0 [] __sys_sendmsg+0xfa/0x1d0 [] do_syscall_64+0x45/0xf0 [] entry_SYSCALL_64_after_hwframe+0x6e/0x76 Handle the proper resource release in the RCU callback function mac802154_llsec_key_del_rcu(). Note that if llsec_lookup_key() finds a key, it gets a refcount via llsec_key_get() and locally copies key id from key_entry (which is a list element). So it's safe to call llsec_key_put() and free the list entry after the RCU grace period elapses. Found by Linux Verification Center (linuxtesting.org). Fixes: 5d637d5aabd8 ("mac802154: add llsec structures and mutators") Cc: stable@vger.kernel.org Signed-off-by: Fedor Pchelkin Acked-by: Alexander Aring Message-ID: <20240228163840.6667-1-pchelkin@ispras.ru> Signed-off-by: Stefan Schmidt --- include/net/cfg802154.h | 1 + net/mac802154/llsec.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h index cd95711b12b8..76d2cd2e2b30 100644 --- a/include/net/cfg802154.h +++ b/include/net/cfg802154.h @@ -401,6 +401,7 @@ struct ieee802154_llsec_key { struct ieee802154_llsec_key_entry { struct list_head list; + struct rcu_head rcu; struct ieee802154_llsec_key_id id; struct ieee802154_llsec_key *key; diff --git a/net/mac802154/llsec.c b/net/mac802154/llsec.c index 8d2eabc71bbe..f13b07ebfb98 100644 --- a/net/mac802154/llsec.c +++ b/net/mac802154/llsec.c @@ -265,19 +265,27 @@ fail: return -ENOMEM; } +static void mac802154_llsec_key_del_rcu(struct rcu_head *rcu) +{ + struct ieee802154_llsec_key_entry *pos; + struct mac802154_llsec_key *mkey; + + pos = container_of(rcu, struct ieee802154_llsec_key_entry, rcu); + mkey = container_of(pos->key, struct mac802154_llsec_key, key); + + llsec_key_put(mkey); + kfree_sensitive(pos); +} + int mac802154_llsec_key_del(struct mac802154_llsec *sec, const struct ieee802154_llsec_key_id *key) { struct ieee802154_llsec_key_entry *pos; list_for_each_entry(pos, &sec->table.keys, list) { - struct mac802154_llsec_key *mkey; - - mkey = container_of(pos->key, struct mac802154_llsec_key, key); - if (llsec_key_id_equal(&pos->id, key)) { list_del_rcu(&pos->list); - llsec_key_put(mkey); + call_rcu(&pos->rcu, mac802154_llsec_key_del_rcu); return 0; } } From defa2cb4e43995f04887c71101c388280f45827b Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 4 Mar 2024 19:42:17 +0200 Subject: [PATCH 6/8] ieee802154: at86rf230: Replace of_gpio.h by proper one of_gpio.h is deprecated and subject to remove. The driver doesn't use it directly, replace it with what is really being used. Signed-off-by: Andy Shevchenko Acked-by: Miquel Raynal Message-ID: <20240304174218.1198411-1-andriy.shevchenko@linux.intel.com> Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/at86rf230.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 6212164ffb36..f632b0cfd5ae 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -11,17 +11,16 @@ */ #include #include +#include #include #include #include #include -#include #include #include #include #include #include -#include #include #include From 7a04ace6c7bd8d3a04a3e8ccfb3c7377f0aa5411 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 4 Mar 2024 19:53:20 +0200 Subject: [PATCH 7/8] ieee802154: mcr20a: Remove unused of_gpio.h of_gpio.h is deprecated and subject to remove. The driver doesn't use it, simply remove the unused header. Signed-off-by: Andy Shevchenko Acked-by: Miquel Raynal Message-ID: <20240304175320.1199496-1-andriy.shevchenko@linux.intel.com> Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/mcr20a.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ieee802154/mcr20a.c b/drivers/net/ieee802154/mcr20a.c index efb1be3c644e..433fb5839203 100644 --- a/drivers/net/ieee802154/mcr20a.c +++ b/drivers/net/ieee802154/mcr20a.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include From b2d23256615c8f8b3215f0155b0234f0e310dfde Mon Sep 17 00:00:00 2001 From: "Ricardo B. Marliere" Date: Tue, 5 Mar 2024 16:55:24 -0300 Subject: [PATCH 8/8] ieee802154: cfg802154: make wpan_phy_class constant Since commit 43a7206b0963 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the wpan_phy_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time. Cc: Greg Kroah-Hartman Suggested-by: Greg Kroah-Hartman Signed-off-by: Ricardo B. Marliere Acked-by: Miquel Raynal Message-ID: <20240305-class_cleanup-wpan-v1-1-376f751fd481@marliere.net> [changed prefix from wifi to ieee802154 by stefan@datenfreihafen.org] Signed-off-by: Stefan Schmidt --- net/ieee802154/sysfs.c | 2 +- net/ieee802154/sysfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ieee802154/sysfs.c b/net/ieee802154/sysfs.c index d2903933805c..6708160ebf9f 100644 --- a/net/ieee802154/sysfs.c +++ b/net/ieee802154/sysfs.c @@ -93,7 +93,7 @@ static SIMPLE_DEV_PM_OPS(wpan_phy_pm_ops, wpan_phy_suspend, wpan_phy_resume); #define WPAN_PHY_PM_OPS NULL #endif -struct class wpan_phy_class = { +const struct class wpan_phy_class = { .name = "ieee802154", .dev_release = wpan_phy_release, .dev_groups = pmib_groups, diff --git a/net/ieee802154/sysfs.h b/net/ieee802154/sysfs.h index 337545b639e9..69961e166257 100644 --- a/net/ieee802154/sysfs.h +++ b/net/ieee802154/sysfs.h @@ -5,6 +5,6 @@ int wpan_phy_sysfs_init(void); void wpan_phy_sysfs_exit(void); -extern struct class wpan_phy_class; +extern const struct class wpan_phy_class; #endif /* __IEEE802154_SYSFS_H */