From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72078C2D0E4 for ; Fri, 27 Nov 2020 13:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B5512224E for ; Fri, 27 Nov 2020 13:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730025AbgK0NHt (ORCPT ); Fri, 27 Nov 2020 08:07:49 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8604 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729576AbgK0NHs (ORCPT ); Fri, 27 Nov 2020 08:07:48 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CjFK15ZP9zLtjd; Fri, 27 Nov 2020 21:07:17 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Fri, 27 Nov 2020 21:07:36 +0800 From: Xiaoming Ni To: , , , , , , CC: , , , , , Subject: [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y Date: Fri, 27 Nov 2020 21:07:31 +0800 Message-ID: <20201127130731.99270-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When CONFIG_MTD_XIP=y, local_irq_disable() is called in xip_disable(). To avoid sleep in interrupt context, we need to call local_irq_enable() before schedule(). The problem call stack is as follows: bug1: do_write_oneword_retry() xip_disable() local_irq_disable() do_write_oneword_once() schedule() bug2: do_write_buffer() xip_disable() local_irq_disable() do_write_buffer_wait() schedule() bug3: do_erase_chip() xip_disable() local_irq_disable() schedule() bug4: do_erase_oneblock() xip_disable() local_irq_disable() schedule() Fixes: 02b15e343aee ("[MTD] XIP for AMD CFI flash.") Cc: stable@vger.kernel.org # v2.6.13 Signed-off-by: Xiaoming Ni --- drivers/mtd/chips/cfi_cmdset_0002.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index a1f3e1031c3d..12c3776f093a 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -1682,7 +1682,11 @@ static int __xipram do_write_oneword_once(struct map_info *map, set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); mutex_unlock(&chip->mutex); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_enable(); schedule(); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_disable(); remove_wait_queue(&chip->wq, &wait); timeo = jiffies + (HZ / 2); /* FIXME */ mutex_lock(&chip->mutex); @@ -1962,7 +1966,11 @@ static int __xipram do_write_buffer_wait(struct map_info *map, set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); mutex_unlock(&chip->mutex); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_enable(); schedule(); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_disable(); remove_wait_queue(&chip->wq, &wait); timeo = jiffies + (HZ / 2); /* FIXME */ mutex_lock(&chip->mutex); @@ -2461,7 +2469,11 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip) set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); mutex_unlock(&chip->mutex); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_enable(); schedule(); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_disable(); remove_wait_queue(&chip->wq, &wait); mutex_lock(&chip->mutex); continue; @@ -2560,7 +2572,11 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); mutex_unlock(&chip->mutex); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_enable(); schedule(); + if (IS_ENABLED(CONFIG_MTD_XIP)) + local_irq_disable(); remove_wait_queue(&chip->wq, &wait); mutex_lock(&chip->mutex); continue; -- 2.27.0