From patchwork Mon May 23 05:28:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 12858437 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A5EBC433F5 for ; Mon, 23 May 2022 05:29:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240056AbiEWF33 (ORCPT ); Mon, 23 May 2022 01:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355608AbiEWF3J (ORCPT ); Mon, 23 May 2022 01:29:09 -0400 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 566302127D; Sun, 22 May 2022 22:28:39 -0700 (PDT) Received: from ubuntu.localdomain (unknown [124.236.130.193]) by mail-app2 (Coremail) with SMTP id by_KCgDHeAhqG4tiw6+eAA--.65502S2; Mon, 23 May 2022 13:28:19 +0800 (CST) From: Duoming Zhou To: linux-wireless@vger.kernel.org Cc: amitkarwar@gmail.com, ganapathi017@gmail.com, sharvari.harisangam@nxp.com, huxinming820@gmail.com, kvalo@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, Duoming Zhou Subject: [PATCH v3] mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv Date: Mon, 23 May 2022 13:28:10 +0800 Message-Id: <20220523052810.24767-1-duoming@zju.edu.cn> X-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j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjfUOb18DUUUU X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAgISAVZdtZ0biwAysS Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There 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 In order to let dev_coredumpv support atomic contexts, this patch changes the gfp_t parameter of kvasprintf_const and kstrdup in kobject_set_name_vargs from GFP_KERNEL to GFP_ATOMIC. What's more, In order to mitigate bug, this patch changes the gfp_t parameter of dev_coredumpv from GFP_KERNEL to GFP_ATOMIC. Fixes: 57670ee882d4 ("mwifiex: device dump support via devcoredump framework") Signed-off-by: Duoming Zhou --- Changes in v3: - Let dev_coredumpv support atomic contexts. drivers/net/wireless/marvell/mwifiex/main.c | 2 +- lib/kobject.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c index ace7371c477..258906920a2 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -1116,7 +1116,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); + GFP_ATOMIC); mwifiex_dbg(adapter, MSG, "== mwifiex dump information to /sys/class/devcoredump end\n"); diff --git a/lib/kobject.c b/lib/kobject.c index 5f0e71ab292..7672c54944c 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -254,7 +254,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, if (kobj->name && !fmt) return 0; - s = kvasprintf_const(GFP_KERNEL, fmt, vargs); + s = kvasprintf_const(GFP_ATOMIC, fmt, vargs); if (!s) return -ENOMEM; @@ -267,7 +267,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, if (strchr(s, '/')) { char *t; - t = kstrdup(s, GFP_KERNEL); + t = kstrdup(s, GFP_ATOMIC); kfree_const(s); if (!t) return -ENOMEM;