Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2829330pxu; Mon, 7 Dec 2020 17:31:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5mbM/fLstt/JEqv8qgM1RoY8vKwxT7iVgiNwitzlFLPAzyLfSs21g/7uHUq+iYcWqlmDS X-Received: by 2002:a17:906:34c3:: with SMTP id h3mr21408976ejb.132.1607391062129; Mon, 07 Dec 2020 17:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607391062; cv=none; d=google.com; s=arc-20160816; b=M7lJnYf3ysnOSnNesEWh2rtpXSoOjFsNdeChgbrhGQtvKxre6Ec9i9AZVZjkFAlWaS iPHFAfqnDJ8DYRf9MX2dKFGsI8h+mKNAPlSMdQ/64rMDiqHQgFNza6xsyH5mwXHh9Cu8 M1w7Zoq6FVjsUlOrmtbw9rWL8QF5PKr5R/lhA+CB9EfG0cMvCDUOGczH1pp85Oj3KLvf GGNPTrmO7NDMCj6ABB6CAn+HS4TANKw3QkbrsHTIM81lvelUlksIwmWmp7xXb61z4irJ I4VKbx4cd0gKSy0ZuNNzR2+0fFaf9i1j82Kbiisceq3AikpGAq7I4QTrKVnBXGA5w+2z pnTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=S7BaEjgr0R+qwjiAEUzUpPcl5Q6l6JYo2/w2nInYlck=; b=o9kOSQJpKaGkwPUxg/WmsM28bMjUL3apz7mYE1Fa/lXa8tQzUCmYgd60vSOvBwDnXe HeKaoI9U5WuiG/jB7J/eZ3rS6B2S0JtpN6eWmnNEQOjdhSVLqHn9y2eWnnM+YRZVZpxl 16k09UAkElueqQj9wkduWsqG6O57X5ACeiFkRpujtzo5AjW9QqVo0ScubZfg8e9OW5Dc g5ZMEgyWc5nceV5VPDrnsMs/WS8vv53KvAZ4TDumRCbneUFmFiD+XQR1JpyaA/XcKu0B ANUyKACQCsrATulB3taSNsipCm1fQE+mWM4DqawNDh0ju9dq6LoQfn9Ax+vV6/GwU3Kc edJg== 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 e14si2723809ejj.571.2020.12.07.17.30.40; Mon, 07 Dec 2020 17:31:02 -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 S1727070AbgLHBXw (ORCPT + 99 others); Mon, 7 Dec 2020 20:23:52 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9126 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgLHBXw (ORCPT ); Mon, 7 Dec 2020 20:23:52 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Cqj8s4LCmz15Xkq; Tue, 8 Dec 2020 09:22:37 +0800 (CST) Received: from [10.67.102.197] (10.67.102.197) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Tue, 8 Dec 2020 09:23:00 +0800 Subject: Re: ping // [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y To: Vignesh Raghavendra , Miquel Raynal CC: , , , , , , , References: <20201127130731.99270-1-nixiaoming@huawei.com> <20201207115228.0a6de398@xps13> <73b539eb-616e-64d8-07d8-4606da2ea2ea@ti.com> From: Xiaoming Ni Message-ID: Date: Tue, 8 Dec 2020 09:23:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.0.1 MIME-Version: 1.0 In-Reply-To: <73b539eb-616e-64d8-07d8-4606da2ea2ea@ti.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.197] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/12/8 2:59, Vignesh Raghavendra wrote: > Hi Xiaoming, > > On 12/7/20 4:23 PM, Miquel Raynal wrote: >> 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. > > Agree with Miquel. Have you done any testing > or is this purely based on code inspection? > I don't have the corresponding device test environment. I found the problem through code review. > What about comment before xip_disable() function: > > /* > * No interrupt what so ever can be serviced while the flash isn't in array > * mode. This is ensured by the xip_disable() and xip_enable() functions > * enclosing any code path where the flash is known not to be in array mode. > * And within a XIP disabled code path, only functions marked with __xipram > * may be called and nothing else (it's a good thing to inspect generated > * assembly to make sure inline functions were actually inlined and that gcc > * didn't emit calls to its own support functions). Also configuring MTD CFI > * support to a single buswidth and a single interleave is also recommended. > */ > > So, I don't think the fix is as simple as this patch. > +xip_enable(); schedule(); +xip_disable(); Do I need to change it to this? > Regards > Vignesh > . > Thanks Xiaoming Ni