Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2622531pxu; Mon, 7 Dec 2020 11:03:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWf1EI41BY4fjDDsUV1IK5PNKRenon6rPcXY7vl2+sKac6TvdmwSQSXASUMTB1eZIoeafH X-Received: by 2002:a17:907:971c:: with SMTP id jg28mr13785908ejc.85.1607367790236; Mon, 07 Dec 2020 11:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607367790; cv=none; d=google.com; s=arc-20160816; b=iEcM3u2swvF4FRdVwt/aB74Y7g6F/aIBxMb60wkiWdrJUbFtjwOMfSFKzf2+R9+Dy8 dxXbmWedxKtLxTkTTEAulyMElHqdLzYMrsoMYqFW6YVcAGn6ThFu/G/B+ltAYqttSo9c bFbDIjmieKL9HKM2eANPEioLlV1Rj7LzTpbK6r9CImWiSo+4OnlXTmThShwam4IsRWrT 9Kzoloq8QMlA1gUyO7QTxU80R7vtQKkKFMryW1N13JX5IJAsmGJBVkhUVyIDz4N5Mu8C wDGf2V6EQmkVQxjTsB4GAq2Gf3XQfp0/bxqT2Qc6JwHavwxjaSKrDaPUA5xkSmV/vQ0T kXIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=l8AmyJmC8gTSyUoOze7WxgteJNUwxEVxb9g16VApPdw=; b=qtpqLd9oUb3cRmoktme9XHztNFOjqlqfSX6nhff+lHt/oTm+XVC4S0ziTm7bEJmZBb JJBaXqM2EW3r9yY4w8JvI56j4FP0rh6dz+5Im1gv53hGWICLfAvO5cRePXb9rkFudbzr +BSLLx5S433viIOsxG5fYqo8BEFaoT8blKyxvlwRbj7fdnUOnBb8vK6ScwYAVlcq+Y0q JNkTm2IQIsBQatIUCOfhBcfIBHIpw4qDukX+V3WbuGkv/Ks/tXZsEX7y0CwIhd0JV1q9 GA2IF18EyvnWDS1K7fZBr7VIRRJONjdjSo1bOYz6doR+wIXl8ByuSWsaQLSnpEXJWD5L Hn/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=uf3lKJX3; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg19si1119964ejc.365.2020.12.07.11.02.28; Mon, 07 Dec 2020 11:03:10 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=uf3lKJX3; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726096AbgLGTAy (ORCPT + 99 others); Mon, 7 Dec 2020 14:00:54 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:34212 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725915AbgLGTAx (ORCPT ); Mon, 7 Dec 2020 14:00:53 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0B7IxPUC093171; Mon, 7 Dec 2020 12:59:25 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1607367565; bh=l8AmyJmC8gTSyUoOze7WxgteJNUwxEVxb9g16VApPdw=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=uf3lKJX3Y7M0KMBKT9zU1izumbaHH2Db6t1lq3zwqAvdV1wzNSPmjQncDfG0tN/xr Q+DwVpd/lP6v/7hRySH3XNULenJWlKsfSEtOyNI0KFP3/jAjJuS6X4LEJ1yhH6X66n cqVT78yK+TdsyXpenbRQ6kEU3VJ4ziMXKN7Ddgks= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0B7IxPMB031013 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 7 Dec 2020 12:59:25 -0600 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 7 Dec 2020 12:59:25 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Mon, 7 Dec 2020 12:59:24 -0600 Received: from [10.250.233.179] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0B7IxLb3066531; Mon, 7 Dec 2020 12:59:22 -0600 Subject: Re: ping // [PATCH] mtd:cfi_cmdset_0002: fix atomic sleep bug when CONFIG_MTD_XIP=y To: Miquel Raynal , Xiaoming Ni CC: , , , , , , , References: <20201127130731.99270-1-nixiaoming@huawei.com> <20201207115228.0a6de398@xps13> From: Vignesh Raghavendra Message-ID: <73b539eb-616e-64d8-07d8-4606da2ea2ea@ti.com> Date: Tue, 8 Dec 2020 00:29:21 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201207115228.0a6de398@xps13> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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. Regards Vignesh