Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2297442pxu; Mon, 7 Dec 2020 02:57:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQ7HZgThiKFhNNKow8kPvnkuCAYBuUIiZX33HGIhCcmI5GuS8LjUOrzM1sd0j1UgL+KTnM X-Received: by 2002:a17:907:3fa3:: with SMTP id hr35mr18343692ejc.71.1607338628734; Mon, 07 Dec 2020 02:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607338628; cv=none; d=google.com; s=arc-20160816; b=oIweAZ6Q7NQnh5jkIgXh+DoQh8Y1OBK+n+tcx7pqFA7Ch1tBlIjJEINYFHwR7T2/LS Qb6dL0QO2PF5TzrjMoFcLej91tKe3hmOSVoJZe51QNBKr+N04UOQv/UbNEHTmHSUzzba RQbRfsBFLe/I6yAKEhK5qK1xa5qPsqZXwBxBwIOlX2JtIkH9QIeEsxuy3Ur+MQKIVsJ7 xpGAP97Z5JWKB3hVg/Ye5sPSH+8vzHE10sY/trRt3aJNIRAaHuvjHDcoJpxg/+2DuNTn IsqM7VbM4vgn8tDyI4rwgrh9Ov2p/L989bDqI3321A3NXai88XAy3iiyfMa8bzaGtO7E ENlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=g5B6nQIw7SsZwimpTdUsSg3Sp+9ylTXQGD/xKnL3GlU=; b=BmKqn2T72QvXLMfOa/86VKUZpLRf8gVNLYKZX/nND/6cyf/x9xku/r2pergOxSub/7 9PzUe9WZoHPWgft5f/lK3xbgNbjHI4yE1vF1rAJvXZ6JhGVZCE3qlpagNwwLck2TYHXc HRIE2zOnW1fBB47VnqEb2MKXteDXZXJYk69HMje7+fx/qmZ5e0zlfYrOLOAhc5k1JAIZ iKL6Pt2NlsNJWZ44c/zdvp1bUQxdL7E3OtdreUitmn/CjspCmWshfe34LXi9mWZxuYKC SIDttlzlN1+qwwfsmOgwwDRbp/e8aj1JkdcI3Lm3wiv8Jhr/hy7nzil+9w6YL04vAPk7 RGKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb10si7918778edb.192.2020.12.07.02.56.45; Mon, 07 Dec 2020 02:57:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726340AbgLGKyP convert rfc822-to-8bit (ORCPT + 99 others); Mon, 7 Dec 2020 05:54:15 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:34161 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725842AbgLGKyO (ORCPT ); Mon, 7 Dec 2020 05:54:14 -0500 X-Originating-IP: 109.220.208.103 Received: from xps13 (lfbn-tou-1-1617-103.w109-220.abo.wanadoo.fr [109.220.208.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 30BCA1BF20E; Mon, 7 Dec 2020 10:53:31 +0000 (UTC) Date: Mon, 7 Dec 2020 11:53:30 +0100 From: Miquel Raynal To: Xiaoming Ni Cc: , , , , , , , , Subject: Re: ping // [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y Message-ID: <20201207115228.0a6de398@xps13> In-Reply-To: References: <20201127130731.99270-1-nixiaoming@huawei.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xiaoming, Xiaoming Ni wrote on Mon, 7 Dec 2020 18:48:33 +0800: > ping > > On 2020/11/27 21:07, Xiaoming Ni wrote: > > 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(); The fix really seems strange to me. I will let Vignesh decide but I think we should consider updating/fixing xip_disable instead. > > 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; > > > Thanks, Miquèl