Received: by 10.192.165.148 with SMTP id m20csp4194254imm; Mon, 30 Apr 2018 13:36:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQ6LLl/H6nctYcnz1WCOBMvBUaKKkTK/P6qhmaaptCdqSDPdRvUirv4YlpNNFVoQamEzej X-Received: by 10.98.210.134 with SMTP id c128mr13344424pfg.240.1525120562165; Mon, 30 Apr 2018 13:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120562; cv=none; d=google.com; s=arc-20160816; b=HXYjDaWvS2csw12L559uCjFRWG/SL7vL/1McaQAUIe7iE2bMjYWlBrInMq2ihBfjHT sh0IT0C/5qSWfwSzKU8U2kncvtbrYXopJz50ydnMXyBYYyfAVyI/ZDn4gRTqjlneOGgZ OrrYeD6ohHUfP71uxENj3AFJdNM3rYQyyWo1jmBCO6+7Q3PTf0KoF4cMeocHmM86dhtN fNJV/AG8cFLP2KrE7foVUQ7wj/8HnfVWgggeTjLL9bCnd/9ML8GW9/f2/X+DytC0/jlm 6xmaFm4VtuKhRx++dNYRRntQztJ/c9/RsGWMwP2vJNp9oAxA2SZ1996nFDpFRz50VnSd VI6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=dYnElPwRF7pLq9y0HWXF7oVDqxX5xbICgyhXmAvvXjM=; b=ylZN4M/8403hg0FBbAtio3bVCIs97NE4P9lnudcKqgglKG8E+dcUILP2mCo/qJ9+oJ 0L5TGkSxQcMoco4pXz9iXz1kG81KGuxLGLy3gLC/HEeMawCtniSTlW3Ra1T5vQ3cMkLp Y60Qvcn8f4DEtyGpSh8+c9gGY2i3JzQNSak4jdyyWZLG1O90TrLLiJIkp8GGlYTX2ck2 9ynbh5zRWEJknONwnEVPP1atnKS63oLIPoLtK2k+r67gnLzX1UAcHLAW54RF83P4xvLB XWmEUJnxYIo/wA0kpMWKZqAQhjXriT0n53aYUzUkadwe482zHXCs5j7/riT3F9XXZZrI 6wXA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si8151413pfk.228.2018.04.30.13.35.48; Mon, 30 Apr 2018 13:36:02 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755495AbeD3UfH (ORCPT + 99 others); Mon, 30 Apr 2018 16:35:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:59046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755452AbeD3TZ6 (ORCPT ); Mon, 30 Apr 2018 15:25:58 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 223F622DC0; Mon, 30 Apr 2018 19:25:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 223F622DC0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joakim Tjernlund , Richard Weinberger , Boris Brezillon Subject: [PATCH 4.4 30/44] mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block. Date: Mon, 30 Apr 2018 12:24:41 -0700 Message-Id: <20180430190947.537410858@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joakim Tjernlund commit 6510bbc88e3258631831ade49033537081950605 upstream. 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: Reviewed-by: Richard Weinberger Signed-off-by: Boris Brezillon Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/chips/cfi_cmdset_0001.c | 16 +++++++++++----- include/linux/mtd/flashchip.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c @@ -825,21 +825,25 @@ static int chip_ready (struct map_info * (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; @@ -1035,8 +1039,8 @@ static void put_chip(struct map_info *ma 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; @@ -1927,6 +1931,8 @@ static int __xipram do_erase_oneblock(st 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, --- 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