Remove extra param of dev_coredumpv and fix bugs
Subsystems (26)
PATCH v4 1/2 devcoredump: remove the useless gfp_t parameter in dev_coredumpv
In reply to Duoming ZhouThe dev_coredumpv() could not be used in atomic context, because it calls kvasprintf_const() and kstrdup() with GFP_KERNEL parameter. The process is shown below:
dev_coredumpv(..., gfp_t gfp)
dev_coredumpm
dev_set_name
kobject_set_name_vargs
kvasprintf_const(GFP_KERNEL, ...); //may sleep
kstrdup(s, GFP_KERNEL); //may sleep
This patch removes gfp_t parameter of dev_coredumpv() and changes the gfp_t parameter of dev_coredumpm() to GFP_KERNEL in order to show dev_coredumpv() could not be used in atomic context.
---
Changes in v4:
- Drop gfp_t parameter of dev_coredumpv.
drivers/base/devcoredump.c | 6 ++---- drivers/bluetooth/btmrvl_sdio.c | 2 +- drivers/bluetooth/hci_qca.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_dump.c | 2 +- drivers/media/platform/qcom/venus/core.c | 2 +- drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c | 2 +- drivers/net/wireless/ath/ath10k/coredump.c | 2 +- drivers/net/wireless/ath/wil6210/wil_crash_dump.c | 2 +- drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c | 2 +- drivers/net/wireless/marvell/mwifiex/main.c | 3 +-- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +-- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +-- drivers/net/wireless/realtek/rtw88/main.c | 2 +- drivers/net/wireless/realtek/rtw89/ser.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/remoteproc_coredump.c | 4 ++-- include/linux/devcoredump.h | 5 ++--- sound/soc/intel/catpt/dsp.c | 2 +- 18 files changed, 21 insertions(+), 27 deletions(-)
drivers/base/devcoredump.c +2 -4
@@ -173,15 +173,13 @@ static void devcd_freev(void *data)* @dev: the struct device for the crashed device * @data: vmalloc data containing the device coredump * @datalen: length of the data -* @gfp: allocation flags * * This function takes ownership of the vmalloc'ed data and will free * it when it is no longer used. See dev_coredumpm() for more information. */ -void dev_coredumpv (struct device *dev,void *data,size_t datalen, -gfp_t gfp) +void dev_coredumpv (struct device *dev,void *data,size_t datalen) { -dev_coredumpm (dev,NULL , data, datalen, gfp, devcd_readv, devcd_freev); +dev_coredumpm (dev,NULL , data, datalen,GFP_KERNEL , devcd_readv, devcd_freev); }EXPORT_SYMBOL_GPL (dev_coredumpv);
drivers/bluetooth/btmrvl_sdio.c +1 -1
@@ -1515,7 +1515,7 @@ static void btmrvl_sdio_coredump(struct device *dev)/* fw_dump_data will be free in device coredump release function * after 5 min */ -dev_coredumpv (&card->func->dev, fw_dump_data, fw_dump_len,GFP_KERNEL ); +dev_coredumpv (&card->func->dev, fw_dump_data, fw_dump_len);BT_INFO ("== btmrvl firmware dump to /sys/class/devcoredump end" ); }
drivers/bluetooth/hci_qca.c +1 -1
@@ -1120,7 +1120,7 @@ static void qca_controller_memdump(struct work_struct *work) qca_memdump->ram_dump_size); memdump_buf = qca_memdump->memdump_buf_head;dev_coredumpv (&hu->serdev->dev, memdump_buf, - qca_memdump->received_dump,GFP_KERNEL ); + qca_memdump->received_dump);cancel_delayed_work (&qca->ctrl_memdump_timeout);kfree (qca->qca_memdump); qca->qca_memdump =NULL ;
drivers/gpu/drm/etnaviv/etnaviv_dump.c +1 -1
@@ -225,5 +225,5 @@ void etnaviv_core_dump(struct etnaviv_gem_submit *submit)etnaviv_core_dump_header (&iter,ETDUMP_BUF_END , iter.data); -dev_coredumpv (gpu->dev, iter.start, iter.data - iter.start,GFP_KERNEL ); +dev_coredumpv (gpu->dev, iter.start, iter.data - iter.start); }
drivers/media/platform/qcom/venus/core.c +1 -1
@@ -49,7 +49,7 @@ static void venus_coredump(struct venus_core *core)memcpy (data, mem_va, mem_size);memunmap (mem_va); -dev_coredumpv (dev, data, mem_size,GFP_KERNEL ); +dev_coredumpv (dev, data, mem_size); }static void venus_event_notify (struct venus_core *core,u32 event)
drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c +1 -1
@@ -281,5 +281,5 @@ void mcp251xfd_dump(const struct mcp251xfd_priv *priv)mcp251xfd_dump_end (priv, &iter);dev_coredumpv (&priv->spi->dev, iter.start, - iter.data - iter.start,GFP_KERNEL ); + iter.data - iter.start); }
drivers/net/wireless/ath/ath10k/coredump.c +1 -1
@@ -1607,7 +1607,7 @@ int ath10k_coredump_submit(struct ath10k *ar)return -ENODATA ; } -dev_coredumpv (ar->dev, dump,le32_to_cpu (dump->len),GFP_KERNEL ); +dev_coredumpv (ar->dev, dump,le32_to_cpu (dump->len));return 0 ; }
drivers/net/wireless/ath/wil6210/wil_crash_dump.c +1 -1
@@ -117,6 +117,6 @@ void wil_fw_core_dump(struct wil6210_priv *wil)/* fw_dump_data will be free in device coredump release function * after 5 min */ -dev_coredumpv (wil_to_dev (wil), fw_dump_data, fw_dump_size,GFP_KERNEL ); +dev_coredumpv (wil_to_dev (wil), fw_dump_data, fw_dump_size);wil_info (wil,"fw core dumped, size %d bytes\n" , fw_dump_size); }
drivers/net/wireless/broadcom/brcm80211/brcmfmac/debug.c +1 -1
@@ -37,7 +37,7 @@ int brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,return err; } -dev_coredumpv (bus->dev, dump, len + ramsize,GFP_KERNEL ); +dev_coredumpv (bus->dev, dump, len + ramsize);return 0 ; }
drivers/net/wireless/marvell/mwifiex/main.c +1 -2
@@ -1115,8 +1115,7 @@ void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)*/ mwifiex_dbg (adapter,MSG ,"== mwifiex dump information to /sys/class/devcoredump start\n" ); -dev_coredumpv (adapter->dev, adapter->devdump_data, adapter->devdump_len, -GFP_KERNEL ); +dev_coredumpv (adapter->dev, adapter->devdump_data, adapter->devdump_len);mwifiex_dbg (adapter,MSG ,"== mwifiex dump information to /sys/class/devcoredump end\n" );
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +1 -2
@@ -2421,6 +2421,5 @@ void mt7615_coredump_work(struct work_struct *work)dev_kfree_skb (skb); } -dev_coredumpv (dev->mt76.dev, dump,MT76_CONNAC_COREDUMP_SZ , -GFP_KERNEL ); +dev_coredumpv (dev->mt76.dev, dump,MT76_CONNAC_COREDUMP_SZ ); }
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +1 -2
@@ -1630,8 +1630,7 @@ void mt7921_coredump_work(struct work_struct *work) }if (dump) -dev_coredumpv (dev->mt76.dev, dump,MT76_CONNAC_COREDUMP_SZ , -GFP_KERNEL ); +dev_coredumpv (dev->mt76.dev, dump,MT76_CONNAC_COREDUMP_SZ );mt7921_reset (&dev->mt76); }
drivers/net/wireless/realtek/rtw88/main.c +1 -1
@@ -414,7 +414,7 @@ static void rtw_fwcd_dump(struct rtw_dev *rtwdev)* framework. Note that a new dump will be discarded if a previous one * hasn't been released yet. */ -dev_coredumpv (rtwdev->dev, desc->data, desc->size,GFP_KERNEL ); +dev_coredumpv (rtwdev->dev, desc->data, desc->size); }static void rtw_fwcd_free (struct rtw_dev *rtwdev,bool free_self)
drivers/net/wireless/realtek/rtw89/ser.c +1 -1
@@ -127,7 +127,7 @@ static void rtw89_ser_cd_send(struct rtw89_dev *rtwdev,* will be discarded if a previous one hasn't been released by * framework yet. */ -dev_coredumpv (rtwdev->dev, buf,sizeof (*buf),GFP_KERNEL ); +dev_coredumpv (rtwdev->dev, buf,sizeof (*buf)); } static void rtw89_ser_cd_free(struct rtw89_dev *rtwdev,
drivers/remoteproc/qcom_q6v5_mss.c +1 -1
@@ -597,7 +597,7 @@ static void q6v5_dump_mba_logs(struct q6v5 *qproc) data =vmalloc (MBA_LOG_SIZE );if (data) {memcpy (data, mba_region,MBA_LOG_SIZE ); -dev_coredumpv (&rproc->dev, data,MBA_LOG_SIZE ,GFP_KERNEL ); +dev_coredumpv (&rproc->dev, data,MBA_LOG_SIZE ); }memunmap (mba_region); }
drivers/remoteproc/remoteproc_coredump.c +2 -2
@@ -309,7 +309,7 @@ void rproc_coredump(struct rproc *rproc) phdr +=elf_size_of_phdr (class); }if (dump_conf ==RPROC_COREDUMP_ENABLED ) { -dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL ); +dev_coredumpv (&rproc->dev, data, data_size);return ; }
@@ -449,7 +449,7 @@ void rproc_coredump_using_sections(struct rproc *rproc) }if (dump_conf ==RPROC_COREDUMP_ENABLED ) { -dev_coredumpv (&rproc->dev, data, data_size,GFP_KERNEL ); +dev_coredumpv (&rproc->dev, data, data_size);return ; }
include/linux/devcoredump.h +2 -3
@@ -52,8 +52,7 @@ static inline void _devcd_free_sgtable(struct scatterlist *table)#ifdef CONFIG_DEV_COREDUMP -void dev_coredumpv (struct device *dev,void *data,size_t datalen, -gfp_t gfp); +void dev_coredumpv (struct device *dev,void *data,size_t datalen); void dev_coredumpm(struct device *dev, struct module *owner, void *data, size_t datalen, gfp_t gfp,
@@ -65,7 +64,7 @@ void dev_coredumpsg(struct device *dev, struct scatterlist *table, size_t datalen, gfp_t gfp);#else static inline void dev_coredumpv (struct device *dev,void *data, -size_t datalen,gfp_t gfp) +size_t datalen) {vfree (data); }
sound/soc/intel/catpt/dsp.c +1 -1
@@ -539,7 +539,7 @@ int catpt_coredump(struct catpt_dev *cdev) pos +=CATPT_DMA_REGS_SIZE ; } -dev_coredumpv (cdev->dev, dump, dump_size,GFP_KERNEL ); +dev_coredumpv (cdev->dev, dump, dump_size);return 0 ; }
Signature · 1 line
2.17.1
PATCH v4 2/2 mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv
In reply to Duoming ZhouThere are sleep in atomic context bugs when uploading device dump data in mwifiex. The root cause is that dev_coredumpv could not be used in atomic contexts, because it calls dev_set_name which include operations that may sleep. The call tree shows execution paths that could lead to bugs:
(Interrupt context)fw_dump_timer_fn
mwifiex_upload_device_dump
dev_coredumpv(..., GFP_KERNEL)
dev_coredumpm()
kzalloc(sizeof(*devcd), gfp); //may sleep dev_set_name
kobject_set_name_vargs
kvasprintf_const(GFP_KERNEL, ...); //may sleep kstrdup(s, GFP_KERNEL); //may sleep
The corresponding fail log is shown below:
[ 135.275938] usb 1-1: == mwifiex dump information to /sys/class/devcoredump start [ 135.281029] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:265 ... [ 135.293613] Call Trace: [ 135.293613] <IRQ> [ 135.293613] dump_stack_lvl+0x57/0x7d [ 135.293613] __might_resched.cold+0x138/0x173 [ 135.293613] ? dev_coredumpm+0xca/0x2e0 [ 135.293613] kmem_cache_alloc_trace+0x189/0x1f0 [ 135.293613] ? devcd_match_failing+0x30/0x30 [ 135.293613] dev_coredumpm+0xca/0x2e0 [ 135.293613] ? devcd_freev+0x10/0x10 [ 135.293613] dev_coredumpv+0x1c/0x20 [ 135.293613] ? devcd_match_failing+0x30/0x30 [ 135.293613] mwifiex_upload_device_dump+0x65/0xb0 [ 135.293613] ? mwifiex_dnld_fw+0x1b0/0x1b0 [ 135.293613] call_timer_fn+0x122/0x3d0 [ 135.293613] ? msleep_interruptible+0xb0/0xb0 [ 135.293613] ? lock_downgrade+0x3c0/0x3c0 [ 135.293613] ? __next_timer_interrupt+0x13c/0x160 [ 135.293613] ? lockdep_hardirqs_on_prepare+0xe/0x220 [ 135.293613] ? mwifiex_dnld_fw+0x1b0/0x1b0 [ 135.293613] __run_timers.part.0+0x3f8/0x540 [ 135.293613] ? call_timer_fn+0x3d0/0x3d0 [ 135.293613] ? arch_restore_msi_irqs+0x10/0x10 [ 135.293613] ? lapic_next_event+0x31/0x40 [ 135.293613] run_timer_softirq+0x4f/0xb0 [ 135.293613] __do_softirq+0x1c2/0x651 ... [ 135.293613] RIP: 0010:default_idle+0xb/0x10 [ 135.293613] RSP: 0018:ffff888006317e68 EFLAGS: 00000246 [ 135.293613] RAX: ffffffff82ad8d10 RBX: ffff888006301cc0 RCX: ffffffff82ac90e1 [ 135.293613] RDX: ffffed100d9ff1b4 RSI: ffffffff831ad140 RDI: ffffffff82ad8f20 [ 135.293613] RBP: 0000000000000003 R08: 0000000000000000 R09: ffff88806cff8d9b [ 135.293613] R10: ffffed100d9ff1b3 R11: 0000000000000001 R12: ffffffff84593410 [ 135.293613] R13: 0000000000000000 R14: 0000000000000000 R15: 1ffff11000c62fd2 ... [ 135.389205] usb 1-1: == mwifiex dump information to /sys/class/devcoredump end
This patch uses delayed work to replace timer and moves the operations that may sleep into a delayed work in order to mitigate bugs, it was tested on Marvell 88W8801 chip whose port is usb and the firmware is usb8801_uapsta.bin. The following is the result after using delayed work to replace timer.
[ 134.936453] usb 1-1: == mwifiex dump information to /sys/class/devcoredump start [ 135.043344] usb 1-1: == mwifiex dump information to /sys/class/devcoredump end
As we can see, there is no bug now.
---
Changes in v4:
- Use delayed work to replace timer.
drivers/net/wireless/marvell/mwifiex/init.c | 10 ++++++---- drivers/net/wireless/marvell/mwifiex/main.h | 2 +- drivers/net/wireless/marvell/mwifiex/sta_event.c | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-)
drivers/net/wireless/marvell/mwifiex/init.c +6 -4
@@ -63,9 +63,11 @@ static void wakeup_timer_fn(struct timer_list *t) adapter->if_ops.card_reset (adapter); } -static void fw_dump_timer_fn (struct timer_list *t) +static void fw_dump_work (struct work_struct *work) { -struct mwifiex_adapter *adapter =from_timer (adapter, t, devdump_timer); +struct mwifiex_adapter *adapter =container_of (work, + struct mwifiex_adapter, + devdump_work.work);mwifiex_upload_device_dump (adapter); }
@@ -321,7 +323,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) adapter->active_scan_triggered = false;timer_setup (&adapter->wakeup_timer, wakeup_timer_fn,0 ); adapter->devdump_len =0 ; -timer_setup (&adapter->devdump_timer, fw_dump_timer_fn,0 ); +INIT_DELAYED_WORK (&adapter->devdump_work, fw_dump_work); }/*
@@ -400,7 +402,7 @@ static void mwifiex_adapter_cleanup(struct mwifiex_adapter *adapter) {del_timer (&adapter->wakeup_timer); -del_timer_sync (&adapter->devdump_timer); +cancel_delayed_work_sync (&adapter->devdump_work);mwifiex_cancel_all_pending_cmd (adapter);wake_up_interruptible (&adapter->cmd_wait_q.wait);wake_up_interruptible (&adapter->hs_activate_wait_q);
drivers/net/wireless/marvell/mwifiex/main.h +1 -1
@@ -1055,7 +1055,7 @@ struct mwifiex_adapter {/* Device dump data/length */ void *devdump_data;int devdump_len; -struct timer_list devdump_timer; +struct delayed_work devdump_work;bool ignore_btcoex_events; };
drivers/net/wireless/marvell/mwifiex/sta_event.c +3 -3
@@ -623,8 +623,8 @@ mwifiex_fw_dump_info_event(struct mwifiex_private *priv,* transmission event get lost, in this cornel case, * user would still get partial of the dump. */ -mod_timer (&adapter->devdump_timer, - jiffies +msecs_to_jiffies (MWIFIEX_TIMER_10S )); +schedule_delayed_work (&adapter->devdump_work, +msecs_to_jiffies (MWIFIEX_TIMER_10S )); }/* Overflow check */
@@ -643,7 +643,7 @@ mwifiex_fw_dump_info_event(struct mwifiex_private *priv,return ; upload_dump: -del_timer_sync (&adapter->devdump_timer); +cancel_delayed_work_sync (&adapter->devdump_work);mwifiex_upload_device_dump (adapter); }
Signature · 1 line
2.17.1
v4 cover Remove extra param of dev_coredumpv and fix bugs
The first patch removes the extra gfp_t param of dev_coredumpv. The second patch fix sleep in atomic context bugs of mwifiex caused by dev_coredumpv.
Duoming Zhou (2):
devcoredump: remove the useless gfp_t parameter in dev_coredumpv
mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv
drivers/base/devcoredump.c | 6 ++---- drivers/bluetooth/btmrvl_sdio.c | 2 +- drivers/bluetooth/hci_qca.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_dump.c | 2 +- drivers/media/platform/qcom/venus/core.c | 2 +- drivers/net/can/spi/mcp251xfd/mcp251xfd-dump.c | 2 +- drivers/net/wireless/ath/ath10k/coredump.c | 2 +- drivers/net/wireless/ath/wil6210/wil_crash_dump.c | 2 +- .../net/wireless/broadcom/brcm80211/brcmfmac/debug.c | 2 +- drivers/net/wireless/marvell/mwifiex/init.c | 10 ++++++---- drivers/net/wireless/marvell/mwifiex/main.c | 3 +-- drivers/net/wireless/marvell/mwifiex/main.h | 2 +- drivers/net/wireless/marvell/mwifiex/sta_event.c | 6 +++--- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +-- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +-- drivers/net/wireless/realtek/rtw88/main.c | 2 +- drivers/net/wireless/realtek/rtw89/ser.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/remoteproc_coredump.c | 4 ++-- include/linux/devcoredump.h | 5 ++--- sound/soc/intel/catpt/dsp.c | 2 +- 21 files changed, 31 insertions(+), 35 deletions(-)
Signature · 1 line
2.17.1
Re: [PATCH v4 1/2] devcoredump: remove the useless gfp_t parameter in dev_coredumpv
In reply to Duoming ZhouQuoted 11 lines · Duoming Zhou
The
dev_coredumpv()could not be used in atomic context, because it callskvasprintf_const()andkstrdup()withGFP_KERNELparameter. The process is shown below:
dev_coredumpv(..., gfp_t gfp)
dev_coredumpm
dev_set_name
kobject_set_name_vargs
kvasprintf_const(GFP_KERNEL, ...); //may sleep
kstrdup(s, GFP_KERNEL); //may sleep
Quoted 3 lines
This patch removes
gfp_tparameter ofdev_coredumpv()and changes thegfp_tparameter ofdev_coredumpm()toGFP_KERNELin order to showdev_coredumpv()could not be used in atomic context.
shouldn't you remove the gfp parameter to dev_coredumpm() as well since it is actually within that function where dev_set_name() is called which cannot be done in atomic context?
Re: [PATCH v4 1/2] devcoredump: remove the useless gfp_t parameter in dev_coredumpv
Hello,
Quoted 12 lines · On Thu, 2 Jun 2022 13:32:48 -0700 Jeff Johnson wrote:
Quoted 11 lines · Duoming Zhou
The
dev_coredumpv()could not be used in atomic context, because it callskvasprintf_const()andkstrdup()withGFP_KERNELparameter. The process is shown below:
dev_coredumpv(..., gfp_t gfp)
dev_coredumpm
dev_set_name
kobject_set_name_vargs
kvasprintf_const(GFP_KERNEL, ...); //may sleep
kstrdup(s, GFP_KERNEL); //may sleep
Quoted 7 lines
Quoted 3 lines
This patch removes
gfp_tparameter ofdev_coredumpv()and changes thegfp_tparameter ofdev_coredumpm()toGFP_KERNELin order to showdev_coredumpv()could not be used in atomic context.shouldn't you remove the gfp parameter to
dev_coredumpm()as well since it is actually within that function wheredev_set_name()is called which cannot be done in atomic context?
Thanks for your suggestion, I will remove the gfp_t parameter of dev_coredumpm() as well.
Best regards,
Duoming Zhou