From patchwork Thu Mar 1 13:39:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Tjernlund X-Patchwork-Id: 879865 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="Rx0rNorH"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="A02hLIaX"; 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 3zsYfR5ZRtz9rxq for ; Fri, 2 Mar 2018 00:47:59 +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=Djx8pi4DVr0pyvYKLS1ge1Md/TRD+yRzKOQ9oGcCESM=; b=Rx0rNorHAvjIpMPRwyGNCkaxvt LITauBHGhfTCgaQDciWQgwHg152rQnZd/bPXF3Y5loxOT8vrSJxs4at9B9BbrpP0/gCFIlANFH1AI uHcMO4uaYUdZV/3jyk6qm8IVcAaieht0YM6Y52jdLzXXfiaHXXFWmCCdA8M6vwpmqLS+1LSEkVIAo kfQHRa0aLWHxdMjVRkxV6B5rAaJEDyfFRT/LJo/uZaJvc4OeK/d3g3HIafDncJyz3aAHbhoUMf6hl 1ypGRS0A9DhELn6JVISo+atuVamOGFHQBGmVQbhu0nE3irM/kYIwDTJi77CECnKry+a1bMDD0kM8A e7eLzfxg==; 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 1erOYn-0000wo-Gd; Thu, 01 Mar 2018 13:47:49 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erOXg-0000Jo-NN for linux-mtd@bombadil.infradead.org; Thu, 01 Mar 2018 13:46:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=RtN/jzAy/FGjrXvHTscoXLHWl2IyBGae5jvtsG06wu4=; b=A02hLIaXBqJ0jcZXiJhAMVpfZ gF5JFXGXe4ibQWwF7kGEk3EDSHfAu9OAiRygV+sM3eA9D8ZUEFkspehew+1/b5vtPCLKvK/pI0Tgd S1PwrnXQgTtc0w/r+D7EtEOMVL0KsgFe2lDrdmjNmYQDEl/jIOUUM3PZeC2+ZVOb7xlpn3d+jlsf1 Svq7iDwW0Lo9kHQhumZyH5+vYsbGEhkr9Zb+7LmpqCKOvKGqnsCcrWCwuNDaSTQyd/mY5eNLMhiEK uLjjhKw+oXz2DdqIfsAKRVAK7iMaMOu3AA5P/5ymAzlweSOyJBEAvA9GNDExKEBXWMhReHqzhX7oO HS0ptBawQ==; Received: from smtp.transmode.se ([31.15.61.139]) by merlin.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1erORK-00038g-7x for linux-mtd@lists.infradead.org; Thu, 01 Mar 2018 13:40:08 +0000 Received: from gentoo-jocke.infinera.com (gentoo-jocke.infinera.com [10.210.72.209]) by smtp.transmode.se (Postfix) with ESMTP id 78F2D118AD16; Thu, 1 Mar 2018 14:39:47 +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 w21DdlNm019758; Thu, 1 Mar 2018 14:39:47 +0100 Received: (from jocke@localhost) by gentoo-jocke.infinera.com (8.14.9/8.14.9/Submit) id w21Ddlb2019757; Thu, 1 Mar 2018 14:39:47 +0100 From: Joakim Tjernlund To: "linux-mtd @ lists . infradead . org" Subject: [PATCH 3/3] cfi_cmdset_0002: Do not allow read/write to suspend erase block. Date: Thu, 1 Mar 2018 14:39:41 +0100 Message-Id: <20180301133941.19660-4-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_084006_414743_3AC33B63 X-CRM114-Status: GOOD ( 10.31 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-1.2 points) 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 , stable@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. Taken from cfi_cmdset_0001 driver. Signed-off-by: Joakim Tjernlund Cc: Reviewed-by: Richard Weinberger --- drivers/mtd/chips/cfi_cmdset_0002.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 56aa6b75213d..d524a64ed754 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -816,9 +816,10 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)))) goto sleep; - /* We could check to see if we're trying to access the sector - * that is currently being erased. However, no user will try - * anything like that so we just wait for the timeout. */ + /* 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 */ /* It's harmless to issue the Erase-Suspend and Erase-Resume @@ -2267,6 +2268,7 @@ static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip) chip->state = FL_ERASING; chip->erase_suspended = 0; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(map->size - 1); INVALIDATE_CACHE_UDELAY(map, chip, adr, map->size, @@ -2356,6 +2358,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, chip->state = FL_ERASING; chip->erase_suspended = 0; chip->in_progress_block_addr = adr; + chip->in_progress_block_mask = ~(len - 1); INVALIDATE_CACHE_UDELAY(map, chip, adr, len,