Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp601765imb; Fri, 1 Mar 2019 08:56:15 -0800 (PST) X-Google-Smtp-Source: APXvYqxDtpL+cboj7cL2G3sjH+89viAHwLSEqsU19o0TERcaZ1qIvY9ExjKDcD8VCL+3SUz8NvGl X-Received: by 2002:a62:e704:: with SMTP id s4mr6464134pfh.94.1551459375789; Fri, 01 Mar 2019 08:56:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551459375; cv=none; d=google.com; s=arc-20160816; b=ujyZ9Q+YiqPLSz/1LZsZvfM8KSjyNRte1OD+laoksgj1gKX+/+1/FvboEosC9a+ekP mfXHSzq/SBYD8bsccbf2PGbUD3ii3wHDrwJafG5qBfD2hQzGtxk0QGLLev7RnKq2fpMP l1mG4vyi1zUpVEFfq1f98wSYfmSzdR4hrDNtwUBFweFrdwE7UIHoYkNpiyjbwwpVeXPf 2988EH0+Jg1vVP0+H3vl/1WZWhm+l7zr16u2Tj50QZ95BC0piWAWk7FVosCjjs3xFe/i yfitNtqbdZmvSy5I03IxWG9Yun4oEOTLxwyosmKjGN33aRlO1m8FoFdcu6qjfjN22rBU rhBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:content-language :content-transfer-encoding:mime-version:message-id:date:subject :in-reply-to:references:cc:to:from:dkim-signature; bh=v8H6VN36oH6WU7j+Z98Gq/uFnx5u2KaHkgPBc2ET138=; b=glJnBO+y/x48Ys0x4E8Kw8hp2PPPUgzRIVB4ezdwkYHwyvuHbeUReoa+rhO9EVsqOf 494sR7keAqJhpIAA69nLR/pdBfyMPm+m72uDav+nBs/NbPLV94cHmwiwQ0TzCURQW53x HYkqJD/K96FbwpduOg7PcsYgaL1hBhGg4wPwko0Fr1JF5VE1SFOS+41PYERUkHhAGWKD +jj8UPcMVM1H+KEXDoN+/9Icn7HKHHtZUWNfNXr1ET1X/ZRu5TYLCAOpjGy97sdVMf5c s4570ZfpYeC41yHBsTYKn6usYEf9DTMD+J50EsxiXEPqc4gJB5d4DlYLb/zDq7Mupdl5 Yfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I6r9OupR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t191si20578849pgd.270.2019.03.01.08.56.00; Fri, 01 Mar 2019 08:56:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I6r9OupR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389279AbfCAQyo (ORCPT + 99 others); Fri, 1 Mar 2019 11:54:44 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45502 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388993AbfCAQyo (ORCPT ); Fri, 1 Mar 2019 11:54:44 -0500 Received: by mail-pg1-f193.google.com with SMTP id y4so11681513pgc.12 for ; Fri, 01 Mar 2019 08:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-transfer-encoding:content-language :thread-index; bh=v8H6VN36oH6WU7j+Z98Gq/uFnx5u2KaHkgPBc2ET138=; b=I6r9OupRZemMH0yWoIO6KKAxYf1g2M9H6rIYxzDE493TA0OORw7nelbafwVUPhXM4m fVD4MwEgb4GOuPkKJ4WVetfD0KEQSqKOh7DB81MrH4hKom+rWxKVYI6L0iqNL+Z0tVUI pmf+vk8V5qFpHYhxrpXASF4weaVEsISeF0AY/NY3JLNk/DyCCFB5UcXj+gFIwEvmpp9z qE4f9M9vdeMyH6mh0xTm1kuJvzvufpznNYV5WUhx2rEB6ZvvAocTbTX1TT1N9moogyxW IUFZSDXwkGHjT26040ToE7KEzOhTD3xqUSPTyqBNEyuPUHbkRCpz+dUzSeHHAOf3yjCh 3D3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:references:in-reply-to:subject:date :message-id:mime-version:content-transfer-encoding:content-language :thread-index; bh=v8H6VN36oH6WU7j+Z98Gq/uFnx5u2KaHkgPBc2ET138=; b=jHq18T1yigBoOleQdN6/gbuCzKKdx3SJSdM2GVHGRboUSh9Dffi02GwUK32MvwgBst iQnPc5PuPDH9I9bmfQT6GK/mLzEXyspwrFb2oZX7xEtlcWAj+XEIuxlWBaBxOH+DgYUV Jmao7DBVetzmMDwo9TP8mlXLGQbuzG65jZpJuoHYxXhQv4SFyPhINEy/h2YCuhOgkLgk wyJmAyJQc4eZrKt0T9Nur8QJWfK/zcDJUjmz9dYnkwU+/piGaZQEdaOyLfli8BltIUaT X77B7ciB8l3Au3avIABnMTOJmf5rm2sNaWgINxWhldVIZYqp2FRfqaAlEPaaBHkAeesR TTHA== X-Gm-Message-State: APjAAAVaougnhawbMBq/bXptbkMETXAcZUmmayZ5JOVubjGhvhInq77h nTGXdb2K9DfcZnQWzIR4Lyc= X-Received: by 2002:a63:cc03:: with SMTP id x3mr5678881pgf.121.1551459282838; Fri, 01 Mar 2019 08:54:42 -0800 (PST) Received: from ikegamiPC (M106072039032.v4.enabler.ne.jp. [106.72.39.32]) by smtp.gmail.com with ESMTPSA id m13sm47711334pff.175.2019.03.01.08.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Mar 2019 08:54:41 -0800 (PST) From: "Tokunori Ikegami" To: "'Boris Brezillon'" Cc: "'Tokunori Ikegami'" , , , , , , , , , "'liujian \(CE\)'" , References: <1551189648-58073-1-git-send-email-liujian56@huawei.com> <016001d4cf71$865e7b60$931b7220$@gmail.com> <4F88C5DDA1E80143B232E89585ACE27D0264F137@DGGEMM528-MBX.china.huawei.com> <20190228164228.734ede80@collabora.com> <005a01d4d03e$39b0e0f0$ad12a2d0$@yahoo.co.jp> <20190301170715.68d89e84@collabora.com> In-Reply-To: <20190301170715.68d89e84@collabora.com> Subject: RE: [PATCH v3] cfi: fix deadloop in cfi_cmdset_0002.c do_write_buffer Date: Sat, 2 Mar 2019 01:54:16 +0900 Message-ID: <000301d4d04f$76c2aad0$64480070$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Content-Language: ja Thread-Index: AQHOptjmAmqem5WpXlLpfOi8uScBsQIgzkq5Atg5CjYCPRAs9gF4c9/ZAQMTnbultcD/MA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Boris-san, > -----Original Message----- > From: linux-mtd [mailto:linux-mtd-bounces@lists.infradead.org] On Behalf > Of Boris Brezillon > Sent: Saturday, March 2, 2019 1:07 AM > To: Tokunori Ikegami > Cc: 'Tokunori Ikegami'; keescook@chromium.org; bbrezillon@kernel.org; > ikegami@allied-telesis.co.jp; richard@nod.at; > linux-kernel@vger.kernel.org; marek.vasut@gmail.com; > linux-mtd@lists.infradead.org; computersforpeace@gmail.com; > dwmw2@infradead.org; 'liujian (CE)'; vigneshr@ti.com > Subject: Re: [PATCH v3] cfi: fix deadloop in cfi_cmdset_0002.c > do_write_buffer > > Hi Ikegami, > > On Fri, 1 Mar 2019 23:51:16 +0900 > "Tokunori Ikegami" wrote: > > > > Except this version no longer does what Vignesh suggested. See how you > > > no longer test if chip_good() is true if time_after() returns true. > So, > > > imagine the thread entering this function is preempted just after the > > > first chip_good() test, and resumed a few ms later. time_after() will > > > return true, but chip_good() might also return true, and you ignore > it. > > > > I think that the following 3 versions will be worked for time_after() > as a same result and follow the Vignesh-san suggestion. > > Let me show you how they are different: > > > > > 1. Original Vignesh-san suggestion > > > > if (chip_good(map, adr, datum)) { > > xip_enable(map, chip, adr); > > goto op_done; > > } > > --> thread preempted here > ==> chip_good() test becomes valid here > --> thread resumed here, but timeout has expired > > > > > if (time_after(jiffies, timeo)) { > > you enter this branch > > > /* Test chip_good() if TRUE incorrectly again so write > failure by time_after() can be avoided. */ > > if (chip_good(map, adr, datum)) { > > chip_good() returns true > > > xip_enable(map, chip, adr); > > goto op_done; > > } > > break; > > } > > > > 2. Liujian-san v3 patch > > > > /* Test chip_good() if FALSE correctly so write failure by > time_after() can be avoided. */ > > --> thread preempted here > ==> chip_good() test becomes valid here > --> thread resumed here, but timeout has expired > > > if (time_after(jiffies, timeo) && !chip_good(map, adr)) > > You do not enter this branch because the chip_good() test is done once > more in case of timeout. > > > break; > > > > if (chip_good(map, adr, datum)) { > > xip_enable(map, chip, adr); > > goto op_done; > > } > > > > 3. My idea > > > > /* Save current jiffies value before chip_good() to avoid write > failure by time_after() without testing chip_good() again. */ > > unsigned long now = jiffies; > > > > if (chip_good(map, adr, datum)) { > > xip_enable(map, chip, adr); > > goto op_done; > > } > > > > --> thread preempted here > ==> chip_good() test becomes valid here > --> thread resumed here, but timeout has expired > > > if (time_after(now, timeo)) > > You do enter this branch, and erroneously report a failure. I do not think that it is not entered here since the value timeo is compare with the saved value now before the chip_bood() by time_after(). > > > break; > > > > See now why your version is not correct? > > Regards, > > Boris > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/