From patchwork Thu Mar 1 13:39:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Tjernlund X-Patchwork-Id: 879875 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infinera.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GRdS9IzB"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="ReGo5tqV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsYrQ3V50z9ryr for ; Fri, 2 Mar 2018 00:56:34 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LVlUOzWUGqZ+6IQfhFMNvBz/w36zWd3q2bBv3gxVyek=; b=GRdS9IzBGkPCtjwZ9OITRrEuO6 Zoo9rivJbFu4Kr1ZLCncrBG1cgiekvUPMt6Z9qCZ7ByC1iyD9ymq8erxMJsjWWWaqR2YH54QkgtGg 9NhjPUGVylBs7R4Jp7oGkrcFDJtQlILh9pwyKmcnCM+Tk0dCQG4xsppoAYHAqjhgVuLIfa6PGhR/W vPFnMo5p8mz2iMv+HkE4vCu9U5S7LDec5vDRI9Q4L44VtZfNqZFs1Fj66andMU3NwIrype6TXVVVB u0D2UDId7VqRcN+8qzehO1qA48Z+C++/5oJhT7K+qF4JFMPoZNVSIQ2TJrzIUNJgJRWMuh/GAiu8x mZeMlU3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erOhB-0005xK-DQ; Thu, 01 Mar 2018 13:56:29 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOgK-0005Cy-9w for linux-mtd@bombadil.infradead.org; Thu, 01 Mar 2018 13:55:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=T5uLjkHzfOofjqiJK/NQblWZMVur/1uhNEoXH0Osqx8=; b=ReGo5tqVu0NsXjP6AoJvv7PAu 4QTnES54iwMcpEFoqPqPwg7mD7hMszqseh2l0Mnn5twnUopjyzS5OE4zAjwvoXt1f00e68lg70dbn nE001cfc0NKD/eMmP0enWt6ug7xvhwBMU20hJ05vpqXeBt73peRIwZzXkDBXR97mGKYSvStNV4bzS 3Y5Wmo187n5edKwuGEnRpdUrPq/VAQSS+O4poDAy65WaOfKK2eX8HtL7JCpYMOZCCorznZiLi25CV EnFbmQJvIGnR/d/Sj5W1qZ+4oh7/Xn1u69LxK3nS0DkIcXxC/gc0r4FfltQ6IC7jo1xWIcQwZd405 rymJqU9Bw==; Received: from smtp.transmode.se ([31.15.61.139]) by casper.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erORG-00076i-Fw for linux-mtd@lists.infradead.org; Thu, 01 Mar 2018 13:40:05 +0000 Received: from gentoo-jocke.infinera.com (gentoo-jocke.infinera.com [10.210.72.209]) by smtp.transmode.se (Postfix) with ESMTP id 9773111899C9; Thu, 1 Mar 2018 14:39:45 +0100 (CET) Received: from gentoo-jocke.infinera.com (gentoo-jocke.infinera.com [127.0.0.1]) by gentoo-jocke.infinera.com (8.14.9/8.14.9) with ESMTP id w21Ddjrb019750; Thu, 1 Mar 2018 14:39:45 +0100 Received: (from jocke@localhost) by gentoo-jocke.infinera.com (8.14.9/8.14.9/Submit) id w21DdjrN019749; Thu, 1 Mar 2018 14:39:45 +0100 From: Joakim Tjernlund To: "linux-mtd @ lists . infradead . org" Subject: [PATCH 1/3] cfi_cmdset_0001: Do not allow read/write to suspend erase block. Date: Thu, 1 Mar 2018 14:39:39 +0100 Message-Id: <20180301133941.19660-2-joakim.tjernlund@infinera.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180301133941.19660-1-joakim.tjernlund@infinera.com> References: <20180301133941.19660-1-joakim.tjernlund@infinera.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_134002_601150_5429CA5F X-CRM114-Status: GOOD ( 13.88 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joakim Tjernlund , Joakim Tjernlund , stable@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Joakim Tjernlund Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine. Signed-off-by: Joakim Tjernlund Cc: --- drivers/mtd/chips/cfi_cmdset_0001.c | 16 +++++++++++----- include/linux/mtd/flashchip.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c index 60d5d19e347f..b59872304ae7 100644 --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c @@ -849,21 +849,25 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long (mode == FL_WRITING && (cfip->SuspendCmdSupport & 1)))) goto sleep; + /* Do not allow suspend iff read/write to EB address */ + if ((adr & chip->in_progress_block_mask) == + chip->in_progress_block_addr) + goto sleep; /* Erase suspend */ - map_write(map, CMD(0xB0), adr); + map_write(map, CMD(0xB0), chip->in_progress_block_addr); /* If the flash has finished erasing, then 'erase suspend' * appears to make some (28F320) flash devices switch to * 'read' mode. Make sure that we switch to 'read status' * mode so we get the right data. --rmk */ - map_write(map, CMD(0x70), adr); + map_write(map, CMD(0x70), chip->in_progress_block_addr); chip->oldstate = FL_ERASING; chip->state = FL_ERASE_SUSPENDING; chip->erase_suspended = 1; for (;;) { - status = map_read(map, adr); + status = map_read(map, chip->in_progress_block_addr); if (map_word_andequal(map, status, status_OK, status_OK)) break; @@ -1059,8 +1063,8 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad sending the 0x70 (Read Status) command to an erasing chip and expecting it to be ignored, that's what we do. */ - map_write(map, CMD(0xd0), adr); - map_write(map, CMD(0x70), adr); + map_write(map, CMD(0xd0), chip->in_progress_block_addr); + map_write(map, CMD(0x70), chip->in_progress_block_addr); chip->oldstate = FL_READY; chip->state = FL_ERASING; break; @@ -1951,6 +1955,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, map_write(map, CMD(0xD0), adr); chip->state = FL_ERASING; chip->erase_suspended = 0; + chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len - 1); ret = INVAL_CACHE_AND_WAIT(map, chip, adr, adr, len, diff --git a/include/linux/mtd/flashchip.h b/include/linux/mtd/flashchip.h index b63fa457febd..3529683f691e 100644 --- a/include/linux/mtd/flashchip.h +++ b/include/linux/mtd/flashchip.h @@ -85,6 +85,7 @@ struct flchip { unsigned int write_suspended:1; unsigned int erase_suspended:1; unsigned long in_progress_block_addr; + unsigned long in_progress_block_mask; struct mutex mutex; wait_queue_head_t wq; /* Wait on here when we're waiting for the chip